Package vs.common

Examples of vs.common.MethodResponse


         
          oos = new ObjectOutputStream(new BufferedOutputStream(socket
              .getOutputStream()));

          MethodRequest mr = (MethodRequest)ois.readObject();
          MethodResponse mresp = null;
         
          String objectId = mr.getObjectId();
          if (StringUtils.isNotEmpty(objectId)) {
           
            // do the dispatching
            Object remote = remoteObjects.get(objectId);
            if (remote != null) {
             
              String methodName = mr.getMethodName();
              if (StringUtils.isNotEmpty(methodName)) {
               
                Object[] params = mr.getParams();
                try {
                  // execute method and reply
                  Object retVal = MethodUtils.invokeMethod(
                      remote, methodName, params);
 
                  mresp = new MethodResponse(
                      MethodResponse.ResultCode.SUCCESS,
                      retVal, null);
                 
                } catch (NoSuchMethodException nsme) {

                  // server error, no such method
                  mresp = new MethodResponse(
                      MethodResponse.ResultCode.REMOTE_OBJECT_EXCEPTION,
                      null, new SimpleRpcException("no such method m=" + methodName));

                } catch (IllegalAccessException iae) {
                 
                  // server error, method not accessible
                  mresp = new MethodResponse(
                      MethodResponse.ResultCode.REMOTE_OBJECT_EXCEPTION,
                      null, new SimpleRpcException("method not accessible, m=" + methodName));
                 
                } catch (InvocationTargetException ite) {
                 
                  // real business object exception
                  mresp = new MethodResponse(
                      MethodResponse.ResultCode.REMOTE_OBJECT_EXCEPTION,
                      null, ite.getTargetException());

                }
              } else {
               
                // server error, invalid method name
                mresp = new MethodResponse(
                    MethodResponse.ResultCode.REMOTE_OBJECT_EXCEPTION,
                    null, new SimpleRpcException("no such method m=" + methodName));
              }
            } else {
             
              // return server error, could not find object
              mresp = new MethodResponse(
                  MethodResponse.ResultCode.SERVER_ERROR,
                  null, new SimpleRpcException("object not found objectId=" + objectId));
            }
          } else {
           
            // return server error, invalid key
            mresp = new MethodResponse(
                MethodResponse.ResultCode.SERVER_ERROR,
                null, new SimpleRpcException("invalid objectId=" + objectId));
          }
         
          // write response
View Full Code Here


  public Object invoke(Object proxy, Method method, Object[] args)
    throws Throwable {
   
    // create the method request
    MethodRequest request = new MethodRequest(objectId, method.getName(), args);
    MethodResponse response = null;
   
    // obviously, this is very inefficient, but for the moment it will do
    synchronized (socket) {

      try {
     
        // connect
        if (!socket.isConnected()) {
          socket.connect(new InetSocketAddress(address, port));
        }
       
        // write method request
        ObjectOutputStream oos = new ObjectOutputStream(
            new BufferedOutputStream(socket.getOutputStream()));
        oos.writeObject(request);
        oos.flush();
       
        // read method response
        ObjectInputStream ois = new ObjectInputStream(
            new BufferedInputStream(socket.getInputStream()));
       
          // get result
        response = (MethodResponse)ois.readObject();
     
      } catch (Exception e) {
       
        // wrap transport exception 
        throw new SimpleRpcException(e);
      }
    }
   
    // handle the returning
    if (response != null) {
      ResultCode code = response.getResultCode();

      // success
      if (MethodResponse.ResultCode.SUCCESS.equals(code)) {

        // return value is null
        if (method.getReturnType().equals(Void.TYPE)) {
          assert response.getReturnValue() == null;
          return null;
         
        // return the return value 
        } else {
          assert response.getReturnValue() != null;
          return response.getReturnValue();
        }

      // throw remote object exception  
      } else if (MethodResponse.ResultCode.REMOTE_OBJECT_EXCEPTION.equals(code)) {
        assert response.getExceptionValue() != null;
        throw response.getExceptionValue();
     
      // throw remote server exception
      } else if (MethodResponse.ResultCode.SERVER_ERROR.equals(code)) {
        assert response.getExceptionValue() != null;
        throw response.getExceptionValue();
       
      // throw unknown exception
      } else {
        throw new SimpleRpcException("unknown exception occured");
      }
View Full Code Here

TOP

Related Classes of vs.common.MethodResponse

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.