Package org.apache.cxf.transports.http.configuration

Examples of org.apache.cxf.transports.http.configuration.HTTPClientPolicy


        }      

        // The need to cache the request is off by default
        boolean needToCacheRequest = false;
       
        HTTPClientPolicy csPolicy = getClient(message);
        setupConnection(message, currentURI, csPolicy);
       
        // If the HTTP_REQUEST_METHOD is not set, the default is "POST".
        String httpRequestMethod =
            (String)message.get(Message.HTTP_REQUEST_METHOD);
        if (httpRequestMethod == null) {
            httpRequestMethod = "POST";
            message.put(Message.HTTP_REQUEST_METHOD, "POST");
        }
               
        boolean isChunking = false;
        int chunkThreshold = 0;
        final AuthorizationPolicy effectiveAuthPolicy = getEffectiveAuthPolicy(message);
        if (this.authSupplier == null) {
            this.authSupplier = createAuthSupplier(effectiveAuthPolicy.getAuthorizationType());
        }
       
        if (this.proxyAuthSupplier == null) {
            this.proxyAuthSupplier = createAuthSupplier(proxyAuthorizationPolicy.getAuthorizationType());
        }

        if (this.authSupplier.requiresRequestCaching()) {
            needToCacheRequest = true;
            isChunking = false;
            LOG.log(Level.FINE,
                    "Auth Supplier, but no Premeptive User Pass or Digest auth (nonce may be stale)"
                    + " We must cache request.");
        }
        if (csPolicy.isAutoRedirect()) {
            needToCacheRequest = true;
            LOG.log(Level.FINE, "AutoRedirect is turned on.");
        }
        if (csPolicy.getMaxRetransmits() > 0) {
            needToCacheRequest = true;
            LOG.log(Level.FINE, "MaxRetransmits is set > 0.");
        }
        // DELETE does not work and empty PUTs cause misleading exceptions
        // if chunking is enabled
        // TODO : ensure chunking can be enabled for non-empty PUTs - if requested
        if (csPolicy.isAllowChunking()
            && isChunkingSupported(message, httpRequestMethod)) {
            //TODO: The chunking mode be configured or at least some
            // documented client constant.
            //use -1 and allow the URL connection to pick a default value
            isChunking = true;
            chunkThreshold = csPolicy.getChunkingThreshold();
        }
        cookies.writeToMessageHeaders(message);

        // The trust decision is relegated to after the "flushing" of the
        // request headers.
View Full Code Here


        this.authorizationPolicy = authorization;
    }
   
    public HTTPClientPolicy getClient(Message message) {
        ClientPolicyCalculator cpc = new ClientPolicyCalculator();
        HTTPClientPolicy messagePol = message.get(HTTPClientPolicy.class);
        if (messagePol != null) {
            return cpc.intersect(messagePol, clientSidePolicy);
        }

        PolicyDataEngine policyDataEngine = bus.getExtension(PolicyDataEngine.class);
View Full Code Here

                             + new String(cachedStream.getBytes()));
                }

                HttpURLConnection oldcon = connection;
               
                HTTPClientPolicy policy = getClient(outMessage);
               
                // Default MaxRetransmits is -1 which means unlimited.
                int maxRetransmits = (policy == null)
                                     ? -1
                                     : policy.getMaxRetransmits();
               
                // MaxRetransmits of zero means zero.
                if (maxRetransmits == 0) {
                    return;
                }
View Full Code Here

     * @param confPolicy the additional policy to be compatible with
     * @return the HTTPClientPolicy for the message
     * @throws PolicyException if no compatible HTTPClientPolicy can be determined
     */
    public static HTTPClientPolicy getClient(Message message, HTTPClientPolicy confPolicy) {
        HTTPClientPolicy pol = message.get(HTTPClientPolicy.class);
        if (pol != null) {
            return intersect(pol, confPolicy);
        }
        AssertionInfoMap amap =  message.get(AssertionInfoMap.class);
        if (null == amap) {
            return confPolicy;
        }
        Collection<AssertionInfo> ais = amap.get(HTTPCLIENTPOLICY_ASSERTION_QNAME);
        if (null == ais) {
            return confPolicy;
        }
        Collection<PolicyAssertion> alternative = new ArrayList<PolicyAssertion>();
        for (AssertionInfo ai : ais) {
            alternative.add(ai.getAssertion());
        }
        HTTPClientPolicy compatible = getClient(alternative);
        if (null != compatible && null != confPolicy) {
            if (PolicyUtils.compatible(compatible, confPolicy)) {
                compatible = intersect(compatible, confPolicy);
            } else {
                LogUtils.log(LOG, Level.SEVERE, "INCOMPATIBLE_HTTPCLIENTPOLICY_ASSERTIONS");
View Full Code Here

     * @return the compatible policy
     * @throws PolicyException if no compatible HTTPClientPolicy can be determined
     */
    public static HTTPClientPolicy getClient(PolicyEngine pe, EndpointInfo ei, Conduit c) {
        Collection<PolicyAssertion> alternative = pe.getClientEndpointPolicy(ei, c).getChosenAlternative();
        HTTPClientPolicy compatible = null;
        for (PolicyAssertion a : alternative) {
            if (HTTPCLIENTPOLICY_ASSERTION_QNAME.equals(a.getName())) {
                HTTPClientPolicy p = JaxbAssertion.cast(a, HTTPClientPolicy.class).getData();
                if (null == compatible) {
                    compatible = p;
                } else {
                    compatible = intersect(compatible, p);
                    if (null == compatible) {
View Full Code Here

     * client policy.
     * @param message the current message
     * @param client the client policy
     */
    public static void assertClientPolicy(Message message, HTTPClientPolicy client) {
        HTTPClientPolicy pol = message.get(HTTPClientPolicy.class);
        if (pol != null) {
            client = intersect(pol, client);
        }

        AssertionInfoMap aim = message.get(AssertionInfoMap.class);
        if (null == aim) {
            return;
        }
        Collection<AssertionInfo> ais = aim.get(HTTPCLIENTPOLICY_ASSERTION_QNAME);         
        if (null == ais || ais.size() == 0) {
            return;
        }  
       
        // assert all assertion(s) that are compatible with the value configured for the conduit
       
        if (MessageUtils.isOutbound(message)) {                       
            for (AssertionInfo ai : ais) {
                HTTPClientPolicy p = (JaxbAssertion.cast(ai.getAssertion(),
                                                          HTTPClientPolicy.class)).getData();
                if (compatible(p, client)) {
                    ai.setAsserted(true);
                }
            }
View Full Code Here

            return null;
        }
       
        // ok - compute compatible policy
       
        HTTPClientPolicy p = new HTTPClientPolicy();
        p.setAccept(combine(p1.getAccept(), p2.getAccept()));
        p.setAcceptEncoding(combine(p1.getAcceptEncoding(), p2.getAcceptEncoding()));
        p.setAcceptLanguage(combine(p1.getAcceptLanguage(), p2.getAcceptLanguage()));
        if (p1.isSetAllowChunking()) {
            p.setAllowChunking(p1.isAllowChunking());
        } else if (p2.isSetAllowChunking()) {
            p.setAllowChunking(p2.isAllowChunking());
        }
        if (p1.isSetAutoRedirect()) {
            p.setAutoRedirect(p1.isAutoRedirect());
        } else if (p2.isSetAutoRedirect()) {
            p.setAutoRedirect(p2.isAutoRedirect());
        }
        p.setBrowserType(combine(p1.getBrowserType(), p2.getBrowserType()));
        if (p1.isSetCacheControl()) {
            p.setCacheControl(p1.getCacheControl());
        } else if (p2.isSetCacheControl()) {
            p.setCacheControl(p2.getCacheControl());
        }
        if (p1.isSetConnection()) {
            p.setConnection(p1.getConnection());
        } else if (p2.isSetConnection()) {
            p.setConnection(p2.getConnection());
        }       
        if (p1.isSetContentType()) {
            p.setContentType(p1.getContentType());
        } else if (p2.isSetContentType()) {
            p.setContentType(p2.getContentType());           
        }
        p.setCookie(combine(p1.getCookie(), p2.getCookie()));
        p.setDecoupledEndpoint(combine(p1.getDecoupledEndpoint(), p2.getDecoupledEndpoint()));
        p.setHost(combine(p1.getHost(), p2.getHost()));
        p.setProxyServer(combine(p1.getProxyServer(), p2.getProxyServer()));
        if (p1.isSetProxyServerPort()) {
            p.setProxyServerPort(p1.getProxyServerPort());
        } else if (p2.isSetProxyServerPort()) {
            p.setProxyServerPort(p2.getProxyServerPort());
        }
        if (p1.isSetProxyServerType()) {
            p.setProxyServerType(p1.getProxyServerType());
        } else if (p2.isSetProxyServerType()) {
            p.setProxyServerType(p2.getProxyServerType());
        }
        p.setReferer(combine(p1.getReferer(), p2.getReferer()));
        if (p1.isSetConnectionTimeout() || p2.isSetConnectionTimeout()) {
            p.setConnectionTimeout(Math.min(p1.getConnectionTimeout(), p2.getConnectionTimeout()));
        }
        if (p1.isSetReceiveTimeout() || p2.isSetReceiveTimeout()) {
            p.setReceiveTimeout(Math.min(p1.getReceiveTimeout(), p2.getReceiveTimeout()));
        }
        
        return p;     
    }
View Full Code Here

    private static boolean compatible(String s1, String s2) {
        return s1 == null || s2 == null || s1.equals(s2);
    }
   
    private static HTTPClientPolicy getClient(Collection<PolicyAssertion> alternative) {     
        HTTPClientPolicy compatible = null;
        for (PolicyAssertion a : alternative) {
            if (HTTPCLIENTPOLICY_ASSERTION_QNAME.equals(a.getName())) {
                HTTPClientPolicy p = JaxbAssertion.cast(a, HTTPClientPolicy.class).getData();
                if (null == compatible) {
                    compatible = p;
                } else {
                    compatible = intersect(compatible, p);
                    if (null == compatible) {
View Full Code Here

        }
       
        GreetMeLater later = new GreetMeLater();
        later.setRequestType(1000);
       
        HTTPClientPolicy pol = new HTTPClientPolicy();
        pol.setReceiveTimeout(100);
        disp.getRequestContext().put(HTTPClientPolicy.class.getName(), pol);
        Response<Object> o = disp.invokeAsync(later);
        try {
            o.get(10, TimeUnit.SECONDS);
            fail("Should have gotten a SocketTimeoutException");
        } catch (ExecutionException ex) {
            assertTrue(ex.getCause() instanceof SocketTimeoutException);
        }

        later.setRequestType(20000);
        pol.setReceiveTimeout(20000);
        disp.getRequestContext().put(HTTPClientPolicy.class.getName(), pol);
        o = disp.invokeAsync(later);
        try {
            o.get(100, TimeUnit.MILLISECONDS);
            fail("Should have gotten a SocketTimeoutException");
View Full Code Here

       
        decoupledEndpointPort--;
        decoupledEndpoint = "http://localhost:" + decoupledEndpointPort + "/decoupled_endpoint";

        HTTPConduit hc = (HTTPConduit)(c.getConduit());
        HTTPClientPolicy cp = hc.getClient();
        cp.setDecoupledEndpoint(decoupledEndpoint);

        LOG.fine("Using decoupled endpoint: " + cp.getDecoupledEndpoint());
    }
View Full Code Here

TOP

Related Classes of org.apache.cxf.transports.http.configuration.HTTPClientPolicy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.