Hi. Thank you for replying.
The error happens when an exception is thrown by the service. From what I
can understand, the Hessian parser failed to recreate the exception thrown
by the service (for my test it was a NullPointerException). This, however,
does not happen when I use HessianProxyFactory to connect to the service.
Unfortunately, I cannot use this method because it cannot handle
Authentication and Proxy. Therefore I was forced to recreate how Hessian
converts the request and sends it using the HttpClient of Apache. Below is
my code for doing that. Can you point out to me where I could have made a
mistake?
START OF CODE
public Object connect(String id, String pwd, String method, Object[]
param)
throws Exception {
// Create an httpClient instance
HttpClient httpClient = new HttpClient();
URL url = new URL(address);
httpClient.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
// Set username and password
httpClient.getState().setCredentials(
new AuthScope(url.getHost(), url.getPort(), null),
new UsernamePasswordCredentials(id, pwd)
);
// Transform request to Hessian binary
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
Hessian2Output output = new Hessian2Output(out);
output.startCall(method);
for (int i = 0; param != null && i < param.length; i++) {
output.writeObject(param[i]);
}
output.completeCall();
output.flush();
} finally {
out.close();
}
// Insert binary stream to connection
PostMethod httpMethod = new PostMethod(url.toString());
httpMethod.setDoAuthentication(true);
((PostMethod) httpMethod).setRequestEntity(
new ByteArrayRequestEntity(out.toByteArray())
);
try {
// Call service
int status = httpClient.executeMethod(httpMethod);
if (status == 200) {
// Read reply
Hessian2Input input =
new Hessian2Input(httpMethod.getResponseBodyAsStream());
input.startReply(); // Error occurs here
Object obj = input.getReplyFault();
if (obj == null) {
obj = input.readObject();
}
input.completeReply();
if (obj instanceof Throwable) {
throw (Throwable) obj;
} else {
return obj;
}
} else {
System.out.println(httpMethod.getResponseBodyAsString());
}
} catch (Throwable e) {
throw new Exception(e);
} finally {
System.out.println("status: " + httpMethod.getStatusLine());
httpMethod.releaseConnection();
}
return null;
}
END OF CODE
Once again, thank you.
- ian
On 6/27/07, Ben Hood <[EMAIL PROTECTED]> wrote:
On 6/20/07, ian tabangay <[EMAIL PROTECTED]> wrote:
> Hi. Has anyone encountered this kind of exception when using the hessian
> 3.1.1? im getting this exception when the server encountered an
exception
> when executing the service. Can anyone give suggestions how i can go
around
> this problem? Thanks.
Could you give us a brief version of the code that causes this problem?
_______________________________________________
hessian-interest mailing list
[email protected]
http://maillist.caucho.com/mailman/listinfo/hessian-interest