I'm trying to workaround this problem with an output CXF interceptor. I
have modified the DELETE request to be a POST request allowing a body. I
want that my interceptor will detect the POST request and will change it to
a DELETE. I'm having some problems to achieve it. How can the interceptor
modify the message object to achieve my goal?

I have written something like this:

public class PostToDeleteWithBodyInterceptor extends
AbstractPhaseInterceptor<Message> {

 public final static String EXTRA_PATH = "/mutatePOSTtoDELETE";

public PostToDeleteWithBodyInterceptor() {
super(Phase.PRE_PROTOCOL);
 }

public void handleMessage(Message message) {
 String path = (String)
message.getExchange().getOutMessage().get(Message.REQUEST_URI);
String method = (String)
message.getExchange().getOutMessage().get(Message.HTTP_REQUEST_METHOD);
 if (method != null && method.equals("POST") && path != null &&
path.endsWith(EXTRA_PATH)) {
// TODO remove EXTRA_PATH
 // TODO transform POST into DELETE
}
 }
}

I have a few doubts:

   - I don't know how to modify the path and the method of the request. I
   have tried modifying the content of the
   - I don't know what is the exact phase where apply it.
   - Why do I need to look for exchange, out message to see current path
   and method? It should be in the message, but the values are null.

Thank you!

[image: i2cat]
Julio C. Barrera Juez
Office phone: +34 93 357 99 27
Distributed Applications and Networks Area (DANA)
i2CAT Foundation, Barcelona, Spain
http://dana.i2cat.net


On 16 October 2013 16:54, Sergey Beryozkin <[email protected]> wrote:

> Hi,
>
> On 16/10/13 15:36, Julio Carlos Barrera Juez wrote:
>
>> Yes, the server is not under my control. I want to develop a client
>> because
>> I like how CXF works and it is a dependency for other issues in my
>> project.
>> Obviously I would never develop a service with body in DELETE requests.
>>
>> The, taking into account that I'm using CXF 2.7.x, is it possible to
>> workaround my problem using CXF?
>>
>>  Probably not at the moment,
> I've opened
> https://issues.apache.org/**jira/browse/CXF-5337<https://issues.apache.org/jira/browse/CXF-5337>
>
> Please watch it.
>
> In meantime, may be it is possible to 'tunnel' it, example, use POST but
> set some header with the real/intended HTTP verb such as DELETE, the target
> server would need to replace POST with DELETE, the easy way is to say
> create Servlet filter which will use HTTPServletRequest wrapper to return
> DELETE, some work is needed there but no changes to the server code itself
> will be required.
>
> Otherwise - try snapshots once CXF-5337 gets resolved
>
> Thanks, Sergey
>
>> Thank you Sergey!
>>
>> [image: i2cat]
>> Julio C. Barrera Juez
>> Office phone: +34 93 357 99 27
>> Distributed Applications and Networks Area (DANA)
>> i2CAT Foundation, Barcelona, Spain
>> http://dana.i2cat.net
>>
>>
>> On 16 October 2013 16:23, Sergey Beryozkin <[email protected]> wrote:
>>
>>  Right, looks like the following has to be done with HTTPClient:
>>>
>>> https://code.google.com/p/****rest-client/source/browse/**<https://code.google.com/p/**rest-client/source/browse/**>
>>> restclient-lib/src/main/java/****org/wiztools/restclient/http/****
>>> EntityEnclosingDelete.java<htt**ps://code.google.com/p/rest-**
>>> client/source/browse/**restclient-lib/src/main/java/**
>>> org/wiztools/restclient/http/**EntityEnclosingDelete.java<https://code.google.com/p/rest-client/source/browse/restclient-lib/src/main/java/org/wiztools/restclient/http/EntityEnclosingDelete.java>
>>> >
>>>
>>>
>>> This is the code based on the advice from HttpClient forums.
>>>
>>> I guess we should check if CXF Async Conduit can be updated respectively
>>>
>>> By the way, I'm assuming you have to do DELETE with a body because you
>>> have some existing/legacy service expecting it this way ? Now and then
>>> users ask about it, and I don't mind to get the Async HTTP conduit
>>> updated
>>> a bit anyway, but if you have say a CXF server listening, then I'm sure
>>> there could be an easier way :-)
>>>
>>> Cheers, Sergey
>>>
>>>
>>> On 16/10/13 15:11, Julio Carlos Barrera Juez wrote:
>>>
>>>  Looking for logs, I've realized that the property is producing changes.
>>>> I
>>>> mean the Async HTTP client is being used. However my DELETE request has
>>>> no
>>>> body. My client interface is JAX-RS annotated, my Resource class is JaxB
>>>> annotated:
>>>>
>>>> @Path("/server/path")
>>>> @DELETE
>>>> @Consumes(MediaType.****APPLICATION_JSON)
>>>>
>>>>    public void deleteResource(Resource resource);
>>>>
>>>> I have a create method working with de same configuration and it works:
>>>>
>>>>    @Path("/server/path")
>>>> @POST
>>>> @Consumes(MediaType.****APPLICATION_JSON)
>>>>
>>>>    public void createResource(Resource resource);
>>>>
>>>> I'm using Jackson as JSON serializer, but I guess it has no relation
>>>> with
>>>> this problem.
>>>>
>>>> These log lines show that the DELETE request has content-lenght 0 and
>>>> the  Async HTTP client is being used
>>>>
>>>> [I/O dispatcher 2] DEBUG
>>>> org.apache.cxf.transport.http.****asyncclient.****AsyncHTTPConduitFactory$2
>>>> -
>>>>
>>>> Connection leased: [id: 2][route: {}->http://my_server][total kept
>>>> alive:
>>>> 0; route allocated: 1 of 1000; total allocated: 0 of 5000]
>>>> [I/O dispatcher 2] DEBUG
>>>> org.apache.cxf.transport.http.****asyncclient.****AsyncHTTPConduitFactory$3
>>>> -
>>>> [exchange: 3] Connection allocated:
>>>> [id:2][route:{}->http:/my_****server][state:null]
>>>> [I/O dispatcher 2] DEBUG org.apache.http.impl.nio.****
>>>> reactor.IOSessionImpl
>>>> -
>>>> http-outgoing-2 192.168.254.86:35152<->server_****ip[ACTIVE][r:]: Set
>>>> attribute
>>>> http.nio.exchange-handler
>>>> [I/O dispatcher 2] DEBUG org.apache.http.impl.nio.****
>>>> reactor.IOSessionImpl
>>>> -
>>>> http-outgoing-2 192.168.254.86:35152<->server_****ip[ACTIVE][rw:]:
>>>> Event
>>>> set [w]
>>>> [I/O dispatcher 2] DEBUG org.apache.http.impl.nio.****
>>>> reactor.IOSessionImpl
>>>> -
>>>> http-outgoing-2 192.168.254.86:35152<->server_****ip[ACTIVE][rw:]: Set
>>>>
>>>> attribute http.nio.http-exchange-state
>>>> [I/O dispatcher 2] DEBUG
>>>> org.apache.cxf.transport.http.****asyncclient.****AsyncHTTPConduitFactory$3
>>>> -
>>>>
>>>> [exchange: 3] Attempt 1 to execute request
>>>> [I/O dispatcher 2] DEBUG org.apache.http.impl.nio.****
>>>> reactor.IOSessionImpl
>>>> -
>>>> http-outgoing-2 192.168.254.86:35152<->server_****ip[ACTIVE][rw:]: Set
>>>> timeout
>>>> 60000
>>>> [I/O dispatcher 2] DEBUG org.apache.http.client.****
>>>> protocol.RequestAuthCache
>>>>
>>>> -
>>>> Auth cache not set in the context
>>>> [I/O dispatcher 2] DEBUG
>>>> org.apache.http.client.****protocol.****RequestTargetAuthentication -
>>>> Target
>>>>
>>>> auth
>>>> state: UNCHALLENGED
>>>> [I/O dispatcher 2] DEBUG
>>>> org.apache.http.client.****protocol.****RequestProxyAuthentication -
>>>> Proxy
>>>>
>>>> auth
>>>> state: UNCHALLENGED
>>>> [I/O dispatcher 2] DEBUG org.apache.http.headers - http-outgoing-2 >> *
>>>> DELETE* /server/path HTTP/1.1
>>>>
>>>> [I/O dispatcher 2] DEBUG org.apache.http.headers - http-outgoing-2 >>
>>>> Accept: text/plain
>>>> [I/O dispatcher 2] DEBUG org.apache.http.headers - http-outgoing-2 >>
>>>> User-Agent: Apache CXF 2.7.4
>>>> [I/O dispatcher 2] DEBUG org.apache.http.headers - http-outgoing-2 >>
>>>> *Content-Length:
>>>> 0*
>>>>
>>>> [I/O dispatcher 2] DEBUG org.apache.http.headers - http-outgoing-2 >>
>>>> Host:
>>>> my_server
>>>> [I/O dispatcher 2] DEBUG org.apache.http.headers - http-outgoing-2 >>
>>>> Connection: Keep-Alive
>>>>
>>>> [image: i2cat]
>>>> Julio C. Barrera Juez
>>>> Office phone: +34 93 357 99 27
>>>> Distributed Applications and Networks Area (DANA)
>>>> i2CAT Foundation, Barcelona, Spain
>>>> http://dana.i2cat.net
>>>>
>>>>
>>>> On 16 October 2013 15:17, Julio Carlos Barrera Juez <
>>>> [email protected]> wrote:
>>>>
>>>>   I don't know how to install CXF Async HTTP transport. I have the maven
>>>>
>>>>> artifact in my project dependencies, but nothing else.
>>>>>
>>>>> [image: i2cat]
>>>>> Julio C. Barrera Juez
>>>>> Office phone: +34 93 357 99 27
>>>>> Distributed Applications and Networks Area (DANA)
>>>>> i2CAT Foundation, Barcelona, Spain
>>>>> http://dana.i2cat.net
>>>>>
>>>>>
>>>>> On 16 October 2013 13:14, Sergey Beryozkin <[email protected]>
>>>>> wrote:
>>>>>
>>>>>   I guess you don't have CXF Async HTTP transport installed ?
>>>>>
>>>>>> Other than that I've no idea, if it won;t work with the Async module
>>>>>> then
>>>>>> I guess it is possible to do
>>>>>> Sergey
>>>>>>
>>>>>> On 16/10/13 11:49, Julio Carlos Barrera Juez wrote:
>>>>>>
>>>>>>   I tried to use this information before, but I don't know how to
>>>>>> solve
>>>>>>
>>>>>>> my
>>>>>>> problem.
>>>>>>>
>>>>>>> I have something like this:
>>>>>>>
>>>>>>> ProxyClassLoader classLoader = new ProxyClassLoader();
>>>>>>>     classLoader.addLoader(******IServiceInterface.class.****
>>>>>>> getClassLoader());
>>>>>>> classLoader.addLoader(******JAXRSClientFactoryBean.class.******
>>>>>>>
>>>>>>>
>>>>>>> getClassLoader());
>>>>>>>
>>>>>>> JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
>>>>>>> bean.setAddress(uri);
>>>>>>> bean.setResourceClass(******IServiceInterface.class);
>>>>>>>     bean.setClassLoader(******classLoader);
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> client (IServiceInterface) bean.create();
>>>>>>>
>>>>>>> Then I can use the client object as usual. But if fails sending
>>>>>>> DELETE
>>>>>>> requests with body.
>>>>>>>
>>>>>>> I tried doing this:
>>>>>>>
>>>>>>> ProxyClassLoader classLoader = new ProxyClassLoader();
>>>>>>>     classLoader.addLoader(******IServiceInterface.class.****
>>>>>>> getClassLoader());
>>>>>>> classLoader.addLoader(******JAXRSClientFactoryBean.class.******
>>>>>>>
>>>>>>>
>>>>>>> getClassLoader());
>>>>>>>
>>>>>>> JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
>>>>>>> bean.setAddress(uri);
>>>>>>> bean.setResourceClass(******IServiceInterface.class);
>>>>>>>     bean.setClassLoader(******classLoader);
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> // allow body in DELETE requests
>>>>>>> Client client = bean.create();
>>>>>>>     WebClient.getConfig(client).******getRequestContext().put("**
>>>>>>> use.****
>>>>>>> async.http.conduit",
>>>>>>> true);
>>>>>>>
>>>>>>> (IServiceInterface) client.******whateverMethodThatSendsDelete(**
>>>>>>> ****);
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> But it didn't work.
>>>>>>>
>>>>>>> What am I missing?
>>>>>>>
>>>>>>> [image: i2cat]
>>>>>>> Julio C. Barrera Juez
>>>>>>> Office phone: +34 93 357 99 27
>>>>>>> Distributed Applications and Networks Area (DANA)
>>>>>>> i2CAT Foundation, Barcelona, Spain
>>>>>>> http://dana.i2cat.net
>>>>>>>
>>>>>>>
>>>>>>> On 16 October 2013 12:00, Sergey Beryozkin <[email protected]>
>>>>>>> wrote:
>>>>>>>
>>>>>>>    Hi
>>>>>>>
>>>>>>>
>>>>>>>> On 16/10/13 09:18, Julio Carlos Barrera Juez wrote:
>>>>>>>>
>>>>>>>>    Hi.
>>>>>>>>
>>>>>>>>
>>>>>>>>> I'm creating a REST client using JAXRSClientFactoryBean and
>>>>>>>>> ProxyClassLoader based on a JAXRS annotated Java interface.
>>>>>>>>>
>>>>>>>>> I want to send a DELETE with body, which is not recommended by
>>>>>>>>> RESTful
>>>>>>>>> philosophy, but it is allowed by HTTP 1.1 RFC.
>>>>>>>>>
>>>>>>>>> The body is not sent by the client and I have read a lot of
>>>>>>>>> problems
>>>>>>>>> to
>>>>>>>>> allow it.
>>>>>>>>>
>>>>>>>>> Is it possible send a body in my DELETE requests with this
>>>>>>>>> configuration?
>>>>>>>>>
>>>>>>>>>     Please check this thread
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>  http://cxf.547215.n5.nabble.********com/JaxRS-Client-with-**
>>>>>>>> Deletes-****
>>>>>>>> td5731444.html<http://cxf.****54**7215.n5.nabble.com/JaxRS-****<http://7215.n5.nabble.com/JaxRS-**>
>>>>>>>> <http://547215.n5.nabble.com/**JaxRS-**<http://547215.n5.nabble.com/JaxRS-**>
>>>>>>>> >
>>>>>>>> Client-with-Deletes-td5731444.******html<http://cxf.547215.n5.****
>>>>>>>> nabble.com/JaxRS-Client-with-****Deletes-td5731444.html<http://nabble.com/JaxRS-Client-with-**Deletes-td5731444.html>
>>>>>>>> <http:/**/cxf.547215.n5.nabble.com/**JaxRS-Client-with-Deletes-**
>>>>>>>> td5731444.html<http://cxf.547215.n5.nabble.com/JaxRS-Client-with-Deletes-td5731444.html>
>>>>>>>> >
>>>>>>>>
>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>>
>>>>>>>> Cheers, Sergey
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>     Thank you!
>>>>>>>>
>>>>>>>>
>>>>>>>>  Regards, Julio
>>>>>>>>>
>>>>>>>>> [image: i2cat]
>>>>>>>>> Julio C. Barrera Juez
>>>>>>>>> Office phone: +34 93 357 99 27
>>>>>>>>> Distributed Applications and Networks Area (DANA)
>>>>>>>>> i2CAT Foundation, Barcelona, Spain
>>>>>>>>> http://dana.i2cat.net
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>  --
>>>>>> Sergey Beryozkin
>>>>>>
>>>>>> Talend Community Coders
>>>>>> http://coders.talend.com/
>>>>>>
>>>>>> Blog: http://sberyozkin.blogspot.com
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>> --
>>> Sergey Beryozkin
>>>
>>> Talend Community Coders
>>> http://coders.talend.com/
>>>
>>> Blog: http://sberyozkin.blogspot.com
>>>
>>>
>>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>
> Blog: http://sberyozkin.blogspot.com
>

Reply via email to