Example usage for org.apache.http.message BasicRequestLine BasicRequestLine

List of usage examples for org.apache.http.message BasicRequestLine BasicRequestLine

Introduction

In this page you can find the example usage for org.apache.http.message BasicRequestLine BasicRequestLine.

Prototype

public BasicRequestLine(String str, String str2, ProtocolVersion protocolVersion) 

Source Link

Usage

From source file:org.esigate.test.TestUtils.java

/**
 * Creates a mock {@link IncomingRequest}.
 * /* w  w  w .j a v  a  2  s.  c  o  m*/
 * @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;
}

From source file:com.subgraph.vega.impl.scanner.VegaHttpRequest.java

@Override
public RequestLine getRequestLine() {
    final String method = getMethod();
    final ProtocolVersion ver = getProtocolVersion();
    return new BasicRequestLine(method, getUriText(), ver);
}

From source file:org.esigate.http.OutgoingRequest.java

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;
}

From source file:org.esigate.http.OutgoingRequest.java

public void setUri(String uri) {
    requestLine = new BasicRequestLine(requestLine.getMethod(), uri, requestLine.getProtocolVersion());
}

From source file:com.messagemedia.restapi.client.v1.internal.http.interceptors.HmacMmv2InterceptorTest.java

@Before
public void setUp() throws IllegalStateException, IOException {
    this.interceptor = new HmacMmv2Interceptor(API_KEY, SECRET_KEY);

    request = Mockito.mock(HttpEntityEnclosingRequest.class);
    Mockito.when(request.getFirstHeader(HTTP.DATE_HEADER)).thenReturn(new BasicHeader("", DATE_HEADER));
    Mockito.when(request.getRequestLine())
            .thenReturn(new BasicRequestLine("POST", "/v1/messages", HttpVersion.HTTP_1_1));
}

From source file:com.joyent.manta.exception.MantaClientHttpResponseExceptionTest.java

private static HttpRequest request() {
    final HttpRequest request = mock(HttpRequest.class);
    when(request.getRequestLine()).thenReturn(new BasicRequestLine("GET", UNIT_TEST_URL, HttpVersion.HTTP_1_1));

    return request;
}

From source file:org.archive.modules.fetcher.BasicExecutionAwareRequest.java

/**
 * Creates an instance of this class using the given request method, URI
 * and the HTTP protocol version./*from ww w  .j  a va2 s .  c o  m*/
 *
 * @param method request method.
 * @param uri request URI.
 * @param ver HTTP protocol version.
 */
public BasicExecutionAwareRequest(final String method, final String uri, final ProtocolVersion ver) {
    this(new BasicRequestLine(method, uri, ver));
}

From source file:org.esigate.servlet.impl.RequestFactory.java

public IncomingRequest create(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
        throws IOException {
    HttpServletRequestContext context = new HttpServletRequestContext(request, response, servletContext,
            filterChain);//from ww  w . ja  v a  2  s  . c  o m
    // 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 (int i = 0; i < src.length; i++) {
            javax.servlet.http.Cookie c = src[i];
            BasicClientCookie dest = new BasicClientCookie(c.getName(), c.getValue());
            builder.addCookie(dest);
        }
    }
    builder.setSession(new HttpServletSession(request));
    builder.setContextPath(request.getContextPath());
    return builder.build();
}

From source file:org.apache.cxf.transport.http.asyncclient.CXFHttpRequest.java

@Override
public RequestLine getRequestLine() {
    return new BasicRequestLine(method, uri != null ? uri.toASCIIString() : "/", HttpVersion.HTTP_1_1);
}

From source file:org.elasticsearch.client.ResponseExceptionTests.java

public void testResponseException() throws IOException {
    ProtocolVersion protocolVersion = new ProtocolVersion("http", 1, 1);
    StatusLine statusLine = new BasicStatusLine(protocolVersion, 500, "Internal Server Error");
    HttpResponse httpResponse = new BasicHttpResponse(statusLine);

    String responseBody = "{\"error\":{\"root_cause\": {}}}";
    boolean hasBody = getRandom().nextBoolean();
    if (hasBody) {
        HttpEntity entity;/*  www.ja va2s .  com*/
        if (getRandom().nextBoolean()) {
            entity = new StringEntity(responseBody, ContentType.APPLICATION_JSON);
        } else {
            //test a non repeatable entity
            entity = new InputStreamEntity(
                    new ByteArrayInputStream(responseBody.getBytes(StandardCharsets.UTF_8)),
                    ContentType.APPLICATION_JSON);
        }
        httpResponse.setEntity(entity);
    }

    RequestLine requestLine = new BasicRequestLine("GET", "/", protocolVersion);
    HttpHost httpHost = new HttpHost("localhost", 9200);
    Response response = new Response(requestLine, httpHost, httpResponse);
    ResponseException responseException = new ResponseException(response);

    assertSame(response, responseException.getResponse());
    if (hasBody) {
        assertEquals(responseBody, EntityUtils.toString(responseException.getResponse().getEntity()));
    } else {
        assertNull(responseException.getResponse().getEntity());
    }

    String message = response.getRequestLine().getMethod() + " " + response.getHost()
            + response.getRequestLine().getUri() + ": " + response.getStatusLine().toString();
    if (hasBody) {
        message += "\n" + responseBody;
    }
    assertEquals(message, responseException.getMessage());
}