Hi.
I emailed before about an error i encountered when i was creating a client
using Hessian 3.1.1. I was trying call a Hessian service without using the
HessianProxyFactory. My reason for doing this is to have more control over
the Url Connection object. Anyways, an exception Encountered an
IOExceptionWrapper: java.lang.UnsupportedOperationException was thown
whenever an exception has been thrown by the service class. The fix was to
use the older version HessianOutput instead of Hessian2Output to encode the
request that i have created.

Here's the code for those who are interested. I used HttpClient of Jakarta
Commons to handle my Http Connection:

START OF CODE

1  public Object connect(String id, String pwd, String method, Object[]
param)
2      throws Exception {
3  // Create an httpClient instance
4    HttpClient httpClient = new HttpClient();
5    URL url = new URL(address);
6    httpClient.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
7  // Set username and password
8    httpClient.getState().setCredentials(
9      new AuthScope(url.getHost(), url.getPort(), null),
10      new UsernamePasswordCredentials(id, pwd)
11    );
12  // Transform request to Hessian binary
13    ByteArrayOutputStream out = new ByteArrayOutputStream();
14    try {
15      AbstractHessianOutput output = new HessianOutput(out);
16      output.startCall(method);
17      for (int i = 0; param != null && i < param.length; i++) {
18        output.writeObject(param[i]);
19      }
20      output.completeCall();
21      output.flush();
22    } finally {
23      out.close ();
24    }
25  // Insert binary stream to connection
26    PostMethod httpMethod = new PostMethod(url.toString());
27    httpMethod.setDoAuthentication(true);
28    ((PostMethod) httpMethod).setRequestEntity(
29      new ByteArrayRequestEntity(out.toByteArray())
30    );
31    try {
32  // Call service
33      int status = httpClient.executeMethod(httpMethod);
34      if (status == HttpURLConnection.HTTP_OK) {
35  // Read reply
36        AbstractHessianInput input =
37          new Hessian2Input(httpMethod.getResponseBodyAsStream());
38        input.startReply();
39        Object obj = input.readObject();
40          input.completeReply ();
41        if (obj instanceof Throwable) {
42          throw (Throwable) obj;
43        } else {
44          return obj;
45        }
46      } else {
47        System.out.println(httpMethod.getResponseBodyAsString());
48      }
49    } catch (Throwable e) {
50      throw new Exception(e);
51    } finally {
52      System.out.println("status: " + httpMethod.getStatusLine());
53      httpMethod.releaseConnection();
54    }
55    return null;
56  }

END OF CODE


Btw, to Ben, thanks for your help.


- ian
_______________________________________________
hessian-interest mailing list
[email protected]
http://maillist.caucho.com/mailman/listinfo/hessian-interest

Reply via email to