Examples of RpcResponse


Examples of ca.evanjones.protorpc.Protocol.RpcResponse

                break;
            }

            // Set the appropriate flags on the RPC object
            // TODO: Handle bad sequence number by ignoring/logging?
            RpcResponse response = builder.build();
            ProtoRpcController rpc = null;
            synchronized (this) {
                rpc = pendingRpcs.remove(response.getSequenceNumber());
                assert response.getStatus() == Protocol.Status.OK;
                assert rpc != null :
                        "No ProtoRpcController for Sequence# " + response.getSequenceNumber();
            }
            rpc.finishRpcSuccess(response.getResponse());
        }
    }
View Full Code Here

Examples of com.googlecode.jsonplugin.rpc.RPCResponse

                    //invoke method
                    try {
                        result = this.invoke(rootObject, smd);
                    } catch (Exception e) {
                        RPCResponse rpcResponse = new RPCResponse();
                        rpcResponse.setId(smd.get("id").toString());
                        rpcResponse.setError(new RPCError(e, RPCErrorCode.EXCEPTION, debug));

                        result = rpcResponse;
                    }
                } else {
                    String message = "SMD request was not in the right format. See http://json-rpc.org";

                    RPCResponse rpcResponse = new RPCResponse();
                    rpcResponse.setError(new RPCError(message, RPCErrorCode.INVALID_PROCEDURE_CALL));
                    result = rpcResponse;
                }

                String json = JSONUtil.serialize(result, excludeProperties, includeProperties,
                        ignoreHierarchy, excludeNullProperties);
                json = addCallbackIfApplicable(request, json);
                JSONUtil.writeJSONToResponse(
                        new SerializationParams(response, this.defaultEncoding, this.wrapWithComments, json, true, false, noCache, -1, -1, prefix, contentType));

                return Action.NONE;
            } else {
                String message = "Request with content type of 'application/json-rpc' was received but SMD is "
                        + "not enabled for this interceptor. Set 'enableSMD' to true to enable it";

                RPCResponse rpcResponse = new RPCResponse();
                rpcResponse.setError(new RPCError(message, RPCErrorCode.SMD_DISABLED));
                result = rpcResponse;
            }

            String json = JSONUtil.serialize(result, excludeProperties, includeProperties, ignoreHierarchy, excludeNullProperties);
            json = addCallbackIfApplicable(request, json);
View Full Code Here

Examples of com.googlecode.jsonplugin.rpc.RPCResponse

    @SuppressWarnings("unchecked")
    public RPCResponse invoke(Object object, Map data) throws IllegalArgumentException,
            IllegalAccessException, InvocationTargetException, JSONException,
            InstantiationException, NoSuchMethodException, IntrospectionException {

        RPCResponse response = new RPCResponse();

        //validate id
        Object id = data.get("id");
        if (id == null) {
            String message = "'id' is required for JSON RPC";
            response.setError(new RPCError(message, RPCErrorCode.METHOD_NOT_FOUND));
            return response;
        }
        //could be a numeric value
        response.setId(id.toString());

        // the map is going to have: 'params', 'method' and 'id' (what is the id for?)
        Class clazz = object.getClass();

        //parameters
        List parameters = (List) data.get("params");
        int parameterCount = parameters != null ? parameters.size() : 0;

        //method
        String methodName = (String) data.get("method");
        if (methodName == null) {
            String message = "'method' is required for JSON RPC";
            response.setError(new RPCError(message, RPCErrorCode.MISSING_METHOD));
            return response;
        }

        Method method = this.getMethod(clazz, methodName, parameterCount);
        if (method == null) {
            String message = "Method " + methodName +
                    " could not be found in action class.";
            response.setError(new RPCError(message, RPCErrorCode.METHOD_NOT_FOUND));
            return response;
        }

        //parameters
        if (parameterCount > 0) {
            Class[] parameterTypes = method.getParameterTypes();
            Type[] genericTypes = method.getGenericParameterTypes();
            List invocationParameters = new ArrayList();

            //validate size
            if (parameterTypes.length != parameterCount) {
                //size mismatch
                String message = "Parameter count in request, " + parameterCount +
                        " do not match expected parameter count for " + methodName + ", " +
                        parameterTypes.length;

                response.setError(new RPCError(message, RPCErrorCode.PARAMETERS_MISMATCH));
                return response;
            }

            //convert parameters
            for (int i = 0; i < parameters.size(); i++) {
                Object parameter = parameters.get(i);
                Class paramType = parameterTypes[i];
                Type genericType = genericTypes[i];

                //clean up the values
                if (dataCleaner != null)
                    parameter = dataCleaner.clean("[" + i + "]", parameter);

                Object converted = populator.convert(paramType, genericType, parameter, method);
                invocationParameters.add(converted);
            }

            response.setResult(method.invoke(object, invocationParameters.toArray()));
        } else {
            response.setResult(method.invoke(object, new Object[0]));
        }

        return response;
    }
View Full Code Here

Examples of com.linkedin.r2.message.rpc.RpcResponse

  }

  @Test
  public void testRpcResponseReversible1() throws IOException
  {
    final RpcResponse res = createRpcResponse();
    assertMsgEquals(res, readRpcRes(writeRes(res)));
  }
View Full Code Here

Examples of com.linkedin.r2.message.rpc.RpcResponse

  @Test
  @SuppressWarnings("deprecation")
  public void testRpcResponseReversible2() throws IOException
  {
    final RpcResponse res = createRpcResponse().builder()
            .setEntity(new byte[] {1,2,3,4})
            .build();
    assertMsgEquals(res, readRpcRes(writeRes(res)));
  }
View Full Code Here

Examples of com.linkedin.r2.message.rpc.RpcResponse

  @Test
  @SuppressWarnings("deprecation")
  public void testChainBuildRpcResponseFromRpcResponseBuilder()
  {
    final RpcResponse res = new RpcResponseBuilder()
            .setEntity(new byte[] {1,2,3,4})
            .build()
            .builder()
              .setEntity(new byte[] {5,6,7,8})
              .build();

    Assert.assertEquals(new byte[] {5,6,7,8}, res.getEntity().copyBytes());
  }
View Full Code Here

Examples of org.apache.hadoop.oncrpc.RpcResponse

            RpcDeniedReply.RejectState.AUTH_ERROR, new VerifierNone());
        rdr.write(reply);

        ChannelBuffer buf = ChannelBuffers.wrappedBuffer(reply.asReadOnlyWrap()
            .buffer());
        RpcResponse rsp = new RpcResponse(buf, info.remoteAddress());
        RpcUtil.sendRpcResponse(ctx, rsp);
        return;
      }
    }

    if (!isIdempotent(rpcCall)) {
      RpcCallCache.CacheEntry entry = rpcCallCache.checkOrAddToCache(client,
          xid);
      if (entry != null) { // in cache
        if (entry.isCompleted()) {
          LOG.info("Sending the cached reply to retransmitted request " + xid);
          RpcUtil.sendRpcResponse(ctx, entry.getResponse());
          return;
        } else { // else request is in progress
          LOG.info("Retransmitted request, transaction still in progress "
              + xid);
          // Ignore the request and do nothing
          return;
        }
      }
    }
   
    SecurityHandler securityHandler = getSecurityHandler(credentials,
        rpcCall.getVerifier());
   
    NFS3Response response = null;
    if (nfsproc3 == NFSPROC3.NULL) {
      response = nullProcedure();
    } else if (nfsproc3 == NFSPROC3.GETATTR) {
      response = getattr(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.SETATTR) {
      response = setattr(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.LOOKUP) {
      response = lookup(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.ACCESS) {
      response = access(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.READLINK) {
      response = readlink(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.READ) {
      if (LOG.isDebugEnabled()) {
          LOG.debug(Nfs3Utils.READ_RPC_START + xid);
      }   
      response = read(xdr, securityHandler, client);
      if (LOG.isDebugEnabled() && (nfsproc3 == NFSPROC3.READ)) {
        LOG.debug(Nfs3Utils.READ_RPC_END + xid);
      }
    } else if (nfsproc3 == NFSPROC3.WRITE) {
      if (LOG.isDebugEnabled()) {
          LOG.debug(Nfs3Utils.WRITE_RPC_START + xid);
      }
      response = write(xdr, channel, xid, securityHandler, client);
      // Write end debug trace is in Nfs3Utils.writeChannel
    } else if (nfsproc3 == NFSPROC3.CREATE) {
      response = create(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.MKDIR) {     
      response = mkdir(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.SYMLINK) {
      response = symlink(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.MKNOD) {
      response = mknod(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.REMOVE) {
      response = remove(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.RMDIR) {
      response = rmdir(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.RENAME) {
      response = rename(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.LINK) {
      response = link(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.READDIR) {
      response = readdir(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.READDIRPLUS) {
      response = readdirplus(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.FSSTAT) {
      response = fsstat(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.FSINFO) {
      response = fsinfo(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.PATHCONF) {
      response = pathconf(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.COMMIT) {
      response = commit(xdr, channel, xid, securityHandler, client);
    } else {
      // Invalid procedure
      RpcAcceptedReply.getInstance(xid,
          RpcAcceptedReply.AcceptState.PROC_UNAVAIL, new VerifierNone()).write(
          out);
    }
    if (response == null) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("No sync response, expect an async response for request XID="
            + rpcCall.getXid());
      }
      return;
    }
    // TODO: currently we just return VerifierNone
    out = response.writeHeaderAndResponse(out, xid, new VerifierNone());
    ChannelBuffer buf = ChannelBuffers.wrappedBuffer(out.asReadOnlyWrap()
        .buffer());
    RpcResponse rsp = new RpcResponse(buf, info.remoteAddress());

    if (!isIdempotent(rpcCall)) {
      rpcCallCache.callCompleted(client, xid, rsp);
    }
View Full Code Here

Examples of org.apache.hadoop.oncrpc.RpcResponse

            RpcDeniedReply.RejectState.AUTH_ERROR, new VerifierNone());
        rdr.write(reply);

        ChannelBuffer buf = ChannelBuffers.wrappedBuffer(reply.asReadOnlyWrap()
            .buffer());
        RpcResponse rsp = new RpcResponse(buf, info.remoteAddress());
        RpcUtil.sendRpcResponse(ctx, rsp);
        return;
      }
    }

    if (!isIdempotent(rpcCall)) {
      RpcCallCache.CacheEntry entry = rpcCallCache.checkOrAddToCache(client,
          xid);
      if (entry != null) { // in cache
        if (entry.isCompleted()) {
          LOG.info("Sending the cached reply to retransmitted request " + xid);
          RpcUtil.sendRpcResponse(ctx, entry.getResponse());
          return;
        } else { // else request is in progress
          LOG.info("Retransmitted request, transaction still in progress "
              + xid);
          // Ignore the request and do nothing
          return;
        }
      }
    }
   
    NFS3Response response = null;
    if (nfsproc3 == NFSPROC3.NULL) {
      response = nullProcedure();
    } else if (nfsproc3 == NFSPROC3.GETATTR) {
      response = getattr(xdr, info);
    } else if (nfsproc3 == NFSPROC3.SETATTR) {
      response = setattr(xdr, info);
    } else if (nfsproc3 == NFSPROC3.LOOKUP) {
      response = lookup(xdr, info);
    } else if (nfsproc3 == NFSPROC3.ACCESS) {
      response = access(xdr, info);
    } else if (nfsproc3 == NFSPROC3.READLINK) {
      response = readlink(xdr, info);
    } else if (nfsproc3 == NFSPROC3.READ) {
      if (LOG.isDebugEnabled()) {
          LOG.debug(Nfs3Utils.READ_RPC_START + xid);
      }   
      response = read(xdr, info);
      if (LOG.isDebugEnabled() && (nfsproc3 == NFSPROC3.READ)) {
        LOG.debug(Nfs3Utils.READ_RPC_END + xid);
      }
    } else if (nfsproc3 == NFSPROC3.WRITE) {
      if (LOG.isDebugEnabled()) {
          LOG.debug(Nfs3Utils.WRITE_RPC_START + xid);
      }
      response = write(xdr, info);
      // Write end debug trace is in Nfs3Utils.writeChannel
    } else if (nfsproc3 == NFSPROC3.CREATE) {
      response = create(xdr, info);
    } else if (nfsproc3 == NFSPROC3.MKDIR) {     
      response = mkdir(xdr, info);
    } else if (nfsproc3 == NFSPROC3.SYMLINK) {
      response = symlink(xdr, info);
    } else if (nfsproc3 == NFSPROC3.MKNOD) {
      response = mknod(xdr, info);
    } else if (nfsproc3 == NFSPROC3.REMOVE) {
      response = remove(xdr, info);
    } else if (nfsproc3 == NFSPROC3.RMDIR) {
      response = rmdir(xdr, info);
    } else if (nfsproc3 == NFSPROC3.RENAME) {
      response = rename(xdr, info);
    } else if (nfsproc3 == NFSPROC3.LINK) {
      response = link(xdr, info);
    } else if (nfsproc3 == NFSPROC3.READDIR) {
      response = readdir(xdr, info);
    } else if (nfsproc3 == NFSPROC3.READDIRPLUS) {
      response = readdirplus(xdr, info);
    } else if (nfsproc3 == NFSPROC3.FSSTAT) {
      response = fsstat(xdr, info);
    } else if (nfsproc3 == NFSPROC3.FSINFO) {
      response = fsinfo(xdr, info);
    } else if (nfsproc3 == NFSPROC3.PATHCONF) {
      response = pathconf(xdr,info);
    } else if (nfsproc3 == NFSPROC3.COMMIT) {
      response = commit(xdr, info);
    } else {
      // Invalid procedure
      RpcAcceptedReply.getInstance(xid,
          RpcAcceptedReply.AcceptState.PROC_UNAVAIL, new VerifierNone()).write(
          out);
    }
    if (response == null) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("No sync response, expect an async response for request XID="
            + rpcCall.getXid());
      }
      return;
    }
    // TODO: currently we just return VerifierNone
    out = response.writeHeaderAndResponse(out, xid, new VerifierNone());
    ChannelBuffer buf = ChannelBuffers.wrappedBuffer(out.asReadOnlyWrap()
        .buffer());
    RpcResponse rsp = new RpcResponse(buf, info.remoteAddress());

    if (!isIdempotent(rpcCall)) {
      rpcCallCache.callCompleted(client, xid, rsp);
    }
View Full Code Here

Examples of org.apache.hadoop.oncrpc.RpcResponse

      RpcAcceptedReply.getInstance(xid,
          RpcAcceptedReply.AcceptState.PROC_UNAVAIL, new VerifierNone()).write(
          out);
   
    ChannelBuffer buf = ChannelBuffers.wrappedBuffer(out.asReadOnlyWrap().buffer());
    RpcResponse rsp = new RpcResponse(buf, info.remoteAddress());
    RpcUtil.sendRpcResponse(ctx, rsp);
  }
View Full Code Here

Examples of org.apache.hadoop.oncrpc.RpcResponse

            RpcDeniedReply.RejectState.AUTH_ERROR, new VerifierNone());
        rdr.write(reply);

        ChannelBuffer buf = ChannelBuffers.wrappedBuffer(reply.asReadOnlyWrap()
            .buffer());
        RpcResponse rsp = new RpcResponse(buf, info.remoteAddress());
        RpcUtil.sendRpcResponse(ctx, rsp);
        return;
      }
    }

    if (!isIdempotent(rpcCall)) {
      RpcCallCache.CacheEntry entry = rpcCallCache.checkOrAddToCache(client,
          xid);
      if (entry != null) { // in cache
        if (entry.isCompleted()) {
          LOG.info("Sending the cached reply to retransmitted request " + xid);
          RpcUtil.sendRpcResponse(ctx, entry.getResponse());
          return;
        } else { // else request is in progress
          LOG.info("Retransmitted request, transaction still in progress "
              + xid);
          // Ignore the request and do nothing
          return;
        }
      }
    }
   
    SecurityHandler securityHandler = getSecurityHandler(credentials,
        rpcCall.getVerifier());
   
    NFS3Response response = null;
    if (nfsproc3 == NFSPROC3.NULL) {
      response = nullProcedure();
    } else if (nfsproc3 == NFSPROC3.GETATTR) {
      response = getattr(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.SETATTR) {
      response = setattr(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.LOOKUP) {
      response = lookup(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.ACCESS) {
      response = access(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.READLINK) {
      response = readlink(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.READ) {
      if (LOG.isDebugEnabled()) {
          LOG.debug(Nfs3Utils.READ_RPC_START + xid);
      }   
      response = read(xdr, securityHandler, client);
      if (LOG.isDebugEnabled() && (nfsproc3 == NFSPROC3.READ)) {
        LOG.debug(Nfs3Utils.READ_RPC_END + xid);
      }
    } else if (nfsproc3 == NFSPROC3.WRITE) {
      if (LOG.isDebugEnabled()) {
          LOG.debug(Nfs3Utils.WRITE_RPC_START + xid);
      }
      response = write(xdr, channel, xid, securityHandler, client);
      // Write end debug trace is in Nfs3Utils.writeChannel
    } else if (nfsproc3 == NFSPROC3.CREATE) {
      response = create(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.MKDIR) {     
      response = mkdir(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.SYMLINK) {
      response = symlink(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.MKNOD) {
      response = mknod(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.REMOVE) {
      response = remove(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.RMDIR) {
      response = rmdir(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.RENAME) {
      response = rename(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.LINK) {
      response = link(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.READDIR) {
      response = readdir(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.READDIRPLUS) {
      response = readdirplus(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.FSSTAT) {
      response = fsstat(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.FSINFO) {
      response = fsinfo(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.PATHCONF) {
      response = pathconf(xdr, securityHandler, client);
    } else if (nfsproc3 == NFSPROC3.COMMIT) {
      response = commit(xdr, securityHandler, client);
    } else {
      // Invalid procedure
      RpcAcceptedReply.getInstance(xid,
          RpcAcceptedReply.AcceptState.PROC_UNAVAIL, new VerifierNone()).write(
          out);
    }
    if (response == null) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("No sync response, expect an async response for request XID="
            + rpcCall.getXid());
      }
      return;
    }
    // TODO: currently we just return VerifierNone
    out = response.writeHeaderAndResponse(out, xid, new VerifierNone());
    ChannelBuffer buf = ChannelBuffers.wrappedBuffer(out.asReadOnlyWrap()
        .buffer());
    RpcResponse rsp = new RpcResponse(buf, info.remoteAddress());

    if (!isIdempotent(rpcCall)) {
      rpcCallCache.callCompleted(client, xid, rsp);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.