private void addXForwardedForHeaderAttribute(HttpServletRequest servletRequest, SecuredServiceRequest secRequest) { // Insert to enable SinqleInquiry Interceptor secRequest.addAttribute(HttpHeaderAttribute.createHttpHeaderAttribute( HttpHeaderAttribute.HEADER_NAME_XFORWARDEDFOR, servletRequest.getRemoteAddr())); }
@Override public void handle(HttpHeaderAttribute attribute) { // //Don't set content-encoding, this is should property that is set by the surrounding // //server logic. // if (attribute.getName().equalsIgnoreCase(HttpHeaderAttribute.HEADER_NAME_CONTENT_ENCODING)) { // return; // } //Don't set content-length, because this depends on using gzip or nor, eg, and can't be decided here. if (attribute.getName().equalsIgnoreCase("Content-Length")) { return; } m_toClientStream.setHeader(attribute.getName(), (String) attribute.getValue()); } }
public static HttpHeaderAttribute createHttpHeaderAttribute(String pName,String pValue){ return new HttpHeaderAttribute(pName,pValue); }
private boolean headerNameIs(HttpHeaderAttribute httpHeaderAttribute, String headerName) { return httpHeaderAttribute.getName().equalsIgnoreCase(headerName); }
private void addReferrerHeaderAttribute(HttpServletRequest servletRequest, SecuredServiceRequest secRequest) { // insert referer String referer = servletRequest.getHeader(HttpHeaderAttribute.HEADER_NAME_REFERER); if (referer != null && referer.length() > 0) { secRequest.addAttribute(HttpHeaderAttribute.createHttpHeaderAttribute( HttpHeaderAttribute.HEADER_NAME_REFERER, referer)); } }
@Override public void handle(HttpHeaderAttribute attribute) { Headers responseHeaders = m_exchange.getResponseHeaders(); boolean headerAlreadyPresent = responseHeaders.getFirst(attribute.getName()) != null; if (headerAlreadyPresent) { return; } responseHeaders.add(attribute.getName(), (String) attribute.getValue()); } }
private void addContentTypeHeaderAttribute(HttpServletRequest servletRequest, SecuredServiceRequest secRequest) { if (servletRequest.getContentType() != null) { secRequest.addAttribute(HttpHeaderAttribute.createHttpHeaderAttribute( HttpHeaderAttribute.HEADER_NAME_CONTENTTYPE, servletRequest.getContentType())); } }
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); }
private void addGzipHeaderIfAccepted(FacadeResponse facadeResponse, Transferable serverResponse) { if (facadeResponse.isGzipAccepted()) { serverResponse.addAttribute(HttpHeaderAttribute.createHttpHeaderAttribute(HttpHeaderAttribute.HEADER_NAME_CONTENT_ENCODING, "gzip")); } }
private void addContentCharsetHeaderAttribute(HttpServletRequest servletRequest, SecuredServiceRequest secRequest) { // this is obviously a misuse of the "Content-Encoding" header that // describes the encoding of the /content/ of the body // and not the body itself. However, it is added to imitate what is done // by the SecurityServiceServlet class. secRequest.addAttribute(HttpHeaderAttribute.createHttpHeaderAttribute( HttpHeaderAttribute.HEADER_NAME_CONTENTCHARSET, getNullSafeEncoding(servletRequest))); }
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; }
public Transferable createStreamTransferable(final String pContentType, final InputStream pPayLoad, final String pCharset) throws IOException { Transferable lTransferable = new TransferableImpl(); lTransferable.setPayload(new StreamPayload(pPayLoad, pCharset)); if (pContentType != null) { String contentType = addCharset(pContentType, pCharset); lTransferable.addAttribute(HttpHeaderAttribute.createHttpHeaderAttribute( HttpHeaderAttribute.HEADER_NAME_CONTENTTYPE, contentType)); } if (pCharset != null) { lTransferable.addAttribute(HttpHeaderAttribute.createHttpHeaderAttribute( HttpHeaderAttribute.HEADER_NAME_CONTENTCHARSET, pCharset)); } return lTransferable; }
responseTransferable.addAttribute(HttpHeaderAttribute.createHttpHeaderAttribute(header.getKey(), headerValues.toString())); LOG.debug("Adding response header -> {}: {}", header.getKey(), header.getValue()); if (acceptEncoding != null && acceptEncoding.contains("gzip")) { responseTransferable.addAttribute(HttpHeaderAttribute.createHttpHeaderAttribute( HttpHeaderAttribute.HEADER_NAME_CONTENT_ENCODING, "gzip")); } else {
lRes.addAttribute(HttpHeaderAttribute.createHttpHeaderAttribute(key, headerValue)); if (LOG.isDebugEnabled()) { LOG.debug("Add Response HeaderAttribute -> " + key + " = " + headerValue);
private Transferable addCommonAttributes(Transferable request) { String pathInfo = getPathInfo(); String additionalPath = FacadeTools.extractAdditionalPathInfo(pathInfo); request.addAttribute(new SimpleTransferAttribute(TransferAttribute.PATHINFO_ATTR, additionalPath)); request.addAttribute(new SimpleTransferAttribute(TransferAttribute.REQUEST_IP_ATTR, getRemoteAddress())); // Is the "X-Forwarded-For" header already set? String headerXForwardedFor = getXForwardedForHeader(); // If not set, set caller's ip, otherwise append caller's ip headerXForwardedFor = (headerXForwardedFor == null) ? getRemoteAddress() : headerXForwardedFor .concat(" ," + getRemoteAddress()); // Create according TransferAttribute request.addAttribute(HttpHeaderAttribute.createHttpHeaderAttribute( HttpHeaderAttribute.HEADER_NAME_XFORWARDEDFOR, headerXForwardedFor)); String referrerHeader = getHttpReferrerHeader(); if (referrerHeader != null) { request.addAttribute(HttpHeaderAttribute.createHttpHeaderAttribute(HttpHeaderAttribute.HEADER_NAME_REFERER, referrerHeader)); } return request; }