Refine search
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);
public void setStatusLine(final ProtocolVersion ver, final int code) { // arguments checked in BasicStatusLine constructor this.statusline = new BasicStatusLine(ver, code, getReason(code)); }
HttpPost httppost = new HttpPost(SERVICE_EPR); StringEntity se = new StringEntity(SOAPRequestXML,HTTP.UTF_8); se.setContentType("text/xml"); httppost.setHeader("Content-Type","application/soap+xml;charset=UTF-8"); httppost.setEntity(se); HttpClient httpclient = new DefaultHttpClient(); BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient.execute(httppost); response.put("HTTPStatus",httpResponse.getStatusLine().toString());
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; }
response.setStatusCode(httpResponse.getStatusLine().getStatusCode()); response.setPostedParms(postParms); EntityUtils.consume(httpResponse.getEntity()); } catch (IOException e) {/*consume quietly*/}
public HttpResponse newHttpResponse(final ProtocolVersion ver, final int status, HttpContext context) { if (ver == null) { throw new IllegalArgumentException("HTTP version may not be null"); } final Locale loc = determineLocale(context); final String reason = reasonCatalog.getReason(status, loc); StatusLine statusline = new BasicStatusLine(ver, status, reason); return new BasicHttpResponse(statusline, reasonCatalog, loc); }
@Test public void headersAndPostParams() throws Exception { MockHttpStack mockHttpStack = new MockHttpStack(); BasicHttpResponse fakeResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), 200, "OK"); fakeResponse.setEntity(new StringEntity("foobar")); mockHttpStack.setResponseToReturn(fakeResponse); BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
public HttpResponse newHttpResponse(final StatusLine statusline, HttpContext context) { if (statusline == null) { throw new IllegalArgumentException("Status line may not be null"); } final Locale loc = determineLocale(context); return new BasicHttpResponse(statusline, reasonCatalog, loc); }
StatusLine statusLine = new BasicStatusLine( protocolVersion, response.getStatusCode(), "" /* reasonPhrase */); BasicHttpResponse apacheResponse = new BasicHttpResponse(statusLine); headers.add(new BasicHeader(header.getName(), header.getValue())); apacheResponse.setHeaders(headers.toArray(new org.apache.http.Header[headers.size()])); entity.setContent(responseStream); entity.setContentLength(response.getContentLength()); apacheResponse.setEntity(entity);
ExecuteBuilder<T> withResponse(int code, String status, String mimeType, String body) { BasicHttpResponse r = new BasicHttpResponse( new BasicStatusLine(HttpVersion.HTTP_1_1, code, status) ); StringEntity e = new StringEntity(body, ContentType.create(mimeType, Charset.forName("UTF-8"))); r.setEntity(e); return withResponse(r); }
response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), evt.getStatus().getCode(), evt.getStatus().name())); } else { response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), evt.getStatus().getCode(), evt.getStatus().name())); evt.getHeaders().asMap().forEach((k, vs) -> vs.forEach(v -> response.addHeader(k, v))); evt.getContentType().ifPresent((ct) -> response.setHeader(CONTENT_TYPE_HEADER, ct)); response.setHeader("Content-length", String.valueOf(data.length));
protected HttpResponse createResponse(int statusCode, ContentType contentType, String content) { final String reason = reasonPhraseCatalog.getReason(statusCode, Locale.ENGLISH); final BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, statusCode, reason); response.setHeader(HTTP.CONTENT_TYPE, contentType.toString()); final StringEntity entity = new StringEntity(content, contentType); response.setEntity(entity); return response; } }
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; }
/** * {@inheritDoc} */ @Override public void addHeader(String name, String value) { if (response != null) { response.addHeader(name, value); } else { super.addHeader(name, value); } }
private static BasicHttpResponse createResponse(int statusCode) { return new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, null)); }
@Test public void headersAndPostParams() throws Exception { MockHttpStack mockHttpStack = new MockHttpStack(); BasicHttpResponse fakeResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), 200, "OK"); fakeResponse.setEntity(new StringEntity("foobar")); mockHttpStack.setResponseToReturn(fakeResponse); BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
@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; }
= new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK")); List<Header> headers = defaultHeaders(); response.setHeaders(headers.toArray(new Header[0]));
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; }
/** * {@inheritDoc} */ @Override public void addHeader(Header header) { if (response != null) { response.addHeader(header); } else { super.addHeader(header); } }