public class ServletTransportProvider extends Object implements TransportProvider, ServletConsts
handleRequest()
method.
The code excerpt below demonstrates how to create an instance of this class and use it in a servlet implementation:
...
public void init(ServletConfig conf) throws ServletException {
_provider = new ServletTransportProvider();
TransportManager.registerProvider(_provider);
Properties props = new Properties();
// property below would normally be passed through a
// servlet init parameter.
props.setProperty(ServletConsts.SERVLET_URL_KEY,
"http://localhost:8080/ubik");
// this tells ubik "under" which transport our object will be exported
props.setProperty(Consts.TRANSPORT_TYPE, ServletConsts.DEFAULT_SERVLET_TRANSPORT_TYPE);
try{
_foo = new UbikFoo();
Hub.exportObject(_foo, props);
}catch(RemoteException e){
throw new ServletException("Could not export Foo", e);
}
}
...
protected void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
_provider.handleRequest(req, res);
}
...
Then, in a client VM, to connect to the remote object, we proceed as follows:
TransportManager.registerProvider(new ServletTransportProvider());
Foo foo = (Foo)Hub.connect(new ServletAddress("http://localhost:8080/ubik"));
NOTE: there can be only ONE instance of this instance registered to the Hub
per web application
handleRequest(HttpServletRequest, HttpServletResponse)DEFAULT_SERVLET_TRANSPORT_TYPE, SERVLET_URL_KEY| Modifier | Constructor and Description |
|---|---|
|
ServletTransportProvider() |
protected |
ServletTransportProvider(String transportType) |
| Modifier and Type | Method and Description |
|---|---|
Connections |
getPoolFor(ServerAddress address)
Returns a client connection pool to the given server address.
|
String |
getTransportType()
Returns this instance's "transport type".
|
void |
handleRequest(javax.servlet.http.HttpServletRequest httpReq,
javax.servlet.http.HttpServletResponse httpRes) |
Server |
newDefaultServer()
This method is called by Ubik RMI's runtime when a server is needed on
the client side to recieve asynchronous responses (i.e.: callbacks).
|
Server |
newServer(Properties props)
This method returns a
Server impl., given the properties passed in. |
void |
shutdown()
Empty implementation.
|
public ServletTransportProvider()
protected ServletTransportProvider(String transportType)
public String getTransportType()
TransportProvidergetTransportType in interface TransportProviderTransportProvider.getTransportType()public Server newDefaultServer() throws RemoteException
TransportProviderServer instance.newDefaultServer in interface TransportProviderServer.RemoteExceptionTransportProvider.newDefaultServer()public Server newServer(Properties props) throws RemoteException
Server impl., given the properties passed in.
A single property is expected: ubik.rmi.transport.servlet.url, whose
value must correspond to the URL of the servlet that is encapsulating this instance.newServer in interface TransportProviderprops - the Properties used to create the server.Server instance.RemoteExceptionServletConsts.SERVLET_URL_KEY,
TransportProvider.newServer(java.util.Properties)public void shutdown()
shutdown in interface TransportProviderTransportProvider.shutdown()public Connections getPoolFor(ServerAddress address) throws RemoteException
TransportProvidergetPoolFor in interface TransportProvideraddress - a ServerAddress.ConnectionOptionsException.RemoteException - if a problem occurs creating the connection.TransportProvider.getPoolFor(org.sapia.ubik.net.ServerAddress)public void handleRequest(javax.servlet.http.HttpServletRequest httpReq,
javax.servlet.http.HttpServletResponse httpRes)
Copyright © 2012 Sapia OSS. All Rights Reserved.