org.apache.jmeter.protocol.http.util.HTTPConstants Java Examples

The following examples show how to use org.apache.jmeter.protocol.http.util.HTTPConstants. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JmeterTestPlanTask.java    From ambari-metrics with Apache License 2.0 6 votes vote down vote up
private HTTPSampler createGetSampler(String name, String domain, int port, String path, String encoding, Map<String, String> parameters) {

    HTTPSampler sampler = new HTTPSampler();
    sampler.setDomain(domain);
    sampler.setPort(port);
    sampler.setPath(path);
    sampler.setMethod(HTTPConstants.GET);

    if (encoding != null)
      sampler.setContentEncoding(encoding);

    for (Map.Entry<String, String> entry : parameters.entrySet()) {
      sampler.addArgument(entry.getKey(), entry.getValue());
    }
    sampler.setName(name);
    return sampler;
  }
 
Example #2
Source File: WebSocketAbstractSampler.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
protected void setConnectionHeaders(ClientUpgradeRequest request, HeaderManager headerManager, CacheManager cacheManager) {
    if (headerManager != null) {
        CollectionProperty headers = headerManager.getHeaders();
        PropertyIterator p = headers.iterator();
        if (headers != null) {
        	while (p.hasNext()){
        		JMeterProperty jMeterProperty = p.next();
        		org.apache.jmeter.protocol.http.control.Header header
                = (org.apache.jmeter.protocol.http.control.Header)
                        jMeterProperty.getObjectValue();
                String n = header.getName();
                if (! HTTPConstants.HEADER_CONTENT_LENGTH.equalsIgnoreCase(n)){
                    String v = header.getValue();
            		request.setHeader(n, v);
                }
        	}
        }
    }
    if (cacheManager != null){
    }
}
 
Example #3
Source File: WebSocketSampler.java    From JMeter-WebSocketSampler with Apache License 2.0 6 votes vote down vote up
public String getServerPort() {
    final String port_s = getPropertyAsString("serverPort", "0");
    Integer port;
    String protocol = getProtocol();
    
    try {
        port = Integer.parseInt(port_s);
    } catch (Exception ex) {
        port = 0;
    }
    
    if (port == 0) {
        if ("wss".equalsIgnoreCase(protocol)) {
            return String.valueOf(HTTPConstants.DEFAULT_HTTPS_PORT);
        } else if ("ws".equalsIgnoreCase(protocol)) {
            return String.valueOf(HTTPConstants.DEFAULT_HTTP_PORT);
        }
    }
    return port.toString();
}
 
Example #4
Source File: WebSocketSampler.java    From JMeter-WebSocketSampler with Apache License 2.0 6 votes vote down vote up
public String getServerPort() {
    final String port_s = getPropertyAsString("serverPort", "0");
    Integer port;
    String protocol = getProtocol();
    
    try {
        port = Integer.parseInt(port_s);
    } catch (Exception ex) {
        port = 0;
    }
    
    if (port == 0) {
        if ("wss".equalsIgnoreCase(protocol)) {
            return String.valueOf(HTTPConstants.DEFAULT_HTTPS_PORT);
        } else if ("ws".equalsIgnoreCase(protocol)) {
            return String.valueOf(HTTPConstants.DEFAULT_HTTP_PORT);
        }
    }
    return port.toString();
}
 
Example #5
Source File: WebSocketAbstractSampler.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * Get the port; apply the default for the protocol if necessary.
 *
 * @return the port number, with default applied if required.
 */
public int getPort() {
    final int port = getPortIfSpecified();
    if (port == UNSPECIFIED_PORT) {
        String prot = getProtocol();
        if (WSS_PROTOCOL.equalsIgnoreCase(prot)) {
            return HTTPConstants.DEFAULT_HTTPS_PORT;
        }
        if (!WS_PROTOCOL.equalsIgnoreCase(prot)) {
            log.warn("Unexpected protocol: " + prot);
        }
        return HTTPConstants.DEFAULT_HTTP_PORT;
    }
    return port;
}
 
Example #6
Source File: WebSocketSampler.java    From JMeter-WebSocketSampler with Apache License 2.0 5 votes vote down vote up
/**
 * Tell whether the default port for the specified protocol is used
 *
 * @return true if the default port number for the protocol is used, false
 * otherwise
 */
public boolean isProtocolDefaultPort() {
    final int port = Integer.parseInt(getServerPort());
    final String protocol = getProtocol();
    return ("ws".equalsIgnoreCase(protocol) && port == HTTPConstants.DEFAULT_HTTP_PORT)
            || ("wss".equalsIgnoreCase(protocol) && port == HTTPConstants.DEFAULT_HTTPS_PORT);
}
 
Example #7
Source File: WebSocketSampler.java    From JMeter-WebSocketSampler with Apache License 2.0 5 votes vote down vote up
/**
 * Tell whether the default port for the specified protocol is used
 *
 * @return true if the default port number for the protocol is used, false
 * otherwise
 */
public boolean isProtocolDefaultPort() {
    final int port = Integer.parseInt(getServerPort());
    final String protocol = getProtocol();
    return ("ws".equalsIgnoreCase(protocol) && port == HTTPConstants.DEFAULT_HTTP_PORT)
            || ("wss".equalsIgnoreCase(protocol) && port == HTTPConstants.DEFAULT_HTTPS_PORT);
}
 
Example #8
Source File: WebSocketSampler.java    From jmeter-websocket with Apache License 2.0 5 votes vote down vote up
public static int getDefaultPort(String protocol,int port){
    if (port==URL_UNSPECIFIED_PORT){
        return
                protocol.equalsIgnoreCase(HTTPConstants.PROTOCOL_HTTP)  ? HTTPConstants.DEFAULT_HTTP_PORT :
                        protocol.equalsIgnoreCase(HTTPConstants.PROTOCOL_HTTPS) ? HTTPConstants.DEFAULT_HTTPS_PORT :
                                port;
    }
    return port;
}
 
Example #9
Source File: WebSocketSampler.java    From jmeter-websocket with Apache License 2.0 5 votes vote down vote up
/**
 * Tell whether the default port for the specified protocol is used
 *
 * @return true if the default port number for the protocol is used, false otherwise
 */
public boolean isProtocolDefaultPort() {
    final int port = getPortIfSpecified();
    final String protocol = getProtocol();
    return port == UNSPECIFIED_PORT ||
            ("ws".equalsIgnoreCase(protocol) && port == HTTPConstants.DEFAULT_HTTP_PORT) ||
            ("wss".equalsIgnoreCase(protocol) && port == HTTPConstants.DEFAULT_HTTPS_PORT);
}
 
Example #10
Source File: WebSocketSampler.java    From jmeter-websocket with Apache License 2.0 5 votes vote down vote up
public int getPort() {
    final int port = getPortIfSpecified();
    if (port == UNSPECIFIED_PORT) {
        String prot = getProtocol();
        if ("wss".equalsIgnoreCase(prot)) {
            return HTTPConstants.DEFAULT_HTTPS_PORT;
        }
        if (!"ws".equalsIgnoreCase(prot)) {
            log.warn("Unexpected protocol: "+prot);
            // TODO - should this return something else?
        }
        return HTTPConstants.DEFAULT_HTTP_PORT;
    }
    return port;
}