private Transferable replaceEndPointUrlBy(URL endpointUrl, URL facadeUrl, Transferable transferable) { String contentType = (String) transferable.getAttributeValue(HttpHeaderAttribute.HEADER_NAME_CONTENTTYPE); if (!contentType.contains("xml") && !contentType.contains("text")) return transferable; String charset = (String) transferable.getAttributeValue(HttpHeaderAttribute.HEADER_NAME_CONTENTCHARSET); String payloadString = transferable.getPayload().toString(); String responseWithFacadeUrls = payloadString.replaceAll(Pattern.quote(endpointUrl.toString())+"(&)*", facadeUrl.toString()+"?"); TextualPayload payloadWithFacadeUrls = new TextualPayload(responseWithFacadeUrls,charset); transferable.setPayload(payloadWithFacadeUrls); return transferable; }
public Transferable createTextualTransferable(final String pContentType, final String pPayLoad, final String pTargetCharset) { Transferable lTransferable = new TransferableImpl(); lTransferable.setPayload(new TextualPayload(pPayLoad, pTargetCharset)); if (pContentType != null) { String contentType = addCharset(pContentType, pTargetCharset); lTransferable.addAttribute(HttpHeaderAttribute.createHttpHeaderAttribute( HttpHeaderAttribute.HEADER_NAME_CONTENTTYPE, contentType)); } if (pTargetCharset != null) { lTransferable.addAttribute(HttpHeaderAttribute.createHttpHeaderAttribute( HttpHeaderAttribute.HEADER_NAME_CONTENTCHARSET, pTargetCharset)); } return lTransferable; }
/** * sets all cache-relevant headers * * @param servletResponse the {@link HttpServletResponse} to add the headers to */ public void setCacheHeaders(HttpServletResponse servletResponse) { addHeader(servletResponse, getTransferable().getAttribute(HttpHeaderAttribute.HEADER_CACHE_CONTROL)); addHeader(servletResponse, getTransferable().getAttribute(HttpHeaderAttribute.HEADER_EXPIRES)); addHeader(servletResponse, getTransferable().getAttribute(HttpHeaderAttribute.HEADER_E_TAG)); addHeader(servletResponse, getTransferable().getAttribute(HttpHeaderAttribute.HEADER_LAST_MODIFIED)); }
private void setPayloadAsStreamPayload(Transferable requestTransferable) throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream(base64DecodePayload(requestTransferable.getPayload())); requestTransferable.setPayload(new StreamPayload(bais, "UTF-8")); }
lQueryString.append(preconfiguredQuery); String specialQueryStr = (String) pRequest.getAttributeValue(TransferAttribute.QUERY_STRING_ATTR); if (specialQueryStr != null) { if (lQueryString.length() > 0) { pRequest.addAttribute(new SimpleTransferAttribute(TransferAttribute.QUERY_STRING_ATTR, lQueryString.toString())); if ((pRequest.getPayload() instanceof QueryStringPayload)) { QueryStringPayload qpayload = (QueryStringPayload) pRequest.getPayload(); addQueryStringPayload(postRequest, qpayload); } else { postRequest.content(new InputStreamHTTPContentWriter(pRequest.getPayload().getAsStream())); LOG.debug("Request Body:\n{}", pRequest.getPayload().toString());
charset = determineCharsetFromHTMLContent(responseTransferable.getPayload().toString()); responseTransferable.getPayload().getAsStream(), charset); responseTransferable.addAttribute(HttpHeaderAttribute.createHttpHeaderAttribute(header.getKey(), headerValues.toString())); LOG.debug("Adding response header -> {}: {}", header.getKey(), header.getValue()); responseTransferable.addAttribute(new SimpleTransferAttribute(TransferAttribute.RESPONSE_STATUS_CODE, String.valueOf(statusCode.getCode()))); String acceptEncoding = (String) pRequest.getAttributeValue("accept-encoding"); if (acceptEncoding != null && acceptEncoding.contains("gzip")) { responseTransferable.addAttribute(HttpHeaderAttribute.createHttpHeaderAttribute( HttpHeaderAttribute.HEADER_NAME_CONTENT_ENCODING, "gzip")); } else { responseTransferable.removeAttribute(HttpHeaderAttribute.HEADER_NAME_CONTENT_ENCODING); LOG.trace(responseTransferable.getPayload().toString()); } else { LOG.trace("Response of Content-Type <" + contentType + "> won't be logged as it is expected to be binary content.");
String dcpType, LicenseReference licRef) { String contentType = (String) requestTransferable.getAttributeValue(HttpHeaderAttribute.HEADER_NAME_CONTENTTYPE); String enconding = (String) requestTransferable.getAttributeValue(HttpHeaderAttribute.HEADER_NAME_CONTENTCHARSET); Payload pPayload = requestTransferable.getPayload();
private boolean isMimeTypeTextOrXML(Transferable lResponse) { return ((String) lResponse.getAttributeValue(HttpHeaderAttribute.HEADER_NAME_CONTENTTYPE)).indexOf("text") != -1 || ((String) lResponse.getAttributeValue(HttpHeaderAttribute.HEADER_NAME_CONTENTTYPE)).indexOf("xml") != -1; }
TransferAttribute lContentType = (TransferAttribute) pResponse.getResponse().getAttribute( HttpHeaderAttribute.HEADER_NAME_CONTENTTYPE); if (lContentType == null) { String lPayloadAsString = pResponse.getResponse().getPayload().toString(); String lUSerInfo = getUserDesignator(pSubject);
lRes.addAttribute(HttpHeaderAttribute.createHttpHeaderAttribute(key, headerValue)); if (LOG.isDebugEnabled()) { LOG.debug("Add Response HeaderAttribute -> " + key + " = " + headerValue); lRes.addAttribute(new SimpleTransferAttribute(TransferAttribute.RESPONSE_STATUS_CODE, String.valueOf(httpResponse.getStatus().getCode()))); lRes.removeAttribute(HttpHeaderAttribute.HEADER_NAME_CONTENT_ENCODING); LOG.debug(lRes.getPayload().toString());
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); }
public Transferable handleException(Exception e, Transferable req) { // get the errorType Payload reqPayload = req.getPayload(); QueryStringPayload queryString = null; // Return if the request structure does not meet our needs if (!(reqPayload instanceof QueryStringPayload)) { try { reqPayload = new QueryStringPayload(req.toString()); } catch (Exception ex) { return createDefaultError(); } } queryString = (QueryStringPayload) reqPayload; // might be more than one! String exceptionType = queryString.getParameterValue("EXCEPTIONS"); exceptionType = (exceptionType == null) ? "XML" : exceptionType.toUpperCase(); Transferable response = null; if (exceptionType.indexOf("BLANK") != -1) { response = generateErrorImage(queryString, null, false); } else if (exceptionType.indexOf("INIMAGE") != -1) { response = generateErrorImage(queryString, ServiceException.ERROR_MESSAGE, true); } else { response = createDefaultError(); } return response; }
private void addGzipHeaderIfAccepted(FacadeResponse facadeResponse, Transferable serverResponse) { if (facadeResponse.isGzipAccepted()) { serverResponse.addAttribute(HttpHeaderAttribute.createHttpHeaderAttribute(HttpHeaderAttribute.HEADER_NAME_CONTENT_ENCODING, "gzip")); } }
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; } } } }
lQueryString.append(preconfiguredQuery); String payloadQuery = requestTransferable.getPayload().toString(); if (payloadQuery != null && payloadQuery.length() > 0) { if (lQueryString.length() > 0) { String specialQueryStr = (String) requestTransferable.getAttributeValue(TransferAttribute.QUERY_STRING_ATTR); if (specialQueryStr != null) { if (lQueryString.length() > 0) { requestTransferable.addAttribute(new SimpleTransferAttribute(TransferAttribute.QUERY_STRING_ATTR, lQueryString.toString()));
private Transferable forwardPost(Transferable owsRequest) throws ServiceException { PostMethod method = new PostMethod(getURL().toString()); String contentType = (String) owsRequest.getAttributeValue(HttpHeaderAttribute.HEADER_NAME_CONTENTTYPE); method.setRequestEntity(new InputStreamRequestEntity(owsRequest.getPayload().getAsStream(), contentType)); Transferable trans; try { trans = initBasicResponseTransferable(method); } catch (Exception e) { throw new ServiceException(String.format("Could not send basic GET request to <%s>.", getURL()), ServiceException.SERVICE_ERROR, e); } finally { method.releaseConnection(); } return trans; }
public void setStatusCodeHeader(HttpServletResponse servletResponse) { String httpCode = (String) getTransferable().getAttributeValue(HttpHeaderAttribute.RESPONSE_STATUS_CODE); if (httpCode != null && httpCode.length() > 0) { // write the correct status code servletResponse.setStatus(Integer.parseInt(httpCode)); } // Write only known HttpHeaders! }
setContentTypeHeader(servletResponse); setCacheHeaders(servletResponse); addHeader(servletResponse, getTransferable().getAttribute(HttpHeaderAttribute.HEADER_LOCATION)); TransferAttribute contentEncoding = getTransferable().getAttribute(HttpHeaderAttribute.HEADER_NAME_CONTENT_ENCODING); boolean gzip = contentEncoding != null && "gzip".equalsIgnoreCase((String) contentEncoding.getValue()); if (gzip) { addHeader(servletResponse, getTransferable().getAttribute(HttpHeaderAttribute.HEADER_NAME_COOKIE)); OutputStream destinationStream; try { return; InputStream sourceStream = getTransferable().getPayload().getAsStream(); writeStream(sourceStream, destinationStream, gzip);
/** * @param owsRequest * @return * @throws ServiceException */ private Transferable forwardGet(Transferable owsRequest) throws ServiceException { GetMethod method = new GetMethod(getURL().toString()); Payload payload = owsRequest.getPayload(); String baseQueryString = method.getQueryString(); if (baseQueryString != null && baseQueryString.length() > 0) { baseQueryString = baseQueryString + "&" + payload.toString(); } else { baseQueryString = payload.toString(); } method.setQueryString(baseQueryString); Transferable trans; try { trans = initBasicResponseTransferable(method); } catch (Exception e) { throw new ServiceException(String.format("Could not send basic GET request to <%s>.", getURL()), ServiceException.SERVICE_ERROR, e); } finally { method.releaseConnection(); } return trans; }
private void addPathinfoAttribute(Transferable secRequest) { String proxyRequestPathInfo = m_wssRequestUrl.getEffectivePathInfo(); if (proxyRequestPathInfo != null) { secRequest .addAttribute(new SimpleTransferAttribute(TransferAttribute.PATHINFO_ATTR, proxyRequestPathInfo)); } }