juddi-cvs@ws.apache.org
[Top] [All Lists]

svn commit: r580488 - in /webservices/juddi/trunk/src/main/java/org/apac

Subject: svn commit: r580488 - in /webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local: AbstractService.java InquiryService.java PublishService.java RequestHandler.java
From:
Date: Fri, 28 Sep 2007 21:14:09 -0000
Author: kstam
Date: Fri Sep 28 14:14:09 2007
New Revision: 580488

URL: http://svn.apache.org/viewvc?rev=580488&view=rev
Log:
JUDDI-113, refactoring so that we can run the registry in a thread of it's own.

Added:
    
webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/RequestHandler.java
      - copied, changed from r580359, 
webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/AbstractService.java
Removed:
    
webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/AbstractService.java
Modified:
    
webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/InquiryService.java
    
webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/PublishService.java

Modified: 
webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/InquiryService.java
URL: 
http://svn.apache.org/viewvc/webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/InquiryService.java?rev=580488&r1=580487&r2=580488&view=diff
==============================================================================
--- 
webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/InquiryService.java
 (original)
+++ 
webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/InquiryService.java
 Fri Sep 28 14:14:09 2007
@@ -27,14 +27,14 @@
 /**
  * @author Kurt Stam (kurt.stam@xxxxxxxxxx)
  */
-public class InquiryService extends AbstractService
+public class InquiryService
 {
 //      collection of valid operations
-         private TreeSet operations = null;
+         private TreeSet<String> operations = null;
          
   public InquiryService() {
                super();
-               operations = new TreeSet();
+               operations = new TreeSet<String>();
                operations.add("find_business");
                operations.add("find_service");
                operations.add("find_binding");
@@ -47,6 +47,9 @@
                operations.add("get_tmodeldetail");
        }
 
+  //Verify that the appropriate endpoint was targeted for
+  // this service request.  The validateRequest method will
+  // throw an UnsupportedException if anything's amiss.
   public void validateRequest(String operation,String version,Element uddiReq)
                throws RegistryException
        {
@@ -74,7 +77,20 @@
        }
   
   public Node inquire(Element uddiReq) throws Exception{
-         return handleRequest(uddiReq);
+      
+      //new RequestHandler on it's own thread
+      RequestHandler requestHandler = new RequestHandler();
+      requestHandler.setUddiReq(uddiReq);
+      String operation = requestHandler.getOperation(uddiReq);
+      String version   = requestHandler.getVersion(uddiReq,operation);
+      validateRequest(operation, version, uddiReq);
+      Thread thread = new Thread(requestHandler, "WorkThread");
+      thread.start();
+      thread.join();
+      if (requestHandler.getException()!=null) {
+          throw new Exception(requestHandler.getException());
+      }
+         return requestHandler.getResponse();
   }
   
 }

Modified: 
webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/PublishService.java
URL: 
http://svn.apache.org/viewvc/webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/PublishService.java?rev=580488&r1=580487&r2=580488&view=diff
==============================================================================
--- 
webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/PublishService.java
 (original)
+++ 
webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/PublishService.java
 Fri Sep 28 14:14:09 2007
@@ -27,14 +27,14 @@
 /**
  * @author Kurt Stam (kurt.stam@xxxxxxxxx)
  */
-public class PublishService extends AbstractService
+public class PublishService
 {
   // collection of valid operations
-  private TreeSet operations = null;
+  private TreeSet<String> operations = null;
 
   public PublishService() {
        super();
-       operations = new TreeSet();
+       operations = new TreeSet<String>();
        operations.add("get_authtoken");
        operations.add("get_registeredinfo");
        operations.add("discard_authtoken");
@@ -80,7 +80,20 @@
                        "supported by the UDDI version 2 Publish API.");
        }
   
-  public Node publish(Element uddiReq) throws Exception{
-         return handleRequest(uddiReq);
+  public Node publish(Element uddiReq) throws Exception
+  {
+      //new RequestHandler on it's own thread
+      RequestHandler requestHandler = new RequestHandler();
+      requestHandler.setUddiReq(uddiReq);
+      String operation = requestHandler.getOperation(uddiReq);
+      String version   = requestHandler.getVersion(uddiReq, operation);
+      validateRequest(operation, version, uddiReq);
+      Thread thread = new Thread(requestHandler, "WorkThread");
+      thread.start();
+      thread.join();
+      if (requestHandler.getException()!=null) {
+          throw new Exception(requestHandler.getException());
+      }
+      return requestHandler.getResponse();
   }
 }

Copied: 
webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/RequestHandler.java
 (from r580359, 
webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/AbstractService.java)
URL: 
http://svn.apache.org/viewvc/webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/RequestHandler.java?p2=webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/RequestHandler.java&p1=webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/AbstractService.java&r1=580359&r2=580488&rev=580488&view=diff
==============================================================================
--- 
webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/AbstractService.java
 (original)
+++ 
webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local/RequestHandler.java
 Fri Sep 28 14:14:09 2007
@@ -42,55 +42,72 @@
 /**
  * @author Kurt Stam (kurt.stam@xxxxxxxxxx)
  */
-public abstract class AbstractService
+public class RequestHandler implements Runnable
 {
   // private reference to the webapp's logger.
-  private static Log log = LogFactory.getLog(AbstractService.class);
+  private static Log log = LogFactory.getLog(RequestHandler.class);
   
   // XML Document Builder
   private static DocumentBuilder docBuilder = null;
-
-  public Node handleRequest(Element uddiReq) throws Exception
+  
+  private String version;
+  private String operation;
+  private Element uddiReq;
+  private Node response;
+  private String exception;
+   
+    /**
+   * Grab the local name of the UDDI request element
+   * from the UDDI Request. If a value isn't returned 
+   * (either null or an empty String is returned) then 
+   * throw a FatalError exception. This is probably a 
+   * configuration problem related to the XML Parser 
+   * that jUDDI is using.
+   * @param uddiReq
+   * @return 
+   * @throws Exception
+   */
+  public String getOperation(Element uddiReq) throws Exception
   {
-    try 
-    {
       if (uddiReq == null)
-        throw new FatalErrorException("A UDDI request was not " +
-          "found in the SOAP message.");
-      
-      // Grab the local name of the UDDI request element
-      // from the UDDI Request. If a value isn't returned 
-      // (either null or an empty String is returned) then 
-      // throw a FatalError exception. This is probably a 
-      // configuration problem related to the XML Parser 
-      // that jUDDI is using.
-      
+          throw new FatalErrorException("A UDDI request was not " +
+            "found in the SOAP message.");
+
       String operation = uddiReq.getLocalName();
       if ((operation == null) || (operation.trim().length() == 0))
         throw new FatalErrorException("The UDDI service operation " +
           "could not be identified.");
-      
-      // Grab the generic attribute value (version value).  If 
-      // one isn't specified or the value specified is not "2.0" 
-      // then throw an exception (this value must be specified 
-      // for all UDDI requests and currently only vesion 2.0
-      // UDDI requests are supported).
-
+      setOperation(operation);
+      return operation;
+  }
+  /**
+   * Grab the generic attribute value (version value).  If 
+   * one isn't specified or the value specified is not "2.0" 
+   * then throw an exception (this value must be specified 
+   * for all UDDI requests and currently only vesion 2.0
+   * UDDI requests are supported).
+   *   
+   * @param uddiReq
+   * @return
+   * @throws Exception
+   */
+  public String getVersion(Element uddiReq, String operation) throws Exception
+  {
       String version = uddiReq.getAttribute("generic");
       if (version == null)
         throw new FatalErrorException("A UDDI generic attribute " +
           "value was not found for UDDI request: "+operation+" (The " +
           "'generic' attribute must be present)");
-
-      // Verify that the appropriate endpoint was targeted for
-      // this service request.  The validateRequest method will
-      // throw an UnsupportedException if anything's amiss.
-
-      validateRequest(operation,version,uddiReq);
-      
+      setVersion(version);
+      return version;
+  }
+  
+  public void run()
+  {
+    try 
+    { 
       // Lookup the appropriate XML handler.  Throw an 
       // UnsupportedException if one could not be located.
-
       HandlerMaker maker = HandlerMaker.getInstance();
                        IHandler requestHandler = maker.lookup(operation);
       if (requestHandler == null)
@@ -141,8 +158,7 @@
       // discarding the temp element) and append 
       // this child to the soap response body
       document.appendChild(element.getFirstChild());
-
-      return document;
+      setResponse(document);
     } 
     catch(Exception ex) // Catch ALL exceptions
     {
@@ -266,15 +282,9 @@
       String fault = "faultCode=" + faultCode + ", faultString=" + faultString 
        + ", faultActor=" + faultActor + ", errno=" + errno + ", errCode=" + 
errCode
        + ", errText=" + errText;
-      throw new Exception(fault);
+      setException(fault);
     }
   }
-
-  /**
-   * 
-   */
-  public abstract void validateRequest(String operation,String generic,Element 
uddiReq)
-       throws RegistryException;
   
   /**
    *
@@ -307,4 +317,34 @@
 
     return docBuilder;
   }
+public String getOperation() {
+    return operation;
+}
+public void setOperation(String operation) {
+    this.operation = operation;
+}
+public Node getResponse() {
+    return response;
+}
+public void setResponse(Node response) {
+    this.response = response;
+}
+public Element getUddiReq() {
+    return uddiReq;
+}
+public void setUddiReq(Element uddiReq) {
+    this.uddiReq = uddiReq;
+}
+public String getVersion() {
+    return version;
+}
+public void setVersion(String version) {
+    this.version = version;
+}
+public String getException() {
+    return exception;
+}
+public void setException(String exception) {
+    this.exception = exception;
+}
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: juddi-cvs-unsubscribe@xxxxxxxxxxxxx
For additional commands, e-mail: juddi-cvs-help@xxxxxxxxxxxxx

<Prev in Thread] Current Thread [Next in Thread>
  • svn commit: r580488 - in /webservices/juddi/trunk/src/main/java/org/apache/juddi/registry/local: AbstractService.java InquiryService.java PublishService.java RequestHandler.java, kstam <=