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; }
protected String appendPathInfo(String escapedEndpointUrl, Transferable pRequest) throws URISyntaxException { Object pathInfo = pRequest.getAttributeValue(TransferAttribute.PATHINFO_ATTR); if (pathInfo == null) { return escapedEndpointUrl; } return addPathInfo(escapedEndpointUrl, (String) pathInfo); } }
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! }
private QueryStringPayload getQueryStringPayload(Transferable request) { Object queryString = request.getAttributeValue(TransferAttribute.QUERY_STRING_ATTR); if (queryString == null) { return null; } return getAsQueryStringPayload((String) queryString); }
protected HTTPClientFactory getHttpClientFactory(Transferable pRequest) { HTTPClientFactory httpClientFactory = (HTTPClientFactory) pRequest.getAttributeValue(HTTP_CLIENT_FACTORY); if (httpClientFactory == null) { return new JDKHTTPClientFactory(); } return httpClientFactory; }
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 void check(FacadeRequest facadeRequest) throws FacadeConstraintViolationException { if (m_acceptPatterns.size() == 0) { return; } String headerVal = (String) facadeRequest.getRequest().getAttributeValue(HttpHeaderAttribute.HEADER_NAME_REFERER); if (headerVal == null || headerVal.equals("")) { throw new FacadeConstraintViolationException("Missing Referrer HTTP header value.", this); } for (Pattern pattern : m_acceptPatterns) { if (pattern.matcher(headerVal).matches()) { return; } } throw new FacadeConstraintViolationException("Referrer value of <" + headerVal + "> does not match this constraint.", this); }
private String modifyContentTypeAttributeValue(Transferable requestTransferable, String contentType) { String contentCharset = (String) requestTransferable.getAttributeValue(HttpHeaderAttribute.HEADER_NAME_CONTENTCHARSET); return new ContentTypeRewriter().rewriteCharset(contentType, contentCharset); }
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();
public Transferable doResponse(Subject subject, InterceptorResponse iresponse) throws InterceptorException, EnforcementServiceException { SecuredServiceRequest req = iresponse.getRequest(); Transferable res = iresponse.getResponse(); String lMimeType = (String) res.getAttributeValue(HttpHeaderAttribute.HEADER_NAME_CONTENTTYPE); // is this a textual document that might contain urls of a secured // service if (lMimeType.indexOf("text") != -1 || lMimeType.indexOf("xml") != -1) { String lServiceEndpoint = ((HttpRequestForward) req.getForward()).getServiceEndpoint(); String lFacadeUrl = ((HttpRequestForward) req.getForward()).getFacadeUrl(); String lEncoding = (String) res.getAttributeValue(HttpHeaderAttribute.HEADER_NAME_CONTENTCHARSET); res.setPayload(replaceURLby(lServiceEndpoint, lFacadeUrl, res.getPayload().toString(), lEncoding, lMimeType)); } return res; }
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; }
String specialQueryStr = (String) requestTransferable.getAttributeValue(TransferAttribute.QUERY_STRING_ATTR); if (specialQueryStr != null) { if (lQueryString.length() > 0) {
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); }
String mimeType = (String) response.getAttributeValue(HttpHeaderAttribute.HEADER_NAME_CONTENTTYPE); LOG.debug("Intercepting GetCapabilites response"); String encoding = (String) response.getAttributeValue(HttpHeaderAttribute.HEADER_NAME_CONTENTCHARSET);
lQueryString.append(preconfiguredQuery); String specialQueryStr = (String) pRequest.getAttributeValue(TransferAttribute.QUERY_STRING_ATTR); if (specialQueryStr != null) { if (lQueryString.length() > 0) {
LOG.debug("Intercepting GetCapabilites response"); String encoding = (String) response.getAttributeValue(HttpHeaderAttribute.HEADER_NAME_CONTENTCHARSET);
LOG.debug("Intercepting GetObservation response"); String encoding = (String) response.getAttributeValue(HttpHeaderAttribute.HEADER_NAME_CONTENTCHARSET);
LOG.debug("Intercepting GetFeatureOfInterest response"); String encoding = (String) response.getAttributeValue(HttpHeaderAttribute.HEADER_NAME_CONTENTCHARSET);
String encoding = (String) response.getAttributeValue(HttpHeaderAttribute.HEADER_NAME_CONTENTCHARSET);
public Transferable doResponse(Subject subject, InterceptorResponse interceptroResponse) throws InterceptorException, EnforcementServiceException { if (!isGetCapabilitiesRequest(interceptroResponse.getRequest())) return interceptroResponse.getResponse(); if (!isMimeTypeTextOrXML(interceptroResponse.getResponse())) return interceptroResponse.getResponse(); Transferable responseTransferable = interceptroResponse.getResponse(); String lEncoding = (String) responseTransferable.getAttributeValue(HttpHeaderAttribute.HEADER_NAME_CONTENTCHARSET); String trimmedCaps = removeUnauthorizedLayersFromCaps(subject, responseTransferable.getPayload().toString(), interceptroResponse); responseTransferable.setPayload(new TextualPayload(trimmedCaps, lEncoding)); return responseTransferable; }