cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "KARR, DAVID" <>
Subject How to handle "happy path" form parameters and show fatal html responses?
Date Tue, 11 Apr 2017 19:33:43 GMT
I now have my little client prototype using ClientBuilder and a MessageBodyReader to unmarshal
form parameters into a POJO.  This works fine in normal circumstances.

When something goes really bad, I don't get a form response, I get an HTML response, but I've
nicely abstracted my media so much, that I now can't easily get to the plain HTML result.

How can I have both the "happy path", and an error handler that prints out the plain text
of the response?

My present method using the client is this:
	public StuffResponse validateToken(String token) {
		WebTarget	target	=;
		Builder request = target.request(MediaType.APPLICATION_JSON_TYPE);
		Form  form    = new Form();
		form.param("TokenID", token);
		StuffResponse    response    = null;
		return, MediaType.APPLICATION_FORM_URLENCODED_TYPE), StuffResponse.class);

When I call it with a "manipulated" environment so the service fails with an HTML response,
I get the following:
SEVERE: No message body reader has been found for class com.att.detsusl.stuffrest.StuffResponse,
ContentType: text/html
Exception in thread "main" No message body
reader has been found for class com.att.detsusl.stuffrest.StuffResponse, ContentType: text/html
	at org.apache.cxf.jaxrs.impl.ResponseImpl.reportMessageHandlerProblem(
	at org.apache.cxf.jaxrs.impl.ResponseImpl.doReadEntity(
	at org.apache.cxf.jaxrs.client.AbstractClient.readBody(
	at org.apache.cxf.jaxrs.client.WebClient.handleResponse(
	at org.apache.cxf.jaxrs.client.WebClient.doResponse(
	at org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(
	at org.apache.cxf.jaxrs.client.WebClient.doInvoke(
	at org.apache.cxf.jaxrs.client.WebClient.doInvoke(
	at org.apache.cxf.jaxrs.client.WebClient.invoke(
	at org.apache.cxf.jaxrs.client.WebClient$SyncInvokerImpl.method(
	at org.apache.cxf.jaxrs.client.WebClient$
	at com.att.detsusl.stuffrest.StuffService.validateToken(

The HTML response is not very likely to happen, but when it happens, I'd like to make sure
it gets into the log.

I know that if I instead post without qualifying with the type, like this:
Response  postResponse    =, MediaType.APPLICATION_FORM_URLENCODED_TYPE));

Then I can get the text of the response.  That might not be helpful here.

View raw message