@Override public HTTPProcessor createProcessor(ExecutorService executorService) { return new JDKHTTPProcessor(executorService); }
public HTTPClientFactory getHttpClientFactory() { if (httpClientFactory == null) { synchronized (this) { if (httpClientFactory == null) { httpClientFactory = new JDKHTTPClientFactory(); } } } return httpClientFactory; }
@Override protected <T> HTTPResponseAdapter<T> process( final HTTPMethod method, final String endpointWithParameter, final KvPCollection header, final HTTPContentWriter contentWriter, final HTTPContentReader<T> contentReader, final HTTPConnectionParameter connectionParameter) throws Exception { HttpURLConnection urlcon = openConnection(endpointWithParameter); urlcon.setRequestMethod(method.name()); applyHeader(urlcon, header); applyConnectionParameter(urlcon, connectionParameter); String contentCharset = getCharsetFromContentTypeHeader(header); sendContent(urlcon, contentCharset, header, contentWriter, connectionParameter.isAllowChunkedRequestContent()); HTTPResponseAdapter<T> response = prepareResponse(endpointWithParameter, urlcon); readResponseContent(urlcon, response, contentReader, connectionParameter); return response; }
private <T> void readResponseContent( HttpURLConnection urlcon, HTTPResponseAdapter<T> response, HTTPContentReader<T> contentReader, HTTPConnectionParameter connectionParameter) throws Exception { InputStream input = openInputStream(urlcon, connectionParameter); if (connectionParameter.isUseContentEncoding()) { // clear content encoding header, if transparent use response.getModifiableHeader().set(HTTPHeader.CONTENT_ENCODING.getName(), null); } if (input == null) { // no content provided return; } readResponseContent(input, response, contentReader); }
private <T> HTTPResponseAdapter<T> prepareResponse( String endpoint, HttpURLConnection urlcon) throws IOException { int code = urlcon.getResponseCode(); KvPCollection headers = new KvPCollection().addAll(urlcon.getHeaderFields()); return createResponseAdapter(endpoint, code, headers); }
private void applyConnectionParameter(HttpURLConnection urlcon, HTTPConnectionParameter connectionParameter) { urlcon.setConnectTimeout(Math.max(0, connectionParameter.getConnectTimeoutInSec() * 1000)); urlcon.setReadTimeout(Math.max(0, connectionParameter.getReadTimeoutInSec() * 1000)); urlcon.setInstanceFollowRedirects(connectionParameter.isFollowRedirects()); urlcon.setUseCaches(false); if (connectionParameter.isUseContentEncoding()) { urlcon.setRequestProperty(HTTPHeader.ACCEPT_ENCODING.getName(), "gzip,deflate"); } if (urlcon instanceof HttpsURLConnection) { HttpsURLConnection httpsUrlCon = (HttpsURLConnection) urlcon; SSLContext sslContext = connectionParameter.getSSLContext(); if (sslContext != null) { httpsUrlCon.setSSLSocketFactory(sslContext.getSocketFactory()); } HostnameVerifier sslHostNameVerifier = connectionParameter.getSSLHostnameVerifier(); if (sslHostNameVerifier != null) { httpsUrlCon.setHostnameVerifier(sslHostNameVerifier); } } String proxy = connectionParameter.getProxy(); if (!proxy.isEmpty()) { warnProxy(proxy); } }
/** * Creates a new WSS 1.1 client object. * @param wssUrl URL of the WSS */ public WSS1_1Adapter(URL wssUrl) { this.wssURLString = wssUrl.toExternalForm(); this.httpClientFactory = new JDKHTTPClientFactory(); }
protected HTTPClientFactory getHttpClientFactory(Transferable pRequest) { HTTPClientFactory httpClientFactory = (HTTPClientFactory) pRequest.getAttributeValue(HTTP_CLIENT_FACTORY); if (httpClientFactory == null) { return new JDKHTTPClientFactory(); } return httpClientFactory; }
protected HTTPClientFactory getHttpClientFactory() { HTTPClientFactory clientFactory = (HTTPClientFactory) getSecurityConfig().getPreConfiguredInstance("httpClientFactory"); if (clientFactory == null) { clientFactory = new JDKHTTPClientFactory(); } return clientFactory; } }
protected void init(final ServletConfig servletConfig, final ServiceConfig serviceConfig, final SecurityConfig secConfig) { if (serviceConfig.getInstance() instanceof PolicyEnforcementServiceLocator) { m_pesLocator = (PolicyEnforcementServiceLocator) serviceConfig.getInstance(); } if (m_pesLocator == null) { m_pesLocator = (PolicyEnforcementServiceLocator) serviceConfig.getProperties().get( "policyEnforcementServiceLocator"); } if (m_pesLocator == null) { // backwards compatibility SecurityConfigPolicyEnforcementServiceLocator securityConfigLocator = new SecurityConfigPolicyEnforcementServiceLocator(); securityConfigLocator.setServiceConfig(serviceConfig); m_pesLocator = securityConfigLocator; } httpClientFactory = (HTTPClientFactory) serviceConfig.getProperties().get(HttpRequestForward.HTTP_CLIENT_FACTORY); if (httpClientFactory == null) { httpClientFactory = new JDKHTTPClientFactory(); } }
httpClientFactory = new JDKHTTPClientFactory();
public void doService(WebSecurityProcessingContext securityCtx, WebContext webCtx, WebSecurityProcessorChain processorChain) throws IOException { HttpServletRequest req = webCtx.getRequest(); HttpServletResponse resp = webCtx.getResponse(); WSSRequestUrlFactory requestUrlFactory = new WSSRequestUrlFactory(); requestUrlFactory.setTargetPathPatternMappingService(getPathMappingService()); EnforcementServiceRequest wssRequestUrl = requestUrlFactory.getInstance(req); String pesId = wssRequestUrl.getEnforcementPointId(); PolicyEnforcementServiceImpl pes = pesLocator.locate(pesId); if (pes == null) { String errorMessage = String.format( "No enforcement point configuration for id <%s>", pesId); resp.sendError(HttpServletResponse.SC_NOT_FOUND, errorMessage); return; } ForwardingSecuredServiceRequestBuilder requestBuilder = new ForwardingSecuredServiceRequestBuilder(wssRequestUrl); requestBuilder.setProtectedServiceEndpoint(new URL(pes.getEndpoint())); //this doesn't work, yet. It simply assumes, that there is a valid path to this endpoint ending with /public requestBuilder.setRedirectionAuthenticationUrl(wssRequestUrl.buildServiceUrl() + "/public"); SecuredServiceRequest secRequest = requestBuilder.build(req, resp); if (getHttpClientFactory() == null){ secRequest.addAttribute(new SimpleTransferAttribute(HttpRequestForward.HTTP_CLIENT_FACTORY, new JDKHTTPClientFactory())); } else { secRequest.addAttribute(new SimpleTransferAttribute(HttpRequestForward.HTTP_CLIENT_FACTORY, getHttpClientFactory())); } authorize(resp, pes, secRequest, securityCtx.getAuthenticationContext()); processorChain.performAccessControl(webCtx); }