home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 November / APCD25112k.iso / feature / webserv / SAMBAR43.ZIP / _SETUP.1 / javaeng.jar / com / sambar / javaeng / SambarConnection.java < prev    next >
Encoding:
Java Source  |  2000-04-03  |  19.4 KB  |  885 lines

  1. /*
  2. **         Sambar Server JAVA Engine Implementation
  3. **
  4. **        Confidential Property of Tod Sambar
  5. **        (c) Copyright Tod Sambar 1999
  6. **        All rights reserved.
  7. */
  8. package com.sambar.javaeng;
  9.  
  10. import java.io.*;
  11. import java.net.*;
  12. import java.text.*;
  13. import java.util.*;
  14. import javax.servlet.*;
  15. import javax.servlet.http.*;
  16. import com.sambar.javaeng.SambarAPI;
  17. import com.sambar.javaeng.SambarUtils;
  18.  
  19. class SambarConnection implements HttpServletRequest, HttpServletResponse 
  20. {
  21.     private long                sreq;
  22.     private SambarContext        scontext;
  23.  
  24.     /*
  25.     ** HttpServletResquest Variables
  26.     */
  27.     private boolean                sessionFromCookie = false;
  28.     private boolean                sessionFromUrl = false;
  29.     private String                sessionid = null;
  30.     private SambarSession        session = null;
  31.     private Cookie[]            cookiesIn = null;
  32.  
  33.     /*
  34.     ** HttpServletResponse Variables
  35.     */
  36.     private int                 status;
  37.     private int                 contentLength;
  38.     private String                 statusString = null;
  39.     private String                 contentType = null;
  40.     private boolean                sentHeader;
  41.     private SambarInputStream    istream = null;
  42.     private SambarOutputStream    ostream = null;
  43.     private PrintWriter            swriter = null;
  44.     private Hashtable             headersOut = new Hashtable(15, 0.9f);
  45.     private Vector                 cookiesOut = new Vector(5);
  46.     private Hashtable            params = null;
  47.  
  48.  
  49.     public SambarConnection(long sreq, SambarContext scontext) 
  50.     {
  51.         this.sreq = sreq;
  52.         this.scontext = scontext;
  53.  
  54.         this.status = SC_OK;
  55.         this.contentLength = 0;
  56.         this.sentHeader = false;
  57.         if (SambarAPI.wasHeaderSent(sreq) > 0)
  58.             this.sentHeader = true;
  59.  
  60.         // Get the sessionid from the query string and/or cookie
  61.         sessionid = getUrlSessionId();
  62.         if (sessionid != null)
  63.         {
  64.             sessionFromUrl = true;
  65.         }
  66.         else
  67.         {
  68.             sessionid = getCookieSessionId();
  69.             if (sessionid != null)
  70.                 sessionFromCookie = false;
  71.         }
  72.     }
  73.  
  74.     public void close()
  75.     {
  76.         if (swriter != null) 
  77.             swriter.close();
  78.     }
  79.  
  80.     /***********************************************************************
  81.     **
  82.     ** ServletRequest Methods
  83.     **
  84.     ***********************************************************************/
  85.     public Object getAttribute(String name)
  86.     {
  87.         if (name.equalsIgnoreCase("isSambarAdmin"))
  88.         {
  89.             if (SambarAPI.isSambarAdmin(sreq) > 0)
  90.                 return new String("true");
  91.         }
  92.         else if (name.equalsIgnoreCase("isSambarUser"))
  93.         {
  94.             if (SambarAPI.isSambarUser(sreq) > 0)
  95.                 return new String("true");
  96.         }
  97.  
  98.         return null;
  99.     }
  100.  
  101.     public Enumeration getAttributeNames() 
  102.     {
  103.         // Not implemented
  104.         return null;
  105.     }
  106.  
  107.     public int getContentLength()
  108.     {
  109.         return SambarAPI.getContentLength(sreq);
  110.     }
  111.  
  112.     public String getContentType()
  113.     {
  114.         return SambarAPI.getContentType(sreq);
  115.     }
  116.  
  117.     /* 
  118.     ** Returns the input stream for reading binary data in the request body 
  119.     */
  120.     public ServletInputStream getInputStream() throws IOException
  121.     {
  122.         if (istream == null) 
  123.              istream = new SambarInputStream(sreq, this);
  124.  
  125.         return (ServletInputStream)istream;
  126.     }
  127.  
  128.     protected void getParameters()
  129.     {
  130.         if (params != null)
  131.             return;
  132.  
  133.         /*
  134.         ** Retrieve the parameters from the Sambar Connection cache
  135.         */
  136.         params = new Hashtable();
  137.         int count = SambarAPI.getParameterCount(sreq);
  138.         for (int i = 0; i < count; i++)
  139.         {
  140.             String name = SambarAPI.getParameterName(sreq, i + 1);
  141.             String value = SambarAPI.getParameterValue(sreq, i + 1);
  142.             if (value == null)
  143.                 value = new String("");
  144.  
  145.             Object pval = params.get(name);
  146.             if (pval == null)
  147.             {
  148.                 params.put(name, value);
  149.             }
  150.             else if (pval instanceof String)
  151.             {
  152.                 Vector pvector = new Vector();
  153.                 pvector.addElement(pval);
  154.                 pvector.addElement(value);
  155.                 params.put(name, pvector);
  156.             }
  157.             else
  158.             {
  159.                 Vector pvector = (Vector)pval;
  160.                 pvector.addElement(value);
  161.             }
  162.         }
  163.  
  164.         return;
  165.     }
  166.  
  167.     public String getParameter(String name)
  168.     {
  169.         return SambarAPI.getParameter(sreq, name);
  170.     }
  171.  
  172.     public void setParameter(String name, String val)
  173.     {
  174.         getParameters();
  175.  
  176.         /* 
  177.         ** Set the parameter in both the servlet paramters and 
  178.         ** server parameters
  179.         */
  180.         SambarAPI.setParameter(sreq, name, val);
  181.         params.put(name, val);
  182.         return; 
  183.     }
  184.  
  185.     public Enumeration getParameterNames()
  186.     {
  187.         getParameters();
  188.         return params.keys();
  189.     }
  190.  
  191.     public String[] getParameterValues(String name)
  192.     {
  193.         getParameters();
  194.         Object val = params.get(name);
  195.  
  196.         if (val == null)
  197.         {
  198.             return new String[0];
  199.         }
  200.         else if (val instanceof String)
  201.         {
  202.             String values[] = {(String)val};
  203.             return values;
  204.         }
  205.         else
  206.         {
  207.             Vector pvector = (Vector)val;
  208.             String values[] = new String[pvector.size()];
  209.             for (int i = 0; i < values.length; i++)
  210.                 values[i] = (String)pvector.elementAt(i);
  211.  
  212.             return values;
  213.         }
  214.     }
  215.  
  216.     public String getProtocol()
  217.     {
  218.         return SambarAPI.getProtocol(sreq);
  219.     }
  220.  
  221.     public String getScheme()
  222.     {
  223.         return SambarAPI.getScheme(sreq);
  224.     }
  225.  
  226.     public String getHostname()
  227.     {
  228.         return SambarAPI.getHostname(sreq);
  229.     }
  230.  
  231.     public String getServerName()
  232.     {
  233.         return SambarAPI.getServerName(sreq);
  234.     }
  235.  
  236.     public int getServerPort()
  237.     {
  238.         return SambarAPI.getServerPort(sreq);
  239.     }
  240.  
  241.     /* 
  242.     ** Returns a buffered reader for reading text in the request body
  243.     */
  244.     public BufferedReader getReader() throws IOException
  245.     {
  246.         // FIX THIS sambar - implement
  247.         return null;
  248.     }
  249.  
  250.     public String getRemoteAddr()
  251.     {
  252.         return SambarAPI.getRemoteAddr(sreq);
  253.     }
  254.  
  255.     public String getRemoteHost()
  256.     {
  257.         return SambarAPI.getRemoteHost(sreq);
  258.     }
  259.  
  260.     public void setAttribute(String name, Object object) 
  261.     {
  262.         // Not implemented
  263.         return;
  264.     }
  265.  
  266.     public String getRealPath(String path)
  267.     {
  268.         return SambarAPI.getRealPath(sreq, path);
  269.     }
  270.  
  271.     public String getContextPath()
  272.     {
  273.         return SambarAPI.getContextPath(sreq);
  274.     }
  275.     
  276.     public boolean isRemoteUserInRole(String name)
  277.     {
  278.         // Not implemented
  279.         return false;
  280.     }
  281.     
  282.     /***********************************************************************
  283.     **
  284.     ** HTTPServletRequest Methods
  285.     **
  286.     ***********************************************************************/
  287.     public String getAuthType()
  288.     {
  289.         return SambarAPI.getAuthType(sreq);
  290.     }
  291.  
  292.     public String getAuthPass()
  293.     {
  294.         return SambarAPI.getAuthPass(sreq);
  295.     }
  296.  
  297.     public Cookie[] getCookies()
  298.     {
  299.         if (cookiesIn == null)
  300.         {
  301.             cookiesIn = SambarUtils.parseCookies(SambarAPI.getHeader(sreq, 
  302.                 "HTTP_COOKIE"));
  303.         }
  304.  
  305.         return cookiesIn;
  306.     }
  307.  
  308.     public long getDateHeader(String name)
  309.     {
  310.         SimpleDateFormat sdf;
  311.         String header = SambarAPI.getHeader(sreq, name);
  312.         if (header == null)
  313.             return -1;
  314.  
  315.         sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
  316.         try
  317.         {
  318.             Date date = sdf.parse(header);
  319.             return date.getTime();
  320.         }
  321.         catch (ParseException formatNotValid)
  322.         {
  323.             // try another format
  324.         }
  325.  
  326.         sdf = new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US);
  327.         try
  328.         {
  329.             Date date = sdf.parse(header);
  330.             return date.getTime();
  331.         }
  332.         catch (ParseException formatNotValid)
  333.         {
  334.             // try another format
  335.         }
  336.  
  337.         sdf = new SimpleDateFormat("EEE  MMMM d HH:mm:ss yyyy", Locale.US);
  338.         try
  339.         {
  340.             Date date = sdf.parse(header);
  341.             return date.getTime();
  342.         }
  343.         catch (ParseException formatNotValid)
  344.         {
  345.             throw new IllegalArgumentException(header);
  346.         }
  347.     }
  348.  
  349.     public String getHeader(String name)
  350.     {
  351.         return SambarAPI.getHeader(sreq, name);
  352.     }
  353.  
  354.     public Enumeration getHeaders(String name)
  355.     {
  356.         // FIX THIS sambar - implement
  357.         return scontext.emptyVector.elements();
  358.     }
  359.  
  360.     public Enumeration getHeaderNames()
  361.     {
  362.         // FIX THIS sambar - implement
  363.         return scontext.emptyVector.elements();
  364.     }
  365.  
  366.     public int getIntHeader(String name)
  367.     {
  368.         String header = SambarAPI.getHeader(sreq, name);
  369.         if (header == null)
  370.             return -1;
  371.  
  372.         return Integer.parseInt(header);
  373.     }
  374.  
  375.     public String getMethod()
  376.     {
  377.         return SambarAPI.getMethod(sreq);
  378.     }
  379.  
  380.     public String getPathInfo()
  381.     {
  382.         return SambarAPI.getPathInfo(sreq);
  383.     }
  384.  
  385.     public String getPathTranslated()
  386.     {
  387.         return SambarAPI.getPathTranslated(sreq);
  388.     }
  389.  
  390.     public String getQueryString()
  391.     {
  392.         return SambarAPI.getQueryString(sreq);
  393.     }
  394.  
  395.     public String getRemoteUser()
  396.     {
  397.         return SambarAPI.getRemoteUser(sreq);
  398.     }
  399.  
  400.     public String getRequestURI()
  401.     {
  402.         return SambarAPI.getRequestURI(sreq);
  403.     }
  404.  
  405.     public String getServletPath()
  406.     {
  407.         return SambarAPI.getServletPath(sreq);
  408.     }
  409.  
  410.     public String getRequestedSessionId()
  411.     {
  412.         return sessionid;
  413.     }
  414.  
  415.     public HttpSession getSession(boolean create)
  416.     {
  417.         if (session != null)
  418.             return session;
  419.  
  420.         if (sessionid != null)
  421.         {
  422.             session = (SambarSession)scontext.getSession(sessionid);
  423.             if (session != null)
  424.                 return session;
  425.         }
  426.  
  427.         if (create == true)
  428.         {
  429.             session = scontext.createSession(this);
  430.             sessionid = session.id;
  431.             return session;
  432.         }
  433.  
  434.         return null;
  435.     }
  436.  
  437.     public HttpSession getSession()
  438.     {
  439.         return getSession(false);
  440.     }
  441.  
  442.     public boolean isRequestedSessionIdValid()
  443.     {
  444.         if (sessionid == null)
  445.             return false;
  446.         else if (scontext.getSession(sessionid) == null)
  447.             return false;
  448.             
  449.         return true;
  450.     }
  451.  
  452.     public boolean isRequestedSessionIdFromCookie()
  453.     {
  454.         return sessionFromCookie;
  455.     }
  456.  
  457.     public boolean isRequestedSessionIdFromUrl()
  458.     {
  459.         return sessionFromUrl;
  460.     }
  461.  
  462.     public boolean isRequestedSessionIdFromURL()
  463.     {
  464.         return isRequestedSessionIdFromUrl();
  465.     }
  466.  
  467.     public RequestDispatcher getRequestDispatcher(String path) 
  468.     {
  469.         if (path == null)
  470.             return null;
  471.  
  472.         if (!path.startsWith("/")) 
  473.         {
  474.             String base = getRequestURI();
  475.             if (base == null)
  476.                 base = "/";
  477.  
  478.             // check for ? string on lookuppath
  479.             int qindex = base.indexOf("?");
  480.  
  481.             if (qindex > -1)
  482.                    base = base.substring(0, qindex);
  483.  
  484.             if (base.length() < 1)
  485.                 base = "/";
  486.  
  487.             path = SambarUtils.catPath(base, path);
  488.  
  489.             if (path == null)
  490.                 return null;
  491.         }
  492.  
  493.         return scontext.getRequestDispatcher(path);
  494.     }
  495.  
  496.     /***********************************************************************
  497.     **
  498.     ** ServletResponse Methods
  499.     **
  500.     ***********************************************************************/
  501.     public String getCharacterEncoding()
  502.     {
  503.         /*
  504.         ** Returns the character set encoding used for this MIME body.
  505.         ** If no content type has yet been assigned, it is implicitly
  506.         ** set to <em>text/plain</em>
  507.         */
  508.         if (contentType == null) 
  509.             contentType = "text/plain";
  510.  
  511.         return SambarUtils.parseCharacterEncoding(contentType);
  512.     }
  513.  
  514.     public ServletOutputStream getOutputStream() throws IOException
  515.     {
  516.         if (ostream == null) 
  517.              ostream = new SambarOutputStream(sreq, this);
  518.  
  519.         return (ServletOutputStream)ostream;
  520.     }
  521.  
  522.     public PrintWriter getWriter() throws IOException
  523.     {
  524.         if (swriter == null) 
  525.         {
  526.             OutputStreamWriter out;
  527.             out = new OutputStreamWriter(getOutputStream(), 
  528.                 getCharacterEncoding());
  529.             swriter = new PrintWriter(out);
  530.         }
  531.  
  532.         return swriter;
  533.     }
  534.  
  535.     public void setContentLength(int len)
  536.     {
  537.         contentLength = len;
  538.         return;
  539.     }
  540.  
  541.     public void setContentType(String type)
  542.     {
  543.         contentType = type;
  544.         return;
  545.     }
  546.  
  547.     /***********************************************************************
  548.     **
  549.     ** HTTPServletResponse Methods
  550.     **
  551.     ***********************************************************************/
  552.     public void addCookie(Cookie cookie)
  553.     {
  554.         cookiesOut.addElement(cookie);
  555.         return;
  556.     }
  557.  
  558.     public boolean containsHeader(String name)
  559.     {
  560.         return headersOut.contains(name.toLowerCase());
  561.     }
  562.  
  563.     public String encodeURL(String url)
  564.     {
  565.         if (isRequestedSessionIdFromCookie())
  566.         {
  567.             return url;
  568.         }
  569.         else
  570.         {
  571.             SambarSession session = (SambarSession)getSession();
  572.             if (session == null)
  573.                 return url;
  574.  
  575.             // Encode the URL with the session ID
  576.             if (url.indexOf('?') == -1)
  577.                 return url + '?' + SambarAPI.SESSION_ID + '=' + session.id;
  578.             else
  579.                 return url + "&" + SambarAPI.SESSION_ID + '=' + session.id;
  580.         }
  581.     }
  582.  
  583.     public String encodeUrl(String url)
  584.     {
  585.         return encodeURL(url);
  586.     }
  587.  
  588.     public String encodeRedirectURL(String url)
  589.     {
  590.         String hostname = SambarAPI.getHostname(sreq);
  591.         if (url.indexOf(hostname) == -1)
  592.             return url;
  593.         else
  594.             return encodeURL(url);
  595.     }
  596.  
  597.     public String encodeRedirectUrl(String url)
  598.     {
  599.         return encodeRedirectURL(url);
  600.     }
  601.  
  602.     public void sendError(int sc, String msg)
  603.     {
  604.         status = sc;
  605.         contentType = "text/html";
  606.         sendHttpHeaders();
  607.  
  608.         SambarAPI.puts(sreq, "<HTML><HEAD>\n");
  609.         SambarAPI.puts(sreq, "<TITLE>" + status + " Servlet Error</TITLE>\n");
  610.         SambarAPI.puts(sreq, "</HEAD><BODY BGCOLOR=#FFFFFF>\n");
  611.         SambarAPI.puts(sreq, "<TABLE BORDER=0 WIDTH=500 CELLPADDING=10 " +
  612.             "CELLSPACING=10>\n");
  613.         SambarAPI.puts(sreq, "<TR><TD BGCOLOR=#990033 ALIGN=LEFT>\n");
  614.         SambarAPI.puts(sreq, "<FONT SIZE=5 COLOR=#FFFFFF><B>" + status);
  615.         SambarAPI.puts(sreq, " " + statusString + "</B></FONT>\n");
  616.         SambarAPI.puts(sreq, "</TR></TD><TR><TD><FONT SIZE=+1><BR>\n");
  617.         SambarAPI.puts(sreq, msg);
  618.         SambarAPI.puts(sreq, "</FONT><BR><BR>\n");
  619.         SambarAPI.puts(sreq, "<A HREF=\"http://www.sambar.com\">");
  620.         SambarAPI.puts(sreq, "<FONT SIZE=2>Powered By Sambar</FONT></A>");
  621.         SambarAPI.puts(sreq, "</TD></TR></TABLE></BODY></HTML>\n");
  622.  
  623.         // Flush and close, so the error can be returned right
  624.         // away, and so any additional data sent is ignored
  625.         SambarAPI.flush(sreq);
  626.         SambarAPI.close(sreq);
  627.         return;
  628.     }
  629.  
  630.     public void sendError(int sc)
  631.     {
  632.         sendError(sc, getStatusString(sc));
  633.         return;
  634.     }
  635.  
  636.     public void sendError(Throwable e)
  637.     {
  638.         sendError(SC_INTERNAL_SERVER_ERROR, 
  639.             e.toString() + ": " + e.getMessage());
  640.     }
  641.  
  642.     public void sendRedirect(String location) throws IOException
  643.     {
  644.         setStatus(SC_MOVED_TEMPORARILY);
  645.         setHeader("Location", location);
  646.         sendHttpHeaders();
  647.         return;
  648.     }
  649.  
  650.     public void setDateHeader(String name, long date)
  651.     {
  652.         addDateHeader(name, date);
  653.     }
  654.  
  655.     public void addDateHeader(String name, long date)
  656.     {
  657.         SimpleDateFormat sdf =
  658.             new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
  659.         TimeZone tz = TimeZone.getTimeZone("GMT");
  660.  
  661.         sdf.setTimeZone(tz);
  662.  
  663.         headersOut.put(name, sdf.format(new Date(date)));
  664.         return;
  665.     }
  666.  
  667.     public void setHeader(String name, String value)
  668.     {
  669.         addHeader(name, value);
  670.     }
  671.  
  672.     public void addHeader(String name, String value)
  673.     {
  674.         int        pos;
  675.  
  676.         // Make sure no newlines are present in the header
  677.         if ((pos = value.indexOf((int)'\n')) > 0) 
  678.         {
  679.             char msgAsArray[] = value.toCharArray();
  680.             msgAsArray[pos] = ' ';
  681.  
  682.             while ((pos = value.indexOf((int)'\n', pos + 1)) > 0)
  683.                 msgAsArray[pos] = ' ';
  684.  
  685.             value = new String(msgAsArray);
  686.         }
  687.  
  688.         headersOut.put(name, value);
  689.         return;
  690.     }
  691.  
  692.     public void setIntHeader(String name, int value)
  693.     {
  694.         addIntHeader(name, value);
  695.     }
  696.  
  697.     public void addIntHeader(String name, int value)
  698.     {
  699.         Integer val = new Integer(value);
  700.         headersOut.put(name, val.toString());
  701.         return;
  702.     }
  703.  
  704.     public void setStatus(int sc, String sm)
  705.     {
  706.         this.status = sc;
  707.         this.statusString = sm;
  708.         return;
  709.     }
  710.  
  711.     public void setStatus(int sc)
  712.     {
  713.         setStatus(sc, null);
  714.         return;
  715.     }
  716.  
  717.     /*
  718.     **
  719.     ** Send the HTTP headers and prepare to send response.
  720.     */
  721.     protected void sendHttpHeaders()
  722.     {
  723.         // Send the status info
  724.         if (statusString == null)
  725.             statusString = getStatusString(status);
  726.  
  727.         if (sentHeader)
  728.             return;
  729.  
  730.         String hdr;
  731.         sentHeader = true;
  732.  
  733.         hdr = "HTTP/1.1 " + status + " " + statusString;
  734.         SambarAPI.puts(sreq, hdr + "\r\n");
  735.  
  736.         if (contentType == null)
  737.             hdr = "Content-Type: text/plain";
  738.         else
  739.             hdr = "Content-Type: " + contentType;
  740.  
  741.         SambarAPI.puts(sreq, hdr + "\r\n");
  742.  
  743.         if (contentLength > 0)
  744.         {
  745.             hdr = "Content-length: " + contentLength;
  746.             SambarAPI.puts(sreq, hdr + "\r\n");
  747.  
  748.             SambarAPI.setKeepAlive(sreq);
  749.  
  750.             if (!containsHeader("Connection"))
  751.                 setHeader("Connection", "Keep-Alive");
  752.             if (!containsHeader("Keep-Alive"))
  753.                 setHeader("Keep-Alive", "timeout=180");
  754.         }
  755.         else
  756.         {
  757.             if (!containsHeader("Connection"))
  758.                 setHeader("Connection", "close");
  759.         }
  760.  
  761.         if (!containsHeader("Date"))
  762.             setDateHeader("Date", System.currentTimeMillis());
  763.  
  764.         if (!containsHeader("Server"))
  765.             setHeader("Server", "SAMBAR4.3/JavaEngine");
  766.  
  767.         if (!containsHeader("MIME-version"))
  768.             setHeader("MIME-version", "1.0");
  769.  
  770.         if (headersOut != null) 
  771.         {
  772.             // Send the headers
  773.             for (Enumeration e = headersOut.keys(); e.hasMoreElements();) 
  774.             {
  775.                 String key = (String) e.nextElement();
  776.                 hdr = key + ": " + headersOut.get(key);
  777.                 SambarAPI.puts(sreq, hdr + "\r\n");
  778.             }
  779.         }
  780.  
  781.         // Send the cookies
  782.         Enumeration elements = cookiesOut.elements();
  783.         while (elements.hasMoreElements()) 
  784.         {
  785.             Cookie cookie = (Cookie)elements.nextElement();
  786.             hdr = "Set-Cookie: " + SambarUtils.encodeCookie(cookie);
  787.             SambarAPI.puts(sreq, hdr + "\r\n");
  788.         }
  789.  
  790.         // Send a terminating blank line
  791.         SambarAPI.puts(sreq, "\r\n");
  792.  
  793.         // Flush the output to the client
  794.         SambarAPI.flush(sreq);
  795.     }
  796.  
  797.     /*
  798.     ** Finds a status string from one of the standard status code.
  799.     */
  800.     public static final String getStatusString(int sc) 
  801.     {
  802.         switch (sc) 
  803.         {
  804.         case SC_ACCEPTED:
  805.             return "Accepted";
  806.         case SC_BAD_GATEWAY:
  807.             return "Bad Gateway";
  808.         case SC_BAD_REQUEST:
  809.             return "Bad Request";
  810.         case SC_CREATED:
  811.             return "Created";
  812.         case SC_FORBIDDEN:
  813.             return "Forbidden";
  814.         case SC_INTERNAL_SERVER_ERROR:
  815.             return "Internal Server Error";
  816.         case SC_MOVED_PERMANENTLY:
  817.             return "Moved Permanently";
  818.         case SC_MOVED_TEMPORARILY:
  819.             return "Moved Temporarily";
  820.         case SC_NO_CONTENT:
  821.             return "No Content";
  822.         case SC_NOT_FOUND:
  823.             return "Not Found";
  824.         case SC_NOT_IMPLEMENTED:
  825.             return "Method Not Implemented";
  826.         case SC_NOT_MODIFIED:
  827.             return "Not Modified";
  828.         case SC_OK:
  829.             return "OK";
  830.         case SC_SERVICE_UNAVAILABLE:
  831.             return "Service Temporarily Unavailable";
  832.         case SC_UNAUTHORIZED:
  833.             return "Authorization Required";
  834.         default:
  835.             return "Response";
  836.         }
  837.     }
  838.  
  839.     /***********************************************************************
  840.     **
  841.     ** Session Methods
  842.     **
  843.     ***********************************************************************/
  844.     public String getUrlSessionId()
  845.     {
  846.         String queryString = getQueryString();
  847.         if (queryString == null)
  848.             return null;
  849.  
  850.         try
  851.         {
  852.             Hashtable params = HttpUtils.parseQueryString(queryString);
  853.             Object o = params.get(SambarAPI.SESSION_ID);
  854.             if (o == null)
  855.                 return null;
  856.  
  857.             if (o instanceof String)
  858.                 return (String)o;
  859.         
  860.             return ((String[])o)[0];
  861.         } 
  862.         catch (IllegalArgumentException ex)
  863.         {
  864.             return null;
  865.         }
  866.  
  867.     }
  868.  
  869.     public String getCookieSessionId()
  870.     {
  871.         Cookie[] cookies = getCookies();
  872.  
  873.         if ((cookies == null) || (cookies.length == 0))
  874.             return null;
  875.  
  876.         for (int i = 0; i < cookies.length; i++)
  877.         {
  878.             if (cookies[i].getName().equals(SambarAPI.SESSION_ID))
  879.                 return cookies[i].getValue();
  880.         }
  881.  
  882.         return null;
  883.     }
  884. }
  885.