Hi Sergey,
That code is the one that works, unmarshalling from the errorMessage I don't
get the exception mentioned before.
This exception is produced when trying to read from the entity, without calling
getMessage, doing this:
ErrorDetail errorDetail = (ErrorDetail) jsonProvider.readFrom(
(Class)ErrorDetail.class,
(Class)ErrorDetail.class,
new Annotation[]{},
MediaType.APPLICATION_JSON_TYPE,
metadataMap,
(InputStream)response.getEntity());
When I first catch the ServerWebApplicationException, I can see that the
errorMessage has already been initialized.
So if ServerWebApplicationException.getMessage() is called, it won't call
readErrorMessage():
public String getMessage() {
if (errorMessage == null) {
errorMessage = readErrorMessage();
}
return errorMessage;
}
Debugging this method I can see this stack the first time getMessage it's
called:
ServerWebApplicationException.getMessage() line: 71
ServerWebApplicationException.toString() line: 107
Fault(Throwable).<init>(Throwable) line: 242
Fault(Exception).<init>(Throwable) line: 77
Fault(RuntimeException).<init>(Throwable) line: 77
Fault(UncheckedException).<init>(Throwable) line: 43
Fault.<init>(Throwable) line: 77
ClientProxyImpl.checkResponse(Method, Response, Message) line:
243
ClientProxyImpl.handleResponse(HttpURLConnection, Message,
OperationResourceInfo) line: 453
ClientProxyImpl.doChainedInvocation(URI,
MultivaluedMap<String,String>, OperationResourceInfo, Object[], int,
MultivaluedMap<ParameterType,Parameter>, List<Object>) line: 445
ClientProxyImpl.invoke(Object, Method, Object[]) line: 177
$Proxy20.getLiquidaciones(Solicitar) line: not available
LiquidacionesServiceClient.getLiquidaciones(String, int) line:
75
LiquidacionesServiceClientErrorTest.testErrorLiquidacionesSolicitarVersionZero()
line: 63
NativeMethodAccessorImpl.invoke0(Method, Object, Object[])
line: not available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
Method.invoke(Object, Object...) line: 597
TestMethod.invoke(Object) line: 59
MethodRoadie.runTestMethod() line: 98
MethodRoadie$2.run() line: 79
MethodRoadie.runBeforesThenTestThenAfters(Runnable) line: 87
MethodRoadie.runTest() line: 77
MethodRoadie.run() line: 42
JUnit4ClassRunner.invokeTestMethod(Method, RunNotifier) line: 88
JUnit4ClassRunner.runMethods(RunNotifier) line: 51
JUnit4ClassRunner$1.run() line: 44
ClassRoadie.runUnprotected() line: 27
ClassRoadie.runProtected() line: 37
JUnit4ClassRunner.run(RunNotifier) line: 42
JUnit4TestMethodReference(JUnit4TestReference).run(TestExecution) line: 49
TestExecution.run(ITestReference[]) line: 38
RemoteTestRunner.runTests(String[], String, TestExecution)
line: 467
RemoteTestRunner.runTests(TestExecution) line: 683
RemoteTestRunner.run() line: 390
RemoteTestRunner.main(String[]) line: 197
So does this mean that when I catch the ServerWebApplicationException the
stream has already been consumed, and therefore I can't obtain the unmarshalled
object from it?
Thanks,
Marcos.
De: Sergey Beryozkin [mailto:[email protected]]
Enviado el: lunes, 21 de marzo de 2011 19:15
Para: [email protected]
CC: Marcos Díez Fernández
Asunto: Re: Extracting object from Response when ServerWebApplicationException
occurs
Hi Marcos
2011/3/21 Marcos Díez Fernández <[email protected]<mailto:[email protected]>>
Hi Sergey,
I don't use ServerWebApplicationException.getMessage() and still get that
exception.
Don't know what else I could try, so I think I'll go with the errorMessage
unmarshalling, although it may not be the most 'proper/correct' way...
This is the code fragment from your earlier message:
InputStream is = new ByteArrayInputStream(e.
getMessage().getBytes("UTF-8"));
ErrorDetail errorDetail = (ErrorDetail) jsonProvider.readFrom(
(Class)ErrorDetail.class,
(Class)ErrorDetail.class,
new Annotation[]{},
MediaType.APPLICATION_JSON_TYPE,
metadataMap,
is);
I can also see that e.getMessage(), in case of ServerWebApppicationException,
internally reads from response.getEntity(), you can check the source :-).
Somewhere the stream is consumed, can you double check where it might be
happening ? I have the test on mainline where ResponseReader is used to do the
same...
thanks, Sergey
Thanks a lot for your help
BR,
Marcos.