Package org.apache.jmeter.protocol.http.config

Examples of org.apache.jmeter.protocol.http.config.MultipartUrlConfig


    private MultipartUrlConfig getMultipartConfig(String contentType) {
        if(isMultipart(contentType)) {
            // Get the boundary string for the multiparts from the content type
            String boundaryString = contentType.substring(contentType.toLowerCase(java.util.Locale.ENGLISH).indexOf("boundary=") + "boundary=".length());
            return new MultipartUrlConfig(boundaryString);
        }
        return null;
    }
View Full Code Here


        // has been handled by the sampler.setPath above, so we just need
        // to do parse the rest of the request if it is not a GET request
        if((!HTTPConstants.CONNECT.equals(getMethod())) && (!HTTPConstants.GET.equals(method))) {
            // Check if it was a multipart http post request
            final String contentType = getContentType();
            MultipartUrlConfig urlConfig = getMultipartConfig(contentType);
            if (urlConfig != null) {
                urlConfig.parseArguments(postData);
                // Tell the sampler to do a multipart post
                sampler.setDoMultipartPost(true);
                // Remove the header for content-type and content-length, since
                // those values will most likely be incorrect when the sampler
                // performs the multipart request, because the boundary string
                // will change
                getHeaderManager().removeHeaderNamed(CONTENT_TYPE);
                getHeaderManager().removeHeaderNamed(CONTENT_LENGTH);

                // Set the form data
                sampler.setArguments(urlConfig.getArguments());
                // Set the file uploads
                sampler.setHTTPFiles(urlConfig.getHTTPFileArgs().asArray());
            // used when postData is pure xml (eg. an xml-rpc call) or for PUT
            } else if (postData.trim().startsWith("<?") || "PUT".equals(sampler.getMethod())) {
                sampler.addNonEncodedArgument("", postData, "");
            } else if (contentType == null || contentType.startsWith(HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED) ){
                // It is the most common post request, with parameter name and values
View Full Code Here

    public static MultipartUrlConfig isMultipart(String contentType)
    {
        if (contentType != null
            && contentType.startsWith(MultipartUrlConfig.MULTIPART_FORM))
        {
            return new MultipartUrlConfig(
                contentType.substring(contentType.indexOf("oundary=") + 8));
        }
        else
        {
            return null;
View Full Code Here

        }
    }
   
    private HTTPSampler createSampler()
    {
        MultipartUrlConfig urlConfig = null;
        HTTPSampler sampler = new HTTPSampler();
        sampler.setDomain(serverName());
        log.debug("Proxy: setting server: " + sampler.getDomain());
        sampler.setMethod(method);
        log.debug("Proxy: method server: " + sampler.getMethod());
        sampler.setPath(serverUrl());
        log.debug("Proxy: setting path: " + sampler.getPath());
        if (numberRequests){
          requestNumber++;
      sampler.setName(requestNumber + " " + sampler.getPath());
        } else {
      sampler.setName(sampler.getPath());
        }
        sampler.setPort(serverPort());
        log.debug("Proxy: setting port: " + sampler.getPort());
        if (url.indexOf("//") > -1)
        {
            String protocol = url.substring(0, url.indexOf(":"));
            log.debug("Proxy: setting protocol to : " + protocol);
            sampler.setProtocol(protocol);
        }
        else if (sampler.getPort() == 443)
        {
            sampler.setProtocol("https");
            log.debug("Proxy: setting protocol to https");
        }
        else
        {
            log.debug("Proxy setting default protocol to: http");
            sampler.setProtocol("http");
        }
        if ((urlConfig = isMultipart(getContentType())) != null)
        {
            urlConfig.parseArguments(postData);
            sampler.setArguments(urlConfig.getArguments());
            sampler.setFileField(urlConfig.getFileFieldName());
            sampler.setFilename(urlConfig.getFilename());
            sampler.setMimetype(urlConfig.getMimeType());
        }
        else
        {
            sampler.parseArguments(postData);
        }
View Full Code Here

   *@exception  IOException  Description of Exception
   ***********************************************************/
  public void sendPostData(URLConnection connection, UrlConfig url)
       throws IOException
  {
    MultipartUrlConfig config = (MultipartUrlConfig)url;
    ((HttpURLConnection)connection).setRequestMethod("POST");

    // If filename was specified then send the post using multipart syntax
    String filename = config.getFilename();
    if ((filename != null) && (filename.trim().length() > 0))
    {
      connection.setRequestProperty("Content-type", "multipart/form-data; boundary=" + BOUNDARY);
      connection.setDoOutput(true);
      connection.setDoInput(true);
      OutputStream out = connection.getOutputStream();//new FileOutputStream("c:\\data\\experiment.txt");//new ByteArrayOutputStream();//
      writeln(out,"--"+BOUNDARY);
      Iterator args = config.getArguments().iterator();
      while (args.hasNext())
      {
        Argument arg = (Argument)args.next();
        writeFormMultipartStyle(out, arg.getName(), (String)arg.getValue());
        writeln(out,"--" + BOUNDARY);
      }
      writeFileToURL(out, filename, config.getFileFieldName(),
           config.getFileStream(),config.getMimeType());

      writeln(out,"--" + BOUNDARY+"--");
      out.flush();
      out.close();
    }
View Full Code Here

   ***********************************************************/
  public HttpTestSample()
  {
    super();
    catClass.debug("Start : HttpTestSample1");
    defaultUrl = new MultipartUrlConfig();
    catClass.debug("End : HttpTestSample1");
  }
View Full Code Here

   *
   *@param  config  the default url
   ***********************************************************/
  public void setDefaultUrl(UrlConfig config)
  {
    MultipartUrlConfig newConfig = new MultipartUrlConfig();
    newConfig.addConfigElement(config);
    defaultUrl = newConfig;
    if (catClass.isDebugEnabled())
    {
      catClass.debug("Setting defaultUrl - " + config.toString());
    }
View Full Code Here

  public static MultipartUrlConfig isMultipart(String contentType)
  {
    if (contentType != null
      && contentType.startsWith(MultipartUrlConfig.MULTIPART_FORM))
    {
      return new MultipartUrlConfig(
        contentType.substring(contentType.indexOf("oundary=") + 8));
    }
    else
    {
      return null;
View Full Code Here

      return null;
    }
  }
  private HTTPSampler createSampler()
  {
    MultipartUrlConfig urlConfig = null;
    HTTPSampler sampler = new HTTPSampler();
    sampler.setDomain(serverName());
    log.debug("Proxy: setting server: "+sampler.getDomain());
    sampler.setMethod(method);
    log.debug("Proxy: method server: "+sampler.getMethod());
    sampler.setPath(serverUrl());
    log.debug("Proxy: setting path: "+sampler.getPath());
    sampler.setName(sampler.getPath());
    sampler.setPort(serverPort());
    log.debug("Proxy: setting port: "+sampler.getPort());
    if (url.indexOf("//") > -1)
    {
      String protocol = url.substring(0, url.indexOf(":"));
      log.debug("Proxy: setting protocol to : "+protocol);
      sampler.setProtocol(protocol);
    }
    else if(sampler.getPort() == 443)
    {
      sampler.setProtocol("https");
      log.debug("Proxy: setting protocol to https");
    }
    else
    {
      log.debug("Proxy setting default protocol to: http");
      sampler.setProtocol("http");
    }
    if ((urlConfig = isMultipart(getContentType())) != null)
    {
      urlConfig.parseArguments(postData);
      sampler.setArguments(urlConfig.getArguments());
      sampler.setFileField(urlConfig.getFileFieldName());
      sampler.setFilename(urlConfig.getFilename());
      sampler.setMimetype(urlConfig.getMimeType());
    }
    else
    {
      sampler.parseArguments(postData);
    }
View Full Code Here

        // has been handled by the sampler.setPath above, so we just need
        // to do parse the rest of the request if it is not a GET request
        if((!HTTPConstants.CONNECT.equals(request.getMethod())) && (!HTTPConstants.GET.equals(request.getMethod()))) {
            // Check if it was a multipart http post request
            final String contentType = request.getContentType();
            MultipartUrlConfig urlConfig = request.getMultipartConfig(contentType);
            String contentEncoding = sampler.getContentEncoding();
            // Get the post data using the content encoding of the request
            String postData = null;
            if (log.isDebugEnabled()) {
                if(!StringUtils.isEmpty(contentEncoding)) {
                    log.debug("Using encoding " + contentEncoding + " for request body");
                }
                else {
                    log.debug("No encoding found, using JRE default encoding for request body");
                }
            }
           
           
            if (!StringUtils.isEmpty(contentEncoding)) {
                postData = new String(request.getRawPostData(), contentEncoding);
            } else {
                // Use default encoding
                postData = new String(request.getRawPostData(), PostWriter.ENCODING);
            }
           
            if (urlConfig != null) {
                urlConfig.parseArguments(postData);
                // Tell the sampler to do a multipart post
                sampler.setDoMultipartPost(true);
                // Remove the header for content-type and content-length, since
                // those values will most likely be incorrect when the sampler
                // performs the multipart request, because the boundary string
                // will change
                request.getHeaderManager().removeHeaderNamed(HttpRequestHdr.CONTENT_TYPE);
                request.getHeaderManager().removeHeaderNamed(HttpRequestHdr.CONTENT_LENGTH);

                // Set the form data
                sampler.setArguments(urlConfig.getArguments());
                // Set the file uploads
                sampler.setHTTPFiles(urlConfig.getHTTPFileArgs().asArray());
            // used when postData is pure xml (eg. an xml-rpc call) or for PUT
            } else if (postData.trim().startsWith("<?")
                    || HTTPConstants.PUT.equals(sampler.getMethod())
                    || isPotentialXml(postData)) {
                sampler.addNonEncodedArgument("", postData, "");
View Full Code Here

TOP

Related Classes of org.apache.jmeter.protocol.http.config.MultipartUrlConfig

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.