Here is the way to do it
// truly async
@Test
public void testRetrieveBookAsync() throws Exception {
String address = "http://localhost:" + PORT +
"/bookstore/retrieve";
WebClient wc = WebClient.create(address);
Future<Book> future = wc.async().method("RETRIEVE", Book.class);
Book book = future.get();
assertEquals("Retrieve", book.getName());
}
or
// async transport is used to do the sync call
@Test
public void testRetrieveBookAsync2() throws Exception {
String address = "http://localhost:" + PORT +
"/bookstore/retrieve";
WebClient wc = WebClient.create(address);
WebClient.getConfig(wc).getRequestContext().put("use.async.http.conduit", true);
Book book = wc.invoke("RETRIEVE", null, Book.class);
assertEquals("Retrieve", book.getName());
}
and add the dependency:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-hc</artifactId>
<version>2.7.5</version>
</dependency>
Thanks to Dan for making it so flexible, very nice
Sergey
On 25/06/13 17:10, Sergey Beryozkin wrote:
Hi
The problem is that HTTPUrlConnection does not support HTTP methods it
is not already statically aware of.
One option will be likely to use the HTTP async transport (which Dan
made to work even in the sync mode) - that one is based on Apache
HTTPClient, another option is to attempt to statically modify
HTTPURLConnection...
Let me experiment a bit and get back to you.
Thanks, Sergey
On 25/06/13 16:49, Fabio Martelli wrote:
Hi All,
I'm facing with the WebClient in order to send a PATCH request to an
OData service.
I tried with the following statement
final Response res = client.invoke("PATCH", obj);
but the following exception has been thrown
javax.ws.rs.client.ClientException: javax.ws.rs.client.ClientException:
org.apache.cxf.interceptor.Fault: Could not send Message.
at
java.net.HttpURLConnection.setRequestMethod(HttpURLConnection.java:428)
at
org.apache.cxf.transport.http.URLConnectionHTTPConduit.setupConnection(URLConnectionHTTPConduit.java:119)
at
org.apache.cxf.transport.http.HTTPConduit.prepare(HTTPConduit.java:467)
at
org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:46)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
at
org.apache.cxf.jaxrs.client.AbstractClient.doRunInterceptorChain(AbstractClient.java:607)
at
org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1017)
at
org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:855)
at
org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:829)
at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:294)
.....
Is there someone that can help me to achieve my target?
Thank you in advance.
Best regards,
F.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com