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

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

Introduction

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

Prototype

public BasicHttpRequest(RequestLine requestLine) 

Source Link

Usage

From source file:com.subgraph.vega.internal.http.proxy.VegaHttpRequestFactory.java

@Override
public HttpRequest newHttpRequest(final RequestLine requestLine) throws MethodNotSupportedException {
    if (isConnectMethod(requestLine.getMethod())) {
        return new BasicHttpRequest(requestLine);
    } else {/*from   w  w  w .j  a v  a  2s  . c  o  m*/
        return super.newHttpRequest(requestLine);
    }
}

From source file:org.callimachusproject.server.util.AnyHttpMethodRequestFactory.java

public HttpRequest newHttpRequest(final RequestLine requestline) throws MethodNotSupportedException {
    if (requestline == null) {
        throw new IllegalArgumentException("Request line may not be null");
    }/*from w  w w  .  j  a v  a 2s  .  c  o  m*/
    String method = requestline.getMethod();
    if (NO_ENTITY_METHODS.contains(method)) {
        return new BasicHttpRequest(requestline);
    } else {
        return new BasicHttpEntityEnclosingRequest(requestline);
    }
}

From source file:com.subgraph.vega.internal.http.requests.RequestCopyHeadersInterceptor.java

private HttpRequest copyBasicRequest(HttpRequest request) {
    if (request == null)
        return null;
    final HttpRequest r = new BasicHttpRequest(request.getRequestLine());
    copyHeaders(request, r);/*  w ww. ja v  a2  s  . com*/
    return r;
}

From source file:com.subgraph.vega.internal.model.requests.HttpMessageCloner.java

private HttpRequest copyBasicRequest(HttpRequest request) {
    if (request == null) {
        return null;
    }// w w w . j  a v a2s  .  co m
    final HttpRequest r = new BasicHttpRequest(request.getRequestLine());
    copyHeaders(request, r);
    return r;
}

From source file:ste.web.http.velocity.BugFreeVelocityHandler.java

@Test
public void parameters() throws Exception {

    QueryString qs = QueryString.create();
    qs.set(TEST_URL_PARAM1, TEST_VALUE1);
    qs.set(TEST_URL_PARAM2, TEST_VALUE2);
    qs.set(TEST_URL_PARAM3, TEST_VALUE3);

    BasicRequestLine req = new BasicRequestLine("GET", qs.apply(new URI("index.v")).toString(),
            HttpVersion.HTTP_1_1);/* w w w.j a v a2  s .c  om*/

    context.setAttribute(ATTR_VIEW, TEST_VIEW2);

    handler.setViewsFolder("/views");
    handler.handle(new BasicHttpRequest(req), response, context);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    response.getEntity().writeTo(baos);
    then(baos.toString()).isEqualTo(String.format("Second (%s,%s,%s)", TEST_VALUE1, TEST_VALUE2, TEST_VALUE3));
}

From source file:org.eclipse.californium.proxy.HttpTranslator.java

/**
 * Gets the http request starting from a CoAP request. The method creates
 * the HTTP request through its request line. The request line is built with
 * the uri coming from the string representing the CoAP method and the uri
 * obtained from the proxy-uri option. If a payload is provided, the HTTP
 * request encloses an HTTP entity and consequently the content-type is set.
 * Finally, the CoAP options are mapped to the HTTP headers.
 * /*from w ww  .  ja  v a2  s .  c  o  m*/
 * @param coapRequest
 *            the coap request
 * 
 * 
 * 
 * @return the http request * @throws TranslationException the translation
 *         exception * @throws URISyntaxException the uRI syntax exception
 */
public static HttpRequest getHttpRequest(Request coapRequest) throws TranslationException {
    if (coapRequest == null) {
        throw new IllegalArgumentException("coapRequest == null");
    }

    HttpRequest httpRequest = null;

    String coapMethod = null;
    switch (coapRequest.getCode()) {
    case GET:
        coapMethod = "GET";
        break;
    case POST:
        coapMethod = "POST";
        break;
    case PUT:
        coapMethod = "PUT";
        break;
    case DELETE:
        coapMethod = "DELETE";
        break;
    }

    // get the proxy-uri
    URI proxyUri;
    try {
        /*
         * The new draft (14) only allows one proxy-uri option. Thus, this
         * code segment has changed.
         */
        String proxyUriString = URLDecoder.decode(coapRequest.getOptions().getProxyUri(), "UTF-8");
        proxyUri = new URI(proxyUriString);
    } catch (UnsupportedEncodingException e) {
        LOGGER.warning("UTF-8 do not support this encoding: " + e);
        throw new TranslationException("UTF-8 do not support this encoding", e);
    } catch (URISyntaxException e) {
        LOGGER.warning("Cannot translate the server uri" + e);
        throw new InvalidFieldException("Cannot get the proxy-uri from the coap message", e);
    }

    // create the requestLine
    RequestLine requestLine = new BasicRequestLine(coapMethod, proxyUri.toString(), HttpVersion.HTTP_1_1);

    // get the http entity
    HttpEntity httpEntity = getHttpEntity(coapRequest);

    // create the http request
    if (httpEntity == null) {
        httpRequest = new BasicHttpRequest(requestLine);
    } else {
        httpRequest = new BasicHttpEntityEnclosingRequest(requestLine);
        ((HttpEntityEnclosingRequest) httpRequest).setEntity(httpEntity);

        // get the content-type from the entity and set the header
        ContentType contentType = ContentType.get(httpEntity);
        httpRequest.setHeader("content-type", contentType.toString());
    }

    // set the headers
    Header[] headers = getHttpHeaders(coapRequest.getOptions().asSortedList(), "");
    for (Header header : headers) {
        httpRequest.addHeader(header);
    }

    return httpRequest;
}