org.benow.service.http
Class HttpServiceRequestHandler

java.lang.Object
  extended by org.benow.web.servlet.RequestHandler
      extended by org.benow.web.servlet.SecureHandler
          extended by org.benow.service.http.HttpServiceRequestHandler
All Implemented Interfaces:
java.lang.Runnable

public class HttpServiceRequestHandler
extends SecureHandler

Parses request url and invokes a service method, returning the result of invocation. Provides an easy way to address services via an http request.

Invocation urls are in the form: /svc/fully.qualified.ServiceName and submission is in post or get form with the following parameters:

This handler allows for much flexibility for http method invocation and result delivery. Due to the use of standard http, it also allows for many differing types of clients to connect. It is also the default connection method for remote invocation used in the Service API.

Additionally, when accessed via a web browser, a javadoc-like display of services and methods is displayed. In such a way development against services is facilitated.

Author:
andy
See Also:
org.benow.java.spec.ParamName, HttpServiceMethod

Nested Class Summary
 class HttpServiceRequestHandler.ServiceInfo
           
 
Field Summary
 
Fields inherited from class org.benow.web.servlet.SecureHandler
CFG_LOGIN_PAGE, COOKIE_USER_INFO
 
Fields inherited from class org.benow.web.servlet.RequestHandler
ENV_PARAMS, ENV_REQUEST, ENV_REQUEST_URL, ENV_RESPONSE, ENV_SESSION, params, request, response, session, url
 
Constructor Summary
HttpServiceRequestHandler(HandlerServlet servlet)
           
 
Method Summary
static boolean canEditService(java.lang.Class<?> serviceClass)
           
 long copy(java.io.InputStream input, java.io.OutputStream out)
           
protected  java.lang.Object doRun(java.io.OutputStream out)
          if it's a collection we need to circumvent castor and handle the marshalling/unmarshalling ourselves (castor has issues with marshalling/unmarshalling lists) the method is in this class so as to eliminate multi-threading issues.
protected  void dumpError(java.io.PrintWriter out, int code, java.lang.String message, java.lang.Throwable t)
          handles exceptions.
static java.lang.String getRedirectToCreateURL(java.lang.String failMsg, java.lang.Class<?> serviceClass, java.lang.String methodSig)
          create url to create method page.
 
Methods inherited from class org.benow.web.servlet.SecureHandler
beforeRun, dirtyRun, doLoginRedirect, doLoginRedirect, doLoginRedirect, getPasswordHash, removeLoginCookie, startRun, validateCookie
 
Methods inherited from class org.benow.web.servlet.RequestHandler
doRun, doRun, getContentType, handleError, handleError, handleError, handleError, handleRequest, run
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpServiceRequestHandler

public HttpServiceRequestHandler(HandlerServlet servlet)
Method Detail

dumpError

protected void dumpError(java.io.PrintWriter out,
                         int code,
                         java.lang.String message,
                         java.lang.Throwable t)
                  throws java.io.IOException,
                         RedirectException
handles exceptions. If a referrer is given and there is a onorg.pkg.SomeException, onSomeException or onSome parameter (where SomeException is the type of the exception being handled) with a value, a redirect is given to a handler url as specified in the value (relative to the referrer). If there is no referrer or no exception displayer defined, an xml exception dump is given.

Overrides:
dumpError in class RequestHandler
Parameters:
response -
t -
out -
Throws:
java.io.IOException
RedirectException
javax.xml.transform.TransformerException

doRun

protected java.lang.Object doRun(java.io.OutputStream out)
                          throws java.lang.Exception
if it's a collection we need to circumvent castor and handle the marshalling/unmarshalling ourselves (castor has issues with marshalling/unmarshalling lists) the method is in this class so as to eliminate multi-threading issues.

Overrides:
doRun in class RequestHandler
Parameters:
coll -
out -
Throws:
javax.xml.transform.TransformerException
org.benow.java.mapping.MappingException
java.io.IOException - void marshallCollection(Collection coll, PrintWriter out) throws TransformerException { out.println(""); for (Iterator i = coll.iterator(); i.hasNext();) { Object curr = i.next(); out.print(" "); if (String.class.equals(curr.getClass())) out.print(curr); else if (Class.class.equals(curr.getClass())) { out.print(((Class) curr).getName()); } else { out.println(); ClassTransformer x = new ClassTransformer(curr); OutputFormat of = x.createDefaultOutputFormat(); of.setOmitXMLDeclaration(true); x.to(out, of); out.print(" "); } out.println(""); } out.println(""); }
java.lang.Exception
See Also:
HttpServiceMethod.unmarshallCollection(Class, String)

canEditService

public static boolean canEditService(java.lang.Class<?> serviceClass)
Parameters:
serviceClass -
Returns:
true if current user has service edit permission

getRedirectToCreateURL

public static java.lang.String getRedirectToCreateURL(java.lang.String failMsg,
                                                      java.lang.Class<?> serviceClass,
                                                      java.lang.String methodSig)
create url to create method page. Call when no service method. Introspects call to smartly generate method sig

Parameters:
failMsg -
serviceClass -
methodSig -
Returns:

copy

public long copy(java.io.InputStream input,
                 java.io.OutputStream out)
          throws java.io.IOException
Throws:
java.io.IOException