org.springframework.remoting.httpinvoker
Class HttpInvokerServiceExporter

java.lang.Object
  extended by org.springframework.remoting.support.RemoteExporter
      extended by org.springframework.remoting.support.RemoteInvocationBasedExporter
          extended by org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter
All Implemented Interfaces:
InitializingBean, Controller

public class HttpInvokerServiceExporter
extends RemoteInvocationBasedExporter
implements Controller, InitializingBean

Web controller that exports the specified service bean as HTTP invoker service endpoint, accessible via an HTTP invoker proxy.

Deserializes remote invocation objects and serializes remote invocation result objects. Uses Java serialization just like RMI, but provides the same ease of setup as Caucho's HTTP-based Hessian and Burlap protocols.

HTTP invoker is the recommended protocol for Java-to-Java remoting. It is more powerful and more extensible than Hessian and Burlap, at the expense of being tied to Java. Nevertheless, it is as easy to set up as Hessian and Burlap, which is its main advantage compared to RMI.

Since:
1.1
Author:
Juergen Hoeller
See Also:
HttpInvokerClientInterceptor, HttpInvokerProxyFactoryBean, RmiServiceExporter, HessianServiceExporter, BurlapServiceExporter

Field Summary
protected static String CONTENT_TYPE_SERIALIZED_OBJECT
           
 
Fields inherited from class org.springframework.remoting.support.RemoteExporter
logger
 
Constructor Summary
HttpInvokerServiceExporter()
           
 
Method Summary
 void afterPropertiesSet()
          Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
protected  ObjectInputStream createObjectInputStream(InputStream is)
          Create an ObjectInputStream for the given InputStream.
protected  ObjectOutputStream createObjectOutputStream(OutputStream os)
          Create an ObjectOutputStream for the given OutputStream.
protected  InputStream decorateInputStream(HttpServletRequest request, InputStream is)
          Return the InputStream to use for reading remote invocations, potentially decorating the given original InputStream.
protected  OutputStream decorateOutputStream(HttpServletRequest request, HttpServletResponse response, OutputStream os)
          Return the OutputStream to use for writing remote invocation results, potentially decorating the given original OutputStream.
protected  RemoteInvocation doReadRemoteInvocation(ObjectInputStream ois)
          Perform the actual reading of an invocation result object from the given ObjectInputStream.
protected  void doWriteRemoteInvocationResult(RemoteInvocationResult result, ObjectOutputStream oos)
          Perform the actual writing of the given invocation result object to the given ObjectOutputStream.
 ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
          Read a remote invocation from the request, execute it, and write the remote invocation result to the response.
protected  RemoteInvocation readRemoteInvocation(HttpServletRequest request)
          Read a RemoteInvocation from the given HTTP request.
protected  RemoteInvocation readRemoteInvocation(HttpServletRequest request, InputStream is)
          Deserialize a RemoteInvocation object from the given InputStream.
protected  void writeRemoteInvocationResult(HttpServletRequest request, HttpServletResponse response, RemoteInvocationResult result)
          Write the given RemoteInvocationResult to the given HTTP response.
protected  void writeRemoteInvocationResult(HttpServletRequest request, HttpServletResponse response, RemoteInvocationResult result, OutputStream os)
          Serialize the given RemoteInvocation to the given OutputStream.
 
Methods inherited from class org.springframework.remoting.support.RemoteInvocationBasedExporter
getRemoteInvocationExecutor, invoke, invokeAndCreateResult, setRemoteInvocationExecutor
 
Methods inherited from class org.springframework.remoting.support.RemoteExporter
checkService, checkServiceInterface, getExporterName, getProxyForService, getService, getServiceInterface, isRegisterTraceInterceptor, setRegisterTraceInterceptor, setService, setServiceInterface
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTENT_TYPE_SERIALIZED_OBJECT

protected static final String CONTENT_TYPE_SERIALIZED_OBJECT
See Also:
Constant Field Values
Constructor Detail

HttpInvokerServiceExporter

public HttpInvokerServiceExporter()
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
Description copied from interface: InitializingBean
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

Specified by:
afterPropertiesSet in interface InitializingBean

handleRequest

public ModelAndView handleRequest(HttpServletRequest request,
                                  HttpServletResponse response)
                           throws IOException,
                                  ClassNotFoundException
Read a remote invocation from the request, execute it, and write the remote invocation result to the response.

Specified by:
handleRequest in interface Controller
Parameters:
request - current HTTP request
response - current HTTP response
Returns:
a ModelAndView to render, or null if handled directly
Throws:
IOException
ClassNotFoundException
See Also:
readRemoteInvocation(HttpServletRequest), RemoteInvocationBasedExporter.invokeAndCreateResult(org.springframework.remoting.support.RemoteInvocation, java.lang.Object), writeRemoteInvocationResult(HttpServletRequest, HttpServletResponse, RemoteInvocationResult)

readRemoteInvocation

protected RemoteInvocation readRemoteInvocation(HttpServletRequest request)
                                         throws IOException,
                                                ClassNotFoundException
Read a RemoteInvocation from the given HTTP request. Delegates to readRemoteInvocation(InputStream) with the servlet request's input stream.

Parameters:
request - current HTTP request
Returns:
the RemoteInvocation object
Throws:
IOException - if thrown by operations on the request
ClassNotFoundException - if thrown by deserialization
See Also:
readRemoteInvocation(HttpServletRequest, java.io.InputStream), ServletRequest.getInputStream()

readRemoteInvocation

protected RemoteInvocation readRemoteInvocation(HttpServletRequest request,
                                                InputStream is)
                                         throws IOException,
                                                ClassNotFoundException
Deserialize a RemoteInvocation object from the given InputStream.

Gives decorateInputStream a chance to decorate the stream first (for example, for custom encryption or compression). Creates a CodebaseAwareObjectInputStream and calls doReadRemoteInvocation to actually read the object.

Can be overridden for custom serialization of the invocation.

Parameters:
request - current HTTP request
is - the InputStream to read from
Returns:
the RemoteInvocation object
Throws:
IOException - if thrown by I/O methods
ClassNotFoundException - if thrown during deserialization
See Also:
decorateInputStream(javax.servlet.http.HttpServletRequest, java.io.InputStream), doReadRemoteInvocation(java.io.ObjectInputStream)

decorateInputStream

protected InputStream decorateInputStream(HttpServletRequest request,
                                          InputStream is)
                                   throws IOException
Return the InputStream to use for reading remote invocations, potentially decorating the given original InputStream.

The default implementation returns the given stream as-is. Can be overridden, for example, for custom encryption or compression.

Parameters:
request - current HTTP request
is - the original InputStream
Returns:
the potentially decorated InputStream
Throws:
IOException

createObjectInputStream

protected ObjectInputStream createObjectInputStream(InputStream is)
                                             throws IOException
Create an ObjectInputStream for the given InputStream. The default implementation creates a CodebaseAwareObjectInputStream.

Spring's CodebaseAwareObjectInputStream is used to explicitly resolve primitive class names. This is done by the standard ObjectInputStream on JDK 1.4+, but needs to be done explicitly on JDK 1.3.

Parameters:
is - the InputStream to read from
Returns:
the new ObjectInputStream instance to use
Throws:
IOException - if creation of the ObjectInputStream failed
See Also:
CodebaseAwareObjectInputStream

doReadRemoteInvocation

protected RemoteInvocation doReadRemoteInvocation(ObjectInputStream ois)
                                           throws IOException,
                                                  ClassNotFoundException
Perform the actual reading of an invocation result object from the given ObjectInputStream.

The default implementation simply calls readObject. Can be overridden for deserialization of a custom wrapper object rather than the plain invocation, for example an encryption-aware holder.

Parameters:
ois - the ObjectInputStream to read from
Returns:
the RemoteInvocationResult object
Throws:
IOException - if thrown by I/O methods
ClassNotFoundException
See Also:
ObjectOutputStream.writeObject(java.lang.Object)

writeRemoteInvocationResult

protected void writeRemoteInvocationResult(HttpServletRequest request,
                                           HttpServletResponse response,
                                           RemoteInvocationResult result)
                                    throws IOException
Write the given RemoteInvocationResult to the given HTTP response.

Note that a request argument was introduced for Spring 1.1.3, which is not backwards-compatible for subclasses that override this method.

Parameters:
request - current HTTP request
response - current HTTP response
result - the RemoteInvocationResult object
Throws:
IOException - if thrown by operations on the response

writeRemoteInvocationResult

protected void writeRemoteInvocationResult(HttpServletRequest request,
                                           HttpServletResponse response,
                                           RemoteInvocationResult result,
                                           OutputStream os)
                                    throws IOException
Serialize the given RemoteInvocation to the given OutputStream.

The default implementation gives decorateOutputStream a chance to decorate the stream first (for example, for custom encryption or compression). Creates an ObjectOutputStream for the final stream and calls doWriteRemoteInvocationResult to actually write the object.

Can be overridden for custom serialization of the invocation.

Parameters:
request - current HTTP request
response - current HTTP response
result - the RemoteInvocationResult object
os - the OutputStream to write to
Throws:
IOException - if thrown by I/O methods
See Also:
decorateOutputStream(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.io.OutputStream), doWriteRemoteInvocationResult(org.springframework.remoting.support.RemoteInvocationResult, java.io.ObjectOutputStream)

decorateOutputStream

protected OutputStream decorateOutputStream(HttpServletRequest request,
                                            HttpServletResponse response,
                                            OutputStream os)
                                     throws IOException
Return the OutputStream to use for writing remote invocation results, potentially decorating the given original OutputStream.

The default implementation returns the given stream as-is. Can be overridden, for example, for custom encryption or compression.

Parameters:
request - current HTTP request
response - current HTTP response
os - the original OutputStream
Returns:
the potentially decorated OutputStream
Throws:
IOException

createObjectOutputStream

protected ObjectOutputStream createObjectOutputStream(OutputStream os)
                                               throws IOException
Create an ObjectOutputStream for the given OutputStream. The default implementation creates a plain ObjectOutputStream.

Parameters:
os - the OutputStream to write to
Returns:
the new ObjectOutputStream instance to use
Throws:
IOException - if creation of the ObjectOutputStream failed

doWriteRemoteInvocationResult

protected void doWriteRemoteInvocationResult(RemoteInvocationResult result,
                                             ObjectOutputStream oos)
                                      throws IOException
Perform the actual writing of the given invocation result object to the given ObjectOutputStream.

The default implementation simply calls writeObject. Can be overridden for serialization of a custom wrapper object rather than the plain invocation, for example an encryption-aware holder.

Parameters:
result - the RemoteInvocationResult object
oos - the ObjectOutputStream to write to
Throws:
IOException - if thrown by I/O methods
See Also:
ObjectOutputStream.writeObject(java.lang.Object)


Copyright (c) 2002-2006 The Spring Framework Project.