org.apache.http.message.BasicRequestLine Java Examples

The following examples show how to use org.apache.http.message.BasicRequestLine. 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: TestUtils.java    From esigate with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a mock {@link IncomingRequest}.
 * 
 * @param uri
 *            the uri
 * @return the {@link IncomingRequest}
 */
public static IncomingRequest.Builder createIncomingRequest(String uri) {
    HttpHost httpHost = UriUtils.extractHost(uri);
    String scheme = httpHost.getSchemeName();
    String host = httpHost.getHostName();
    int port = httpHost.getPort();
    RequestLine requestLine = new BasicRequestLine("GET", uri, HttpVersion.HTTP_1_1);
    IncomingRequest.Builder builder = IncomingRequest.builder(requestLine);
    builder.setContext(new ContainerRequestContext() {
    });
    // Remove default ports
    if (port == -1 || (port == Http.DEFAULT_HTTP_PORT && "http".equals(scheme))
            || (port == Http.DEFAULT_HTTPS_PORT && "https".equals(scheme))) {
        builder.addHeader("Host", host);
    } else {
        builder.addHeader("Host", host + ":" + port);
    }
    builder.setSession(new MockSession());
    return builder;
}
 
Example #2
Source File: OutgoingRequest.java    From esigate with Apache License 2.0 5 votes vote down vote up
public OutgoingRequest(String method, String uri, ProtocolVersion version, DriverRequest originalRequest,
        RequestConfig requestConfig, OutgoingRequestContext context) {
    super(method, uri, version);
    requestLine = new BasicRequestLine(method, uri, version);
    this.requestConfig = requestConfig;
    this.context = context;
    this.originalRequest = originalRequest;
}
 
Example #3
Source File: CXFHttpRequest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public RequestLine getRequestLine() {
    return new BasicRequestLine(
            method,
            uri != null ? uri.toASCIIString() : "/",
            HttpVersion.HTTP_1_1);
}
 
Example #4
Source File: StringHttpMessages.java    From BUbiNG with Apache License 2.0 4 votes vote down vote up
public HttpRequest(final String method, final String url) {
	this.requestLine = new BasicRequestLine(method, url, PROTOCOL_VERSION);
}
 
Example #5
Source File: RandomTestMocks.java    From BUbiNG with Apache License 2.0 4 votes vote down vote up
public HttpRequest(final int maxNumberOfHeaders, final int maxLenghtOfHeader, final int pos) {
	this.requestLine = new BasicRequestLine("GET", RandomStringUtils.randomAlphabetic(RNG.nextInt(maxLenghtOfHeader) + 1), PROTOCOL_VERSION);
	Header[] headers = randomHeaders(maxNumberOfHeaders, maxLenghtOfHeader);
	headers[RNG.nextInt(headers.length)] = new BasicHeader("Position", Integer.toString(pos));
	this.setHeaders(headers);
}
 
Example #6
Source File: HttpRequestPrinter.java    From Bastion with GNU General Public License v3.0 4 votes vote down vote up
private void writeRequestLine(URL url, Writer writer, BasicLineFormatter formatter) throws IOException {
    BasicRequestLine requestLine = new BasicRequestLine(request.method().getValue(), url.getFile(), new ProtocolVersion("HTTP", 1, 1));
    writer.append(BasicLineFormatter.formatRequestLine(requestLine, formatter)).append("\r\n");
}
 
Example #7
Source File: AWSSigningRequestInterceptorTest.java    From aws-signing-request-interceptor with MIT License 4 votes vote down vote up
private void mockRequest(String url) throws Exception {
    when(request.getURI()).thenReturn(new URI(url));
    when(request.getRequestLine()).thenReturn(new BasicRequestLine("GET", url, new ProtocolVersion("HTTP", 1, 1)));
    when(request.getAllHeaders()).thenReturn(new Header[]{});
    when(request.getOriginal()).thenReturn(request);
}
 
Example #8
Source File: OutgoingRequest.java    From esigate with Apache License 2.0 4 votes vote down vote up
public void setUri(String uri) {
    requestLine = new BasicRequestLine(requestLine.getMethod(), uri, requestLine.getProtocolVersion());
}
 
Example #9
Source File: IncomingRequest.java    From esigate with Apache License 2.0 4 votes vote down vote up
public static Builder builder(String uri) {
    return new Builder(new BasicRequestLine("GET", uri, HttpVersion.HTTP_1_1));
}
 
Example #10
Source File: RequestFactory.java    From esigate with Apache License 2.0 4 votes vote down vote up
public IncomingRequest create(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
        throws IOException {
    HttpServletRequestContext context =
            new HttpServletRequestContext(request, response, servletContext, filterChain);
    // create request line
    String uri =
            UriUtils.createURI(request.getScheme(), request.getServerName(), request.getServerPort(),
                    request.getRequestURI(), request.getQueryString(), null);
    ProtocolVersion protocolVersion = BasicLineParser.parseProtocolVersion(request.getProtocol(), null);
    IncomingRequest.Builder builder =
            IncomingRequest.builder(new BasicRequestLine(request.getMethod(), uri, protocolVersion));
    builder.setContext(context);
    // copy headers
    @SuppressWarnings("rawtypes")
    Enumeration names = request.getHeaderNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        @SuppressWarnings("rawtypes")
        Enumeration values = request.getHeaders(name);
        while (values.hasMoreElements()) {
            String value = (String) values.nextElement();
            builder.addHeader(name, value);
        }
    }
    // create entity
    HttpServletRequestEntity entity = new HttpServletRequestEntity(request);
    builder.setEntity(entity);

    builder.setRemoteAddr(request.getRemoteAddr());
    builder.setRemoteUser(request.getRemoteUser());
    HttpSession session = request.getSession(false);
    if (session != null) {
        builder.setSessionId(session.getId());
    }
    builder.setUserPrincipal(request.getUserPrincipal());

    // Copy cookies
    // As cookie header contains only name=value so we don't need to copy
    // all attributes!
    javax.servlet.http.Cookie[] src = request.getCookies();
    if (src != null) {
        for (Cookie c : src) {
            BasicClientCookie dest = new BasicClientCookie(c.getName(), c.getValue());
            builder.addCookie(dest);
        }
    }
    builder.setSession(new HttpServletSession(request));
    builder.setContextPath(request.getContextPath());
    return builder.build();
}