From 96735d4ae3f34de051e2614afddf17b583224cad Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 30 Aug 2007 18:56:46 +0000 Subject: [PATCH] added an atomic method for simple, one-off calls git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1088 9efc2488-bf62-4759-914b-345cdb29e865 --- src/java/org/opensrf/ClientSession.java | 14 ++++++++++++++ src/java/org/opensrf/MethodException.java | 3 +++ 2 files changed, 17 insertions(+) diff --git a/src/java/org/opensrf/ClientSession.java b/src/java/org/opensrf/ClientSession.java index e36ef07..bc3b8e2 100644 --- a/src/java/org/opensrf/ClientSession.java +++ b/src/java/org/opensrf/ClientSession.java @@ -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); + } + } } diff --git a/src/java/org/opensrf/MethodException.java b/src/java/org/opensrf/MethodException.java index bf47313..f87e638 100644 --- a/src/java/org/opensrf/MethodException.java +++ b/src/java/org/opensrf/MethodException.java @@ -7,5 +7,8 @@ public class MethodException extends Exception { public MethodException(String info) { super(info); } + public MethodException(Throwable cause) { + super(cause); + } } -- 2.11.0