Java – com.caucho.hessian.client.HessianRuntimeException : com. caucho.hessian.io.HessianProtocolException: ‘<' is unknown code

com.caucho.hessian.client.HessianRuntimeException : com. caucho.hessian.io.HessianProtocolException: ‘<' is unknown code... here is a solution to the problem.

com.caucho.hessian.client.HessianRuntimeException : com. caucho.hessian.io.HessianProtocolException: ‘<' is unknown code

I’m trying to establish basic Hessian communication between two Android devices.

The client sends the message AsyncTask

public class AsyncHessian extends AsyncTask<String,String,String> {

@Override
protected String doInBackground(String... params) {

String url = "http://192.168.1.37:8080/test/test";
    try{
        HessianProxyFactory factory = new HessianProxyFactory();
        TService basic = (TService) factory.create(TService.class, url);
        basic.hello();
        Log.i("Hello", "Hessian!");
    }
    catch(Exception e){e.printStackTrace(); }
    return "";
}

Implementation of the server-side interface

public class TServiceImpl extends HessianServlet implements TService{

public static void main(String[] args) throws Exception {
    Server server = new Server(8080);
    Context context = new Context(server, "/", Context.SESSIONS);
    context.addServlet(TServiceImpl.class, "/test");
    server.start();
}

public void hello() {
    System.out.println("Hello Hessian!");
}

Interface

public interface TService {
public void hello();

The server is running jetty on the Android device.
Messages are being sent from the application to the server.

I’m sure the message has reached its destination because I get an ECONNREFUSED error when jetty stops. Now, when it opens, I get its title.

Solution

Configure your servlets in your web.xml

<servlet>
    <servlet-name>testService</servlet-name>
    <servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>
    <init-param>
        <param-name>home-class</param-name>
        <param-value>TServiceImpl's full name</param-value>
    </init-param>
    <init-param>
        <param-name>home-api</param-name>
        <param-value>TService's full name</param-value>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>testService</servlet-name>
    <url-pattern>/test</url-pattern>
</servlet-mapping>

See also: http://hessian.caucho.com/doc/hessian-overview.xtp#Configurationforstandardweb.xml

Related Problems and Solutions