com.google.gwt.user.server.rpc.RPC类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(15.6k)|赞(0)|评价(0)|浏览(216)

本文整理了Java中com.google.gwt.user.server.rpc.RPC类的一些代码示例,展示了RPC类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RPC类的具体详情如下:
包路径:com.google.gwt.user.server.rpc.RPC
类名称:RPC

RPC介绍

[英]Utility class for integrating with the RPC system. This class exposes methods for decoding of RPC requests, encoding of RPC responses, and invocation of RPC calls on service objects. The operations exposed by this class can be reused by framework implementors such as Spring and G4jsf to support a wide range of service invocation policies.

Canonical Example

The following example demonstrates the canonical way to use this class. com.google.gwt.examples.rpc.server.CanonicalExample#processCall(String)

Advanced Example

The following example shows a more advanced way of using this class to create an adapter between GWT RPC entities and POJOs. com.google.gwt.examples.rpc.server.AdvancedExample#doPost
[中]用于与RPC系统集成的实用程序类。此类公开了用于解码RPC请求、编码RPC响应和调用服务对象上的RPC调用的方法。此类公开的操作可以被Spring和G4jsf等框架实现者重用,以支持广泛的服务调用策略。
####典型例子
下面的示例演示了使用此类的规范方法。通用域名格式。谷歌。gwt。例子。rpc。服务器CanonicalExample#processCall(字符串)
####高级范例
下面的示例显示了使用此类在GWT RPC实体和POJO之间创建适配器的更高级方法。通用域名格式。谷歌。gwt。例子。rpc。服务器高级示例#doPost

代码示例

代码示例来源:origin: com.google.gwt/gwt-servlet

return decodeRequest(encodedRequest, null);

代码示例来源:origin: com.google.gwt/gwt-servlet

public static String invokeAndEncodeResponse(Object target, Method serviceMethod, Object[] args,
  SerializationPolicy serializationPolicy, int flags) throws SerializationException {
 if (serviceMethod == null) {
  throw new NullPointerException("serviceMethod");
 }
 if (serializationPolicy == null) {
  throw new NullPointerException("serializationPolicy");
 }
 String responsePayload;
 try {
  Object result = serviceMethod.invoke(target, args);
  responsePayload = encodeResponseForSuccess(serviceMethod, result, serializationPolicy, flags);
 } catch (IllegalAccessException e) {
  SecurityException securityException =
    new SecurityException(formatIllegalAccessErrorMessage(target, serviceMethod));
  securityException.initCause(e);
  throw securityException;
 } catch (IllegalArgumentException e) {
  SecurityException securityException =
    new SecurityException(formatIllegalArgumentErrorMessage(target, serviceMethod, args));
  securityException.initCause(e);
  throw securityException;
 } catch (InvocationTargetException e) {
  // Try to encode the caught exception
  //
  Throwable cause = e.getCause();
  responsePayload = encodeResponseForFailure(serviceMethod, cause, serializationPolicy, flags);
 }
 return responsePayload;
}

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * Returns a string that encodes the result of calling a service method, which
 * could be the value returned by the method or an exception thrown by it.
 * 
 * <p>
 * This method does no security checking; security checking must be done on
 * the method prior to this invocation.
 * </p>
 * 
 * @param target instance on which to invoke the serviceMethod
 * @param serviceMethod the method to invoke
 * @param args arguments used for the method invocation
 * @return a string which encodes either the method's return or a checked
 *         exception thrown by the method
 * 
 * @throws SecurityException if the method cannot be accessed or if the number
 *           or type of actual and formal arguments differ
 * @throws SerializationException if an object could not be serialized by the
 *           stream
 * @throws UnexpectedException if the serviceMethod throws a checked exception
 *           that is not declared in its signature
 */
public static String invokeAndEncodeResponse(Object target, Method serviceMethod, Object[] args)
  throws SerializationException {
 return invokeAndEncodeResponse(target, serviceMethod, args, getDefaultSerializationPolicy());
}

代码示例来源:origin: kaaproject/kaa

Object result = serviceMethod.invoke(target, args);
responsePayload = RPC.encodeResponseForSuccess(serviceMethod, result,
  serializationPolicy, flags);
  .encodeResponseForFailure(serviceMethod, cause, serializationPolicy, flags);

代码示例来源:origin: kaaproject/kaa

@Override
public String processCall(String payload) throws SerializationException {
 try {
  perThreadRequest.set(getThreadLocalRequest());
  Object handler = getBean(getThreadLocalRequest());
  RPCRequest rpcRequest = RPC.decodeRequest(payload, handler.getClass(), this);
  onAfterRequestDeserialized(rpcRequest);
  if (LOG.isDebugEnabled()) {
   LOG.debug("Invoking " + handler.getClass().getName()
     + "." + rpcRequest.getMethod().getName());
  }
  return RpcHelper
    .invokeAndEncodeResponse(
      handler,
      rpcRequest.getMethod(),
      rpcRequest.getParameters(),
      rpcRequest.getSerializationPolicy()
    );
 } catch (IncompatibleRemoteServiceException ex) {
  log("An IncompatibleRemoteServiceException was thrown while processing this call.", ex);
  return RPC.encodeResponseForFailure(null, ex);
 } catch (SerializationException ex) {
  LOG.error("An SerializationException was thrown while processing this call.", ex);
  throw ex;
 } finally {
  perThreadRequest.set(null);
 }
}

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * Returns a string that encodes the object. It is an error to try to encode
 * an object that is not assignable to the service method's return type.
 * 
 * @param serviceMethod the method whose result we are encoding
 * @param object the instance that we wish to encode
 * @return a string that encodes the object, if the object is compatible with
 *         the service method's declared return type
 * 
 * @throws IllegalArgumentException if the result is not assignable to the
 *           service method's return type
 * @throws NullPointerException if the service method is <code>null</code>
 * @throws SerializationException if the result cannot be serialized
 */
public static String encodeResponseForSuccess(Method serviceMethod, Object object)
  throws SerializationException {
 return encodeResponseForSuccess(serviceMethod, object, getDefaultSerializationPolicy());
}

代码示例来源:origin: sk.seges.acris/acris-security-openid-core

@Override
public String processCall(String payload) throws SerializationException {
  try {
    RPCRequest req = RPC.decodeRequest(payload, null, this);
    RemoteService service = getServiceInstance(req.getMethod().getDeclaringClass());
    return RPC.invokeAndEncodeResponse(service, req.getMethod(), req.getParameters(),
        req.getSerializationPolicy(), req.getFlags());
  } catch (IncompatibleRemoteServiceException ex) {
    log("IncompatibleRemoteServiceException in the processCall(String) method.", ex);
    return RPC.encodeResponseForFailure(null, ex);
  }
}

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * Returns a string that encodes an exception. If method is not
 * <code>null</code>, it is an error if the exception is not in the method's
 * list of checked exceptions.
 * 
 * @param serviceMethod the method that threw the exception, may be
 *          <code>null</code>
 * @param cause the {@link Throwable} that was thrown
 * @return a string that encodes the exception
 * 
 * @throws NullPointerException if the cause is <code>null</code>
 * @throws SerializationException if the result cannot be serialized
 * @throws UnexpectedException if the result was an unexpected exception (a
 *           checked exception not declared in the serviceMethod's signature)
 */
public static String encodeResponseForFailure(Method serviceMethod, Throwable cause)
  throws SerializationException {
 return encodeResponseForFailure(serviceMethod, cause, getDefaultSerializationPolicy());
}

代码示例来源:origin: org.appverse.web.framework.modules.backend.frontfacade.gwt/appverse-web-modules-backend-frontfacade-gwt

@Override
public String processCall(final String payload)
    throws SerializationException {
  try {
    Object presentationService = applicationContext.getBean(serviceName
        .get());
    if (!(presentationService instanceof RemoteService)) {
      throw new IllegalArgumentException(
          "Requested Spring Bean is not a GWT RemoteService Presentation Service: "
              + payload + " (" + presentationService + ")");
    }
    RPCRequest rpcRequest = RPC.decodeRequest(payload,
        presentationService.getClass(), this);
    if (presentationService instanceof AuthenticationServiceFacade
        && rpcRequest.getMethod().equals(
            AuthenticationServiceFacade.class
                .getMethod("getXSRFSessionToken"))) {
      return RPC.encodeResponseForSuccess(rpcRequest.getMethod(),
          SecurityHelper.createXSRFToken(getThreadLocalRequest()));
    }
    return RPC.invokeAndEncodeResponse(presentationService,
        rpcRequest.getMethod(), rpcRequest.getParameters(),
        rpcRequest.getSerializationPolicy(), rpcRequest.getFlags());
  } catch (Exception e) {
    GWTPresentationException pex = new GWTPresentationException(
        e.getMessage());
    return RPC.encodeResponseForFailure(null, pex);
  }
}

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * Returns a string that encodes the object. It is an error to try to encode
 * an object that is not assignable to the service method's return type.
 * 
 * <p>
 * If the serializationPolicy parameter is not <code>null</code>, it is used
 * to determine what types can be encoded as part of this response. If this
 * parameter is <code>null</code>, then only subtypes of
 * {@link com.google.gwt.user.client.rpc.IsSerializable IsSerializable} or
 * types which have custom field serializers may be encoded.
 * </p>
 * 
 * @param serviceMethod the method whose result we are encoding
 * @param object the instance that we wish to encode
 * @param serializationPolicy determines the serialization policy to be used
 * @return a string that encodes the object, if the object is compatible with
 *         the service method's declared return type
 * 
 * @throws IllegalArgumentException if the result is not assignable to the
 *           service method's return type
 * @throws NullPointerException if the serviceMethod or the
 *           serializationPolicy are <code>null</code>
 * @throws SerializationException if the result cannot be serialized
 */
public static String encodeResponseForSuccess(Method serviceMethod, Object object,
  SerializationPolicy serializationPolicy) throws SerializationException {
 return encodeResponseForSuccess(serviceMethod, object, serializationPolicy,
   AbstractSerializationStream.DEFAULT_FLAGS);
}

代码示例来源:origin: fr.putnami.pwt/pwt

@Override
  protected void processPost(HttpServletRequest request, HttpServletResponse response) throws Throwable {
    try {
      String requestPayload = this.readContent(request);
      RPCRequest rpcRequest = RPC.decodeRequest(requestPayload, this.getClass(), this);

      String responsePayload =
        RPC.invokeAndEncodeResponse(this, rpcRequest.getMethod(), rpcRequest.getParameters(),
          rpcRequest.getSerializationPolicy(), rpcRequest.getFlags());

      boolean gzipEncode =
        RPCServletUtils.acceptsGzipEncoding(request)
          && RPCServletUtils.exceedsUncompressedContentLengthLimit(responsePayload);

      RPCServletUtils.writeResponse(null, response, responsePayload, gzipEncode);
    } catch (Exception e) {
      this.logger.error("Request processing failed", e);
      throw Throwables.propagate(e);
    }
  }
}

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * Returns a string that encodes an exception. If method is not
 * <code>null</code>, it is an error if the exception is not in the method's
 * list of checked exceptions.
 * 
 * <p>
 * If the serializationPolicy parameter is not <code>null</code>, it is used
 * to determine what types can be encoded as part of this response. If this
 * parameter is <code>null</code>, then only subtypes of
 * {@link com.google.gwt.user.client.rpc.IsSerializable IsSerializable} or
 * types which have custom field serializers may be encoded.
 * </p>
 * 
 * @param serviceMethod the method that threw the exception, may be
 *          <code>null</code>
 * @param cause the {@link Throwable} that was thrown
 * @param serializationPolicy determines the serialization policy to be used
 * @return a string that encodes the exception
 * 
 * @throws NullPointerException if the cause or the serializationPolicy
 *           are <code>null</code>
 * @throws SerializationException if the result cannot be serialized
 * @throws UnexpectedException if the result was an unexpected exception (a
 *           checked exception not declared in the serviceMethod's signature)
 */
public static String encodeResponseForFailure(Method serviceMethod, Throwable cause,
  SerializationPolicy serializationPolicy) throws SerializationException {
 return encodeResponseForFailure(serviceMethod, cause, serializationPolicy,
   AbstractSerializationStream.DEFAULT_FLAGS);
}

代码示例来源:origin: com.google.gwt/gwt-servlet

rpcRequest = RPC.decodeRequest(payload, delegate.getClass(), this);
} catch (IncompatibleRemoteServiceException ex) {
 log(
   "An IncompatibleRemoteServiceException was thrown while processing this call.",
   ex);
 return RPC.encodeResponseForFailedRequest(null, ex);

代码示例来源:origin: com.google.gwt/gwt-servlet

public static String encodeResponseForSuccess(Method serviceMethod, Object object,
  SerializationPolicy serializationPolicy, int flags) throws SerializationException {
 if (serviceMethod == null) {
  throw new NullPointerException("serviceMethod cannot be null");
 }
 if (serializationPolicy == null) {
  throw new NullPointerException("serializationPolicy");
 }
 Class<?> methodReturnType = serviceMethod.getReturnType();
 if (methodReturnType != void.class && object != null) {
  Class<?> actualReturnType;
  if (methodReturnType.isPrimitive()) {
   actualReturnType = getPrimitiveClassFromWrapper(object.getClass());
  } else {
   actualReturnType = object.getClass();
  }
  if (actualReturnType == null || !methodReturnType.isAssignableFrom(actualReturnType)) {
   throw new IllegalArgumentException("Type '" + printTypeName(object.getClass())
     + "' does not match the return type in the method's signature: '"
     + getSourceRepresentation(serviceMethod) + "'");
  }
 }
 return encodeResponse(methodReturnType, object, false, flags, serializationPolicy);
}

代码示例来源:origin: com.google.gwt/gwt-servlet

try {
 onAfterRequestDeserialized(rpcRequest);
 return RPC.invokeAndEncodeResponse(delegate, rpcRequest.getMethod(),
   rpcRequest.getParameters(), rpcRequest.getSerializationPolicy(),
   rpcRequest.getFlags());
   "An IncompatibleRemoteServiceException was thrown while processing this call.",
   ex);
 return RPC.encodeResponseForFailedRequest(rpcRequest, ex);
} catch (RpcTokenException tokenException) {
 log("An RpcTokenException was thrown while processing this call.",
   tokenException);
 return RPC.encodeResponseForFailedRequest(rpcRequest, tokenException);

代码示例来源:origin: com.google.gwt/gwt-servlet

return invokeAndEncodeResponse(target, serviceMethod, args, serializationPolicy,
  AbstractSerializationStream.DEFAULT_FLAGS);

代码示例来源:origin: com.google.gwt/gwt-servlet

+ moduleBaseURL
    + "'; a legacy, 1.3.3 compatible, serialization policy will be used.  You may experience SerializationExceptions as a result.");
serializationPolicy = RPC.getDefaultSerializationPolicy();

代码示例来源:origin: com.google.gwt/gwt-servlet

public static String encodeResponseForFailure(Method serviceMethod, Throwable cause,
  SerializationPolicy serializationPolicy, int flags) throws SerializationException {
 if (cause == null) {
  throw new NullPointerException("cause cannot be null");
 }
 if (serializationPolicy == null) {
  throw new NullPointerException("serializationPolicy");
 }
 if (serviceMethod != null && !RPCServletUtils.isExpectedException(serviceMethod, cause)) {
  throw new UnexpectedException("Service method '" + getSourceRepresentation(serviceMethod)
    + "' threw an unexpected exception: " + cause.toString(), cause);
 }
 return encodeResponse(cause.getClass(), cause, true, flags, serializationPolicy);
}

代码示例来源:origin: com.vaadin.external.atmosphere/atmosphere-gwt-poll

RPCRequest rpcRequest = RPC.decodeRequest(payload, this.getClass(), this);
onAfterRequestDeserialized(rpcRequest);
return RPC.invokeAndEncodeResponse(this, rpcRequest.getMethod(),
    rpcRequest.getParameters(), rpcRequest.getSerializationPolicy(),
    rpcRequest.getFlags());
    "An IncompatibleRemoteServiceException was thrown while processing this call.",
    ex);
return RPC.encodeResponseForFailure(null, ex);

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * Returns a string that encodes an exception. If <code>rpcRequest</code>
 * is <code>null</code> a default serialization policy and default request
 * flags will be used. Otherwise these information are taken from
 * <code>rpcRequest</code>.
 * <p>
 * This method should be used if the RPC request could not be decoded or
 * could not be executed because of an exception thrown, e.g.
 * {@link IncompatibleRemoteServiceException}, {@link RpcTokenException}
 * </p>
 * @param rpcRequest the RPCRequest that failed to execute, may be null
 * @param cause the {@link Throwable} that was thrown
 * @return a String that encodes the exception
 * @throws SerializationException if the result cannot be serialized
 */
public static String encodeResponseForFailedRequest(RPCRequest rpcRequest, Throwable cause)
  throws SerializationException {
 if (rpcRequest == null) {
  return RPC.encodeResponseForFailure(null, cause,
    getDefaultSerializationPolicy(), AbstractSerializationStream.DEFAULT_FLAGS);
 } else {
  return RPC.encodeResponseForFailure(null, cause,
    rpcRequest.getSerializationPolicy(), rpcRequest.getFlags());
 }
}

相关文章