I am current building a JAX-RS client using Apache CXF version 3.1.11. I have been looking at some simple examples online and it appears the WebClient class has gone missing.
See the example code below that I found online.
public static void main(String[] args) throws JsonParseException,
JsonMappingException, IOException {
WebClient client = WebClient
.create("http://localhost:8080/",
Collections.singletonList(new JacksonJsonProvider()))
.path("test").accept(MediaType.APPLICATION_JSON_TYPE);
Message message = client.get(Message.class);
System.out.println("Message recieved : " + message);
}
I cannot find the WebClient class anywhere in the code and im using the following maven dependencies.
Please could someone confirm if I am missing a dependency or if WebClient has been removed from version 3.1.11
If you're not sure about specific provider implementation, you can use classes which are standar parts of JAX-RS instead, which are duo Client
and WebTarget
. But for marshalling things, sure, you probably still need specific dependency configured, either manually or it's been already provided by the Apache CXF .
Client client = ClientBuilder.newBuilder().build();
WebTarget target = client
.target("http://localhost:8080/");
Response response = target.request().get();
Message message = client.readEntity(Message.class);
/*
// now.. process the message
for (Message message : message.get...) {.. }
*/
response.close(); // close connections.
您需要添加cxf-rt-frontend- jaxrs而不是cxf-rt-frontend-jaxws
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.