Package com.adito.util

Examples of com.adito.util.ProxiedHttpMethod


    }

    if (log.isDebugEnabled())
      log.debug("Connecting to [" + proxiedURL + "] ");

    ProxiedHttpMethod method;

         if (!requestProcessor.getWebForward().getFormType().equals(WebForwardTypes.FORM_SUBMIT_NONE) &&
             !requestProcessor.getWebForward().getFormType().equals("") &&
             !requestProcessor.getWebForward().getFormType().equals(WebForwardTypes.FORM_SUBMIT_JAVASCRIPT) &&
             !Boolean.TRUE.equals(launchSession.getAttribute(LAUNCH_ATTR_AUTH_POSTED))) {

            /**
             * This code will automatically submit form parameters.
             *
             * LDP - Use the full URI with parameters as we need to ensure parameters are sent as they are received.
             */
      method = new ProxiedHttpMethod(requestProcessor.getWebForward().getFormType(),
          SessionInfoReplacer.replace(requestProcessor.getSessionInfo(),
          requestProcessor.getUriEncoded()),
          requestProcessor.getWebForward().getFormType().equals(WebForwardTypes.FORM_SUBMIT_POST)? new MultiMap() : requestParameters,
          requestProcessor.getSessionInfo(),
          requestProcessor.getWebForward().getFormType().equals(WebForwardTypes.FORM_SUBMIT_POST));

      if (requestProcessor.getWebForward().getEncoding() != null && !requestProcessor.getWebForward().getEncoding().equals(WebForwardTypes.DEFAULT_ENCODING))
                method.setCharsetEncoding(requestProcessor.getWebForward().getEncoding());

            StringTokenizer tokens = new StringTokenizer(requestProcessor.getWebForward().getFormParameters(), "\n");
            int idx;
            String param;
            while (tokens.hasMoreTokens()) {
                param = SessionInfoReplacer.replace(requestProcessor.getLaunchSession().getSession(), tokens.nextToken().trim());
                idx = param.indexOf('=');
                if (idx > -1 && idx < param.length()-1) {
                    method.addParameter(param.substring(0, idx), param.substring(idx + 1));
                } else
                    method.addParameter(param, "");
            }
           
            launchSession.setAttribute(LAUNCH_ATTR_AUTH_POSTED, Boolean.TRUE);
        } else {
          /**
             * LDP - Use the full URI with parameters as we need to ensure parameters are sent as they are received.
           */
          method = new ProxiedHttpMethod(requestProcessor.getMethod(),
          SessionInfoReplacer.replace(requestProcessor.getSessionInfo(),
            requestProcessor.getUriEncoded()),
            requestParameters,
          requestProcessor.getSessionInfo(),
          requestProcessor.getRequest().getContentType()!=null &&
          requestProcessor.getRequest().getContentType().startsWith("application/x-www-form-urlencoded"));

            if (requestProcessor.getWebForward().getEncoding() != null && !requestProcessor.getWebForward().getEncoding().equals(WebForwardTypes.DEFAULT_ENCODING))
                method.setCharsetEncoding(requestProcessor.getWebForward().getEncoding());
        }

    int contentLength = 0;
    String contentType = null;
   
    for (Enumeration e = requestProcessor.getHeaderNames(); e.hasMoreElements();) {

      String hdr = (String) e.nextElement();

      if (ignoreHeaders.containsKey(hdr)) {
        if (log.isDebugEnabled())
          log.debug("Ignoring " + hdr + " = " + requestProcessor.getHeader(hdr));
        continue;
      }

      // See if there any replacements for this header
      List replacements = WebForwardDatabaseFactory.getInstance().getReplacementsForContent(launchSession.getSession().getUser().getPrincipalName(),
        Replacement.REPLACEMENT_TYPE_SENT_HEADER,
        hdr,
        proxiedURL.toExternalForm());

      Enumeration vals = requestProcessor.getHeaders(hdr);
      while (vals.hasMoreElements()) {
        String val = (String) vals.nextElement();

        // Do the replacements
        for (Iterator i = replacements.iterator(); i.hasNext();) {
          Replacement r = (Replacement) i.next();
          val = val.replaceAll(r.getMatchPattern(), r.getReplacePattern());
        }

        if (val != null) {
          if (hdr.equalsIgnoreCase(HttpConstants.HDR_HOST)) {
            if (proxiedURL.getPort() == -1) {
              val = proxiedURL.getHost();
            } else {
              val = proxiedURL.getHost() + ":" + proxiedURL.getPort();
            }
          } else if (hdr.equalsIgnoreCase(HttpConstants.HDR_COOKIE)) {
            // We shouldnt supply our local cookies
            if (log.isDebugEnabled())
              log.debug(" Splitting cookie " + val);
            String[] cookieVals = val.split("\\;");
            StringBuffer newVal = new StringBuffer();
            for (int i = 0; i < cookieVals.length; i++) {
              if (log.isDebugEnabled())
                log.debug("Cookie = " + cookieVals[i]);
              int idx = cookieVals[i].indexOf('=');
              String cn = "";
              String cv = "";
              if(idx==-1) {
                cn = Util.trimBoth(cookieVals[i]);
              } else if(idx < cookieVals[i].length()-1) {
                cn = Util.trimBoth(cookieVals[i].substring(0, idx));
                cv = Util.trimBoth(cookieVals[i].substring(idx + 1));     
              } else {
                cn = Util.trimBoth(cookieVals[i].substring(0, idx));         
              }
              if (cn.equals("webForward") || cn.equals(Constants.LOGON_TICKET)
                || cn.equals(Constants.DOMAIN_LOGON_TICKET)
                || (cn.equals(sessionIdCookieName) && cv.equals(requestProcessor.getSession().getId()))) {
                if (log.isDebugEnabled())
                  log.debug("  Omiting cookie " + cn + "=" + cv);
              } else {
                // TODO is it ok to store the cookie map in
                // memory?
                CookieItem cookie = cookieMap.getByFakeCookieName(cn);
                if (cookie == null) {
                  if (log.isDebugEnabled())
                    log.debug("  Cookie " + cn + " unmapped, ignoring");
                  // Un-mapped cookie, ignore
                } else {
                  if (log.isDebugEnabled())
                    log.debug("  Including cookie " + cn + "=" + cv);
                  if (newVal.length() > 0) {
                    newVal.append("; ");
                  }
                  newVal.append(cookie.getRealCookieName());
                  newVal.append("=");
                  newVal.append(Util.urlDecode(cv));
                }
              }
            }
            if (newVal.length() == 0) {
              if (log.isDebugEnabled())
                log.debug("Send no cookies");
              val = null;
            } else {
              val = newVal.toString();
              if (log.isDebugEnabled())
                log.debug("Using cooking val of " + val);
            }
          }
          // Change the refererer
          else if (hdr.equalsIgnoreCase(HttpConstants.HDR_REFERER)) {
            try {
              URL refUrl = new URL(val);
              refUrl.getQuery();
              if (log.isDebugEnabled())
                log.debug("Splitting refererer query string [" + val + "] " + refUrl.getQuery());
              if (refUrl.getFile() != null) {
                 
                  ProxyURIDetails uriDetails = RequestParameterMap.parseProxyPath(refUrl.getFile(), "UTF-8");
                  if(uriDetails.getProxiedURL() == null) {
                      /* If the referer is not a proxied URL then don't send a referer. This
                       * way a target server won't know its a request from Adito by
                       * examining the referer
                       */
                      val = null;
                  }
                  else {
                      val = uriDetails.getProxiedURL().toExternalForm();
                  }
              }
            } catch (MalformedURLException murle) {

            }
          } else if (hdr.equalsIgnoreCase(HttpConstants.HDR_CONTENT_LENGTH)) {
            contentLength = Integer.parseInt(val);
            continue;
          } else if(hdr.equalsIgnoreCase(HttpConstants.HDR_CONTENT_TYPE)) {
            contentType = val;
            continue;
          } else if (hdr.equalsIgnoreCase(HttpConstants.HDR_CONNECTION)) {
            // Handled by the Maverick HTTP client
            continue;
          }

          if (val != null) {
            method.getProxiedRequest().addHeaderField(hdr, val);
          }

          if (log.isDebugEnabled())
            log.debug("Adding request property " + hdr + " = " + val);
        }
      }
    }

    // Proxy headers
    method.getProxiedRequest().setHeaderField("Via", Branding.PRODUCT_NAME);
   
    if(requestParameters.isMultipart() && requestParameters.getMultipartDataLength()  > 0) {
        method.setContent(getDebugStream(requestParameters.getMultipartData()), requestParameters.getMultipartDataLength(), requestParameters.getOriginalContentType());
        }
        else if(!requestParameters.isWwwFormURLEncoded() && contentLength > 0) {
            method.setContent(getDebugStream(requestProcessor.getRequest().getInputStream()), requestParameters.getOriginalContentLength(), requestParameters.getOriginalContentType());
        }

    serverResponse = client.execute(method);

    responseCode = serverResponse.getStatus();
View Full Code Here


    try {
      URL target = getTarget(launchSession, request);
      setRequestEncoding(launchSession, target, request);
      HttpClient client = getClient(launchSession, target);
      ProxiedHttpMethod method = getMethod(client, launchSession, request, target);
      processPortsAndXForwarding(method, request);
      checkProcessedContent(launchSession, method, request);
      addCustomHeaders(webForward, method);
     
      /* If this webforward has JavaScript form authentication and this hasn't
       * yet been processed, then we make sure the content that comes back from
       * the target is not encoded using gzip or any other compression methods.
       * This is because we will be tacking on some content and its easy to
       * deal with unencoded.
       *
       * TODO We may want to support at least Gzip at some point
       */
      if (webForward.getFormType().equals(WebForwardTypes.FORM_SUBMIT_JAVASCRIPT)
          && !Boolean.TRUE.equals(launchSession.getAttribute(LAUNCH_ATTR_AUTH_POSTED))) {
        method.getProxiedRequest().removeFields("Accept-Encoding");
      }
     
      com.maverick.http.HttpResponse clientResponse = doExecute(client, method);
      connectionError = false;
      checkInsecureIIS(webForward, clientResponse);
View Full Code Here

  }

  ProxiedHttpMethod getMethod(HttpClient client, LaunchSession launchSession, RequestHandlerRequest request, URL target) {

    ReverseProxyWebForward webForward = (ReverseProxyWebForward) launchSession.getResource();
    ProxiedHttpMethod method;

    VariableReplacement v = new VariableReplacement();
    v.setRequest(request);
    v.setSession(launchSession.getSession());
    v.setPolicy(launchSession.getPolicy());
   
    /**
     * POST parameters are now not being
     */

    if (!webForward.getFormType().equals(WebForwardTypes.FORM_SUBMIT_NONE)
        && !webForward.getFormType().equals(WebForwardTypes.FORM_SUBMIT_NONE)
        && !webForward.getFormType().equals("")
        && !webForward.getFormType().equals(WebForwardTypes.FORM_SUBMIT_JAVASCRIPT)
        && !Boolean.TRUE.equals(launchSession.getAttribute(LAUNCH_ATTR_AUTH_POSTED))) {

      /**
       * This code will automatically submit form parameters. If it is a post,
       * then we ignore the parameters request and use the webforward target.
       */
      method = new ProxiedHttpMethod(webForward.getFormType(),
              target.getFile(),
              webForward.getFormType().equals(WebForwardTypes.FORM_SUBMIT_POST) new MultiMap() : new MultiMap(request.getParameters()),
              launchSession.getSession(),
              webForward.getFormType().equals(WebForwardTypes.FORM_SUBMIT_POST));

      if (webForward.getCharset() != null
          && !webForward.getCharset().equals("")
          && !webForward.getCharset().equals(WebForwardTypes.DEFAULT_ENCODING))
        method.setCharsetEncoding(webForward.getCharset());

      StringTokenizer tokens = new StringTokenizer(webForward.getFormParameters(), "\n");
      int idx;
      String param;
     
      while (tokens.hasMoreTokens()) {
        param = v.replace(tokens.nextToken().trim());
        idx = param.indexOf('=');
        if (idx > -1) {
          method.addParameter(param.substring(0, idx), param.substring(idx + 1));
        } else
          method.addParameter(param, "");
      }
     
      launchSession.setAttribute(LAUNCH_ATTR_AUTH_POSTED, Boolean.TRUE);
      processRequestHeaders(request, method);
     
      // Do not send through any cookies on the authentication request
      method.getProxiedRequest().removeFields(HttpConstants.HDR_COOKIE);
      client.removeAllCookies();

    } else {
      method = new ProxiedHttpMethod(request.getMethod(),
              request.getURIEncoded(),
              new MultiMap(request.getParameters()),
              launchSession.getSession(),
              request.getContentType() != null && request.getContentType()
                      .toLowerCase()
                      .startsWith("application/x-www-form-urlencoded"));
      if (webForward.getCharset() != null
          && !webForward.getCharset().equals("")
          && !webForward.getCharset().equals(WebForwardTypes.DEFAULT_ENCODING))
        method.setCharsetEncoding(webForward.getCharset());
      processRequestHeaders(request, method);
    }

    return method;
  }
View Full Code Here

TOP

Related Classes of com.adito.util.ProxiedHttpMethod

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.