> Hi,
> I am writing a client to the server (no changes on server possible), that
> sends responses with no message body, with response status 200. CXF throws
> than WebApplicationException, as it expects status 204 in such situation.
> Is there a way to change the status "on-the-fly", before the response is
> parsed? Tried with interceptors, with no success...
>
>
Where is this WebApplicationException originating from ? Is client trying to
read the response body and fails ?
Do you use WebClient like this :

client.get(Book.class) ?

when the concrete type, as opposed to Response as expected, the runtime
thinks that the response stream has to be read. Can you try using Response,
say,

Response response = client.get();

?

CXF 2.3.3 has a ResponseReader utility class for reading Response entities

But you can also change the status from the custom *in* interceptor, do
message.getExchange().put(Message.RESPONSE_CODE, 204);

Cheers, Sergey

=========================================================================
Hi Sergey,

WebApplicationException comes from AbstractClient.readBody(), inside catch:

MessageBodyReader mbr = 
ProviderFactory.getInstance(inMessage).createMessageBodyReader(
try {
   return mbr.readFrom(cls, type, anns, contentType, new MetadataMap<String, 
Object>(r.getMetadata(), true, true), conn.getInputStream());
} catch (Exception ex) {
   throw new WebApplicationException();
}

Few lines before is the status checked, in some cases (204) simply null is 
returned. So yes, client tries to read the body.

I use CXF in cooperation with Spring, so I'm not sure, what exactly should I 
answer, so I will simply attach part o stacktrace:
javax.ws.rs.WebApplicationException
        at 
org.apache.cxf.jaxrs.client.AbstractClient.readBody(AbstractClient.java:391)
        at 
org.apache.cxf.jaxrs.client.ClientProxyImpl.handleResponse(ClientProxyImpl.java:444)
        at 
org.apache.cxf.jaxrs.client.ClientProxyImpl.doChainedInvocation(ClientProxyImpl.java:428)
        at 
org.apache.cxf.jaxrs.client.ClientProxyImpl.invoke(ClientProxyImpl.java:171)
        at $Proxy88.update(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at 
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
        at 
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
        at $Proxy95.update(Unknown Source)
(lower in stacktrace is no important stuff)

I tried the trick with IN interceptor and different phases, did not work... 
Which phase you think it should be? I tried to debug this, the status is taken 
from HttpURLConnection, can it be really overridden?

Thanks

====

Greets
> Tomasz
>
>

Capgemini Polska Sp. z o.o.,
ul. Piękna 18, 00-549 Warszawa
Sąd Rejonowy dla M.ST. Warszawy, XII Wydział Gospodarczy Rejestrowy, nr KRS: 
0000040605
NIP: 526-11-84-467,
wysokość kapitału zakładowego: 16 397 097,00 ZŁ






This message contains information that may be privileged or confidential and is 
the property of the Capgemini Group. It is 
intended only for the person to whom it is addressed. If you are not the 
intended recipient, you are not authorized to 
read, print, retain, copy, disseminate, distribute, or use this message or any 
part thereof. If you receive this message 
in error, please notify the sender immediately and delete all copies of this 
message.

Reply via email to