org.benow.service.http
Class HttpServiceMethod

java.lang.Object
  extended by org.benow.service.ServiceConnectionMethod
      extended by org.benow.service.http.HttpServiceMethod
All Implemented Interfaces:
java.io.Serializable

public class HttpServiceMethod
extends org.benow.service.ServiceConnectionMethod

A service connection that speaks http(s) over the wire to the http provider servlet (and request handler) to parse and pass to remote service manager. Service name, method, params, etc are formatted in http form post format and so are directly compatible with http spec (and can be debugged with a standard servlet). Likewise, the request handler receives in standard http (of course) and can be debugged with a web browser.

Author:
andy
See Also:
HttpServiceRequestHandler, Serialized Form

Field Summary
static org.benow.java.config.entry.StringConfigurationEntry CFG_EXTERNAL_URL
           
static java.net.URL HTTP_SERVICE_REMOTE_ACCESS_URL
          Set this to specify the way to access the service from a remote location.
 
Constructor Summary
HttpServiceMethod()
           
HttpServiceMethod(java.lang.String user, java.lang.String pass, java.lang.String host)
           
HttpServiceMethod(java.lang.String user, java.lang.String pass, java.lang.String host, int port)
           
HttpServiceMethod(java.net.URL url)
           
 
Method Summary
 boolean accepts(java.net.URL url)
           
protected  HTTPClient.HTTPConnection createConnection()
           
protected  org.benow.java.source.ClassSource createSource(java.lang.String accessorName, java.lang.Class<? extends org.benow.service.Service> serviceInterface)
           
protected  java.lang.Object decodeResponse(java.lang.String text)
          Decodes the respons from the server.
protected  java.net.URL doGetRemoteAccessURL()
           
 HTTPClient.HTTPResponse doPost(java.lang.String file, java.util.List<HTTPClient.NVPair> paramPairs)
           
protected  void doSendEvent(org.benow.service.ListenerStub stub, java.lang.Object notifier, org.benow.java.notify.event.Event event)
           
protected  void doSubscribeToEvents(org.benow.java.notify.Listener listener)
           
protected  void doUnsubscribe()
           
 java.lang.String getLocalIdentifier()
           
static boolean isSimple(java.lang.Class<?> type)
           
 java.lang.Object remoteExec(java.lang.String methodSig, java.lang.Class<?> serviceClass, java.util.Map<java.lang.String,java.lang.Object> params)
           
protected  HTTPClient.HTTPResponse sendMethodRequest(java.lang.String methodSig, java.lang.Class<?> serviceClass, java.util.Map<java.lang.String,java.lang.Object> params)
          Encodes and sends a request to the server over the network.
 java.lang.Object sendServiceMethodRequest(java.lang.Class<?> serviceClass, java.lang.String methodName, java.lang.Object[] args)
           
 
Methods inherited from class org.benow.service.ServiceConnectionMethod
createListenerStub, getAccessor, getListenerForStubKey, getRemoteAccessURL, setRemoteAccessURL
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CFG_EXTERNAL_URL

public static final org.benow.java.config.entry.StringConfigurationEntry CFG_EXTERNAL_URL

HTTP_SERVICE_REMOTE_ACCESS_URL

public static java.net.URL HTTP_SERVICE_REMOTE_ACCESS_URL
Set this to specify the way to access the service from a remote location. Remote access is required for listener callback, loopback invocation, etc.

HACK: this is a bit of a hack because it applies across the whole vm, if there are multiple services, each bound to an IP, the will falsely give the same remoteAccessURL. The solution to this is to get the connection from the service provider (ie http service servlet), which doesnt easily fit into service connection manager. there is likely a way around it, but not an obvious one.

Constructor Detail

HttpServiceMethod

public HttpServiceMethod()
                  throws javax.naming.ConfigurationException
Throws:
javax.naming.ConfigurationException

HttpServiceMethod

public HttpServiceMethod(java.lang.String user,
                         java.lang.String pass,
                         java.lang.String host)
                  throws java.text.ParseException
Throws:
java.text.ParseException

HttpServiceMethod

public HttpServiceMethod(java.lang.String user,
                         java.lang.String pass,
                         java.lang.String host,
                         int port)

HttpServiceMethod

public HttpServiceMethod(java.net.URL url)
                  throws java.text.ParseException
Throws:
java.text.ParseException
Method Detail

sendServiceMethodRequest

public java.lang.Object sendServiceMethodRequest(java.lang.Class<?> serviceClass,
                                                 java.lang.String methodName,
                                                 java.lang.Object[] args)

createConnection

protected HTTPClient.HTTPConnection createConnection()
                                              throws HTTPClient.ProtocolNotSuppException,
                                                     java.net.MalformedURLException
Throws:
HTTPClient.ProtocolNotSuppException
java.net.MalformedURLException

remoteExec

public java.lang.Object remoteExec(java.lang.String methodSig,
                                   java.lang.Class<?> serviceClass,
                                   java.util.Map<java.lang.String,java.lang.Object> params)
                            throws org.benow.service.ServiceInvocationException,
                                   java.lang.reflect.InvocationTargetException
Specified by:
remoteExec in class org.benow.service.ServiceConnectionMethod
Throws:
org.benow.service.ServiceInvocationException
java.lang.reflect.InvocationTargetException

isSimple

public static boolean isSimple(java.lang.Class<?> type)

sendMethodRequest

protected HTTPClient.HTTPResponse sendMethodRequest(java.lang.String methodSig,
                                                    java.lang.Class<?> serviceClass,
                                                    java.util.Map<java.lang.String,java.lang.Object> params)
                                             throws java.io.IOException,
                                                    HTTPClient.ModuleException,
                                                    javax.xml.transform.TransformerException,
                                                    org.benow.service.ServiceInvocationException,
                                                    java.lang.reflect.InvocationTargetException
Encodes and sends a request to the server over the network. Request is made as a HTTP form posting. Within the request param is the specifics of service, method and params. Within subsequest params may be extended param information. An example follows:
  get /service HTTP/1.0
  Cookie: auth-cookie-info-12345
  
  --- request ---
  <service name="my.service.Name">
    <method name="doSomething">
      <param name="param1Name" type="org.object.Type">
        <!-- value of org.object.Type instance as marshalled to xml -->
        <name>...</name>
        <value>...</value>
      </param>
      <param name="param2Name" type="java.io.InputStream" postParam="param2name"/> 
    </method>
  </service>
  ---- param2Name --- <-- file post param for certain types -->
  .....
 

Throws:
javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
java.lang.reflect.InvocationTargetException
org.benow.service.ServiceInvocationException
java.io.IOException
HTTPClient.ModuleException

doPost

public HTTPClient.HTTPResponse doPost(java.lang.String file,
                                      java.util.List<HTTPClient.NVPair> paramPairs)
                               throws java.io.IOException,
                                      HTTPClient.ModuleException,
                                      org.benow.service.ServiceInvocationException,
                                      java.lang.reflect.InvocationTargetException
Throws:
java.io.IOException
HTTPClient.ModuleException
org.benow.service.ServiceInvocationException
java.lang.reflect.InvocationTargetException

decodeResponse

protected java.lang.Object decodeResponse(java.lang.String text)
                                   throws java.lang.Exception
Decodes the respons from the server. Response might be a or an . ... ... ... Something bad happened

Parameters:
text -
Returns:
Throws:
java.io.IOException
java.text.ParseException
java.lang.InstantiationException
java.lang.Exception

createSource

protected org.benow.java.source.ClassSource createSource(java.lang.String accessorName,
                                                         java.lang.Class<? extends org.benow.service.Service> serviceInterface)
                                                  throws org.benow.java.spec.SpecificationException
Specified by:
createSource in class org.benow.service.ServiceConnectionMethod
Throws:
org.benow.java.spec.SpecificationException

getLocalIdentifier

public java.lang.String getLocalIdentifier()

accepts

public boolean accepts(java.net.URL url)
Specified by:
accepts in class org.benow.service.ServiceConnectionMethod

doSubscribeToEvents

protected void doSubscribeToEvents(org.benow.java.notify.Listener listener)
                            throws java.io.IOException
Specified by:
doSubscribeToEvents in class org.benow.service.ServiceConnectionMethod
Throws:
java.io.IOException

doUnsubscribe

protected void doUnsubscribe()
                      throws java.io.IOException
Specified by:
doUnsubscribe in class org.benow.service.ServiceConnectionMethod
Throws:
java.io.IOException

doSendEvent

protected void doSendEvent(org.benow.service.ListenerStub stub,
                           java.lang.Object notifier,
                           org.benow.java.notify.event.Event event)
                    throws java.io.IOException,
                           org.benow.service.ServiceInvocationException,
                           java.lang.reflect.InvocationTargetException
Specified by:
doSendEvent in class org.benow.service.ServiceConnectionMethod
Throws:
java.io.IOException
org.benow.service.ServiceInvocationException
java.lang.reflect.InvocationTargetException

doGetRemoteAccessURL

protected java.net.URL doGetRemoteAccessURL()
Specified by:
doGetRemoteAccessURL in class org.benow.service.ServiceConnectionMethod