List of usage examples for org.apache.http.entity InputStreamEntity setChunked
public void setChunked(boolean z)
From source file:com.michaeljones.httpclient.apache.ApacheMethodClient.java
@Override public int PutFile(String url, String filePath, List<Pair<String, String>> queryParams, StringBuilder redirect) throws FileNotFoundException { try {//www.ja v a 2 s. c o m URIBuilder fileUri = new URIBuilder(url); if (queryParams != null) { // Query params are optional. In the case of a redirect the url will contain // all the params. for (Pair<String, String> queryParam : queryParams) { fileUri.addParameter(queryParam.getFirst(), queryParam.getSecond()); } } HttpPut httpPut = new HttpPut(fileUri.build()); InputStream fileInStream = new FileInputStream(filePath); InputStreamEntity chunkedStream = new InputStreamEntity(fileInStream, -1, ContentType.APPLICATION_OCTET_STREAM); chunkedStream.setChunked(true); httpPut.setEntity(chunkedStream); CloseableHttpResponse response = clientImpl.execute(httpPut); try { Header[] hdrs = response.getHeaders("Location"); if (redirect != null && hdrs.length > 0) { String redirectLocation = hdrs[0].getValue(); redirect.append(redirectLocation); LOGGER.debug("Redirect to: " + redirectLocation); } return response.getStatusLine().getStatusCode(); } finally { // I believe this releases the connection to the client pool, but does not // close the connection. response.close(); } } catch (IOException | URISyntaxException ex) { throw new RuntimeException("Apache method putQuery: " + ex.getMessage()); } }
From source file:net.sf.smbt.btc.utils.BTCResourceUtils.java
public void upload(String portID, String command, File file) { String query = portID + command; boolean verbose = true; boolean requestFailed = false; HttpResponse response;/*from ww w . ja v a 2 s. co m*/ HttpEntity entity; HttpClient httpclient = new DefaultHttpClient(); try { InputStreamEntity reqEntity = new InputStreamEntity(new FileInputStream(file), -1); reqEntity.setContentType("application/xml"); reqEntity.setChunked(true); HttpPost httpput = new HttpPost(query); httpput.setEntity(reqEntity); if (verbose) { System.out.println("-------- open ubibot connection --------"); System.out.println("executing request: " + httpput.getURI()); } response = httpclient.execute(httpput); // execute this mother entity = response.getEntity(); String ubiResponse = ""; String statusLine = response.getStatusLine().toString() + "\n"; String delims = "[ ]+"; String[] tokens = statusLine.split(delims); if (tokens[1].equals("200")) { // success System.out.println("\nserver response:"); System.out.println(statusLine); ubiResponse = EntityUtils.toString(entity); } else { // bad request System.out.println("\nbad request. status code: \n"); System.out.println(statusLine); System.out.println("check the HTTP status codes"); ubiResponse = EntityUtils.toString(entity) + "\n\n"; Header[] respHeader; respHeader = response.getAllHeaders(); for (int i = 0; i < respHeader.length; i++) { ubiResponse += respHeader[i].toString() + "\n"; } if (verbose) System.out.print(ubiResponse); requestFailed = true; // "***failed request***"; } } catch (IOException e) { e.printStackTrace(); } finally { // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); if (verbose) { System.out.println("----------- connection closed ----------\n"); } } }
From source file:com.phonegap.plugins.CloudStorage.java
/** * Executes the request and returns PluginResult. *//from w w w . j ava 2 s.co m * @param action The action to execute. * @param data JSONArry of arguments for the plugin. * 'url': server url for upload * 'file URI': URI of file to upload * 'X-Auth-Token': authentication header to use for this request * @param callbackId The callback id used when calling back into JavaScript. * @return A PluginResult object with a status and message. * */ public PluginResult execute(String action, JSONArray data, String callbackId) { PluginResult result = null; if (ACTION_UPLOAD.equals(action) || ACTION_STORE.equals(action)) { try { String serverUrl = data.get(0).toString(); String imageURI = data.getString(1).toString(); String token = null; if (ACTION_UPLOAD.equals(action)) { token = data.getString(2).toString(); } File file = new File(new URI(imageURI)); try { HttpClient httpclient = new DefaultHttpClient(); HttpPut httpput = new HttpPut(serverUrl); InputStreamEntity reqEntity = new InputStreamEntity(new FileInputStream(file), -1); if (ACTION_UPLOAD.equals(action)) { reqEntity.setContentType("binary/octet-stream"); reqEntity.setChunked(true); // Send in multiple parts if needed } else { reqEntity.setContentType("image/jpg"); } httpput.setEntity(reqEntity); if (token != null) { httpput.addHeader("X-Auth-Token", token); } HttpResponse response = httpclient.execute(httpput); Log.d(LOG_TAG, "http response: " + response.getStatusLine().getStatusCode() + response.getStatusLine().getReasonPhrase()); //Do something with response... result = new PluginResult(Status.OK, response.getStatusLine().getStatusCode()); } catch (Exception e) { Log.d(LOG_TAG, e.getLocalizedMessage()); result = new PluginResult(Status.ERROR); } } catch (JSONException e) { Log.d(LOG_TAG, e.getLocalizedMessage()); result = new PluginResult(Status.JSON_EXCEPTION); } catch (Exception e1) { Log.d(LOG_TAG, e1.getLocalizedMessage()); result = new PluginResult(Status.ERROR); } } return result; }
From source file:com.intel.cosbench.client.swift.SwiftClient.java
public void storeStreamedObject(String container, String object, InputStream data, long length) throws IOException, SwiftException { SwiftResponse response = null;//from w w w . j ava 2 s . co m try { method = HttpClientUtil.makeHttpPut(getObjectPath(container, object)); method.setHeader(X_AUTH_TOKEN, authToken); InputStreamEntity entity = new InputStreamEntity(data, length); if (length < 0) entity.setChunked(true); else entity.setChunked(false); entity.setContentType("application/octet-stream"); ((HttpPut) method).setEntity(entity); response = new SwiftResponse(client.execute(method)); if (response.getStatusCode() == SC_CREATED) return; if (response.getStatusCode() == SC_ACCEPTED) return; if (response.getStatusCode() == SC_NOT_FOUND) throw new SwiftFileNotFoundException("container not found: " + container, response.getResponseHeaders(), response.getStatusLine()); throw new SwiftException("unexpected return from server", response.getResponseHeaders(), response.getStatusLine()); } finally { if (response != null) response.consumeResposeBody(); } }
From source file:de.hshannover.f4.trust.ifmapj.channel.ApacheCoreCommunicationHandler.java
@Override public InputStream doActualRequest(InputStream is) throws IOException { InputStreamEntity ise = null; HttpResponse response = null;//from w w w .ja v a2 s .c o m InputStream ret = null; Header hdr = null; HttpEntity respEntity = null; StatusLine status = null; ise = new InputStreamEntity(is, is.available()); ise.setChunked(false); mHttpPost.setEntity(ise); // do the actual request try { mHttpConnection.sendRequestHeader(mHttpPost); mHttpConnection.sendRequestEntity(mHttpPost); response = mHttpConnection.receiveResponseHeader(); mHttpConnection.receiveResponseEntity(response); } catch (HttpException e) { throw new IOException(e); } // check if we got a 200 status back, otherwise go crazy status = response.getStatusLine(); if (status.getStatusCode() != 200) { throw new IOException("HTTP Status Code: " + status.getStatusCode() + " " + status.getReasonPhrase()); } // check whether the response uses gzip hdr = response.getFirstHeader("Content-Encoding"); mResponseGzip = hdr == null ? false : hdr.getValue().contains("gzip"); respEntity = response.getEntity(); if (respEntity != null) { ret = respEntity.getContent(); } if (ret == null) { throw new IOException("no content in response"); } return ret; }
From source file:org.cerberus.service.rest.impl.RestService.java
@Override public AnswerItem<AppService> callREST(String servicePath, String requestString, String method, List<AppServiceHeader> headerList, List<AppServiceContent> contentList, String token, int timeOutMs) { AnswerItem result = new AnswerItem(); AppService serviceREST = factoryAppService.create("", AppService.TYPE_REST, method, "", "", "", "", "", "", "", "", null, "", null); MessageEvent message = null;/*from w ww .ja va 2s . c o m*/ if (StringUtils.isNullOrEmpty(servicePath)) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE_SERVICEPATHMISSING); result.setResultMessage(message); return result; } if (StringUtils.isNullOrEmpty(method)) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE_METHODMISSING); result.setResultMessage(message); return result; } // If token is defined, we add 'cerberus-token' on the http header. if (token != null) { headerList.add( factoryAppServiceHeader.create(null, "cerberus-token", token, "Y", 0, "", "", null, "", null)); } CloseableHttpClient httpclient; httpclient = HttpClients.createDefault(); try { // Timeout setup. RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(timeOutMs).build(); AppService responseHttp = null; switch (method) { case AppService.METHOD_HTTPGET: LOG.info("Start preparing the REST Call (GET). " + servicePath + " - " + requestString); servicePath = StringUtil.addQueryString(servicePath, requestString); serviceREST.setServicePath(servicePath); HttpGet httpGet = new HttpGet(servicePath); // Timeout setup. httpGet.setConfig(requestConfig); // Header. for (AppServiceHeader contentHeader : headerList) { httpGet.addHeader(contentHeader.getKey(), contentHeader.getValue()); } serviceREST.setHeaderList(headerList); // Saving the service before the call Just in case it goes wrong (ex : timeout). result.setItem(serviceREST); LOG.info("Executing request " + httpGet.getRequestLine()); responseHttp = executeHTTPCall(httpclient, httpGet); if (responseHttp != null) { serviceREST.setResponseHTTPBody(responseHttp.getResponseHTTPBody()); serviceREST.setResponseHTTPCode(responseHttp.getResponseHTTPCode()); serviceREST.setResponseHTTPVersion(responseHttp.getResponseHTTPVersion()); serviceREST.setResponseHeaderList(responseHttp.getResponseHeaderList()); } break; case AppService.METHOD_HTTPPOST: LOG.info("Start preparing the REST Call (POST). " + servicePath); serviceREST.setServicePath(servicePath); HttpPost httpPost = new HttpPost(servicePath); // Timeout setup. httpPost.setConfig(requestConfig); // Content if (!(StringUtil.isNullOrEmpty(requestString))) { InputStream stream = new ByteArrayInputStream(requestString.getBytes(StandardCharsets.UTF_8)); InputStreamEntity reqEntity = new InputStreamEntity(stream); reqEntity.setChunked(true); httpPost.setEntity(reqEntity); serviceREST.setServiceRequest(requestString); } else { List<NameValuePair> nvps = new ArrayList<NameValuePair>(); for (AppServiceContent contentVal : contentList) { nvps.add(new BasicNameValuePair(contentVal.getKey(), contentVal.getValue())); } httpPost.setEntity(new UrlEncodedFormEntity(nvps)); serviceREST.setContentList(contentList); } // Header. for (AppServiceHeader contentHeader : headerList) { httpPost.addHeader(contentHeader.getKey(), contentHeader.getValue()); } serviceREST.setHeaderList(headerList); // Saving the service before the call Just in case it goes wrong (ex : timeout). result.setItem(serviceREST); LOG.info("Executing request " + httpPost.getRequestLine()); responseHttp = executeHTTPCall(httpclient, httpPost); if (responseHttp != null) { serviceREST.setResponseHTTPBody(responseHttp.getResponseHTTPBody()); serviceREST.setResponseHTTPCode(responseHttp.getResponseHTTPCode()); serviceREST.setResponseHTTPVersion(responseHttp.getResponseHTTPVersion()); serviceREST.setResponseHeaderList(responseHttp.getResponseHeaderList()); } else { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE); message.setDescription(message.getDescription().replace("%SERVICE%", servicePath)); message.setDescription(message.getDescription().replace("%DESCRIPTION%", "Any issue was found when calling the service. Coud be a reached timeout during the call (." + timeOutMs + ")")); result.setResultMessage(message); return result; } break; } // Get result Content Type. if (responseHttp != null) { serviceREST.setResponseHTTPBodyContentType(AppServiceService.guessContentType(serviceREST, AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON)); } result.setItem(serviceREST); message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CALLSERVICE); message.setDescription(message.getDescription().replace("%SERVICEMETHOD%", method)); message.setDescription(message.getDescription().replace("%SERVICEPATH%", servicePath)); result.setResultMessage(message); } catch (SocketTimeoutException ex) { LOG.info("Exception when performing the REST Call. " + ex.toString()); message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE_TIMEOUT); message.setDescription(message.getDescription().replace("%SERVICEURL%", servicePath)); message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(timeOutMs))); result.setResultMessage(message); return result; } catch (Exception ex) { LOG.error("Exception when performing the REST Call. " + ex.toString()); message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE); message.setDescription(message.getDescription().replace("%SERVICE%", servicePath)); message.setDescription( message.getDescription().replace("%DESCRIPTION%", "Error on CallREST : " + ex.toString())); result.setResultMessage(message); return result; } finally { try { httpclient.close(); } catch (IOException ex) { LOG.error(ex.toString()); } } return result; }
From source file:org.dataconservancy.access.connector.HttpDcsConnector.java
@Override public String uploadFile(InputStream is, long length) throws DcsClientFault { HttpPost post;/*w w w . j ava2s.c om*/ try { post = new HttpPost(config.getUploadFileUrl().toURI()); } catch (URISyntaxException e) { final String msg = "Malformed upload file endpoint URL " + config.getUploadFileUrl() + ": " + e.getMessage(); log.debug(msg, e); throw new DcsClientFault(msg, e); } InputStreamEntity data = new InputStreamEntity(is, length); data.setContentType("binary/octet-stream"); data.setChunked(true); post.setEntity(data); HttpResponse resp = execute(post, HttpStatus.SC_ACCEPTED); try { resp.getEntity().consumeContent(); } catch (IOException e) { throw new DcsClientFault("Problem releasing resources", e); } Header header = resp.getFirstHeader("X-dcs-src"); if (header == null) { throw new DcsClientFault( "Server response missing required header X-dcs-src for post to " + config.getUploadFileUrl()); } return header.getValue(); }
From source file:com.fujitsu.dc.core.rs.box.DcEngineSvcCollectionResource.java
/** * relay??.//w w w . j ava2 s. co m * @param method * @param uriInfo URI * @param path ?? * @param headers * @param is * @return JAX-RS Response */ public Response relaycommon(String method, UriInfo uriInfo, String path, HttpHeaders headers, InputStream is) { String cellName = this.davRsCmp.getCell().getName(); String boxName = this.davRsCmp.getBox().getName(); String requestUrl = String.format("http://%s:%s/%s/%s/%s/service/%s", DcCoreConfig.getEngineHost(), DcCoreConfig.getEnginePort(), DcCoreConfig.getEnginePath(), cellName, boxName, path); // baseUrl? String baseUrl = uriInfo.getBaseUri().toString(); // ??? HttpClient client = new DefaultHttpClient(); HttpUriRequest req = null; if (method.equals(HttpMethod.POST)) { HttpPost post = new HttpPost(requestUrl); InputStreamEntity ise = new InputStreamEntity(is, -1); ise.setChunked(true); post.setEntity(ise); req = post; } else if (method.equals(HttpMethod.PUT)) { HttpPut put = new HttpPut(requestUrl); InputStreamEntity ise = new InputStreamEntity(is, -1); ise.setChunked(true); put.setEntity(ise); req = put; } else if (method.equals(HttpMethod.DELETE)) { HttpDelete delete = new HttpDelete(requestUrl); req = delete; } else { HttpGet get = new HttpGet(requestUrl); req = get; } req.addHeader("X-Baseurl", baseUrl); req.addHeader("X-Request-Uri", uriInfo.getRequestUri().toString()); // ?INDEXIDTYPE? if (davCmp instanceof DavCmpEsImpl) { DavCmpEsImpl test = (DavCmpEsImpl) davCmp; req.addHeader("X-Dc-Es-Index", test.getEsColType().getIndex().getName()); req.addHeader("X-Dc-Es-Id", test.getNodeId()); req.addHeader("X-Dc-Es-Type", test.getEsColType().getType()); req.addHeader("X-Dc-Es-Routing-Id", this.davRsCmp.getCell().getId()); req.addHeader("X-Dc-Box-Schema", this.davRsCmp.getBox().getSchema()); } // ??? MultivaluedMap<String, String> multivalueHeaders = headers.getRequestHeaders(); for (Iterator<Entry<String, List<String>>> it = multivalueHeaders.entrySet().iterator(); it.hasNext();) { Entry<String, List<String>> entry = it.next(); String key = (String) entry.getKey(); if (key.equalsIgnoreCase(HttpHeaders.CONTENT_LENGTH)) { continue; } List<String> valueList = (List<String>) entry.getValue(); for (Iterator<String> i = valueList.iterator(); i.hasNext();) { String value = (String) i.next(); req.setHeader(key, value); } } if (log.isDebugEnabled()) { log.debug("?EngineRelay " + req.getMethod() + " " + req.getURI()); Header[] reqHeaders = req.getAllHeaders(); for (int i = 0; i < reqHeaders.length; i++) { log.debug("RelayHeader[" + reqHeaders[i].getName() + "] : " + reqHeaders[i].getValue()); } } // Engine?? HttpResponse objResponse = null; try { objResponse = client.execute(req); } catch (ClientProtocolException e) { throw DcCoreException.ServiceCollection.SC_INVALID_HTTP_RESPONSE_ERROR; } catch (Exception ioe) { throw DcCoreException.ServiceCollection.SC_ENGINE_CONNECTION_ERROR.reason(ioe); } // ResponseBuilder res = Response.status(objResponse.getStatusLine().getStatusCode()); Header[] headersResEngine = objResponse.getAllHeaders(); // ? for (int i = 0; i < headersResEngine.length; i++) { // Engine????Transfer-Encoding???? // ?MW????????Content-Length???Transfer-Encoding???? // 2?????????????????????? if ("Transfer-Encoding".equalsIgnoreCase(headersResEngine[i].getName())) { continue; } // Engine????Date???? // Web??MW?Jetty???2????????? if (HttpHeaders.DATE.equalsIgnoreCase(headersResEngine[i].getName())) { continue; } res.header(headersResEngine[i].getName(), headersResEngine[i].getValue()); } InputStream isResBody = null; // ? HttpEntity entity = objResponse.getEntity(); if (entity != null) { try { isResBody = entity.getContent(); } catch (IllegalStateException e) { throw DcCoreException.ServiceCollection.SC_UNKNOWN_ERROR.reason(e); } catch (IOException e) { throw DcCoreException.ServiceCollection.SC_ENGINE_CONNECTION_ERROR.reason(e); } final InputStream isInvariable = isResBody; // ?? StreamingOutput strOutput = new StreamingOutput() { @Override public void write(final OutputStream os) throws IOException { int chr; try { while ((chr = isInvariable.read()) != -1) { os.write(chr); } } finally { isInvariable.close(); } } }; res.entity(strOutput); } // ?? return res.build(); }
From source file:com.yahoo.ycsb.webservice.rest.RestClient.java
private int httpExecute(HttpEntityEnclosingRequestBase request, String data) throws IOException { requestTimedout.setIsSatisfied(false); Thread timer = new Thread(new Timer(execTimeout, requestTimedout)); timer.start();/*from ww w .j av a2 s.c o m*/ int responseCode = 200; for (int i = 0; i < headers.length; i = i + 2) { request.setHeader(headers[i], headers[i + 1]); } InputStreamEntity reqEntity = new InputStreamEntity(new ByteArrayInputStream(data.getBytes()), ContentType.APPLICATION_FORM_URLENCODED); reqEntity.setChunked(true); request.setEntity(reqEntity); CloseableHttpResponse response = client.execute(request); responseCode = response.getStatusLine().getStatusCode(); HttpEntity responseEntity = response.getEntity(); // If null entity don't bother about connection release. if (responseEntity != null) { InputStream stream = responseEntity.getContent(); if (compressedResponse) { stream = new GZIPInputStream(stream); } BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8")); StringBuffer responseContent = new StringBuffer(); String line = ""; while ((line = reader.readLine()) != null) { if (requestTimedout.isSatisfied()) { // Must avoid memory leak. reader.close(); stream.close(); EntityUtils.consumeQuietly(responseEntity); response.close(); client.close(); throw new TimeoutException(); } responseContent.append(line); } timer.interrupt(); // Closing the input stream will trigger connection release. stream.close(); } EntityUtils.consumeQuietly(responseEntity); response.close(); client.close(); return responseCode; }
From source file:io.personium.core.rs.box.PersoniumEngineSvcCollectionResource.java
/** * relay??.// w ww . j a v a 2s .c o m * @param method * @param uriInfo URI * @param path ?? * @param headers * @param is * @return JAX-RS Response */ public Response relaycommon(String method, UriInfo uriInfo, String path, HttpHeaders headers, InputStream is) { String cellName = this.davRsCmp.getCell().getName(); String boxName = this.davRsCmp.getBox().getName(); String requestUrl = String.format("http://%s:%s/%s/%s/%s/service/%s", PersoniumUnitConfig.getEngineHost(), PersoniumUnitConfig.getEnginePort(), PersoniumUnitConfig.getEnginePath(), cellName, boxName, path); // baseUrl? String baseUrl = uriInfo.getBaseUri().toString(); // ??? HttpClient client = new DefaultHttpClient(); HttpUriRequest req = null; if (method.equals(HttpMethod.POST)) { HttpPost post = new HttpPost(requestUrl); InputStreamEntity ise = new InputStreamEntity(is, -1); ise.setChunked(true); post.setEntity(ise); req = post; } else if (method.equals(HttpMethod.PUT)) { HttpPut put = new HttpPut(requestUrl); InputStreamEntity ise = new InputStreamEntity(is, -1); ise.setChunked(true); put.setEntity(ise); req = put; } else if (method.equals(HttpMethod.DELETE)) { HttpDelete delete = new HttpDelete(requestUrl); req = delete; } else { HttpGet get = new HttpGet(requestUrl); req = get; } req.addHeader("X-Baseurl", baseUrl); req.addHeader("X-Request-Uri", uriInfo.getRequestUri().toString()); if (davCmp instanceof DavCmpFsImpl) { DavCmpFsImpl dcmp = (DavCmpFsImpl) davCmp; req.addHeader("X-Personium-Fs-Path", dcmp.getFsPath()); req.addHeader("X-Personium-Fs-Routing-Id", dcmp.getCellId()); } req.addHeader("X-Personium-Box-Schema", this.davRsCmp.getBox().getSchema()); // ??? MultivaluedMap<String, String> multivalueHeaders = headers.getRequestHeaders(); for (Iterator<Entry<String, List<String>>> it = multivalueHeaders.entrySet().iterator(); it.hasNext();) { Entry<String, List<String>> entry = it.next(); String key = (String) entry.getKey(); if (key.equalsIgnoreCase(HttpHeaders.CONTENT_LENGTH)) { continue; } List<String> valueList = (List<String>) entry.getValue(); for (Iterator<String> i = valueList.iterator(); i.hasNext();) { String value = (String) i.next(); req.setHeader(key, value); } } if (log.isDebugEnabled()) { log.debug("?EngineRelay " + req.getMethod() + " " + req.getURI()); Header[] reqHeaders = req.getAllHeaders(); for (int i = 0; i < reqHeaders.length; i++) { log.debug("RelayHeader[" + reqHeaders[i].getName() + "] : " + reqHeaders[i].getValue()); } } // Engine?? HttpResponse objResponse = null; try { objResponse = client.execute(req); } catch (ClientProtocolException e) { throw PersoniumCoreException.ServiceCollection.SC_INVALID_HTTP_RESPONSE_ERROR; } catch (Exception ioe) { throw PersoniumCoreException.ServiceCollection.SC_ENGINE_CONNECTION_ERROR.reason(ioe); } // ResponseBuilder res = Response.status(objResponse.getStatusLine().getStatusCode()); Header[] headersResEngine = objResponse.getAllHeaders(); // ? for (int i = 0; i < headersResEngine.length; i++) { // Engine????Transfer-Encoding???? // ?MW????????Content-Length???Transfer-Encoding???? // 2?????????????????????? if ("Transfer-Encoding".equalsIgnoreCase(headersResEngine[i].getName())) { continue; } // Engine????Date???? // Web??MW?Jetty???2????????? if (HttpHeaders.DATE.equalsIgnoreCase(headersResEngine[i].getName())) { continue; } res.header(headersResEngine[i].getName(), headersResEngine[i].getValue()); } InputStream isResBody = null; // ? HttpEntity entity = objResponse.getEntity(); if (entity != null) { try { isResBody = entity.getContent(); } catch (IllegalStateException e) { throw PersoniumCoreException.ServiceCollection.SC_UNKNOWN_ERROR.reason(e); } catch (IOException e) { throw PersoniumCoreException.ServiceCollection.SC_ENGINE_CONNECTION_ERROR.reason(e); } final InputStream isInvariable = isResBody; // ?? StreamingOutput strOutput = new StreamingOutput() { @Override public void write(final OutputStream os) throws IOException { int chr; try { while ((chr = isInvariable.read()) != -1) { os.write(chr); } } finally { isInvariable.close(); } } }; res.entity(strOutput); } // ?? return res.build(); }