com.google.gwt.user.server.rpc.RPC.encodeResponseForSuccess()方法的使用及代码示例

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

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

RPC.encodeResponseForSuccess介绍

[英]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.
[中]返回对对象进行编码的字符串。尝试对不可分配给服务方法的返回类型的对象进行编码是错误的。

代码示例

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

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

代码示例来源: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: 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: inferred/FreeBuilder

/**
 * Server-side deserialize does not match server-side serialize, so we can't test a round trip.
 */
public static <T> void gwtSerialize(T object) throws SerializationException {
 RPC.encodeResponseForSuccess(arbitraryVoidReturningMethod(), object);
}

代码示例来源: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: net.wetheinter/gwt-user

/**
 * 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: com.vaadin.external.gwt/gwt-user

/**
 * 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: com.vaadin.external.gwt/gwt-user

/**
 * 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: net.wetheinter/gwt-user

/**
 * 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: org.opencms/opencms-core

/**
 * Serializes a CmsPublishData object into string form using the GWT serialization.<p>
 *
 * @param data the publish data
 *
 * @return the serialized publish data
 */
protected String getSerializedPublishData(CmsPublishData data) {
  try {
    String prefetchedData = RPC.encodeResponseForSuccess(
      I_CmsPublishService.class.getMethod("getInitData", java.util.HashMap.class),
      data,
      CmsPrefetchSerializationPolicy.instance());
    return prefetchedData;
  } catch (Exception e) {
    LOG.error(e.getLocalizedMessage(), e);
    return null;
  }
}

代码示例来源:origin: org.opencms/opencms-core

/**
 * Serializes the result of the given method for RPC-prefetching.<p>
 *
 * @param method the method
 * @param data the result to serialize
 *
 * @return the serialized data
 *
 * @throws SerializationException if something goes wrong
 */
public static String serialize(Method method, Object data) throws SerializationException {
  String result = RPC.encodeResponseForSuccess(method, data, CmsPrefetchSerializationPolicy.instance());
  result = CmsEncoder.escapeXml(result, true);
  return result;
}

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

static String encodeResponse(RPCRequest rpcRequest, Object message) throws SerializationException {
  if (rpcRequest == null) {
    throw new NullPointerException("rpcRequest");
  }
  if (rpcRequest.getSerializationPolicy() == null) {
    throw new NullPointerException("serializationPolicy");
  }
  String responsePayload;
  responsePayload = RPC.encodeResponseForSuccess(rpcRequest.getMethod(), message,
      rpcRequest.getSerializationPolicy(), rpcRequest.getFlags());
  return responsePayload;
}

代码示例来源:origin: org.kuali.student.core/ks-common-ui

public String getMessagesByGroupsEncodingString(String locale, String[] keys){
  Method serviceMethod;
  try {
    serviceMethod = MessagesRpcGwtServlet.class.getMethod("getMessagesByGroups", String.class, ArrayList.class);
    
    LocaleInfo localeInfo = new LocaleInfo();
    localeInfo.setLocaleLanguage(locale);
    ArrayList<String> messageGroupKeys = new ArrayList (Arrays.asList(keys));
    ArrayList<MessageInfo> messages = new ArrayList<MessageInfo>();
    for (MessageInfo info : getMessageService().getMessagesByGroups(localeInfo, messageGroupKeys, ContextUtils.getContextInfo())){
      messages.add(info);
    }
    
    Map<Class<?>, Boolean> whitelist = new HashMap<Class<?>, Boolean>();
    whitelist.put(MessageService.class, true);
    whitelist.put(MessageInfo.class,true);
    whitelist.put(LocaleInfo.class,true);
    
    KSSerializationPolicy myPolicy = new KSSerializationPolicy(whitelist);
    
    //String serializedData = RPC.encodeResponseForSuccess(serviceMethod, messageList,KSSerializationPolicy.getInstance());
    String serializedData = RPC.encodeResponseForSuccess(serviceMethod, messages, myPolicy);
    LOG.info("preloaded " + messages.size() + " messages for " + keys);
    return SerializationUtils.escapeForSingleQuotedJavaScriptString(serializedData);
  } catch (Exception e) {
    LOG.error(e);
    return "";
  }
}

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

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: org.opencms/opencms-core

/**
 * Opens the property dialog for a resource to be created with the 'New' dialog.<p>
 *
 * @param builder the resource builder used by the 'New' dialog to create the resource
 */
public void editPropertiesForNewResource(CmsNewResourceBuilder builder) {
  try {
    CmsPropertiesBean propData = builder.getPropertyData();
    String serializedPropData = RPC.encodeResponseForSuccess(
      I_CmsVfsService.class.getMethod("loadPropertyData", CmsUUID.class),
      propData,
      CmsPrefetchSerializationPolicy.instance());
    getRpcProxy(I_CmsPropertyClientRpc.class).editPropertiesForNewResource(serializedPropData);
    m_newResourceBuilder = builder;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: net.wetheinter/gwt-user

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: net.sf.gwt-widget/gwt-sl

/**
 * Handles method invocation on a service and is invoked by
 * {@link #processCall(String)}.
 * 
 * @param service
 *            Service to invoke method on
 * @param targetMethod
 *            Method to invoke.
 * @param targetParameters
 *            Parameters to pass to method. Can be null for no arguments.
 * @param rpcRequest
 *            RPCRequest instance for this request
 * @return Return RPC encoded result.
 * @throws Exception
 */
protected String invokeMethodOnService(Object service, Method targetMethod, Object[] targetParameters,
    RPCRequest rpcRequest) throws Exception {
  Object result = targetMethod.invoke(service, targetParameters);
  SerializationPolicy serializationPolicy = getSerializationPolicyProvider().getSerializationPolicyForSuccess(rpcRequest, service, targetMethod, targetParameters, result);
  String encodedResult = RPC.encodeResponseForSuccess(rpcRequest.getMethod(), result, serializationPolicy, serializationFlags);
  return encodedResult;
}

代码示例来源:origin: sk.seges.acris/acris-server-components

/**
 * Handles method invocation on a service and is invoked by
 * {@link #processCall(String)}.
 * 
 * @param service
 *            Service to invoke method on
 * @param targetMethod
 *            Method to invoke.
 * @param targetParameters
 *            Parameters to pass to method. Can be null for no arguments.
 * @param rpcRequest
 *            RPCRequest instance for this request
 * @return Return RPC encoded result.
 * @throws Exception
 */
protected String invokeMethodOnService(Object service, Method targetMethod, Object[] targetParameters,
        RPCRequest rpcRequest) throws Exception {
    Object result = targetMethod.invoke(service, targetParameters);
    SerializationPolicy serializationPolicy = getSerializationPolicyProvider().getSerializationPolicyForSuccess(rpcRequest, service, targetMethod, targetParameters, result);
    String encodedResult = RPC.encodeResponseForSuccess(rpcRequest.getMethod(), result, serializationPolicy, serializationFlags);
    return encodedResult;
}

代码示例来源: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: net.officefloor.plugin/officeplugin_gwt

payload = RPC.encodeResponseForSuccess(rpc.getMethod(),
    result, rpc.getSerializationPolicy(),
    rpc.getFlags());

相关文章