Hi,
I have a service that calls another service to get a Date object. I have
recently found some edge cases where the date is not available. I've been
returning the date in our "ResponseEnvelope<Date> dueDateEnvelope" class,
which is bundled into the the javax.ws.rs.core.Response as an entity by the
composing service.
This works fine, but I just found an edge case where the date isn't found,
and I was surprised to find that when that happens, and when I try to
return the ResponseEnvelope<Date> from the composing service with a
NOT_FOUND status, I am getting an exception saying
"MessageBodyProviderNotFoundException: MessageBodyWriter not found for
media type=text/html".
My return statement from the composing service looks like this:
return Response.status(Status.NOT_FOUND).entity(dueDateEnvelope).build();
I tried returning the same ResponseEnvelope<Date> returned by the date
service when the Date is null, and I get this exception:
org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException:
MessageBodyWriter not found for media type=text/html, type=class
com.ep.resid.support.rest.ResponseEnvelope, genericType=class
com.ep.resid.support.rest.ResponseEnvelope.
I tried stuffing a random date into the envelope, I tried changing the
ResponseEnvelope to ResponseEnvelope<String> and giving it a nominal value
but I get the same error. I also tried creating a new
ResponseEnvelope<Date> (and also using String) and that didn't work
either. I have a feeling I'm doing something stupid, but so far, I'm not
seeing it.
When the date service finds a date, all's well, I can extract the Date
payload from the envelope and
I have no trouble with any message body readers/writers but when the
service returns null for the date I am unable to include the
ResponseEnvelope<Date> or ResponseEnvelope<String> without the exception
happening, even if I provide a date or a string. If I remove the envelope
from being returned in the Response as an entity, I can return a 404 and no
exception occurs. I want to return the envelope, however, because I want
to return the envelope with its DLQ support and log the error.
I suspect that it may be the way that I'm calling the date service, but I
don't see anything obviously wrong with it. Here's the call made by the
composing service to the composed date service:
private Date getDueDateByAiring(Date triggerDate, MadeForMarketGroup mfmg,
String reuseMarketName) {
SimpleDateFormat simpleDateFormat = new
SimpleDateFormat("yyyy-MM-dd");
String triggerDateString = simpleDateFormat.format(triggerDate);
ResponseEnvelope<Date> dueDateEnvelope = ClientBuilder.newClient()
.target(urlService.getDueDatesUrl())
.path("duedatecalc")
.path("byrevenue")
.path(triggerDateString)
.path("mfmgroup")
.path(mfmg.getMadeForMarketGroupName())
.path("reusemkt")
.path(reuseMarketName)
.request(MediaType.APPLICATION_JSON_TYPE)
.get(Response.class)
.readEntity(new GenericType<ResponseEnvelope<Date>>() {});
Date dueDate = null;
if(dueDateEnvelope.getSucceeded() == Boolean.FALSE) {
log.error("HIT ERROR! status: "+dueDateEnvelope.getSucceeded());
return dueDate;
}
dueDate = dueDateEnvelope.getPayload();
return dueDate;
}
Am I invoking the service incorrectly? I don't understand why the
readEntity(...) call above would work when the date is found which it does,
and I have no trouble extracting the date, but when the date service can't
find a date, then all of a sudden the run time can't handle the
envelope?!? If I don't include the envelope, no exception happens.
Obviously, I'm confused...
Does anybody understand what's happening here?
Thanks!!!