Version 3

    The servlet invoker is server invoker implementation that uses a servlet running within  a web container to accept initial client invocation requests.  The servlet request is then passed onto the servlet invoker for processing.


    The deployment for this particular server invoker is a little different than the other server invokers since a web deployment is also required.  To start, the servlet invoker will need to be configured and deployed.  This can be done by adding the Connector MBean service to an existing service xml or creating a new one.  The following is an example of how to declare a Connector that uses the servlet invoker:


       <mbean code="org.jboss.remoting.transport.Connector"
          display-name="Servlet transport Connector">
          <attribute name="InvokerLocator">servlet://localhost:8080/servlet-invoker/ServerInvokerServlet</attribute>
          <attribute name="Configuration">
                   <handler subsystem="test">org.jboss.test.remoting.transport.web.WebInvocationHandler</handler>

    An important point of configuration to note is that the value for the InvokerLocator attribute is the exact url used to access the servlet for the servlet invoker (more on how to define this below), with the exception of the protocol being servlet instead of http.  This is important because if using automatic discovery, this is the locator url that will be discovered and used by clients to connect to this server invoker.


    The next step is to configure and deploy the servlet that fronts the servlet invoker.  The pre-built deployment file for this servlet is the servlet-invoker.war file (which can be found in the release distribution or under the output/lib/ directory if doing a source build).  By default, it is actually an exploded war, so the servlet-invoker.war is actually a directory so that can be more easily configured (feel free to zip up into an actual war file if prefer).  In the WEB-INF directory is located the web.xml file.  This is a standard web configuration file and should look like:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC
       "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    <!-- The the JBossRemoting server invoker servlet web.xml descriptor -->
            <description>The ServerInvokerServlet receives requests via HTTP
               protocol from within a web container and passes it onto the
               ServletServerInvoker for processing.
                <description>The servlet server invoker</description>

    This file can be changed to meet any web requirements you might have, such as adding security or changing the actual url context that the servlet maps to.  If the url that the servlet maps to is changed, will need to change the value for the InvokerLocator in the Connector configuration mentioned above.  Also note that there is a parameter, invokerName, that has the value of the object name of the servlet server invoker.  This is what the ServerInvokerServlet uses to lookup the server invoker which it will pass the requests onto.


    Due to the way the servlet invoker is currently configured an deployed, it must run within the JBoss application server and is not portable to other web servers. 



    Exception handling


    If the ServletServerInvoker catches any exception thrown from the invocation handler invoke() call, it will send an error to the client with a status of 500 and include the original exception message as it's error message.  From the client side, the client invoker will actually throw a CannotConnectException, which will have root exception as its cause.  The cause should be an IOException with the server's message.  For example, the stack trace from the exception thrown within the test case org.jboss.remoting.transport.servlet.test.ServletInvokerTestClient is:

    org.jboss.remoting.CannotConnectException: Can not connect http client invoker.
         at org.jboss.remoting.transport.http.HTTPClientInvoker.useHttpURLConnection(
         at org.jboss.remoting.transport.http.HTTPClientInvoker.transport(
         at org.jboss.remoting.RemoteClientInvoker.invoke(
         at org.jboss.remoting.Client.invoke(
         at org.jboss.remoting.Client.invoke(
         at org.jboss.remoting.transport.servlet.test.ServletInvokerTestClient.testInvocation(
         at org.jboss.remoting.transport.servlet.test.ServletInvokerTestClient.main(
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(
         at java.lang.reflect.Method.invoke(
         at com.intellij.rt.execution.application.AppMain.main(
    Caused by: Server returned HTTP response code: 500 for URL: http://localhost:8080/servlet-invoker/ServerInvokerServlet
         at org.jboss.remoting.transport.http.HTTPClientInvoker.useHttpURLConnection(
         ... 11 more




    One of the issues of using HTTP/Servlet invoker is that the invocation handlers (those that implement ServerInvocationHandler), can not provide very much detail in regards to what is returned in regards to a web context.  For example, the content type used for the

    response is the same as that of the request.  Also can not set specific response header values or send specific error status.