Examples of HeaderManager


Examples of org.apache.jmeter.protocol.http.control.HeaderManager

    }
    return 0;
  }

  private HeaderManager createHeaderManager() {
    HeaderManager manager = new HeaderManager();
    Iterator keys = headers.keySet().iterator();
    while (keys.hasNext()) {
      String key = (String) keys.next();
      if (!key.equals(PROXY_CONNECTION) && !key.equals(CONTENT_LENGTH)) {
        manager.add((Header) headers.get(key));
      }
    }
    manager.setName("Browser-derived headers");
    manager.setProperty(TestElement.TEST_CLASS, HeaderManager.class.getName());
    manager.setProperty(TestElement.GUI_CLASS, HeaderPanel.class.getName());
    return manager;
  }
View Full Code Here

Examples of org.apache.jmeter.protocol.http.control.HeaderManager

  private JButton loadButton;

  private JButton saveButton;

  public HeaderPanel() {
    headerManager = new HeaderManager();
    tableModel = new InnerTableModel(headerManager);
    init();
  }
View Full Code Here

Examples of org.apache.jmeter.protocol.http.control.HeaderManager

    // Instantiate the sampler
    HTTPSamplerBase sampler = HTTPSamplerFactory.newInstance(httpSamplerName);
   
    HttpRequestHdr request = new HttpRequestHdr(sampler);
    SampleResult result = null;
    HeaderManager headers = null;

    try {
      request.parse(new BufferedInputStream(clientSocket.getInputStream()));

      // Populate the sampler. It is the same sampler as we sent into
      // the constructor of the HttpRequestHdr instance above
            request.getSampler(pageEncodings, formEncodings);

      /*
       * Create a Header Manager to ensure that the browsers headers are
       * captured and sent to the server
       */
      headers = request.getHeaderManager();
      sampler.setHeaderManager(headers);
     
      /*
       * If we are trying to spoof https, change the protocol
       */
      boolean forcedHTTP = false; // so we know when to revert
      if (httpsSpoof) {
        if (httpsSpoofMatch.length() > 0){
          String url = request.getUrl();
          if (url.matches(httpsSpoofMatch)){
            sampler.setProtocol(HTTPConstants.PROTOCOL_HTTPS);
            forcedHTTP = true;
          }
        } else {
            sampler.setProtocol(HTTPConstants.PROTOCOL_HTTPS);
          forcedHTTP = true;
        }
      }
      sampler.threadStarted(); // Needed for HTTPSampler2
      result = sampler.sample();
     
      /*
       * If we're dealing with text data, and if we're spoofing https,
       * replace all occurences of "https://" with "http://" for the client.
       * TODO - also check the match string to restrict the changes further?
       */
      if (forcedHTTP && SampleResult.TEXT.equals(result.getDataType()))
      {
        final String enc = result.getDataEncodingWithDefault();
        String noHttpsResult = new String(result.getResponseData(),enc);
        final String HTTPS_HOST = // match https://host[:port]/ and drop default port if present
          "https://([^:/]+)(:"+HTTPConstants.DEFAULT_HTTPS_PORT_STRING+")?"; // $NON-NLS-1$ $NON-NLS-2$
        noHttpsResult = noHttpsResult.replaceAll(HTTPS_HOST, "http://$1"); // $NON-NLS-1$
        result.setResponseData(noHttpsResult.getBytes(enc));
      }

            // Find the page encoding and possibly encodings for forms in the page
            // in the response from the web server
            String pageEncoding = addPageEncoding(result);
            addFormEncodings(result, pageEncoding);

      writeToClient(result, new BufferedOutputStream(clientSocket.getOutputStream()), forcedHTTP);
    } catch (UnknownHostException uhe) {
      log.warn("Server Not Found.", uhe);
      writeErrorToClient(HttpReplyHdr.formServerNotFound());
      result = generateErrorResult(result, uhe); // Generate result (if nec.) and populate it
    } catch (IllegalArgumentException e) {
      log.error("Not implemented (probably used https)", e);
      writeErrorToClient(HttpReplyHdr.formNotImplemented());     
      result = generateErrorResult(result, e); // Generate result (if nec.) and populate it
    } catch (Exception e) {
      log.error("Exception when processing sample", e);
      writeErrorToClient(HttpReplyHdr.formTimeout());
      result = generateErrorResult(result, e); // Generate result (if nec.) and populate it
    } finally {
      if (log.isDebugEnabled()) {
        log.debug("Will deliver sample " + sampler.getName());
      }
      /*
       * We don't want to store any cookies in the generated test plan
       */
      if (headers != null) {
        headers.removeHeaderNamed("cookie");// Always remove cookies // $NON-NLS-1$
        headers.removeHeaderNamed("Authorization");// Always remove authorization // $NON-NLS-1$
        // Remove additional headers
        for(int i=0; i < headersToRemove.length; i++){
          headers.removeHeaderNamed(headersToRemove[i]);
        }
        }
      target.deliverSampler(sampler, new TestElement[] { captureHttpHeaders ? headers : null }, result);
      try {
        clientSocket.close();
View Full Code Here

Examples of org.apache.jmeter.protocol.http.control.HeaderManager

    protected int setPostHeaders(PostMethod post) {
      int length=0;// Take length from file
        if (getHeaderManager() != null) {
            // headerManager was set, so let's set the connection
            // to use it.
            HeaderManager mngr = getHeaderManager();
            int headerSize = mngr.size();
            for (int idx = 0; idx < headerSize; idx++) {
                Header hd = mngr.getHeader(idx);
                if (HEADER_CONTENT_LENGTH.equalsIgnoreCase(hd.getName())) {// Use this to override file length
                  length = Integer.parseInt(hd.getValue());
                }
                // All the other headers are set up by HTTPSampler2.setupConnection()
            }
View Full Code Here

Examples of org.apache.jmeter.protocol.http.control.HeaderManager

        setConnectionCookies(url, getCookieManager());
        setByte((byte)0xff); // Attributes not supported
    }

    private int getHeaderSize(String method, URL url) {
        HeaderManager headers = getHeaderManager();
        CookieManager cookies = getCookieManager();
        AuthManager auth = getAuthManager();
        int hsz = 1; // Host always
        if(method.equals(POST)) {
            String fn = getFilename();
            if(fn != null && fn.trim().length() > 0) {
                hsz += 3;
            } else {
                hsz += 2;
            }
        }
        if(headers != null) {
            hsz += headers.size();
        }
        if(cookies != null) {
            hsz += cookies.getCookieCount();
        }
        if(auth != null) {
View Full Code Here

Examples of org.apache.jmeter.protocol.http.control.HeaderManager

    }


    private String setConnectionHeaders(URL url, String host, String method)
    throws IOException {
        HeaderManager headers = getHeaderManager();
        AuthManager auth = getAuthManager();
        StringBuffer hbuf = new StringBuffer();
        // Allow Headers to override Host setting
        hbuf.append("Host").append(COLON_SPACE).append(host).append(NEWLINE);//$NON-NLS-1$
        setInt(0xA00b); //Host
        setString(host);
        if(headers != null) {
            CollectionProperty coll = headers.getHeaders();
            PropertyIterator i = coll.iterator();
            while(i.hasNext()) {
                Header header = (Header)i.next().getObjectValue();
                String n = header.getName();
                String v = header.getValue();
View Full Code Here

Examples of org.apache.jmeter.protocol.http.control.HeaderManager

        // Check which HTTPSampler class we should use
        String httpSamplerName = target.getSamplerTypeName();

        HttpRequestHdr request = new HttpRequestHdr(httpSamplerName);
        SampleResult result = null;
        HeaderManager headers = null;
        HTTPSamplerBase sampler = null;
        log.debug(port + "====================================================================");
        try {
            // Now, parse initial request (in case it is a CONNECT request)
            byte[] ba = request.parse(new BufferedInputStream(clientSocket.getInputStream()));
            if (ba.length == 0) {
                log.warn(port + "Empty request, ignored");
                throw new JMeterException(); // hack to skip processing
            }
            if (log.isDebugEnabled()) {
                log.debug(port + "Initial request: " + new String(ba));
            }
            outStreamClient = clientSocket.getOutputStream();

            if ((request.getMethod().startsWith(HTTPConstants.CONNECT)) && (outStreamClient != null)) {
                log.debug(port + "Method CONNECT => SSL");
                // write a OK reponse to browser, to engage SSL exchange
                outStreamClient.write(("HTTP/1.0 200 OK\r\n\r\n").getBytes(SampleResult.DEFAULT_HTTP_ENCODING)); // $NON-NLS-1$
                outStreamClient.flush();
               // With ssl request, url is host:port (without https:// or path)
                String[] param = request.getUrl().split(":")// $NON-NLS-1$
                if (param.length == 2) {
                    log.debug(port + "Start to negotiate SSL connection, host: " + param[0]);
                    clientSocket = startSSL(clientSocket, param[0]);
                } else {
                    // Should not happen, but if it does we don't want to continue
                    log.error("In SSL request, unable to find host and port in CONNECT request: " + request.getUrl());
                    throw new JMeterException(); // hack to skip processing
                }
                // Re-parse (now it's the http request over SSL)
                try {
                    ba = request.parse(new BufferedInputStream(clientSocket.getInputStream()));
                } catch (IOException ioe) { // most likely this is because of a certificate error
                    final String url = param.length>0 " for '"+ param[0] +"'" : "";
                    log.warn(port + "Problem with SSL certificate"+url+"? Ensure browser is set to accept the JMeter proxy cert: " + ioe.getMessage());
                    // won't work: writeErrorToClient(HttpReplyHdr.formInternalError());
                    result = generateErrorResult(result, request, ioe, "\n**ensure browser is set to accept the JMeter proxy certificate**"); // Generate result (if nec.) and populate it
                    throw new JMeterException(); // hack to skip processing
                }
                if (log.isDebugEnabled()) {
                    log.debug(port + "Reparse: " + new String(ba));
                }
                if (ba.length == 0) {
                    log.warn(port + "Empty response to http over SSL. Probably waiting for user to authorize the certificate for " + request.getUrl());
                    throw new JMeterException(); // hack to skip processing
                }
            }

            SamplerCreator samplerCreator = SAMPLERFACTORY.getSamplerCreator(request, pageEncodings, formEncodings);
            sampler = samplerCreator.createAndPopulateSampler(request, pageEncodings, formEncodings);

            /*
             * Create a Header Manager to ensure that the browsers headers are
             * captured and sent to the server
             */
            headers = request.getHeaderManager();
            sampler.setHeaderManager(headers);

            sampler.threadStarted(); // Needed for HTTPSampler2
            if (log.isDebugEnabled()) {
                log.debug(port + "Execute sample: " + sampler.getMethod() + " " + sampler.getUrl());
            }
            result = sampler.sample();

            // Find the page encoding and possibly encodings for forms in the page
            // in the response from the web server
            String pageEncoding = addPageEncoding(result);
            addFormEncodings(result, pageEncoding);

            writeToClient(result, new BufferedOutputStream(clientSocket.getOutputStream()));
            samplerCreator.postProcessSampler(sampler, result);
        } catch (JMeterException jme) {
            // ignored, already processed
        } catch (UnknownHostException uhe) {
            log.warn(port + "Server Not Found.", uhe);
            writeErrorToClient(HttpReplyHdr.formServerNotFound());
            result = generateErrorResult(result, request, uhe); // Generate result (if nec.) and populate it
        } catch (IllegalArgumentException e) {
            log.error(port + "Not implemented (probably used https)", e);
            writeErrorToClient(HttpReplyHdr.formNotImplemented("Probably used https instead of http. " +
                    "To record https requests, see " +
                    "<a href=\"http://jmeter.apache.org/usermanual/component_reference.html#HTTP(S)_Test_Script_Recorder\">HTTP(S) Test Script Recorder documentation</a>"));
            result = generateErrorResult(result, request, e); // Generate result (if nec.) and populate it
        } catch (Exception e) {
            log.error(port + "Exception when processing sample", e);
            writeErrorToClient(HttpReplyHdr.formInternalError());
            result = generateErrorResult(result, request, e); // Generate result (if nec.) and populate it
        } finally {
            if (log.isDebugEnabled()) {
                if(sampler != null) {
                    log.debug(port + "Will deliver sample " + sampler.getName());
                }
            }
            /*
             * We don't want to store any cookies in the generated test plan
             */
            if (headers != null) {
                headers.removeHeaderNamed(HTTPConstants.HEADER_COOKIE);// Always remove cookies
                headers.removeHeaderNamed(HTTPConstants.HEADER_AUTHORIZATION);// Always remove authorization
                // Remove additional headers
                for(String hdr : HEADERS_TO_REMOVE){
                    headers.removeHeaderNamed(hdr);
                }
            }
            if(result != null) // deliverSampler allows sampler to be null, but result must not be null
            {
                target.deliverSampler(sampler, new TestElement[] { captureHttpHeaders ? headers : null }, result);
View Full Code Here

Examples of org.apache.jmeter.protocol.http.control.HeaderManager

  public AuthManager getAuthManager() {
    return (AuthManager) getProperty(AUTH_MANAGER).getObjectValue();
  }

  public void setHeaderManager(HeaderManager value) {
    HeaderManager mgr = getHeaderManager();
    if (mgr != null) {
      log.warn("Existing Manager " + mgr.getName() + " superseded by " + value.getName());
    }
    setProperty(new TestElementProperty(HEADER_MANAGER, value));
  }
View Full Code Here

Examples of org.apache.jmeter.protocol.http.control.HeaderManager

    }
    return 0;
  }

  private HeaderManager createHeaderManager() {
    HeaderManager manager = new HeaderManager();
    Iterator keys = headers.keySet().iterator();
    while (keys.hasNext()) {
      String key = (String) keys.next();
      if (!key.equals(PROXY_CONNECTION) && !key.equals(CONTENT_LENGTH)) {
        manager.add((Header) headers.get(key));
      }
    }
    manager.setName("Browser-derived headers");
    manager.setProperty(TestElement.TEST_CLASS, HeaderManager.class.getName());
    manager.setProperty(TestElement.GUI_CLASS, HeaderPanel.class.getName());
    return manager;
  }
View Full Code Here

Examples of org.apache.jmeter.protocol.http.control.HeaderManager

        HttpRequestHdr req = new HttpRequestHdr();
        ByteArrayInputStream bis = null;
        bis = new ByteArrayInputStream("GET xxx HTTP/1.0\r\nname:value \r\n".getBytes("ISO-8859-1"));
        req.parse(bis);
        bis.close();
        HeaderManager mgr = req.getHeaderManager();
        Header header;
        mgr.getHeaders();
        header = mgr.getHeader(0);
        assertEquals("name",header.getName());
        assertEquals("value",header.getValue());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.