Object result = serviceMethod.invoke(target, args); responsePayload = RPC.encodeResponseForSuccess(serviceMethod, result, serializationPolicy, flags);
/** * 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); }
/** * 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()); }
/** * 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); }
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; }
/** * 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); }
/** * 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); }
/** * 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()); }
/** * 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()); }
/** * 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; } }
/** * 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; }
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; }
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 ""; } }
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; }
/** * 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); } }
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; }
/** * 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; }
/** * 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; }
@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); } }
payload = RPC.encodeResponseForSuccess(rpc.getMethod(), result, rpc.getSerializationPolicy(), rpc.getFlags());