cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ivo van Dongen <...@func.nl>
Subject Setting expect-continue header on ws clients
Date Tue, 02 Oct 2007 14:50:24 GMT
Hello,

I'm new to this list and CXF so I'm sorry if I missed anything :). We're 
currently migrating from XFire to cfx beginning with our client side. 
This seems to be fairly painless except for one little issue. With  
XFire we used an implementation of the ClientFactoryBean to set up our 
clients in Spring (attached below). For some services we needed to set 
the expect-continue httpheader to make sure everything went smooth. We 
did this with the following:

    private void enableOrDisableExpectHttpContinueHeader(Object 
servicePort) {
        Client client = ((XFireProxy) 
Proxy.getInvocationHandler(servicePort)).getClient();
        HttpClientParams httpClientParams = new HttpClientParams();
        
httpClientParams.setBooleanParameter("http.protocol.expect-continue",isUsingExpectContinueHTTPHeader());
        
client.setProperty(CommonsHttpMessageSender.HTTP_CLIENT_PARAMS,httpClientParams);
    }

I can't seem to find a similar way to do this with CXF using the 
JaxWsProxyFactoryBean or a sublcass derived from it. I know I'm missing 
something, could someone point me in the right direction?

Thanks in advance,
Ivo van Dongen

The XFireClientFactoryBean we used with Xfire/Sring:

public class XFireClientFactoryBean implements FactoryBean {

    private String webserviceUrl;
    private Class implementingClass;
    private boolean usingExpectContinueHTTPHeader = true;
    private List inHandlers = new ArrayList();
    private List outHandlers = new ArrayList();
   

    /**
     * @return an XFire service. The object's implementation is
     * determined by the <code>implementingClass</code> property.
     *
     * @see org.springframework.beans.factory.FactoryBean#getObject()
     */
    public Object getObject() {
        Object servicePort = getServicePort(getXFireService());
        enableOrDisableExpectHttpContinueHeader(servicePort);
        setHandlersOnServicePort(servicePort);
        return servicePort;
    }

    /**
     * @return the value of the bean's <code>implementingClass</code>
     * property.
     * @see org.springframework.beans.factory.FactoryBean#getObjectType()
     */
    public Class getObjectType() {
        return getImplementingClass();
    }

   
    /**
     * @return always returns false.
     * @see org.springframework.beans.factory.FactoryBean#isSingleton()
     */
    public boolean isSingleton() {
        return false;
    }
   
    /**
     * @return the value of {@link #getJsr181AndJaxbAwareService()}
     */
    public Service getXFireService() {
        return getJsr181AndJaxbAwareService();
    }
   
    /**
     * Creates an XFire service port for the url at 
<code>webserviceUrl</code>.
     * The service's type is determined by <code>implementingClass</code>.
     * @param serviceModel
     * @return
     * @throws MalformedURLException
     */
    private Object getServicePort(Service serviceModel) {
        Object servicePort;
        try {
            servicePort = new 
XFireProxyFactory().create(serviceModel,getWebserviceUrl());
            return servicePort;
        } catch (MalformedURLException e) {
            throw new ApplicationContextException("Can't create web 
service client of type " + getImplementingClass()
                    + " since the url set with the 'webserviceUrl' 
property is malformed. It's value is " +
                    getWebserviceUrl());
        }
    }
   
    /**
     * Enables or disables the <code>Expect-Continue</code> HTTP header. 
Some services
     * (the backstage services for example) can't handle this header 
well. Set
     * <code>usingExpectContinueHTTPHeader</code> property to 
<code>false</code> to
     * disable the feature.
     * @param servicePort a service port
     */
    private void enableOrDisableExpectHttpContinueHeader(Object 
servicePort) {
        Client client = ((XFireProxy) 
Proxy.getInvocationHandler(servicePort)).getClient();
        HttpClientParams httpClientParams = new HttpClientParams();
        
httpClientParams.setBooleanParameter("http.protocol.expect-continue",isUsingExpectContinueHTTPHeader());
        
client.setProperty(CommonsHttpMessageSender.HTTP_CLIENT_PARAMS,httpClientParams);
    }
   
    /**
     * Sets the handlers on the created {@link Client}
     * @param servicePort
     */
    @SuppressWarnings("unchecked")
    private void setHandlersOnServicePort(Object servicePort) {
        Client client = ((XFireProxy) 
Proxy.getInvocationHandler(servicePort)).getClient();
        if(inHandlers != null) {
            client.getInHandlers().addAll(inHandlers);
        }
        if(outHandlers != null) {
            client.getOutHandlers().addAll(outHandlers);
        }
    }
   
    /**
     * @return an XFire service model, aware of Jsr-181 and Jaxb2 
annotations.
     */
    private Service getJsr181AndJaxbAwareService() {
        Service serviceModel =
              new AnnotationServiceFactory(
               new Jsr181WebAnnotations(),
               XFireFactory.newInstance().getXFire().getTransportManager(),
               new AegisBindingProvider(new 
JaxbTypeRegistry())).create(getImplementingClass());
        return serviceModel;
    }
   


    /**
     * @return Returns the implementingClass.
     */
    public Class getImplementingClass() {
        return implementingClass;
    }

    /**
     * @param implementingClass The implementingClass to set.
     */
    public void setImplementingClass(Class implementingClass) {
        this.implementingClass = implementingClass;
    }

    /**
     * @return Returns the usingExpectContinueHTTPHeader.
     */
    public boolean isUsingExpectContinueHTTPHeader() {
        return usingExpectContinueHTTPHeader;
    }

    /**
     * @param usingExpectContinueHTTPHeader The 
usingExpectContinueHTTPHeader to set.
     */
    public void setUsingExpectContinueHTTPHeader(
            boolean usingExpectContinueHTTPHeader) {
        this.usingExpectContinueHTTPHeader = usingExpectContinueHTTPHeader;
    }

    /**
     * @return Returns the webserviceUrl.
     */
    public String getWebserviceUrl() {
        return webserviceUrl;
    }

    /**
     * @param webserviceUrl The webserviceUrl to set.
     */
    public void setWebserviceUrl(String webserviceUrl) {
        this.webserviceUrl = webserviceUrl;
    }
   
    /**
     * @param inHandlers the Handlers
     */
    public void setInHandlers(List inHandlers) {
        this.inHandlers = inHandlers;
    }

    /**
     * @param outHandlers the Handlers
     */
    public void setOutHandlers(List outHandlers) {
        this.outHandlers = outHandlers;
    }
}

-- 
Ivo van Dongen
Func. Internet Integration
Prins Hendrikkade 20-21, 1012 TL Amsterdam
W http://www.func.nl
T +31 20 4230000
F +31 20 4223500 


Mime
View raw message