[MOBY-guts] biomoby commit
Martin Senger
senger at dev.open-bio.org
Sun May 27 19:18:17 UTC 2007
senger
Sun May 27 15:18:17 EDT 2007
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/service
In directory dev.open-bio.org:/tmp/cvs-serv26856/src/main/org/biomoby/service
Modified Files:
BaseService.java
Log Message:
moby-live/Java/src/main/org/biomoby/service BaseService.java,1.7,1.8
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/BaseService.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/BaseService.java 2006/04/29 21:22:30 1.7
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/BaseService.java 2007/05/27 19:18:17 1.8
@@ -21,9 +21,11 @@
import org.apache.axis.MessageContext;
import javax.servlet.http.HttpServletRequest;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Properties;
import java.util.Enumeration;
+import java.util.Properties;
/**
* A base class for all Biomoby services (if their providers choose to
@@ -160,13 +162,11 @@
// but I want to keep the constructor of this class without
// any throwing exception, so I simulate here what toolkit can do
if (toolkit == null) {
- Vector v = new Vector();
+ List<String> v = new ArrayList<String>();
Properties props = System.getProperties();
for (Enumeration en = props.propertyNames(); en.hasMoreElements(); )
- v.addElement (en.nextElement());
- String[] results = new String [v.size()];
- v.copyInto (results);
- return results;
+ v.add ((String)en.nextElement());
+ return v.toArray (new String[] {});
}
return toolkit.getAttributeNames();
}
@@ -204,6 +204,22 @@
}
/**************************************************************************
+ * Returns a servlet request instance - the one that delivered a
+ * request to this service. <p>
+ *
+ * @return a servlet request, or null if the request is not
+ * available
+ *************************************************************************/
+ public HttpServletRequest getServletRequest() {
+ MessageContext ctx = MessageContext.getCurrentContext();
+ if (ctx == null)
+ return null;
+ HttpServletRequest req =
+ (HttpServletRequest)ctx.getProperty (HTTPConstants.MC_HTTP_SERVLETREQUEST);
+ return req;
+ }
+
+ /**************************************************************************
* Returns the Internet Protocol (IP) address of the client or
* last proxy that sent the request. <p>
*
@@ -219,6 +235,57 @@
}
/**************************************************************************
+ * Returns HTTP headers that were used when delivering a request
+ * to this services. <p>
+ *
+ * @return a set of name-value pairs representinh HTTP headers; if
+ * the headers are not accessible, an empty set is returned (never
+ * null)
+ *************************************************************************/
+ public Properties getHTTPHeaders() {
+ Properties headers = new Properties();
+ MessageContext ctx = MessageContext.getCurrentContext();
+ if (ctx == null)
+ return headers;
+ HttpServletRequest req =
+ (HttpServletRequest)ctx.getProperty (HTTPConstants.MC_HTTP_SERVLETREQUEST);
+ if (req == null)
+ return headers;
+ for (Enumeration en = req.getHeaderNames(); en.hasMoreElements(); ) {
+ String headerName = (String)en.nextElement();
+ String headerValue = req.getHeader (headerName);
+ if (headerValue != null)
+ headers.put (headerName, headerValue);
+ }
+ return headers;
+ }
+
+ /**************************************************************************
+ * Returns length (in bytes) of the request coming to this service. <p>
+ *
+ * The length is taken from the HTTP headers. This is only a
+ * convenient method extracting one header from those available by
+ * the {@link #getHTTPHeaders getHTTPHeaders}. >p>
+ *
+ * @return a length of the request, or zero if the request length
+ * is not available
+ *************************************************************************/
+ public int getRequestLength() {
+ MessageContext ctx = MessageContext.getCurrentContext();
+ if (ctx == null)
+ return 0;
+ HttpServletRequest req =
+ (HttpServletRequest)ctx.getProperty (HTTPConstants.MC_HTTP_SERVLETREQUEST);
+ if (req == null)
+ return 0;
+ try {
+ return new Integer (req.getHeader ("content-length")).intValue();
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
+ /**************************************************************************
* A utility method returning true if 'value' is neither null nor
* a string consisting only from whitespaces.
*************************************************************************/
More information about the MOBY-guts
mailing list