Java 类org.apache.http.message.BasicRequestLine 实例源码

项目:purecloud-iot    文件:HttpRequestWrapper.java   
@Override
public RequestLine getRequestLine() {
    if (this.requestLine == null) {
        String requestUri;
        if (this.uri != null) {
            requestUri = this.uri.toASCIIString();
        } else {
            requestUri = this.original.getRequestLine().getUri();
        }
        if (requestUri == null || requestUri.isEmpty()) {
            requestUri = "/";
        }
        this.requestLine = new BasicRequestLine(this.method, requestUri, getProtocolVersion());
    }
    return this.requestLine;
}
项目:sana.mobile    文件:DispatchRequestFactory.java   
@Override
public HttpRequest newHttpRequest(String method, String uri)
        throws MethodNotSupportedException {
    RequestLine line = new BasicRequestLine(method, uri, HttpVersion.HTTP_1_1);

    HttpUriRequest request = null;
    if(method.equals(HttpGet.METHOD_NAME)){
        request = new HttpGet(uri);
    }else if(method.equals(HttpPost.METHOD_NAME)){
        request = new HttpPost(uri);
    }else if(method.equals(HttpPut.METHOD_NAME)){
        request = new HttpPut(uri);
    }else if(method.equals(HttpPut.METHOD_NAME)){
        request = new HttpDelete(uri);
    }
    return request;
}
项目:holico    文件:HttpTranslatorTest.java   
@Test
public final void getCoapRequestLocalResourceTest() throws TranslationException {
    String resourceName = "localResource";
    String resourceString = "/" + resourceName;

    for (String httpMethod : COAP_METHODS) {
        // create the http request
        RequestLine requestLine = new BasicRequestLine(httpMethod, resourceString, HttpVersion.HTTP_1_1);
        HttpRequest httpRequest = new BasicHttpRequest(requestLine);

        // translate the request
        Request coapRequest = HttpTranslator.getCoapRequest(httpRequest, PROXY_RESOURCE, true);
        assertNotNull(coapRequest);

        // check the method translation
        int coapMethod = Integer.parseInt(HttpTranslator.HTTP_TRANSLATION_PROPERTIES.getProperty("http.request.method." + httpMethod));
        assertTrue(coapRequest.getCode() == coapMethod);

        // check the uri-path
        String uriPath = coapRequest.getFirstOption(OptionNumberRegistry.URI_PATH).getStringValue();
        assertEquals(uriPath, resourceName);

        // check the absence of the proxy-uri option
        assertNull(coapRequest.getFirstOption(OptionNumberRegistry.PROXY_URI));
    }
}
项目:irond    文件:BasicAccessAuthenticationTest.java   
private HttpRequest getHttpRequest(String user, String pass){
    HttpRequestFactory factory = new DefaultHttpRequestFactory();
    HttpRequest req = null;
    String base64 = new String(Base64.encodeBase64(
            user.concat(":").concat(pass).getBytes()));
    try {
        req = factory.newHttpRequest(
                new BasicRequestLine("POST", "https://localhost:8444/",
                        HttpVersion.HTTP_1_1));
        req.addHeader("Accept-Encoding", "gzip,deflate");
        req.addHeader("Content-Type", "application/soap+xml;charset=UTF-8");
        req.addHeader("User-Agent", "IROND Testsuite/1.0");
        req.addHeader("Host", "localhost:8444");
        req.addHeader("Content-Length", "198");
        req.addHeader("Authorization", "Basic "+base64);
    } catch (MethodNotSupportedException e) {
        e.printStackTrace();
    }
    return req;
}
项目:elasticsearch_my    文件:SyncResponseListenerTests.java   
private static Response mockResponse() {
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    RequestLine requestLine = new BasicRequestLine("GET", "/", protocolVersion);
    StatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "OK");
    HttpResponse httpResponse = new BasicHttpResponse(statusLine);
    return new Response(requestLine, new HttpHost("localhost", 9200), httpResponse);
}
项目:elasticsearch_my    文件:FailureTrackingResponseListenerTests.java   
private static Response mockResponse() {
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    RequestLine requestLine = new BasicRequestLine("GET", "/", protocolVersion);
    StatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "OK");
    HttpResponse httpResponse = new BasicHttpResponse(statusLine);
    return new Response(requestLine, new HttpHost("localhost", 9200), httpResponse);
}
项目:lams    文件:HttpRequestBase.java   
public RequestLine getRequestLine() {
    String method = getMethod();
    ProtocolVersion ver = getProtocolVersion();
    URI uri = getURI();
    String uritext = null;
    if (uri != null) {
        uritext = uri.toASCIIString();
    }
    if (uritext == null || uritext.length() == 0) {
        uritext = "/";
    }
    return new BasicRequestLine(method, uritext, ver);
}
项目:lams    文件:RequestWrapper.java   
public RequestLine getRequestLine() {
    String method = getMethod();
    ProtocolVersion ver = getProtocolVersion();
    String uritext = null;
    if (uri != null) {
        uritext = uri.toASCIIString();
    }
    if (uritext == null || uritext.length() == 0) {
        uritext = "/";
    }
    return new BasicRequestLine(method, uritext, ver);
}
项目:messagemedia-rest-api-java-sdk    文件: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));
}
项目:remote-files-sync    文件:HttpRequestWrapper.java   
public RequestLine getRequestLine() {
    String requestUri = null;
    if (this.uri != null) {
        requestUri = this.uri.toASCIIString();
    } else {
        requestUri = this.original.getRequestLine().getUri();
    }
    if (requestUri == null || requestUri.length() == 0) {
        requestUri = "/";
    }
    return new BasicRequestLine(this.method, requestUri, getProtocolVersion());
}
项目:remote-files-sync    文件:HttpRequestBaseHC4.java   
public RequestLine getRequestLine() {
    final String method = getMethod();
    final ProtocolVersion ver = getProtocolVersion();
    final URI uri = getURI();
    String uritext = null;
    if (uri != null) {
        uritext = uri.toASCIIString();
    }
    if (uritext == null || uritext.length() == 0) {
        uritext = "/";
    }
    return new BasicRequestLine(method, uritext, ver);
}
项目:purecloud-iot    文件:HttpRequestBase.java   
@Override
public RequestLine getRequestLine() {
    final String method = getMethod();
    final ProtocolVersion ver = getProtocolVersion();
    final URI uriCopy = getURI(); // avoids possible window where URI could be changed
    String uritext = null;
    if (uriCopy != null) {
        uritext = uriCopy.toASCIIString();
    }
    if (uritext == null || uritext.isEmpty()) {
        uritext = "/";
    }
    return new BasicRequestLine(method, uritext, ver);
}
项目:purecloud-iot    文件:RequestWrapper.java   
@Override
public RequestLine getRequestLine() {
    final ProtocolVersion ver = getProtocolVersion();
    String uritext = null;
    if (uri != null) {
        uritext = uri.toASCIIString();
    }
    if (uritext == null || uritext.isEmpty()) {
        uritext = "/";
    }
    return new BasicRequestLine(getMethod(), uritext, ver);
}
项目:purecloud-iot    文件:InternalHttpRequest.java   
@Override
public RequestLine getRequestLine() {
    final ProtocolVersion ver = getProtocolVersion();
    final URI uriCopy = getURI();
    String uritext = null;
    if (uriCopy != null) {
        uritext = uriCopy.toASCIIString();
    }
    if (uritext == null || uritext.isEmpty()) {
        uritext = "/";
    }
    return new BasicRequestLine(getMethod(), uritext, ver);
}
项目:Visit    文件:HttpRequestWrapper.java   
public RequestLine getRequestLine() {
    String requestUri = null;
    if (this.uri != null) {
        requestUri = this.uri.toASCIIString();
    } else {
        requestUri = this.original.getRequestLine().getUri();
    }
    if (requestUri == null || requestUri.length() == 0) {
        requestUri = "/";
    }
    return new BasicRequestLine(this.method, requestUri, getProtocolVersion());
}
项目:Visit    文件:HttpRequestBaseHC4.java   
public RequestLine getRequestLine() {
    final String method = getMethod();
    final ProtocolVersion ver = getProtocolVersion();
    final URI uri = getURI();
    String uritext = null;
    if (uri != null) {
        uritext = uri.toASCIIString();
    }
    if (uritext == null || uritext.length() == 0) {
        uritext = "/";
    }
    return new BasicRequestLine(method, uritext, ver);
}
项目:cJUnit-mc626    文件:HttpRequestBase.java   
public RequestLine getRequestLine() {
    String method = getMethod();
    ProtocolVersion ver = getProtocolVersion();
    URI uri = getURI();
    String uritext = null;
    if (uri != null) {
        uritext = uri.toASCIIString();
    }
    if (uritext == null || uritext.length() == 0) {
        uritext = "/";
    }
    return new BasicRequestLine(method, uritext, ver);
}
项目:cJUnit-mc626    文件:RequestWrapper.java   
public RequestLine getRequestLine() {
    String method = getMethod();
    ProtocolVersion ver = getProtocolVersion();
    String uritext = null;
    if (uri != null) {
        uritext = uri.toASCIIString();
    }
    if (uritext == null || uritext.length() == 0) {
        uritext = "/";
    }
    return new BasicRequestLine(method, uritext, ver);
}
项目:ZTLib    文件:HttpRequestWrapper.java   
public RequestLine getRequestLine() {
    String requestUri = null;
    if (this.uri != null) {
        requestUri = this.uri.toASCIIString();
    } else {
        requestUri = this.original.getRequestLine().getUri();
    }
    if (requestUri == null || requestUri.length() == 0) {
        requestUri = "/";
    }
    return new BasicRequestLine(this.method, requestUri, getProtocolVersion());
}
项目:ZTLib    文件:HttpRequestBaseHC4.java   
public RequestLine getRequestLine() {
    final String method = getMethod();
    final ProtocolVersion ver = getProtocolVersion();
    final URI uri = getURI();
    String uritext = null;
    if (uri != null) {
        uritext = uri.toASCIIString();
    }
    if (uritext == null || uritext.length() == 0) {
        uritext = "/";
    }
    return new BasicRequestLine(method, uritext, ver);
}
项目:holico    文件:HttpTranslatorTest.java   
@Test(expected = TranslationException.class)
public final void getCoapRequestConnectMethodTest() throws TranslationException {
    RequestLine requestLine = new BasicRequestLine("connect", "http://localhost", HttpVersion.HTTP_1_1);
    HttpRequest httpRequest = new BasicHttpRequest(requestLine);

    HttpTranslator.getCoapRequest(httpRequest, "", true);
}
项目:holico    文件:HttpTranslatorTest.java   
@Test(expected = TranslationException.class)
public final void getCoapRequestOptionsMethodTest() throws TranslationException {
    RequestLine requestLine = new BasicRequestLine("options", "http://localhost", HttpVersion.HTTP_1_1);
    HttpRequest httpRequest = new BasicHttpRequest(requestLine);

    HttpTranslator.getCoapRequest(httpRequest, "", true);
}
项目:holico    文件:HttpTranslatorTest.java   
@Test(expected = TranslationException.class)
public final void getCoapRequestTraceMethodTest() throws TranslationException {
    RequestLine requestLine = new BasicRequestLine("trace", "/resource", HttpVersion.HTTP_1_1);
    HttpRequest httpRequest = new BasicHttpRequest(requestLine);

    HttpTranslator.getCoapRequest(httpRequest, "", true);
}
项目:holico    文件:HttpTranslatorTest.java   
@Test(expected = TranslationException.class)
public final void getCoapRequestUnknownMethodTest() throws TranslationException {
    RequestLine requestLine = new BasicRequestLine("UNKNOWN", "/resource", HttpVersion.HTTP_1_1);
    HttpRequest httpRequest = new BasicHttpRequest(requestLine);

    HttpTranslator.getCoapRequest(httpRequest, "", true);
}
项目:holico    文件:HttpTranslatorTest.java   
/**
 * @param coapServerUri
 * @param uri
 * @throws TranslationException
 */
private void getCoapRequestTemplateTest(String coapServerUri, String uri) throws TranslationException {
    for (String httpMethod : COAP_METHODS) {
        // create the http request
        RequestLine requestLine = new BasicRequestLine(httpMethod, uri, HttpVersion.HTTP_1_1);
        HttpRequest httpRequest = new BasicHttpRequest(requestLine);

        // translate the request
        Request coapRequest = HttpTranslator.getCoapRequest(httpRequest, PROXY_RESOURCE, true);
        assertNotNull(coapRequest);

        // check the method translation
        int coapMethod = Integer.parseInt(HttpTranslator.HTTP_TRANSLATION_PROPERTIES.getProperty("http.request.method." + httpMethod));
        assertTrue(coapRequest.getCode() == coapMethod);

        // check the proxy-uri
        String proxyUri = coapRequest.getFirstOption(OptionNumberRegistry.PROXY_URI).getStringValue();

        if (!proxyUri.equals(coapServerUri)) {
            try {
                coapServerUri = URLDecoder.decode(coapServerUri, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        if (!coapServerUri.contains("coap://")) {
            coapServerUri = "coap://" + coapServerUri;
        }
        assertEquals(proxyUri, coapServerUri);

        // check the absence of the uri-* options
        assertNull(coapRequest.getFirstOption(OptionNumberRegistry.URI_PATH));
        assertNull(coapRequest.getFirstOption(OptionNumberRegistry.URI_HOST));
        assertNull(coapRequest.getFirstOption(OptionNumberRegistry.URI_QUERY));
        assertNull(coapRequest.getFirstOption(OptionNumberRegistry.URI_PORT));
    }
}
项目:BUbiNG    文件:StringHttpMessages.java   
public HttpRequest(final String method, final String url) {
    this.requestLine = new BasicRequestLine(method, url, PROTOCOL_VERSION);
}
项目:BUbiNG    文件:RandomTestMocks.java   
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);
}
项目:Bastion    文件:HttpRequestPrinter.java   
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");
}
项目:aws-signing-request-interceptor    文件:AWSSigningRequestInterceptorTest.java   
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);
}
项目:holico    文件:HttpTranslatorTest.java   
@Test
public final void getCoapRequestPayloadTest() throws TranslationException {
    String coapServerUri = "coap://coapServer:5684/helloWorld";

    for (String httpMethod : COAP_METHODS) {
        // create the http request
        RequestLine requestLine = new BasicRequestLine(httpMethod, "/" + PROXY_RESOURCE + "/" + coapServerUri, HttpVersion.HTTP_1_1);
        BasicHttpEntityEnclosingRequest httpRequest = new BasicHttpEntityEnclosingRequest(requestLine);

        // create the entity
        String contentString = "aaa";
        HttpEntity httpEntity = new ByteArrayEntity(contentString.getBytes(Charset.forName("ISO_8859_1")), ContentType.TEXT_PLAIN);
        httpRequest.setEntity(httpEntity);

        // set the content-type
        httpRequest.setHeader("content-type", "text/plain;  charset=iso-8859-1");

        // create the header
        String headerName = "if-match";
        String headerValue = "\"737060cd8c284d8af7ad3082f209582d\"";
        Header header = new BasicHeader(headerName, headerValue);
        httpRequest.addHeader(header);

        // translate the request
        Request coapRequest = HttpTranslator.getCoapRequest(httpRequest, PROXY_RESOURCE, true);
        assertNotNull(httpRequest);

        // check the method translation
        int coapMethod = Integer.parseInt(HttpTranslator.HTTP_TRANSLATION_PROPERTIES.getProperty("http.request.method." + httpMethod));
        assertTrue(coapRequest.getCode() == coapMethod);

        // check the proxy-uri
        String proxyUri = coapRequest.getFirstOption(OptionNumberRegistry.PROXY_URI).getStringValue();
        assertEquals(proxyUri, coapServerUri);

        // check the absence of the uri-* options
        assertNull(coapRequest.getFirstOption(OptionNumberRegistry.URI_PATH));
        assertNull(coapRequest.getFirstOption(OptionNumberRegistry.URI_HOST));
        assertNull(coapRequest.getFirstOption(OptionNumberRegistry.URI_QUERY));
        assertNull(coapRequest.getFirstOption(OptionNumberRegistry.URI_PORT));

        // check the payload
        assertNotNull(coapRequest.getPayload());
        assertArrayEquals(contentString.getBytes(Charset.forName("UTF-8")), coapRequest.getPayload());

        // check the option
        assertFalse(coapRequest.getOptions().isEmpty());
        int optionNumber = Integer.parseInt(HttpTranslator.HTTP_TRANSLATION_PROPERTIES.getProperty("http.message.header." + headerName));
        assertEquals(coapRequest.getFirstOption(optionNumber).getStringValue(), headerValue);

        // check the content-type
        assertEquals(coapRequest.getContentType(), MediaTypeRegistry.TEXT_PLAIN);
    }
}