Package org.jabsorb

Examples of org.jabsorb.JSONRPCResult


     
      // Extract the arguments     
      args = methodUtil.transferToJavaParameters(jsonReq, this.serviceInterface);
     
    } catch (Exception e) {
      JSONRPCResult errorResult = new JSONRPCResult(
          JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause());
      return errorResult.toString().getBytes("UTF-8");
    }

    // invoke the request   
    Object result = null;
    Object[] parameters = null;
    if (null != args && hasSessionParam(jsonOperation)) {
      parameters = new Object[args.length + 1];
      parameters[0] = request.getSession(false);
      for (int i = 0; i < args.length; i++) {
        parameters[i + 1] = args[i];
      }
    } else {
      parameters = args;
    }

    try {
      JSONObject jsonResponse = new JSONObject();
         
      // result = wire.invoke(jsonOperation, args);
      result = jsonOperation.invoke(this.serviceInstance, parameters);
      JavaBean2JSON transform = new JavaBean2JSON();

      try {
        // FIXME: this only checks for String and not primitive types
        if (!(result instanceof java.lang.String)) {
          jsonResponse.put("result", transform.toJSON(result));
        } else {
          jsonResponse.put("result", result);
        }
        jsonResponse.putOpt("id", id);

        // get response to send to client
        return jsonResponse.toString().getBytes("UTF-8");
      } catch (Exception e) {
        JSONRPCResult errorResult = new JSONRPCResult(
            JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause());
        return errorResult.toString().getBytes("UTF-8");
      }
    } catch (InvocationTargetException e) {
      JSONRPCResult errorResult = new JSONRPCResult(
          JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause());
      return errorResult.toString().getBytes("UTF-8");
    } catch (RuntimeException e) {
      JSONRPCResult errorResult = new JSONRPCResult(
          JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause());
      return errorResult.toString().getBytes("UTF-8");
    } catch (IllegalAccessException e) {
      JSONRPCResult errorResult = new JSONRPCResult(
          JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause());
      return errorResult.toString().getBytes("UTF-8");
    } catch (Exception e) {
      JSONRPCResult errorResult = new JSONRPCResult(
          JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause());
      return errorResult.toString().getBytes("UTF-8");
    }
  } 
View Full Code Here


        JSONRPCBridge jsonrpcBridge = new JSONRPCBridge();
        jsonrpcBridge.registerObject("Service", serviceInstance, serviceInterface);
        session.setAttribute("JSONRPCBridge", jsonrpcBridge);

        org.json.JSONObject jsonReq = null;
        JSONRPCResult jsonResp = null;
        jsonReq = new org.json.JSONObject(requestData);

        String method = jsonReq.getString("method");
        if ((method != null) && (method.indexOf('.') < 0)) {
            jsonReq.putOpt("method", "Service" + "." + method);
        }

        // invoke the request
        jsonResp = jsonrpcBridge.call(new Object[] {request}, jsonReq);

        return jsonResp.toString().getBytes("UTF-8");
    }
View Full Code Here

        } catch (RuntimeException re) {
            if (re.getCause() instanceof javax.security.auth.login.LoginException) {
                throw re;
            } else {
                //some other exception
                JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, re);
                return errorResult.toString().getBytes("UTF-8");
            }
        }

        if (!responseMessage.isFault()) {
            //successful execution of the invocation
            if (jsonOperation.getWrapper().getDataBinding().equals(JSONDataBinding.NAME)) {
                result = responseMessage.getBody();
              return result.toString().getBytes("UTF-8");
            } else {
                if (jsonOperation.getOutputType().getLogical().size() == 0) {
                    // void operation (json-rpc notification)
                    try {
                        JSONObject jsonResponse = new JSONObject();
                        jsonResponse.put("result", "");
                        //get response to send to client
                        return jsonResponse.toString().getBytes("UTF-8");
                    } catch (Exception e) {
                        throw new ServiceRuntimeException("Unable to create JSON response", e);
                    }

                } else {
                    // regular operation returning some value
                    try {
                        result = responseMessage.getBody();
                        JSONObject jsonResponse = new JSONObject();
                        //JSONObject put will remove the entry if it's value is null
                        //and per javadoc, we should pass JSONObject.NULL
                        if(result == null) {
                            jsonResponse.put("result", JSONObject.NULL);
                        } else {
                            jsonResponse.put("result", result);
                        }
                        jsonResponse.putOpt("id", id);
                        //get response to send to client
                        return jsonResponse.toString().getBytes("UTF-8");
                    } catch (Exception e) {
                        throw new ServiceRuntimeException("Unable to create JSON response", e);
                    }
                }
            }
        } else {
            //exception thrown while executing the invocation
            Throwable exception = (Throwable)responseMessage.getBody();
            JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, exception );
            return errorResult.toString().getBytes("UTF-8");
        }

   }
View Full Code Here

        JSONRPCBridge jsonrpcBridge = new JSONRPCBridge();
        jsonrpcBridge.registerObject("Service", serviceInstance, serviceInterface);
        session.setAttribute("JSONRPCBridge", jsonrpcBridge);
       
        org.json.JSONObject jsonReq = null;
        JSONRPCResult jsonResp = null;
        jsonReq = new org.json.JSONObject(requestData);

        String method = jsonReq.getString("method");
        if ((method != null) && (method.indexOf('.') < 0)) {
            jsonReq.putOpt("method", "Service" + "." + method);
        }

        // invoke the request
        jsonResp = jsonrpcBridge.call(new Object[] {request}, jsonReq);

        return jsonResp.toString().getBytes("UTF-8");
    }
View Full Code Here

        } catch (RuntimeException re) {
            if (re.getCause() instanceof javax.security.auth.login.LoginException) {
                throw re;
            } else {
                //some other exception
                JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, re);
                return errorResult.toString().getBytes("UTF-8");
            }
        }

        if (!responseMessage.isFault()) {
            //successful execution of the invocation
            if (jsonOperation.getWrapper().getDataBinding().equals(JSONDataBinding.NAME)) {
                result = responseMessage.getBody();
              return result.toString().getBytes("UTF-8");
            } else {
                if (jsonOperation.getOutputType() == null) {
                    // void operation (json-rpc notification)
                    try {
                        JSONObject jsonResponse = new JSONObject();
                        jsonResponse.put("result", "");
                        //get response to send to client
                        return jsonResponse.toString().getBytes("UTF-8");
                    } catch (Exception e) {
                        throw new ServiceRuntimeException("Unable to create JSON response", e);
                    }                   

                } else {
                    // regular operation returning some value
                    try {
                        result = responseMessage.getBody();
                        JSONObject jsonResponse = new JSONObject();
                        jsonResponse.put("result", result);
                        jsonResponse.putOpt("id", id);
                        //get response to send to client
                        return jsonResponse.toString().getBytes("UTF-8");
                    } catch (Exception e) {
                        throw new ServiceRuntimeException("Unable to create JSON response", e);
                    }                   
                }
            }
        } else {
            //exception thrown while executing the invocation
            Throwable exception = (Throwable)responseMessage.getBody();
            JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, exception );
            return errorResult.toString().getBytes("UTF-8");
        }
   }
View Full Code Here

        JSONRPCBridge jsonrpcBridge = new JSONRPCBridge();
        jsonrpcBridge.registerObject("Service", serviceInstance, serviceInterface);
        session.setAttribute("JSONRPCBridge", jsonrpcBridge);

        org.json.JSONObject jsonReq = null;
        JSONRPCResult jsonResp = null;
        jsonReq = new org.json.JSONObject(requestData);

        String method = jsonReq.getString("method");
        if ((method != null) && (method.indexOf('.') < 0)) {
            jsonReq.putOpt("method", "Service" + "." + method);
        }

        // invoke the request
        jsonResp = jsonrpcBridge.call(new Object[] {request}, jsonReq);

        return jsonResp.toString().getBytes("UTF-8");
    }
View Full Code Here

        } catch (RuntimeException re) {
            if (re.getCause() instanceof javax.security.auth.login.LoginException) {
                throw re;
            } else {
                //some other exception
                JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, re);
                return errorResult.toString().getBytes("UTF-8");
            }
        }

        if (!responseMessage.isFault()) {
            //successful execution of the invocation
            if (jsonOperation.getWrapper().getDataBinding().equals(JSONDataBinding.NAME)) {
                result = responseMessage.getBody();
              return result.toString().getBytes("UTF-8");
            } else {
                if (jsonOperation.getOutputType().getLogical().size() == 0) {
                    // void operation (json-rpc notification)
                    try {
                        JSONObject jsonResponse = new JSONObject();
                        jsonResponse.put("result", "");
                        //get response to send to client
                        return jsonResponse.toString().getBytes("UTF-8");
                    } catch (Exception e) {
                        throw new ServiceRuntimeException("Unable to create JSON response", e);
                    }

                } else {
                    // regular operation returning some value
                    try {
                        result = responseMessage.getBody();
                        JSONObject jsonResponse = new JSONObject();
                        //JSONObject put will remove the entry if it's value is null
                        //and per javadoc, we should pass JSONObject.NULL
                        if(result == null) {
                            jsonResponse.put("result", JSONObject.NULL);
                        } else {
                            jsonResponse.put("result", result);
                        }
                        jsonResponse.putOpt("id", id);
                        //get response to send to client
                        return jsonResponse.toString().getBytes("UTF-8");
                    } catch (Exception e) {
                        throw new ServiceRuntimeException("Unable to create JSON response", e);
                    }
                }
            }
        } else {
            //exception thrown while executing the invocation
            Throwable exception = (Throwable)responseMessage.getBody();
            JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, exception );
            return errorResult.toString().getBytes("UTF-8");
        }

   }
View Full Code Here

        JSONRPCBridge jsonrpcBridge = new JSONRPCBridge();
        jsonrpcBridge.registerObject("Service", serviceInstance, serviceInterface);
        session.setAttribute("JSONRPCBridge", jsonrpcBridge);
       
        org.json.JSONObject jsonReq = null;
        JSONRPCResult jsonResp = null;
        jsonReq = new org.json.JSONObject(requestData);

        String method = jsonReq.getString("method");
        if ((method != null) && (method.indexOf('.') < 0)) {
            jsonReq.putOpt("method", "Service" + "." + method);
        }

        // invoke the request
        jsonResp = jsonrpcBridge.call(new Object[] {request}, jsonReq);

        return jsonResp.toString().getBytes("UTF-8");
    }
View Full Code Here

        } catch (RuntimeException re) {
            if (re.getCause() instanceof javax.security.auth.login.LoginException) {
                throw re;
            } else {
                //some other exception
                JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, re);
                return errorResult.toString().getBytes("UTF-8");
            }
        }

        if (!responseMessage.isFault()) {
            //successful execution of the invocation
            try {
                result = responseMessage.getBody();
                JSONObject jsonResponse = new JSONObject();
                jsonResponse.put("result", result);
                jsonResponse.putOpt("id", id);
                //get response to send to client
                return jsonResponse.toString().getBytes("UTF-8");
            } catch (Exception e) {
                throw new ServiceRuntimeException("Unable to create JSON response", e);
            }
        } else {
            //exception thrown while executing the invocation
            Throwable exception = (Throwable)responseMessage.getBody();
            JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, exception );
            return errorResult.toString().getBytes("UTF-8");
        }
   }
View Full Code Here

          }
        }
      }
      catch (NoSuchElementException e) {
        e.printStackTrace();
        output = new JSONRPCResult(JSONRPCResult.CODE_ERR_NOMETHOD, null, JSONRPCResult.MSG_ERR_NOMETHOD);
      }
      catch (JSONException e) {
        e.printStackTrace();
        output = new JSONRPCResult(JSONRPCResult.CODE_ERR_PARSE, null, JSONRPCResult.MSG_ERR_PARSE);
      }
      catch (Throwable t) {
        t.printStackTrace();
        output = new JSONRPCResult(JSONRPCResult.CODE_ERR_PARSE, null, t.getMessage());
      }

      return response;
    }
    finally {
View Full Code Here

TOP

Related Classes of org.jabsorb.JSONRPCResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.