cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "KARR, DAVID" <dk0...@att.com>
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	= client.target(getStuffHostPort()).path(getStuffPath());
		Builder request = target.request(MediaType.APPLICATION_JSON_TYPE);
		Form  form    = new Form();
		form.param("TokenID", token);
		StuffResponse    response    = null;
		return request.post(Entity.entity(form, 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" javax.ws.rs.client.ResponseProcessingException: 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(ResponseImpl.java:439)
	at org.apache.cxf.jaxrs.impl.ResponseImpl.doReadEntity(ResponseImpl.java:390)
	at org.apache.cxf.jaxrs.client.AbstractClient.readBody(AbstractClient.java:524)
	at org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1122)
	at org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1110)
	at org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1035)
	at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:892)
	at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:863)
	at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:426)
	at org.apache.cxf.jaxrs.client.WebClient$SyncInvokerImpl.method(WebClient.java:1562)
	at org.apache.cxf.jaxrs.client.WebClient$SyncInvokerImpl.post(WebClient.java:1502)
	at org.apache.cxf.jaxrs.client.spec.InvocationBuilderImpl.post(InvocationBuilderImpl.java:150)
	at com.att.detsusl.stuffrest.StuffService.validateToken(StuffService.java:105)
----------

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    = request.post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));
----------------

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

Mime
View raw message