List of usage examples for org.apache.commons.httpclient HttpMethod removeRequestHeader
public abstract void removeRequestHeader(Header paramHeader);
From source file:com.groupon.odo.Proxy.java
/** * Execute a request through Odo processing * * @param httpMethodProxyRequest/*from www. j ava2 s. c o m*/ * @param httpServletRequest * @param httpServletResponse * @param history */ private void executeProxyRequest(HttpMethod httpMethodProxyRequest, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, History history) { try { RequestInformation requestInfo = requestInformation.get(); // Execute the request // removing accept headers so that the server doesn't encode anything // TODO: make this handle things like gzip encoding httpMethodProxyRequest.removeRequestHeader(Constants.HEADER_ACCEPT_ENCODING); httpMethodProxyRequest.removeRequestHeader(Constants.HEADER_ACCEPT); // set virtual host so the server knows how to direct the request // If the host header exists then this uses that value // Otherwise the hostname from the URL is used processVirtualHostName(httpMethodProxyRequest, httpServletRequest); cullDisabledPaths(); // define output stream OutputStream outStream = new ByteArrayOutputStream(); requestInfo.hasCustomResponse = hasCustomResponse(); if (!requestInfo.hasCustomResponse) { logger.info("Sending request to server"); history.setModified(requestInfo.modified); executeRequest(httpMethodProxyRequest, httpServletRequest, httpServletResponse, history, outStream); } if (requestInfo.selectedResponsePaths.size() > 0) { requestInfo.outputString = outStream.toString(); } logOriginalResponseHistory(httpServletResponse, history, outStream); String jsonpCallback = stripJSONPToOutstr(httpServletRequest); applyResponseOverrides(httpServletResponse, httpServletRequest, history); writeResponseOutput(httpServletResponse, outStream, jsonpCallback); // store history history.setModified(requestInfo.modified); logRequestHistory(httpMethodProxyRequest, httpServletResponse, history); } catch (Exception e) { e.printStackTrace(); return; } }
From source file:com.groupon.odo.Proxy.java
/** * Apply any applicable header overrides to request * * @param httpMethodProxyRequest/*from www.j a v a 2 s . co m*/ * @throws Exception */ private void processRequestHeaderOverrides(HttpMethod httpMethodProxyRequest) throws Exception { for (EndpointOverride selectedPath : requestInformation.get().selectedRequestPaths) { List<EnabledEndpoint> points = selectedPath.getEnabledEndpoints(); for (EnabledEndpoint endpoint : points) { if (endpoint.getOverrideId() == Constants.PLUGIN_REQUEST_HEADER_OVERRIDE_ADD) { httpMethodProxyRequest.addRequestHeader(endpoint.getArguments()[0].toString(), endpoint.getArguments()[1].toString()); requestInformation.get().modified = true; } else if (endpoint.getOverrideId() == Constants.PLUGIN_REQUEST_HEADER_OVERRIDE_REMOVE) { httpMethodProxyRequest.removeRequestHeader(endpoint.getArguments()[0].toString()); requestInformation.get().modified = true; } } } }
From source file:org.apache.wookie.proxy.ProxyClient.java
private String executeMethod(HttpMethod method, Configuration properties) throws Exception, AuthenticationException { // Execute the method. try {/* w w w. j a va2s .c o m*/ HttpClient client = new HttpClient(); // set the clients proxy values if needed ConnectionsPrefsManager.setProxySettings(client, properties); if (fUseProxyAuthentication) { if (fBase64Auth != null) { method.setRequestHeader("Authorization", fBase64Auth); } else { List<String> authPrefs = new ArrayList<String>(2); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); // send the basic authentication response even before the server gives an unauthorized response client.getParams().setAuthenticationPreemptive(true); // Pass our credentials to HttpClient client.getState().setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM), new UsernamePasswordCredentials(fProxyUsername, fProxyPassword)); } } // Add user language to http request in order to notify server of user's language Locale locale = Locale.getDefault(); method.setRequestHeader("Accept-Language", locale.getLanguage()); //$NON-NLS-1$ method.removeRequestHeader("Content-Type"); //method.setRequestHeader("Content-Type","application/json"); //method.setRequestHeader("Referer", ""); //method.removeRequestHeader("Referer"); method.setRequestHeader("Accept", "*/*"); int statusCode = client.executeMethod(method); //System.out.println("response="+method.getResponseBodyAsString()); //System.out.println("method="+method.toString()); //System.out.println("response="+method.getResponseBodyAsStream()); if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) { Header hType = method.getResponseHeader("Content-Type"); if (hType != null) { fContentType = hType.getValue(); } // for now we are only expecting Strings //return method.getResponseBodyAsString(); return readFully(new InputStreamReader(method.getResponseBodyAsStream(), "UTF-8")); } else if (statusCode == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED || statusCode == HttpStatus.SC_UNAUTHORIZED) { throw new AuthenticationException("Authentication failed:" + method.getStatusLine() + ' ' + method.getURI() + ' ' + method.getStatusText()); } else { throw new Exception("Method failed: " + method.getStatusLine() + ' ' + method.getURI() + ' ' //$NON-NLS-1$ + method.getStatusText()); } } catch (IOException e) { throw e; } finally { // Release the connection. method.releaseConnection(); } }
From source file:org.infoscoop.request.SendPortalCredentialHeaderAuthenticator.java
public void doAuthentication(HttpClient client, ProxyRequest request, HttpMethod method, String uid, String pwd) throws ProxyAuthenticationException { String uidHeaderNameHeader = request.getRequestHeader(UID_PARAM_NAME); String uidHeaderName = (uidHeaderNameHeader != null) ? uidHeaderNameHeader : this.uidHeaderName; try {/*from www . ja v a 2 s . c om*/ method.removeRequestHeader(uidHeaderName); method.addRequestHeader(uidHeaderName, uid); } catch (Exception e) { throw new ProxyAuthenticationException(e); } }
From source file:org.mule.transport.as2.As2MessageDispatcher.java
/** * Set AS2 Specific Headers// w ww .ja v a2s .c o m * */ private void setAS2Headers(MuleEvent event, HttpMethod httpMethod) { logger.debug("DBG: inside " + getClass() + ".setAS2Headers()"); String asTo = as2Connector.getPartnerId(); logger.debug(AS2Constants.HEADER_TO + ": " + asTo); String asFrom = as2Connector.getSenderId(); logger.debug(AS2Constants.HEADER_FROM + ": " + asFrom); String subject = (String) endpoint.getProperty("subject"); /* N.B. Content-Type is already set in the AS2ObjectToHttpMethodRequest */ httpMethod.setRequestHeader( new Header(AS2Constants.HEADER_CONTENT_DISPOSITION, AS2Constants.HEADER_ATTACHMENT_VALUE)); httpMethod.setRequestHeader(new Header(AS2Constants.HEADER_FROM, asFrom)); httpMethod.setRequestHeader( new Header(AS2Constants.HEADER_EDIINT_FEATURES, AS2Constants.HEADER_EDIINT_FEATURES_VALUE)); httpMethod.setRequestHeader(new Header(AS2Constants.HEADER_DATE, new Date().toString())); httpMethod.setRequestHeader(new Header(AS2Constants.HEADER_TO, asTo)); httpMethod.setRequestHeader(new Header(AS2Constants.HEADER_DISPOSITION_NOTIFICATION_TO, asFrom)); // httpMethod.setRequestHeader(new Header(AS2Constants.HEADER_SIMPLE_FROM, "qvc@qvc.com")); httpMethod.setRequestHeader(new Header(AS2Constants.HEADER_VERSION, AS2Constants.HEADER_AS2_VERSION_VALUE)); httpMethod.setRequestHeader( new Header(AS2Constants.HEADER_MIME_VERSION, AS2Constants.HEADER_MIME_VERSION_VALUE)); httpMethod.setRequestHeader(new Header(AS2Constants.HEADER_RECIPIENT_ADDRESS, endpoint.getEndpointURI().getAddress().replaceFirst("as2", "http"))); httpMethod.setRequestHeader(new Header(AS2Constants.HEADER_MESSAGE_ID, "<AS2_" + RandomStringUtils.randomAlphanumeric(4) + "@" + asFrom + "_" + asTo + ">")); if (subject != null) { httpMethod.setRequestHeader(new Header(AS2Constants.HEADER_SUBJECT, as2Connector.getFilenameParser().getFilename(event.getMessage(), subject))); } /* Remove MULE Message Headers */ httpMethod.removeRequestHeader("X-MULE_ENDPOINT"); httpMethod.removeRequestHeader("X-MULE_ENCODING"); httpMethod.removeRequestHeader("X-MULE_ROOT_MESSAGE_ID"); httpMethod.removeRequestHeader("X-MULE_CORRELATION_ID"); httpMethod.removeRequestHeader("X-MULE_SESSION"); }
From source file:org.mule.transport.legstar.http.LegstarHttpMessageDispatcher.java
/** * We override this method because we need to perform LegStar messaging specific * transformations and also need to force the http header content type. * {@inheritDoc}/*w w w. j ava2 s . com*/ * */ public final HttpMethod getMethod(final MuleEvent event) throws TransformerException { if (_log.isDebugEnabled()) { _log.debug("Creating http method for endpoint " + getEndpoint()); } HttpMethod httpMethod = super.getMethod(event); /* Force the content type expected by the Mainframe */ httpMethod.removeRequestHeader(HttpConstants.HEADER_CONTENT_TYPE); httpMethod.addRequestHeader(HttpConstants.HEADER_CONTENT_TYPE, LEGSTAR_HTTP_CONTENT_TYPE); if (isHostTraceOn(event.getMessage()) || _log.isDebugEnabled()) { httpMethod.addRequestHeader(LEGSTAR_HTTP_HEADER_TRACE_MODE, "true"); } return httpMethod; }