[ 
https://issues.apache.org/jira/browse/CXF-2585?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12792002#action_12792002
 ] 

Sergey Beryozkin commented on CXF-2585:
---------------------------------------

Hi,

here is the code for a custom interceptor :

public class EmptyPostOutInterceptor extends AbstractPhaseInterceptor<Message> {
                
        public EmptyPostOutInterceptor() {
             super(Phase.PRE_MARSHAL);
            
        } 

        public void handleMessage(Message message) throws Fault {
            if ("POST".equals(message.get(Message.HTTP_REQUEST_METHOD))) {
                message.put("org.apache.cxf.post.empty", true);
            }
        }
    }

you can register it from Spring like this, assuming you use jaxrs:client :

<jaxrs:client>
<jaxrs:outInterceptors>
   <bean class="org.custom.EmptyPostOutInterceptor"/>
</jaxrs:outInterceptors>
</jaxrs:client>


Here is a Java code :

@Test
    public void testEmptyPostProxy() throws Exception {
        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); 
        bean.setAddress("http://localhost:9080";);
        bean.setResourceClass(BookStore.class);
        bean.getOutInterceptors().add(new EmptyPostOutInterceptor());
        BookStore store = bean.create(BookStore.class);
        store.emptypost();
        assertEquals(204, WebClient.client(store).getResponse().getStatus());
    }

give it a try please and let me know how it goes. 
It is really a temp measure, the fix will be in 2.2.6 (to be released possibly 
in Jan)

> Already connected exception when using a proxy created with JAXRSClientFactory
> ------------------------------------------------------------------------------
>
>                 Key: CXF-2585
>                 URL: https://issues.apache.org/jira/browse/CXF-2585
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.2.5
>         Environment: JDK 1.5.0.18
>            Reporter: S.Allegro
>            Assignee: Sergey Beryozkin
>             Fix For: 2.2.6, 2.3
>
>
> I'm trying to get a very simple Rest client working, but I always got this 
> exception:
> java.lang.IllegalStateException: Already connected
>       at 
> java.net.HttpURLConnection.setFixedLengthStreamingMode(HttpURLConnection.java:100)
>       at 
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.thresholdNotReached(HTTPConduit.java:1885)
>       at 
> org.apache.cxf.io.AbstractThresholdOutputStream.close(AbstractThresholdOutputStream.java:99)
>       at 
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1976)
>       at 
> org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
>       at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:637)
>       at 
> org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
>       at 
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
>       at 
> org.apache.cxf.jaxrs.client.ClientProxyImpl.doChainedInvocation(ClientProxyImpl.java:429)
>       at 
> org.apache.cxf.jaxrs.client.ClientProxyImpl.invoke(ClientProxyImpl.java:166)
>       at $Proxy16.doSomething(Unknown Source)
>       at com.francetelecom.resttest.RestTest.main(RestTest.java:27)
> Here is my jax-rs interface:
> @Path("/")
> public interface RestWS {
>     @POST
>     @Path("/test")
>     public String doSomething( @QueryParam("param") String paramName);
> }
> And here the way my client uses it:
> RestWS proxy = 
> JAXRSClientFactory.create("http://localhost:8080/RestWSMock",RestWS.class);
> proxy.doSomething("bob");
> I can not get it simpler. Any idea what's wrong ?
> regards

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to