List of usage examples for org.apache.commons.httpclient HttpMethod getResponseFooters
public abstract Header[] getResponseFooters();
From source file:com.feilong.tools.net.httpclient3.HttpClientUtil.java
/** * ?log./*from ww w . j a v a2 s.com*/ * * @param httpMethod * the http method * @param httpClientConfig * the http client config * @return the http method response attribute map for log */ private static Map<String, Object> getHttpMethodResponseAttributeMapForLog(HttpMethod httpMethod, HttpClientConfig httpClientConfig) { Map<String, Object> map = new LinkedHashMap<String, Object>(); Object statusCode = null; try { statusCode = httpMethod.getStatusCode(); } catch (Exception e) { statusCode = e.getClass().getName() + " " + e.getMessage(); } String statusText = null; try { statusText = httpMethod.getStatusText(); } catch (Exception e) { statusText = e.getClass().getName() + " " + e.getMessage(); } map.put("httpMethod.getRequestHeaders()-->map", NameValuePairUtil.toMap(httpMethod.getRequestHeaders())); map.put("httpMethod.getStatusCode()", statusCode); map.put("httpMethod.getStatusText()", statusText); map.put("httpMethod.getStatusLine()", "" + httpMethod.getStatusLine()); map.put("httpMethod.getResponseHeaders()-->map", NameValuePairUtil.toMap(httpMethod.getResponseHeaders())); map.put("httpMethod.getResponseFooters()", httpMethod.getResponseFooters()); map.put("httpClientConfig", httpClientConfig); return map; }
From source file:org.apache.ode.axis2.httpbinding.HttpHelper.java
public static String responseToString(HttpMethod m) { StringBuilder sb = new StringBuilder(256); try {//from w ww. j a va2 s.com sb.append("HTTP Response Details: \n").append(m.getName()).append(" ").append(m.getURI()); } catch (URIException e) { // not that important if (log.isDebugEnabled()) log.debug(e); } sb.append("\nStatus-Line: ").append(m.getStatusLine()); Header[] headers = m.getResponseHeaders(); if (headers.length != 0) sb.append("\nResponse Headers: "); for (int i = 0; i < headers.length; i++) { Header h = headers[i]; sb.append("\n\t").append(h.getName()).append(": ").append(h.getValue()); } try { if (StringUtils.isNotEmpty(m.getResponseBodyAsString())) { sb.append("\nResponse Entity:\n").append(m.getResponseBodyAsString()); } } catch (IOException e) { log.error(e); } Header[] footers = m.getResponseFooters(); if (footers.length != 0) sb.append("\nResponse Footers: "); for (int i = 0; i < footers.length; i++) { Header h = footers[i]; sb.append("\n\t").append(h.getName()).append(": ").append(h.getValue()); } return sb.toString(); }
From source file:org.deegree.ogcwebservices.wass.wss.operation.DoServiceHandler.java
/** * This method does the actual request to the secured service. It returns the response of the * secured service as an inputstream. It also replace the GetCapabilities request - responses * with the facadeurl given by the client. * * @param request// www .j a va 2 s. c o m * send by the client a DoService Request. * @param securedService * the service for which this wss is proxying, must be put in the deegreeparams of * the configuration file. * @param requestedCharset * this wss uses, also read from the deegreeparams in the configuration file. * @param timeout * how long to wait for a response. Service dependable therefor also read from the * deegreeparams in the config file. * @param securedServiceName * the name of the service for which we are proxying -> config. * @return the http response of the secured service as an inputstream. * @throws DoServiceException * if an error occurs wile sending the request or treating the response. see * org.deegree.ogcwebservices.csw.manager.CatalogueHarvester#getNextMetadataRecord */ public DoServiceResponse sendRequest(DoService request, URL securedService, String requestedCharset, int timeout, String securedServiceName) throws DoServiceException { if (requestAllowed) { Header[] headers = null; InputStream body = null; Header[] footers = null; String proxyRequest = null; try { proxyRequest = URLDecoder.decode(request.getPayload(), CharsetUtils.getSystemCharset()); } catch (UnsupportedEncodingException e) { LOG.logError(e.getMessage(), e); throw new DoServiceException(Messages.getMessage("WASS_ERROR_INTERNAL", "WSS")); } LOG.logDebug("encoded proxyrequest: " + request.getPayload() + "\ndecoded proxy: " + proxyRequest); String dcp = request.getDcp(); HttpClient client = new HttpClient(); client = WebUtils.enableProxyUsage(client, securedService); StringRequestEntity requestEntity = null; HttpClientParams params = client.getParams(); params.setSoTimeout(timeout); HttpMethod requestMethod = null; try { String contentType = null; for (RequestParameter param : request.getRequestParameters()) { if (param.getId().toLowerCase().trim().contains("mime-type")) contentType = param.getParameter(); } requestEntity = new StringRequestEntity(proxyRequest, contentType, requestedCharset); } catch (UnsupportedEncodingException e1) { throw new DoServiceException(Messages.getMessage("WASS_ERROR_ENCODING_NOT_SUPPORTED", "WSS")); } if (dcp.equalsIgnoreCase("http_post")) { // the url to the service must be written in the deegreeparams in the configuration // xml requestMethod = new PostMethod(securedService.toExternalForm()); ((PostMethod) requestMethod).setRequestEntity(requestEntity); } else if (dcp.equalsIgnoreCase("http_get")) { requestMethod = new GetMethod(securedService.toExternalForm()); requestMethod.setQueryString(proxyRequest); } else { throw new DoServiceException(Messages.getMessage("WASS_ERROR_NOT_POST_OR_GET", "WSS")); } // getDataRequest try { // make header parameters of the requestParameters. for (RequestParameter param : request.getRequestParameters()) { if (!param.getId().toLowerCase().trim().contains("mime-type"))// Contenttype requestMethod.addRequestHeader(param.getId(), param.getParameter()); } // Call the secured service client.executeMethod(requestMethod); headers = requestMethod.getResponseHeaders(); footers = requestMethod.getResponseFooters(); body = requestMethod.getResponseBodyAsStream(); if (body == null) throw new DoServiceException(Messages.getMessage("WASS_ERROR_GOT_NO_RESPONSE", "WSS")); } catch (HttpException e) { LOG.logError(e.getMessage(), e); throw new DoServiceException(Messages.getMessage("WASS_ERROR_EXCEPTION_IN_RESPONSE", "WSS")); } catch (IOException e) { LOG.logError(e.getMessage(), e); throw new DoServiceException(Messages.getMessage("WASS_ERROR_IN_TRANSPORT", "WSS")); } try { // Replace the given urls with the facadeurls if it is a GetCapabilities request if (proxyRequest.trim().contains("GetCapabilities")) { Operation[] operations = null; OGCCapabilitiesDocument doc = null; /* * For now just check these service, others may be "secured" in the future. */ if ("WFS".equals(securedServiceName)) { doc = new WFSCapabilitiesDocument(); doc.load(body, securedService.toExternalForm()); WFSCapabilities cap = (WFSCapabilities) doc.parseCapabilities(); operations = cap.getOperationsMetadata().getOperations(); replaceFacadeURL(operations, request.getFacadeURL()); doc = org.deegree.ogcwebservices.wfs.XMLFactory.export(cap); } else if (("WMS").equals(securedServiceName)) { doc = new WMSCapabilitiesDocument(); doc.load(body, securedService.toExternalForm()); doc = WMSCapabilitiesDocumentFactory.getWMSCapabilitiesDocument(doc.getRootElement()); WMSCapabilities cap = (WMSCapabilities) doc.parseCapabilities(); org.deegree.owscommon_new.Operation[] ops = cap.getOperationMetadata().getOperations() .toArray(new org.deegree.owscommon_new.Operation[0]); replaceFacadeURL(ops, request.getFacadeURL()); doc = org.deegree.ogcwebservices.wms.XMLFactory.export(cap); } else if (("WCS").equals(securedServiceName)) { doc = new WCSCapabilitiesDocument(); doc.load(body, securedService.toExternalForm()); WCSCapabilities cap = (WCSCapabilities) doc.parseCapabilities(); operations = cap.getCapabilitiy().getOperations().getOperations(); replaceFacadeURL(operations, request.getFacadeURL()); doc = org.deegree.ogcwebservices.wcs.XMLFactory.export(cap); } else if (("CSW").equals(securedServiceName)) { doc = new CatalogueCapabilitiesDocument(); doc.load(body, securedService.toExternalForm()); CatalogueCapabilities cap = (CatalogueCapabilities) doc.parseCapabilities(); operations = cap.getOperationsMetadata().getOperations(); replaceFacadeURL(operations, request.getFacadeURL()); doc = org.deegree.ogcwebservices.csw.XMLFactory_2_0_0.export(cap, null); } body = new ByteArrayInputStream(doc.getAsString().getBytes()); } } catch (IOException e) { LOG.logError(e.getMessage(), e); throw new DoServiceException(Messages.getMessage("WASS_ERROR_READING_BODY", "WSS")); } catch (InvalidCapabilitiesException e) { LOG.logError(e.getMessage(), e); throw new DoServiceException(Messages.getMessage("WASS_ERROR_CAPABILITIES_RESPONSE", "WSS")); } catch (SAXException e) { LOG.logError(e.getMessage(), e); throw new DoServiceException(Messages.getMessage("WASS_ERROR_FACADE_URL", "WSS")); } catch (XMLParsingException e) { LOG.logError(e.getMessage(), e); throw new DoServiceException(Messages.getMessage("WASS_ERROR_READING_BODY", "WSS")); } return new DoServiceResponse(headers, body, footers); } return null; }