added an atomic method for simple, one-off calls
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Thu, 30 Aug 2007 18:56:46 +0000 (18:56 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Thu, 30 Aug 2007 18:56:46 +0000 (18:56 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1088 9efc2488-bf62-4759-914b-345cdb29e865

src/java/org/opensrf/ClientSession.java
src/java/org/opensrf/MethodException.java

index e36ef07..bc3b8e2 100644 (file)
@@ -146,5 +146,19 @@ public class ClientSession extends Session {
         if(req == null) return;
         req.setComplete();
     }
+
+    public static Object atomicRequest(String service, String method, Object[] params) throws MethodException {
+        try {
+            ClientSession session = new ClientSession(service);
+            Request osrfRequest = session.request(method, params);
+            Result result = osrfRequest.recv(600000);
+            if(result.getStatusCode() != 200) 
+                throw new MethodException( 
+                    "Request "+service+":"+method+":"+" failed with status code " + result.getStatusCode());
+            return result.getContent();
+        } catch(Exception e) {
+            throw new MethodException(e);
+        }
+    }
 }
 
index bf47313..f87e638 100644 (file)
@@ -7,5 +7,8 @@ public class MethodException extends Exception {
     public MethodException(String info) {
         super(info);
     }
+    public MethodException(Throwable cause) {
+        super(cause);
+    }
 }