Package com.atlassian.sal.api.net

Examples of com.atlassian.sal.api.net.Request


        String appType = req.getParameter(APP_TYPE);
        ApplicationLink appLink = getApplicationLink(resp, appId, appType);
        try
        {
            final ApplicationLinkRequestFactory requestFactory = appLink.createAuthenticatedRequestFactory();
            Request request = prepareRequest(req, methodType, finalPath, requestFactory);
            request.execute(new ProxyResponseHandler(resp));
        }
        catch(ResponseException re)
        {
            final String finalUrl = appLink.getRpcUrl() + finalPath;
            return handleProxyingException(finalUrl, req, resp, re);
View Full Code Here


    private Request prepareRequest(HttpServletRequest req,
            Request.MethodType methodType, String url,
            final ApplicationLinkRequestFactory requestFactory)
            throws CredentialsRequiredException, IOException
    {
        Request request = requestFactory.createRequest(methodType, url);
        // remove xsrf token check on the destination. Assumes this servlet requires an xsrf token
        request.setHeader("X-Atlassian-Token", "no-check");
        // forward the original ip or pass on already forwarded ip so logging is accurate.
        String xForward = req.getHeader("X-Forwarded-For");
        request.setHeader("X-Forwarded-For", xForward != null ? xForward : req.getRemoteAddr());

        if (methodType == Request.MethodType.POST)
        {

           String ctHeader = req.getHeader("Content-Type");
           if (ctHeader != null)
           {
               request.setHeader("Content-Type", ctHeader);
           }

           if (ctHeader != null && ctHeader.contains("application/x-www-form-urlencoded"))
           {
               List<String> params = new ArrayList<String>();
               final Map<String, String[]> parameterMap = (Map<String, String[]>) req.getParameterMap();
               for (String name : parameterMap.keySet())
               {
                   if (RESERVED_PARAMS.contains(name))
                   {
                       continue;
                   }
                   params.add(name);
                   params.add(req.getParameter(name));
               }
               request.addRequestParameters((String[]) params.toArray(new String[params.size()]));
           }
           else
           {
               String enc = req.getCharacterEncoding();
               String str = IOUtils.toString(req.getInputStream(), (enc == null ? "ISO8859_1" : enc));
               request.setRequestBody(str);
           }
        }
        return request;
    }
View Full Code Here

TOP

Related Classes of com.atlassian.sal.api.net.Request

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.