cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Glinski, Tomasz" <>
Subject AW: Changing response staus on the client side
Date Tue, 22 Mar 2011 15:35:55 GMT
> 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,

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:
        at org.apache.cxf.jaxrs.client.AbstractClient.readBody(
        at org.apache.cxf.jaxrs.client.ClientProxyImpl.handleResponse(
        at org.apache.cxf.jaxrs.client.ClientProxyImpl.doChainedInvocation(
        at org.apache.cxf.jaxrs.client.ClientProxyImpl.invoke(
        at $Proxy88.update(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(
        at java.lang.reflect.Method.invoke(
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(
        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?



> 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.
View raw message