public void handleFacadeResponseHeaders(final Transferable wssResponse) { Collection<TransferAttribute> wssResponseHeaders = wssResponse.getAttributes(); for (TransferAttribute tAttr : wssResponseHeaders) { if (tAttr.getName().equalsIgnoreCase("Transfer-Encoding")) { // do nothing // TODO problem with "Transfer-Encoding: chunked" if (LOG.isDebugEnabled()) { LOG.debug("Ignoring header 'Transfer-Encoding': " + tAttr.getValue()); } } else { if (tAttr instanceof HttpHeaderAttribute) { HttpHeaderAttribute httpHeaderAttribute = (HttpHeaderAttribute) tAttr; m_headerHandler.handle(httpHeaderAttribute); } else { continue; } } } }
private Map<String, String> getHttpHeaderAttributes(Transferable requestTransferable) throws IOException { Map<String, String> httpHeaderAttributes = new HashMap<>(); Iterator<TransferAttribute> attributeIterator = requestTransferable.getAttributes().iterator(); while (attributeIterator.hasNext()) { TransferAttribute attribute = attributeIterator.next(); String attributeName = attribute.getName(); Object attributeValue = attribute.getValue(); if (attribute instanceof HttpHeaderAttribute) { if (attributeName.equals(HttpHeaderAttribute.HEADER_NAME_CONTENTTYPE)) { if (((String) attributeValue).startsWith("application/octe")) { setPayloadAsStreamPayload(requestTransferable); } else { attributeValue = modifyContentTypeAttributeValue(requestTransferable, (String) attributeValue); } } else if (attributeName.equals(HttpHeaderAttribute.HEADER_NAME_CONTENTCHARSET)) { // don't set the 'wrong' charset content encoding continue; } addToHeaderAttributes(attributeName, (String) attributeValue, httpHeaderAttributes); } else if (attribute instanceof SimpleTransferAttribute) { if (attributeName.toLowerCase().startsWith("accept")) { String stringAttributeValue = String.valueOf(attributeValue); if (!attributeName.toLowerCase().equals("accept-encoding") || "gzip".equalsIgnoreCase(stringAttributeValue)) { addToHeaderAttributes(attributeName, stringAttributeValue, httpHeaderAttributes); } } } } return httpHeaderAttributes; }
public Transferable doService(Transferable request, Credential credential, URL facadeUrl, String dcpType, LicenseReference licenseReference) throws ServiceException { String additionalPathInfo = (String) request.getAttributeValue(TransferAttribute.PATHINFO_ATTR); if (additionalPathInfo == null) { additionalPathInfo = ""; } String additionalQueryString = (String) request.getAttributeValue(TransferAttribute.QUERY_STRING_ATTR); if (additionalQueryString == null) { additionalQueryString = ""; } List<HttpHeaderAttribute> headersList = new LinkedList<>(); for (TransferAttribute attrib : request.getAttributes()) { if (attrib instanceof HttpHeaderAttribute) { headersList.add((HttpHeaderAttribute) attrib); } } HttpHeaderAttribute[] headers = headersList.toArray(new HttpHeaderAttribute[headersList.size()]); String postXML = createPostXML("1.1", credential, request, facadeUrl, dcpType, licenseReference); String uri = MessageFormat.format("{0}{1}?{2}", getWssURLString(), additionalPathInfo, additionalQueryString); HTTPContentRequest httpRequest = httpClientFactory.create(uri).post().contentType("text/xml", "UTF-8"); for (HttpHeaderAttribute httpHeaderAttribute : headers) { if (headerNameIs(httpHeaderAttribute, "Content-Type") || headerNameIs(httpHeaderAttribute, "Content-Encoding")) { continue; } httpRequest.header(httpHeaderAttribute.getName(), (String) httpHeaderAttribute.getValue()); } httpRequest.content(postXML); return execute(httpRequest); }