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


Java BasicHttpResponse.setEntity方法代碼示例

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


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

示例1: post_whenResponseIsFailure_logsException

import org.apache.http.message.BasicHttpResponse; //導入方法依賴的package包/類
@Test
public void post_whenResponseIsFailure_logsException() throws IOException {
    ArgumentCaptor<HttpPost> requestCaptor = ArgumentCaptor.forClass(HttpPost.class);
    HttpClient httpClient = mock(HttpClient.class);
    BasicHttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("http", 1, 1), 400, ""));
    response.setEntity(new StringEntity("failure reason here"));

    when(httpClient.execute(requestCaptor.capture())).thenReturn(response);

    MsTeamsNotification w = factory.getMsTeamsNotification(httpClient);

    MsTeamsNotificationPayloadContent content = new MsTeamsNotificationPayloadContent();
    content.setBuildDescriptionWithLinkSyntax("http://foo");
    content.setCommits(new ArrayList<Commit>());

    w.setPayload(content);
    w.setEnabled(true);
    w.post();

    assertNotNull(w.getResponse());
    assertFalse(w.getResponse().getOk());
}
 
開發者ID:spyder007,項目名稱:teamcity-msteams-notifier,代碼行數:23,代碼來源:MsTeamsNotificationTest.java

示例2: createOkSearchResponse

import org.apache.http.message.BasicHttpResponse; //導入方法依賴的package包/類
private BasicHttpResponse createOkSearchResponse() throws UnsupportedEncodingException {
    BasicHttpResponse okSearchResponse = createOkResponse();
    HttpEntity searchResponseEntity = new StringEntity("" +
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
            "   <D:multistatus xmlns:D=\"DAV:\"\n" +
            "      xmlns:R=\"http://example.org/propschema\">\n" +
            "     <D:response>" +
            "       <D:propstat>\n" +
            "       <uid>Inbox</uid>" +
            "       <href>http://example.org/Exchange/user/Inbox</href>\n" +
            "     </D:propstat></D:response>\n" +
            "     <D:response>" +
            "       <D:propstat>\n" +
            "       <uid>Drafts</uid>" +
            "       <href>http://example.org/Exchange/user/Drafts</href>\n" +
            "     </D:propstat></D:response>\n" +
            "     <D:response>" +
            "       <D:propstat>\n" +
            "       <uid>Folder2</uid>" +
            "       <href>http://example.org/Exchange/user/Folder2</href>\n" +
            "     </D:propstat></D:response>\n" +
            "   </D:multistatus>");
    okSearchResponse.setEntity(searchResponseEntity);

    return okSearchResponse;
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:27,代碼來源:WebDavStoreTest.java

示例3: transformResponse

import org.apache.http.message.BasicHttpResponse; //導入方法依賴的package包/類
private static HttpResponse transformResponse(Response response) {
  int code = response.code();
  String message = response.message();
  BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message);

  ResponseBody body = response.body();
  InputStreamEntity entity = new InputStreamEntity(body.byteStream(), body.contentLength());
  httpResponse.setEntity(entity);

  Headers headers = response.headers();
  for (int i = 0, size = headers.size(); i < size; i++) {
    String name = headers.name(i);
    String value = headers.value(i);
    httpResponse.addHeader(name, value);
    if ("Content-Type".equalsIgnoreCase(name)) {
      entity.setContentType(value);
    } else if ("Content-Encoding".equalsIgnoreCase(name)) {
      entity.setContentEncoding(value);
    }
  }

  return httpResponse;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:OkApacheClient.java

示例4: transformResponse

import org.apache.http.message.BasicHttpResponse; //導入方法依賴的package包/類
private static HttpResponse transformResponse(Response response) throws IOException {
  int code = response.code();
  String message = response.message();
  BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message);

  ResponseBody body = response.body();
  InputStreamEntity entity = new InputStreamEntity(body.byteStream(), body.contentLength());
  httpResponse.setEntity(entity);

  Headers headers = response.headers();
  for (int i = 0, size = headers.size(); i < size; i++) {
    String name = headers.name(i);
    String value = headers.value(i);
    httpResponse.addHeader(name, value);
    if ("Content-Type".equalsIgnoreCase(name)) {
      entity.setContentType(value);
    } else if ("Content-Encoding".equalsIgnoreCase(name)) {
      entity.setContentEncoding(value);
    }
  }

  return httpResponse;
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:24,代碼來源:OkApacheClient.java

示例5: performRequest

import org.apache.http.message.BasicHttpResponse; //導入方法依賴的package包/類
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    String url = request.getUrl();
    HashMap<String, String> map = new HashMap();
    map.putAll(request.getHeaders());
    map.putAll(additionalHeaders);
    if (this.mUrlRewriter != null) {
        String rewritten = this.mUrlRewriter.rewriteUrl(url);
        if (rewritten == null) {
            throw new IOException("URL blocked by rewriter: " + url);
        }
        url = rewritten;
    }
    HttpURLConnection connection = openConnection(new URL(url), request);
    for (String headerName : map.keySet()) {
        connection.addRequestProperty(headerName, (String) map.get(headerName));
    }
    setConnectionParametersForRequest(connection, request);
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    if (connection.getResponseCode() == -1) {
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }
    BasicHttpResponse response = new BasicHttpResponse(new BasicStatusLine(protocolVersion,
            connection.getResponseCode(), connection.getResponseMessage()));
    response.setEntity(entityFromConnection(connection));
    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            response.addHeader(new BasicHeader((String) header.getKey(), (String) ((List)
                    header.getValue()).get(0)));
        }
    }
    return response;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:34,代碼來源:OkHttpStack.java

示例6: createOkResponseWithForm

import org.apache.http.message.BasicHttpResponse; //導入方法依賴的package包/類
private BasicHttpResponse createOkResponseWithForm() {
    BasicHttpResponse okayResponseWithForm = createOkResponse();
    BasicHttpEntity okayResponseWithFormEntity = new BasicHttpEntity();
    String form = "<form action=\"owaauth.dll\"></form>";
    okayResponseWithFormEntity.setContent(new ByteArrayInputStream(form.getBytes()));
    okayResponseWithForm.setEntity(okayResponseWithFormEntity);
    return okayResponseWithForm;
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:9,代碼來源:WebDavStoreTest.java

示例7: performRequest

import org.apache.http.message.BasicHttpResponse; //導入方法依賴的package包/類
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError {
    String url = request.getUrl();
    HashMap<String, String> map = new HashMap();
    map.putAll(request.getHeaders());
    map.putAll(additionalHeaders);
    if (this.mUrlRewriter != null) {
        String rewritten = this.mUrlRewriter.rewriteUrl(url);
        if (rewritten == null) {
            throw new IOException("URL blocked by rewriter: " + url);
        }
        url = rewritten;
    }
    HttpURLConnection connection = openConnection(new URL(url), request);
    for (String headerName : map.keySet()) {
        connection.addRequestProperty(headerName, (String) map.get(headerName));
    }
    setConnectionParametersForRequest(connection, request);
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    if (connection.getResponseCode() == -1) {
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }
    StatusLine responseStatus = new BasicStatusLine(protocolVersion, connection.getResponseCode(), connection.getResponseMessage());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    if (hasResponseBody(request.getMethod(), responseStatus.getStatusCode())) {
        response.setEntity(entityFromConnection(connection));
    }
    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            response.addHeader(new BasicHeader((String) header.getKey(), (String) ((List) header.getValue()).get(0)));
        }
    }
    return response;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:34,代碼來源:HurlStack.java

示例8: performRequest

import org.apache.http.message.BasicHttpResponse; //導入方法依賴的package包/類
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    String url = request.getUrl();
    HashMap<String, String> map = new HashMap<String, String>();
    map.putAll(request.getHeaders());
    map.putAll(additionalHeaders);
    if (mUrlRewriter != null) {
        String rewritten = mUrlRewriter.rewriteUrl(url);
        if (rewritten == null) {
            throw new IOException("URL blocked by rewriter: " + url);
        }
        url = rewritten;
    }
    URL parsedUrl = new URL(url);
    HttpURLConnection connection = openConnection(parsedUrl, request);
    for (String headerName : map.keySet()) {
        connection.addRequestProperty(headerName, map.get(headerName));
    }
    setConnectionParametersForRequest(connection, request);
    // Initialize HttpResponse with data from the HttpURLConnection.
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    int responseCode = connection.getResponseCode();
    if (responseCode == -1) {
        // -1 is returned by getResponseCode() if the response code could not be retrieved.
        // Signal to the caller that something was wrong with the connection.
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }
    StatusLine responseStatus = new BasicStatusLine(protocolVersion,
            connection.getResponseCode(), connection.getResponseMessage());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    if (hasResponseBody(request.getMethod(), responseStatus.getStatusCode())) {
        response.setEntity(entityFromConnection(connection));
    }
    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
            response.addHeader(h);
        }
    }
    return response;
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:43,代碼來源:HurlStack.java

示例9: createHttpResponseProxy

import org.apache.http.message.BasicHttpResponse; //導入方法依賴的package包/類
private static HttpResponseProxy createHttpResponseProxy(HttpEntity entity) {
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    BasicStatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "mock response");
    BasicHttpResponse response = new BasicHttpResponse(statusLine);
    response.setEntity(entity);
    return new HttpResponseProxy(response);
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:8,代碼來源:ClientExecutionAndRequestTimerTestUtils.java

示例10: performRequest

import org.apache.http.message.BasicHttpResponse; //導入方法依賴的package包/類
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    String url = request.getUrl();
    HashMap<String, String> map = new HashMap();
    map.putAll(request.getHeaders());
    map.putAll(additionalHeaders);
    if (this.mUrlRewriter != null) {
        String rewritten = this.mUrlRewriter.rewriteUrl(url);
        if (rewritten == null) {
            throw new IOException("URL blocked by rewriter: " + url);
        }
        url = rewritten;
    }
    HttpURLConnection connection = openConnection(new URL(url), request);
    for (String headerName : map.keySet()) {
        connection.addRequestProperty(headerName, (String) map.get(headerName));
    }
    setConnectionParametersForRequest(connection, request);
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    if (connection.getResponseCode() == -1) {
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }
    StatusLine responseStatus = new BasicStatusLine(protocolVersion, connection
            .getResponseCode(), connection.getResponseMessage());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    if (hasResponseBody(request.getMethod(), responseStatus.getStatusCode())) {
        response.setEntity(entityFromConnection(connection));
    }
    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            response.addHeader(new BasicHeader((String) header.getKey(), (String) ((List)
                    header.getValue()).get(0)));
        }
    }
    return response;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:37,代碼來源:MyHttpStack.java

示例11: setUp

import org.apache.http.message.BasicHttpResponse; //導入方法依賴的package包/類
@Before
	public void setUp() throws Exception {
        HttpClient httpClient = mock(HttpClient.class);
        BasicHttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("http", 1, 1), 200, ""));
        PostMessageResponse successfulResponse = new PostMessageResponse();
        successfulResponse.setOk(true);
        successfulResponse.setError("channel_not_found");
        response.setEntity(new StringEntity(successfulResponse.toJson()));

        when(httpClient.execute(isA(HttpUriRequest.class))).thenReturn(response);
		msteamsNotificationImpl = new MsTeamsNotificationImpl(httpClient);
		spyMsTeamsNotification = spy(msteamsNotificationImpl);
		whl = new MsTeamsNotificationListener(sBuildServer, settings, configSettings, manager, factory);
		projSettings = new MsTeamsNotificationProjectSettings();
		when(factory.getMsTeamsNotification()).thenReturn(spyMsTeamsNotification);
		//when(manager.isRegisteredFormat("JSON")).thenReturn(true);
//		when(manager.getFormat("JSON")).thenReturn(payload);
		//when(manager.getServer()).thenReturn(sBuildServer);
		when(sBuildServer.getProjectManager()).thenReturn(projectManager);
		when(projectManager.findProjectById("project1")).thenReturn(sProject);
		when(sBuildServer.getHistory()).thenReturn(buildHistory);
		when(sBuildServer.getRootUrl()).thenReturn("http://test.server");
		when(previousSuccessfulBuild.getBuildStatus()).thenReturn(Status.NORMAL);
		when(previousSuccessfulBuild.isPersonal()).thenReturn(false);
		when(previousFailedBuild.getBuildStatus()).thenReturn(Status.FAILURE);
		when(previousFailedBuild.isPersonal()).thenReturn(false);
		finishedSuccessfulBuilds.add(previousSuccessfulBuild);
		finishedFailedBuilds.add(previousFailedBuild);
		sBuildType.setProject(sProject);
		when(settings.getSettings(sRunningBuild.getProjectId(), "msteamsNotifications")).thenReturn(projSettings);
		whl.register();
	}
 
開發者ID:spyder007,項目名稱:teamcity-msteams-notifier,代碼行數:33,代碼來源:MsTeamsNotificationListenerTest.java

示例12: createBasicHttpResponse

import org.apache.http.message.BasicHttpResponse; //導入方法依賴的package包/類
private BasicHttpResponse createBasicHttpResponse() {
    BasicHttpEntity entity = new BasicHttpEntity();
    entity.setContent(new ByteArrayInputStream(new byte[0]));

    BasicHttpResponse response = new BasicHttpResponse(
            new ProtocolVersion("http", 1, 1),
            200,
            "OK");
    response.setEntity(entity);
    return response;
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:12,代碼來源:AmazonHttpClientTest.java

示例13: performRequest

import org.apache.http.message.BasicHttpResponse; //導入方法依賴的package包/類
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    String url = request.getUrl();
    HashMap<String, String> map = new HashMap<String, String>();
    map.putAll(request.getHeaders());
    map.putAll(additionalHeaders);
    if (mUrlRewriter != null) {
        String rewritten = mUrlRewriter.rewriteUrl(url);
        if (rewritten == null) {
            throw new IOException("URL blocked by rewriter: " + url);
        }
        url = rewritten;
    }
    URL parsedUrl = new URL(url);
    HttpURLConnection connection = openConnection(parsedUrl, request);
    for (String headerName : map.keySet()) {
        connection.addRequestProperty(headerName, map.get(headerName));
    }
    setConnectionParametersForRequest(connection, request);
    // Initialize HttpResponse with data from the HttpURLConnection.
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    int responseCode = connection.getResponseCode();
    if (responseCode == -1) {
        // -1 is returned by getResponseCode() if the response code could not be retrieved.
        // Signal to the caller that something was wrong with the connection.
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }
    StatusLine responseStatus = new BasicStatusLine(protocolVersion,
            connection.getResponseCode(), connection.getResponseMessage());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    response.setEntity(entityFromConnection(connection));
    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
            response.addHeader(h);
        }
    }
    return response;
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:41,代碼來源:HurlStack.java

示例14: head

import org.apache.http.message.BasicHttpResponse; //導入方法依賴的package包/類
@Override
public HttpResponse head() {
	BasicHttpResponse response = new BasicHttpResponse(this.response.getStatusLine());
	Header[] allHeaders = this.response.getAllHeaders();
	for (Header allHeader : allHeaders)
		response.addHeader(allHeader);
	response.setEntity(new ByteArrayEntity(new byte[]{}));
	return response;
}
 
開發者ID:Coffeeboys,項目名稱:RenewPass,代碼行數:10,代碼來源:InMemoryCacheEntry.java

示例15: createOkPropfindResponse

import org.apache.http.message.BasicHttpResponse; //導入方法依賴的package包/類
private BasicHttpResponse createOkPropfindResponse() throws UnsupportedEncodingException {
    BasicHttpResponse okPropfindResponse = createOkResponse();
    HttpEntity propfindResponseEntity = new StringEntity("" +
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
            "<D:multistatus xmlns:D=\"DAV:\" xmlns:e=\"urn:schemas:httpmail:\">\n" +
            "  <D:response><e:inbox>http://example.org/Exchange/user/Inbox</e:inbox></D:response>\n" +
            "</D:multistatus>");
    okPropfindResponse.setEntity(propfindResponseEntity);

    return okPropfindResponse;
}
 
開發者ID:scoute-dich,項目名稱:K9-MailClient,代碼行數:12,代碼來源:WebDavStoreTest.java


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