本文整理汇总了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());
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}