Tynamo™-SNAP
v1.0.4

com.qindesign.servlet.example
Class FastOneWireServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.qindesign.servlet.example.FastOneWireServlet
All Implemented Interfaces:
Servlet, ServletConfig

public class FastOneWireServlet
extends HttpServlet

Simple 1-Wire servlet that can list adapters and devices, and can also read a device. The output is XML.

The output is generated according to the following rules:

Version:
1.0.4
Author:
Shawn Silverman

Constructor Summary
FastOneWireServlet()
           
 
Method Summary
 void destroy()
          Destroys the servlet.
protected  void doGet(HttpServletRequest req, HttpServletResponse resp)
          Process a GET request.
 void init()
          Initializes the servlet.
protected  void printDevice(HttpServletRequest req, HttpServletResponse resp, DSPortAdapter a, OneWireContainer c)
          Retrieves a value from the given container.
protected  void printErrorMessage(HttpServletResponse resp, String msg)
          Prints an error message.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doOptions, doPost, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FastOneWireServlet

public FastOneWireServlet()
Method Detail

init

public void init()
          throws ServletException
Initializes the servlet.

Overrides:
init in class GenericServlet
Throws:
ServletException

destroy

public void destroy()
Destroys the servlet.

Specified by:
destroy in interface Servlet
Overrides:
destroy in class GenericServlet

doGet

protected void doGet(HttpServletRequest req,
                     HttpServletResponse resp)
              throws ServletException,
                     IOException
Process a GET request.

Overrides:
doGet in class HttpServlet
Throws:
ServletException
IOException

printErrorMessage

protected void printErrorMessage(HttpServletResponse resp,
                                 String msg)
                          throws IOException
Prints an error message. This assumes the response has not already been committed.

Parameters:
resp - the HTTP response object
msg - the error message, a string
Throws:
IOException

printDevice

protected void printDevice(HttpServletRequest req,
                           HttpServletResponse resp,
                           DSPortAdapter a,
                           OneWireContainer c)
                    throws OneWireIOException,
                           OneWireException,
                           IOException
Retrieves a value from the given container. This simple implementation only reads values from temperature containers.

Remember to use begin/endExclusive calls on the adapter, and also try to perform output as late as possible to allow for an error status to be generated in the calling code. If the response has already been committed (eg. obtaining the output stream), then any 1-Wire exeption cannot be properly reported to the user.

Parameters:
req - the HTTP request object, for extracting request parameters, etc.
resp - the HTTP response object, for setting the status and getting the output stream, etc.
a - the port adapter, for exclusive calls, etc.
c - the 1-Wire container object, assumed to be present
Throws:
OneWireIOException
OneWireException
IOException

Tynamo™-SNAP
v1.0.4

© 2001-2007 Shawn Silverman