当前位置: 首页>>代码示例>>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;未经允许,请勿转载。