I am writing a wrapper REST API (say, API X) for an accessible REST API (say, API Y) written in Apache CXF. For the shell, I use CXF Webclient. This is what I call Y from X.
@GET
@Path("{userName}")
public Response getUser(@PathParam("userName") String userName) {
try {
WebClient client
= WebClient.create("https://localhost:8080/um/services/um");
Response response = client.path("users/" + userName)
.accept(MediaType.APPLICATION_JSON)
.get();
User user = (User) response.getEntity();
return Response.ok(user).build();
} catch (Exception e) {
return handleResponse(ResponseStatus.FAILED, e);
}
}
Here the user class is copied from Y to X, because I cannot use Y as a dependency for X. The only difference is the package name. Now, when I submit a request, I get a class exception in User user = (User) response.getEntity();.
java.lang.ClassCastException: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream cannot be cast to org.comp.rest.api.bean.User
Maybe because the class package name is different?
Can someone help me get a response on a User object?
source
share