org.gsm.oneapi.server
Class OneAPIServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.gsm.oneapi.server.OneAPIServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
CancelMMSDeliveryReportSubscriptionServlet, CancelMMSReceiptReportSubscriptionServlet, CancelSMSDeliveryReportSubscriptionServlet, CancelSMSReceiptReportSubscriptionServlet, LocationServlet, MMSDeliveryReportSubscriptionServlet, MMSReceiptReportSubscriptionServlet, PaymentServlet, QueryMMSDeliveryStatusServlet, QuerySMSDeliveryStatusServlet, RetrieveMMSMessageServlet, RetrieveMMSMessagesServlet, RetrieveSMSMessagesServlet, SendMMSServlet, SendSMSServlet, SMSDeliveryReportSubscriptionServlet, SMSReceiptReportSubscriptionServlet

public class OneAPIServlet
extends javax.servlet.http.HttpServlet

Provides constants and utilities to the individual OneAPI servlets

See Also:
Serialized Form

Field Summary
static int ACCEPTED
           
static int AUTHENTICATION_FAILURE
           
static int BAD_REQUEST
           
static int CREATED
           
static boolean dumpRequestAndResponse
           
static int FORBIDDEN
           
static int METHOD_NOT_SUPPORTED
           
static int NOCONTENT
           
static int NONAUTHORITATIVE
           
static int NOT_FOUND
           
static int OK
           
static long serialVersionUID
           
 
Constructor Summary
OneAPIServlet()
           
 
Method Summary
static boolean checkRequestParameters(javax.servlet.http.HttpServletResponse response, ValidationRule[] rules)
          This function implements the specific parameter validation rules applying to each OneAPI servlet (specifically request parameters).
 void doDelete(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          By default make HTTP delete requests return a not supported error.
 void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          By default make HTTP get requests return a not supported error.
 void doHead(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          By default make HTTP head requests return a not supported error.
 void doOptions(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          By default make HTTP options requests return a not supported error.
 void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          By default make HTTP post requests return a not supported error.
 void doPut(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          By default make HTTP put requests return a not supported error.
 void doTrace(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          By default make HTTP trace requests return a not supported error.
protected  void dumpRequestDetails(javax.servlet.http.HttpServletRequest request, org.apache.log4j.Logger callerLogger)
          Output the request details to the log4j output
static java.lang.String getRequestHostnameAndContext(javax.servlet.http.HttpServletRequest request)
          Get the base URL based on the incoming request
static java.lang.String[] getRequestParts(javax.servlet.http.HttpServletRequest request)
          Get the slash separated path components from the incoming request
 void init()
          Default servlet initialisation method - should be overridden by the individual servlet
static boolean isAuthorizationFailed(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Is a starter function to check the request Basic authorization
static boolean isCorrectlyFormattedNumber(java.lang.String tel)
          Check on valid telephone number formats.
static boolean isCorrectlyFormattedURL(java.lang.String url)
          Check on valid URL formats.
static boolean isTrue(java.lang.String s)
          Convert to a boolean value
 java.util.Date makeUTCDateTime(int year, int month, int day, int hour, int minute, int second)
          Utility function to create a java.util.Date object from constituent date/ time fields (UTC clock)
static java.lang.String nullOrTrimmed(java.lang.String s)
          Ensure the input value is either a null value or a trimmed string
static boolean parseBoolean(java.lang.String s)
          Alternate function name to convert to a boolean value
static double parseDouble(java.lang.String s)
          Convert to a double value
static int parseInt(java.lang.String s)
          Convert to an integer value
static long parseLong(java.lang.String s)
          Convert to a long value
static void sendError(javax.servlet.http.HttpServletResponse response, int errorCode, int errorType, java.lang.String messageId, java.lang.String errorText, java.lang.String errorInformation)
          This is a helper to send an error response
static void sendJSONResponse(javax.servlet.http.HttpServletResponse response, java.lang.String jsonResponse, int status, java.lang.String location)
          This is a helper to send the formed JSON response
static java.lang.String urlEncode(java.lang.String s)
          Do basic URL encoding based on UTF-8
static boolean validateRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String[] requestParts, java.lang.String[] validationRules)
          This function implements initial checks on the format of the requested URL
 
Methods inherited from class javax.servlet.http.HttpServlet
getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values

BAD_REQUEST

public static final int BAD_REQUEST
See Also:
Constant Field Values

AUTHENTICATION_FAILURE

public static final int AUTHENTICATION_FAILURE
See Also:
Constant Field Values

FORBIDDEN

public static final int FORBIDDEN
See Also:
Constant Field Values

NOT_FOUND

public static final int NOT_FOUND
See Also:
Constant Field Values

METHOD_NOT_SUPPORTED

public static final int METHOD_NOT_SUPPORTED
See Also:
Constant Field Values

OK

public static final int OK
See Also:
Constant Field Values

CREATED

public static final int CREATED
See Also:
Constant Field Values

ACCEPTED

public static final int ACCEPTED
See Also:
Constant Field Values

NONAUTHORITATIVE

public static final int NONAUTHORITATIVE
See Also:
Constant Field Values

NOCONTENT

public static final int NOCONTENT
See Also:
Constant Field Values

dumpRequestAndResponse

public static boolean dumpRequestAndResponse
Constructor Detail

OneAPIServlet

public OneAPIServlet()
Method Detail

nullOrTrimmed

public static java.lang.String nullOrTrimmed(java.lang.String s)
Ensure the input value is either a null value or a trimmed string


parseInt

public static int parseInt(java.lang.String s)
Convert to an integer value


parseLong

public static long parseLong(java.lang.String s)
Convert to a long value


isTrue

public static boolean isTrue(java.lang.String s)
Convert to a boolean value


parseBoolean

public static boolean parseBoolean(java.lang.String s)
Alternate function name to convert to a boolean value


parseDouble

public static double parseDouble(java.lang.String s)
Convert to a double value


urlEncode

public static java.lang.String urlEncode(java.lang.String s)
Do basic URL encoding based on UTF-8


init

public void init()
          throws javax.servlet.ServletException
Default servlet initialisation method - should be overridden by the individual servlet

Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException

doGet

public void doGet(javax.servlet.http.HttpServletRequest request,
                  javax.servlet.http.HttpServletResponse response)
           throws java.io.IOException,
                  javax.servlet.ServletException
By default make HTTP get requests return a not supported error. The individual servlet can replace this if it should be supported.

Overrides:
doGet in class javax.servlet.http.HttpServlet
Throws:
java.io.IOException
javax.servlet.ServletException

doPost

public void doPost(javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
            throws java.io.IOException,
                   javax.servlet.ServletException
By default make HTTP post requests return a not supported error. The individual servlet can replace this if it should be supported.

Overrides:
doPost in class javax.servlet.http.HttpServlet
Throws:
java.io.IOException
javax.servlet.ServletException

doDelete

public void doDelete(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response)
              throws java.io.IOException,
                     javax.servlet.ServletException
By default make HTTP delete requests return a not supported error. The individual servlet can replace this if it should be supported.

Overrides:
doDelete in class javax.servlet.http.HttpServlet
Throws:
java.io.IOException
javax.servlet.ServletException

doPut

public void doPut(javax.servlet.http.HttpServletRequest request,
                  javax.servlet.http.HttpServletResponse response)
           throws java.io.IOException,
                  javax.servlet.ServletException
By default make HTTP put requests return a not supported error. The individual servlet can replace this if it should be supported.

Overrides:
doPut in class javax.servlet.http.HttpServlet
Throws:
java.io.IOException
javax.servlet.ServletException

doHead

public void doHead(javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
            throws java.io.IOException,
                   javax.servlet.ServletException
By default make HTTP head requests return a not supported error. The individual servlet can replace this if it should be supported.

Overrides:
doHead in class javax.servlet.http.HttpServlet
Throws:
java.io.IOException
javax.servlet.ServletException

doTrace

public void doTrace(javax.servlet.http.HttpServletRequest request,
                    javax.servlet.http.HttpServletResponse response)
             throws java.io.IOException,
                    javax.servlet.ServletException
By default make HTTP trace requests return a not supported error. The individual servlet can replace this if it should be supported.

Overrides:
doTrace in class javax.servlet.http.HttpServlet
Throws:
java.io.IOException
javax.servlet.ServletException

doOptions

public void doOptions(javax.servlet.http.HttpServletRequest request,
                      javax.servlet.http.HttpServletResponse response)
               throws java.io.IOException,
                      javax.servlet.ServletException
By default make HTTP options requests return a not supported error. The individual servlet can replace this if it should be supported.

Overrides:
doOptions in class javax.servlet.http.HttpServlet
Throws:
java.io.IOException
javax.servlet.ServletException

sendJSONResponse

public static void sendJSONResponse(javax.servlet.http.HttpServletResponse response,
                                    java.lang.String jsonResponse,
                                    int status,
                                    java.lang.String location)
                             throws java.io.IOException
This is a helper to send the formed JSON response

Parameters:
response -
jsonResponse -
status -
location -
Throws:
java.io.IOException

sendError

public static void sendError(javax.servlet.http.HttpServletResponse response,
                             int errorCode,
                             int errorType,
                             java.lang.String messageId,
                             java.lang.String errorText,
                             java.lang.String errorInformation)
This is a helper to send an error response

Parameters:
response -
errorCode -
errorType -
messageId -
errorText -
errorInformation -

getRequestHostnameAndContext

public static java.lang.String getRequestHostnameAndContext(javax.servlet.http.HttpServletRequest request)
Get the base URL based on the incoming request

Parameters:
request -

getRequestParts

public static java.lang.String[] getRequestParts(javax.servlet.http.HttpServletRequest request)
Get the slash separated path components from the incoming request

Parameters:
request -

dumpRequestDetails

protected void dumpRequestDetails(javax.servlet.http.HttpServletRequest request,
                                  org.apache.log4j.Logger callerLogger)
Output the request details to the log4j output

Parameters:
request -
callerLogger -

isAuthorizationFailed

public static boolean isAuthorizationFailed(javax.servlet.http.HttpServletRequest request,
                                            javax.servlet.http.HttpServletResponse response)
Is a starter function to check the request Basic authorization

Parameters:
request -
response -

validateRequest

public static boolean validateRequest(javax.servlet.http.HttpServletRequest request,
                                      javax.servlet.http.HttpServletResponse response,
                                      java.lang.String[] requestParts,
                                      java.lang.String[] validationRules)
This function implements initial checks on the format of the requested URL

Parameters:
request -
response -
requestParts -
validationRules -
Returns:
true is the request is considered valid

checkRequestParameters

public static boolean checkRequestParameters(javax.servlet.http.HttpServletResponse response,
                                             ValidationRule[] rules)
This function implements the specific parameter validation rules applying to each OneAPI servlet (specifically request parameters).

Parameters:
response -
rules -
Returns:
true if all parameter validation rules have been passed
See Also:
ValidationRule

makeUTCDateTime

public java.util.Date makeUTCDateTime(int year,
                                      int month,
                                      int day,
                                      int hour,
                                      int minute,
                                      int second)
Utility function to create a java.util.Date object from constituent date/ time fields (UTC clock)

Parameters:
year -
month -
day -
hour -
minute -
second -

isCorrectlyFormattedNumber

public static boolean isCorrectlyFormattedNumber(java.lang.String tel)
Check on valid telephone number formats. Extend the regular expression rules in telFormats if needed.


isCorrectlyFormattedURL

public static boolean isCorrectlyFormattedURL(java.lang.String url)
Check on valid URL formats. Extend the regular expression rules in urlFormats if needed.