1) You might want to have MessageBodyWriter<ResponseEvent> on server side. You might need to register this @Provider. This would enable your POJO to be written to server's output stream. For instance (not tested):
@Provider
class ResponseEventWriter implements MessageBodyWriter<ResponseEvent> {
@Override
public boolean isWriteable(Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType) {
return true;
}
@Override
public long getSize(ResponseEvent t, Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType) {
return t.getDn().length();
}
@Override
public void writeTo(ResponseEvent t, Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream) throws IOException,
WebApplicationException {
entityStream.write(t.getDn().getBytes());
}
}
2) You need to have MessageBodyReader<ResponseEvent> on client side.
For instance:
@Provider
public class ResponseEventReader implements MessageBodyReader<ResponseEvent> {
@Override
public boolean isReadable(Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType) {
return true;
}
@Override
public ResponseEvent readFrom(Class<ResponseEvent> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
throws IOException, WebApplicationException {
StringBuilder sb = new StringBuilder();
try(InputStreamReader isr = new InputStreamReader(entityStream)) {
char[] c = new char[1];
while (isr.read(c) != -1)
sb.append(c);
} catch (IOException e) {
//do something
}
ResponseEvent event = new ResponseEvent();
event.setDn(sb.toString());
return event;
}
}
You need to register this provider on client side. You do this for instance using JAXRS client, instead of cxf client (available since cxf 3), for instance with something like:
Client client = ClientBuilder.newClient();
client = client.register(ResponseEventReader.class);
Response agentLogoutResponse = client.target(/*whateveryourpath + */ "agentLogout")
.request().accept(MediaType.APPLICATION_JSON)
.buildPost(Entity.text("1301")).invoke();
Then you can read your entity as
ResponseEvent event = agentLogoutResponse.readEntity(ResponseEvent.class);