當前位置: 首頁>>代碼示例>>Java>>正文


Java BasicHttpEntityEnclosingRequest.setEntity方法代碼示例

本文整理匯總了Java中org.apache.http.message.BasicHttpEntityEnclosingRequest.setEntity方法的典型用法代碼示例。如果您正苦於以下問題:Java BasicHttpEntityEnclosingRequest.setEntity方法的具體用法?Java BasicHttpEntityEnclosingRequest.setEntity怎麽用?Java BasicHttpEntityEnclosingRequest.setEntity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.message.BasicHttpEntityEnclosingRequest的用法示例。


在下文中一共展示了BasicHttpEntityEnclosingRequest.setEntity方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testResponsesToPOSTWithoutCacheControlOrExpiresAreNotCached

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testResponsesToPOSTWithoutCacheControlOrExpiresAreNotCached() throws Exception {
    emptyMockCacheExpectsNoPuts();

    final BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/",
            HttpVersion.HTTP_1_1);
    post.setHeader("Content-Length", "128");
    post.setEntity(HttpTestUtils.makeBody(128));

    originResponse.removeHeaders("Cache-Control");
    originResponse.removeHeaders("Expires");

    EasyMock.expect(
            mockBackend.execute(
                    EasyMock.isA(HttpRoute.class),
                    EasyMock.isA(HttpRequestWrapper.class),
                    EasyMock.isA(HttpClientContext.class),
                    EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);

    replayMocks();

    impl.execute(route, HttpRequestWrapper.wrap(post), context, null);

    verifyMocks();
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:26,代碼來源:TestProtocolRequirements.java

示例2: testResponsesToPUTsAreNotCached

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testResponsesToPUTsAreNotCached() throws Exception {
    emptyMockCacheExpectsNoPuts();

    final BasicHttpEntityEnclosingRequest put = new BasicHttpEntityEnclosingRequest("PUT", "/",
            HttpVersion.HTTP_1_1);
    put.setEntity(HttpTestUtils.makeBody(128));
    put.addHeader("Content-Length", "128");

    originResponse.setHeader("Cache-Control", "max-age=3600");

    EasyMock.expect(
            mockBackend.execute(
                    EasyMock.isA(HttpRoute.class),
                    EasyMock.isA(HttpRequestWrapper.class),
                    EasyMock.isA(HttpClientContext.class),
                    EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);

    replayMocks();

    impl.execute(route, HttpRequestWrapper.wrap(put), context, null);

    verifyMocks();
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:25,代碼來源:TestProtocolRequirements.java

示例3: testDoesNotModifyHeaderOnRequest

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
private void testDoesNotModifyHeaderOnRequest(final String header, final String value) throws Exception {
    final BasicHttpEntityEnclosingRequest req =
        new BasicHttpEntityEnclosingRequest("POST","/",HttpVersion.HTTP_1_1);
    req.setEntity(HttpTestUtils.makeBody(128));
    req.setHeader("Content-Length","128");
    req.setHeader(header,value);

    final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();

    EasyMock.expect(
            mockBackend.execute(
                    EasyMock.eq(route),
                    EasyMock.capture(cap),
                    EasyMock.isA(HttpClientContext.class),
                    EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);

    replayMocks();
    impl.execute(route, HttpRequestWrapper.wrap(req), context, null);
    verifyMocks();

    final HttpRequest captured = cap.getValue();
    Assert.assertEquals(value, captured.getFirstHeader(header).getValue());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:24,代碼來源:TestProtocolRequirements.java

示例4: testDoesNotAddHeaderToRequestIfNotPresent

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
private void testDoesNotAddHeaderToRequestIfNotPresent(final String header) throws Exception {
    final BasicHttpEntityEnclosingRequest req =
        new BasicHttpEntityEnclosingRequest("POST","/",HttpVersion.HTTP_1_1);
    req.setEntity(HttpTestUtils.makeBody(128));
    req.setHeader("Content-Length","128");
    req.removeHeaders(header);

    final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();

    EasyMock.expect(
            mockBackend.execute(
                    EasyMock.eq(route),
                    EasyMock.capture(cap),
                    EasyMock.isA(HttpClientContext.class),
                    EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);

    replayMocks();
    impl.execute(route, HttpRequestWrapper.wrap(req), context, null);
    verifyMocks();

    final HttpRequest captured = cap.getValue();
    Assert.assertNull(captured.getFirstHeader(header));
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:24,代碼來源:TestProtocolRequirements.java

示例5: testHTTP1_1RequestsWithBodiesOfKnownLengthMustHaveContentLength

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Ignore
public void testHTTP1_1RequestsWithBodiesOfKnownLengthMustHaveContentLength() throws Exception {
    final BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/",
            HTTP_1_1);
    post.setEntity(mockEntity);

    replayMocks();

    final HttpResponse response = impl.execute(route, HttpRequestWrapper.wrap(post), context, null);

    verifyMocks();

    Assert
            .assertEquals(HttpStatus.SC_LENGTH_REQUIRED, response.getStatusLine()
                    .getStatusCode());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:17,代碼來源:TestProtocolDeviations.java

示例6: createRealRequest

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
/**
 * Creates a request that can be accepted by the AndroidHttpClient
 * @param request The request information
 * @throws UnsupportedEncodingException
 */
private static BasicHttpEntityEnclosingRequest createRealRequest(Request request) throws UnsupportedEncodingException {
	BasicHttpEntityEnclosingRequest realRequest = new BasicHttpEntityEnclosingRequest(request.getVerb(), request.getUrl());

	if (request.getContent() != null) {
		realRequest.setEntity(new ByteArrayEntity(request.getContent()));
	}

	Map<String, String> headers = request.getHeaders();

	for (String key : headers.keySet()) {
		realRequest.addHeader(key, headers.get(key));
	}

	return realRequest;
}
 
開發者ID:ashank,項目名稱:Office-365-SDK-for-Android,代碼行數:21,代碼來源:FroyoHttpConnection.java

示例7: proxyRequest

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
/**
 * For the given servlet request, return a new request object (for use with
 * Apache HttpClient), that may be executed in place of the original request
 * to make the real service call.
 *
 * @throws javax.servlet.ServletException
 */
private HttpUriRequest proxyRequest(HttpServletRequest request) throws ServletException,
        IOException {
    String newUri = serviceUriForRequest(request);

    BasicHttpEntityEnclosingRequest httpRequest
            = new BasicHttpEntityEnclosingRequest(request.getMethod(), newUri);
    HttpEntity entity = new InputStreamEntity(request.getInputStream(),
            request.getContentLength());
    httpRequest.setEntity(entity);

    try {
        // Sadly have to do this to set the URI; it is not derived from the original httpRequest
        HttpRequestWrapper wrappedRequest = HttpRequestWrapper.wrap(httpRequest);
        wrappedRequest.setURI(new URI(newUri));

        // Somehow, content type header does not come in the original request either
        wrappedRequest.setHeader("Content-Type", "application/json");

        return wrappedRequest;
    } catch (URISyntaxException e) {
        LOGGER.error("Syntax exception in service URI, " + newUri, e);
        throw new LightblueServletException("Syntax exception in service URI, " + newUri, e);
    }
}
 
開發者ID:lightblue-platform,項目名稱:lightblue-client,代碼行數:32,代碼來源:AbstractLightblueProxyServlet.java

示例8: generateRequest

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
public HttpRequest generateRequest() {
    synchronized (this.httpExchange) {
        HttpRequest request = this.httpExchange.getRequest();
        System.out.println("[proxy->origin] " + this.httpExchange.getId() + " " + request.getRequestLine());
        ConsoleFactory.printToConsole("[proxy->origin] " + this.httpExchange.getId() + " " + request.getRequestLine(),true);
        // Rewrite request!!!!
        if (request instanceof HttpEntityEnclosingRequest) {
            BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest(
                    request.getRequestLine());
            r.setEntity(((HttpEntityEnclosingRequest) request).getEntity());
            return r;
        } else {
            return new BasicHttpRequest(request.getRequestLine());
        }
    }
}
 
開發者ID:HuaweiSNC,項目名稱:OpsDev,代碼行數:17,代碼來源:NHttpReverseProxy.java

示例9: testJsonBody

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testJsonBody() throws Exception {
    MyController controller = new MyController();

    ReflectionControllerRequestHandler handler = new ControllerBuilder(new GsonBuilder().create())
            .addController(controller)
            .withPathPrefix("/")
            .create();


    HttpCoreContext context = HttpCoreContext.create();
    BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("PUT", "/stuff/putthis");
    request.setHeader("Content-Type", "application/json");
    request.setEntity(new StringEntity("{ \"name\": \"paul\" }"));


    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, ""));

    handler.handle(request, response, context);

    assertTrue(response.getStatusLine().getStatusCode() == 200);
    String resultBody = EntityUtils.toString(response.getEntity());
    assertTrue("itworked".equals(resultBody));
}
 
開發者ID:dinocore1,項目名稱:MiniWeb,代碼行數:25,代碼來源:ReflectionControllerTest.java

示例10: performRegistration

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
public void performRegistration() throws Exception {
  String nodeConfigString = getNodeConfig().toString();
  log.info("Registering Selendroid node with following config:\n" + nodeConfigString + "\n" +
          "at Selenium Grid hub: " + hub.toExternalForm());

  BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST",
          hub.toExternalForm());
  request.setEntity(new StringEntity(nodeConfigString));

  HttpResponse response = getHttpClient().execute(getHttpHost(), request);

  if (response.getStatusLine().getStatusCode() != 200) {
    throw new SelendroidException("Error sending the registration request. Response from server: " +
            response.getStatusLine().toString());
  }
}
 
開發者ID:selendroid,項目名稱:selendroid,代碼行數:17,代碼來源:SelfRegisteringRemote.java

示例11: buildLogHttpRequest

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
private HttpRequest buildLogHttpRequest(String content) throws UnsupportedEncodingException {
    BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/log");
    BasicHttpEntity entity = new BasicHttpEntity();
    entity.setContent(new ByteArrayInputStream(content.getBytes("UTF-8")));
    request.setEntity(entity);
    return request;
}
 
開發者ID:geminiKim,項目名稱:logregator,代碼行數:8,代碼來源:HttpCollectorHandlerTest.java

示例12: testOrderOfMultipleAllowHeadersIsPreservedOnRequests

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testOrderOfMultipleAllowHeadersIsPreservedOnRequests() throws Exception {
    final BasicHttpEntityEnclosingRequest put = new BasicHttpEntityEnclosingRequest("PUT", "/",
            HttpVersion.HTTP_1_1);
    put.setEntity(body);
    put.addHeader("Allow", "GET, HEAD");
    put.addHeader("Allow", "DELETE");
    put.addHeader("Content-Length", "128");
    testOrderOfMultipleHeadersIsPreservedOnRequests("Allow", HttpRequestWrapper.wrap(put));
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:11,代碼來源:TestProtocolRequirements.java

示例13: testOrderOfMultipleContentEncodingHeadersIsPreservedOnRequests

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testOrderOfMultipleContentEncodingHeadersIsPreservedOnRequests() throws Exception {
    final BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/",
            HttpVersion.HTTP_1_1);
    post.setEntity(body);
    post.addHeader("Content-Encoding", "gzip");
    post.addHeader("Content-Encoding", "compress");
    post.addHeader("Content-Length", "128");
    testOrderOfMultipleHeadersIsPreservedOnRequests("Content-Encoding", HttpRequestWrapper.wrap(post));
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:11,代碼來源:TestProtocolRequirements.java

示例14: testOrderOfMultipleContentLanguageHeadersIsPreservedOnRequests

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testOrderOfMultipleContentLanguageHeadersIsPreservedOnRequests() throws Exception {
    final BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/",
            HttpVersion.HTTP_1_1);
    post.setEntity(body);
    post.addHeader("Content-Language", "mi");
    post.addHeader("Content-Language", "en");
    post.addHeader("Content-Length", "128");
    testOrderOfMultipleHeadersIsPreservedOnRequests("Content-Language", HttpRequestWrapper.wrap(post));
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:11,代碼來源:TestProtocolRequirements.java

示例15: testOrderOfMultipleExpectHeadersIsPreservedOnRequests

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testOrderOfMultipleExpectHeadersIsPreservedOnRequests() throws Exception {
    final BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/",
            HttpVersion.HTTP_1_1);
    post.setEntity(body);
    post.addHeader("Expect", "100-continue");
    post.addHeader("Expect", "x-expect=true");
    post.addHeader("Content-Length", "128");
    testOrderOfMultipleHeadersIsPreservedOnRequests("Expect", HttpRequestWrapper.wrap(post));
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:11,代碼來源:TestProtocolRequirements.java


注:本文中的org.apache.http.message.BasicHttpEntityEnclosingRequest.setEntity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。