当前位置: 首页>>代码示例>>Java>>正文


Java HTTPSamplerBase.parseArguments方法代码示例

本文整理汇总了Java中org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.parseArguments方法的典型用法代码示例。如果您正苦于以下问题:Java HTTPSamplerBase.parseArguments方法的具体用法?Java HTTPSamplerBase.parseArguments怎么用?Java HTTPSamplerBase.parseArguments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase的用法示例。


在下文中一共展示了HTTPSamplerBase.parseArguments方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createUrlFromAnchor

import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase; //导入方法依赖的package包/类
/**
 * Create a new Sampler based on an HREF string plus a contextual URL
 * object. Given that an HREF string might be of three possible forms, some
 * processing is required.
 */
public static HTTPSamplerBase createUrlFromAnchor(String parsedUrlString, URL context) throws MalformedURLException {
    if (log.isDebugEnabled()) {
        log.debug("Creating URL from Anchor: " + parsedUrlString + ", base: " + context);
    }
    URL url = ConversionUtils.makeRelativeURL(context, parsedUrlString);
    HTTPSamplerBase sampler =HTTPSamplerFactory.newInstance();
    sampler.setDomain(url.getHost());
    sampler.setProtocol(url.getProtocol());
    sampler.setPort(url.getPort());
    sampler.setPath(url.getPath());
    sampler.parseArguments(url.getQuery());

    return sampler;
}
 
开发者ID:botelhojp,项目名称:apache-jmeter-2.10,代码行数:20,代码来源:HtmlParsingUtils.java

示例2: makeContext

import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase; //导入方法依赖的package包/类
private HTTPSamplerBase makeContext(String url) throws MalformedURLException {
    URL u = new URL(url);
    HTTPSamplerBase context = new HTTPNullSampler();
    context.setDomain(u.getHost());
    context.setPath(u.getPath());
    context.setPort(u.getPort());
    context.setProtocol(u.getProtocol());
    context.parseArguments(u.getQuery());
    return context;
}
 
开发者ID:botelhojp,项目名称:apache-jmeter-2.10,代码行数:11,代码来源:TestAnchorModifier.java

示例3: computeFromPostBody

import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase; //导入方法依赖的package包/类
/**
 * Compute sampler informations from Request Header
 * @param sampler {@link HTTPSamplerBase}
 * @param request {@link HttpRequestHdr}
 * @throws Exception
 */
protected void computeFromPostBody(HTTPSamplerBase sampler,
        HttpRequestHdr request) throws Exception {
    // If it was a HTTP GET request, then all parameters in the URL
    // 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, "");
        } else if (contentType == null || 
                (contentType.startsWith(HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED) && 
                        !isBinaryContent(contentType))) {
            // It is the most common post request, with parameter name and values
            // We also assume this if no content type is present, to be most backwards compatible,
            // but maybe we should only parse arguments if the content type is as expected
            sampler.parseArguments(postData.trim(), contentEncoding); //standard name=value postData
        } else if (postData.length() > 0) {
            if (isBinaryContent(contentType)) {
                try {
                    File tempDir = new File(getBinaryDirectory());
                    File out = File.createTempFile(request.getMethod(), getBinaryFileSuffix(), tempDir);
                    FileUtils.writeByteArrayToFile(out,request.getRawPostData());
                    HTTPFileArg [] files = {new HTTPFileArg(out.getPath(),"",contentType)};
                    sampler.setHTTPFiles(files);
                } catch (IOException e) {
                    log.warn("Could not create binary file: "+e);
                }
            } else {
                // Just put the whole postbody as the value of a parameter
                sampler.addNonEncodedArgument("", postData, ""); //used when postData is pure xml (ex. an xml-rpc call)
            }
        }
    }
}
 
开发者ID:botelhojp,项目名称:apache-jmeter-2.10,代码行数:81,代码来源:DefaultSamplerCreator.java

示例4: createUrlFromAnchor

import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase; //导入方法依赖的package包/类
/**
 * Create a new Sampler based on an HREF string plus a contextual URL
 * object. Given that an HREF string might be of three possible forms, some
 * processing is required.
 *
 * @param parsedUrlString
 *            the url from the href
 * @param context
 *            the context in which the href was found. This is used to
 *            extract url information that might be missing in
 *            <code>parsedUrlString</code>
 * @return sampler with filled in information about the fully parsed url
 * @throws MalformedURLException
 *             when the given url (<code>parsedUrlString</code> plus
 *             <code>context</code> is malformed)
 */
public static HTTPSamplerBase createUrlFromAnchor(String parsedUrlString, URL context) throws MalformedURLException {
    if (log.isDebugEnabled()) {
        log.debug("Creating URL from Anchor: " + parsedUrlString + ", base: " + context);
    }
    URL url = ConversionUtils.makeRelativeURL(context, parsedUrlString);
    HTTPSamplerBase sampler =HTTPSamplerFactory.newInstance();
    sampler.setDomain(url.getHost());
    sampler.setProtocol(url.getProtocol());
    sampler.setPort(url.getPort());
    sampler.setPath(url.getPath());
    sampler.parseArguments(url.getQuery());

    return sampler;
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:31,代码来源:HtmlParsingUtils.java


注:本文中的org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.parseArguments方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。