List of usage examples for com.google.gwt.user.client.rpc IncompatibleRemoteServiceException IncompatibleRemoteServiceException
public IncompatibleRemoteServiceException(String msg)
From source file:com.apress.progwt.server.gwt.RPC1524.java
License:Apache License
/** * Returns an {@link RPCRequest} that is built by decoding the * contents of an encoded RPC request and optionally validating that * type can handle the request. If the type parameter is not * <code>null</code>, the implementation checks that the type is * assignable to the {@link RemoteService} interface requested in the * encoded request string.//from w w w. j a v a 2 s. c o m * * <p> * If the serializationPolicyProvider parameter is not * <code>null</code>, it is asked for a {@link SerializationPolicy} * to use to restrict the set of types that can be decoded from the * request. 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 can be decoded. * </p> * * <p> * Invoking this method with <code>null</code> for the type * parameter, <code>decodeRequest(encodedRequest, null)</code>, is * equivalent to calling <code>decodeRequest(encodedRequest)</code>. * </p> * * @param encodedRequest * a string that encodes the {@link RemoteService} * interface, the service method, and the arguments to pass * to the service method * @param type * if not <code>null</code>, the implementation checks * that the type is assignable to the {@link RemoteService} * interface encoded in the encoded request string. * @param serializationPolicyProvider * if not <code>null</code>, the implementation asks * this provider for a {@link SerializationPolicy} which * will be used to restrict the set of types that can be * decoded from this request * @return an {@link RPCRequest} instance * * @throws NullPointerException * if the encodedRequest is <code>null</code> * @throws IllegalArgumentException * if the encodedRequest is an empty string * @throws IncompatibleRemoteServiceException * if any of the following conditions apply: * <ul> * <li>if the types in the encoded request cannot be * deserialized</li> * <li>if the {@link ClassLoader} acquired from * <code>Thread.currentThread().getContextClassLoader()</code> * cannot load the service interface or any of the types * specified in the encodedRequest</li> * <li>the requested interface is not assignable to * {@link RemoteService}</li> * <li>the service method requested in the encodedRequest * is not a member of the requested service interface</li> * <li>the type parameter is not <code>null</code> and * is not assignable to the requested * {@link RemoteService} interface * </ul> */ public static RPCRequest decodeRequest(String encodedRequest, Class<?> type, SerializationPolicyProvider serializationPolicyProvider) { if (encodedRequest == null) { throw new NullPointerException("encodedRequest cannot be null"); } if (encodedRequest.length() == 0) { throw new IllegalArgumentException("encodedRequest cannot be empty"); } ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try { ServerSerializationStreamReader streamReader = new ServerSerializationStreamReader(classLoader, serializationPolicyProvider); streamReader.prepareToRead(encodedRequest); // Read the name of the RemoteService interface String serviceIntfName = streamReader.readString(); if (type != null) { if (!implementsInterface(type, serviceIntfName)) { // The service does not implement the requested // interface throw new IncompatibleRemoteServiceException("Blocked attempt to access interface '" + serviceIntfName + "', which is not implemented by '" + printTypeName(type) + "'; this is either misconfiguration or a hack attempt"); } } SerializationPolicy serializationPolicy = streamReader.getSerializationPolicy(); Class<?> serviceIntf; try { serviceIntf = getClassFromSerializedName(serviceIntfName, classLoader); if (!RemoteService.class.isAssignableFrom(serviceIntf)) { // The requested interface is not a RemoteService // interface throw new IncompatibleRemoteServiceException("Blocked attempt to access interface '" + printTypeName(serviceIntf) + "', which doesn't extend RemoteService; this is either misconfiguration or a hack attempt"); } } catch (ClassNotFoundException e) { throw new IncompatibleRemoteServiceException( "Could not locate requested interface '" + serviceIntfName + "' in default classloader", e); } String serviceMethodName = streamReader.readString(); int paramCount = streamReader.readInt(); Class<?>[] parameterTypes = new Class[paramCount]; for (int i = 0; i < parameterTypes.length; i++) { String paramClassName = streamReader.readString(); try { parameterTypes[i] = getClassFromSerializedName(paramClassName, classLoader); } catch (ClassNotFoundException e) { throw new IncompatibleRemoteServiceException( "Parameter " + i + " of is of an unknown type '" + paramClassName + "'", e); } } try { Method method = serviceIntf.getMethod(serviceMethodName, parameterTypes); Object[] parameterValues = new Object[parameterTypes.length]; for (int i = 0; i < parameterValues.length; i++) { parameterValues[i] = streamReader.deserializeValue(parameterTypes[i]); } return new RPCRequest(method, parameterValues, serializationPolicy); } catch (NoSuchMethodException e) { throw new IncompatibleRemoteServiceException( formatMethodNotFoundErrorMessage(serviceIntf, serviceMethodName, parameterTypes)); } } catch (SerializationException ex) { throw new IncompatibleRemoteServiceException(ex.getMessage(), ex); } }
From source file:com.brightedu.server.util.MyRPC.java
License:Apache License
/** * Returns an {@link RPCRequest} that is built by decoding the contents of * an encoded RPC request and optionally validating that type can handle the * request. If the type parameter is not <code>null</code>, the * implementation checks that the type is assignable to the * {@link RemoteService} interface requested in the encoded request string. * /*from w ww . j a v a 2 s .c o m*/ * <p> * If the serializationPolicyProvider parameter is not <code>null</code>, it * is asked for a {@link SerializationPolicy} to use to restrict the set of * types that can be decoded from the request. 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 can be decoded. * </p> * * <p> * Invoking this method with <code>null</code> for the type parameter, * <code>decodeRequest(encodedRequest, null)</code>, is equivalent to * calling <code>decodeRequest(encodedRequest)</code>. * </p> * * @param encodedRequest * a string that encodes the {@link RemoteService} interface, the * service method, and the arguments to pass to the service * method * @param type * if not <code>null</code>, the implementation checks that the * type is assignable to the {@link RemoteService} interface * encoded in the encoded request string. * @param serializationPolicyProvider * if not <code>null</code>, the implementation asks this * provider for a {@link SerializationPolicy} which will be used * to restrict the set of types that can be decoded from this * request * @return an {@link RPCRequest} instance * * @throws NullPointerException * if the encodedRequest is <code>null</code> * @throws IllegalArgumentException * if the encodedRequest is an empty string * @throws IncompatibleRemoteServiceException * if any of the following conditions apply: * <ul> * <li>if the types in the encoded request cannot be * deserialized</li> * <li>if the {@link ClassLoader} acquired from * <code>Thread.currentThread().getContextClassLoader()</code> * cannot load the service interface or any of the types * specified in the encodedRequest</li> * <li>the requested interface is not assignable to * {@link RemoteService}</li> * <li>the service method requested in the encodedRequest is not * a member of the requested service interface</li> * <li>the type parameter is not <code>null</code> and is not * assignable to the requested {@link RemoteService} interface * </ul> */ public static RPCRequest decodeRequest(String encodedRequest, Class<?> type, SerializationPolicyProvider serializationPolicyProvider) { if (encodedRequest == null) { throw new NullPointerException("encodedRequest cannot be null"); } if (encodedRequest.length() == 0) { throw new IllegalArgumentException("encodedRequest cannot be empty"); } ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try { ServerSerializationStreamReader streamReader = new ServerSerializationStreamReader(classLoader, serializationPolicyProvider); streamReader.prepareToRead(encodedRequest); RpcToken rpcToken = null; if (streamReader.hasFlags(AbstractSerializationStream.FLAG_RPC_TOKEN_INCLUDED)) { // Read the RPC token rpcToken = (RpcToken) streamReader.deserializeValue(RpcToken.class); } // Read the name of the RemoteService interface String serviceIntfName = maybeDeobfuscate(streamReader, streamReader.readString()); if (type != null) { if (!implementsInterface(type, serviceIntfName)) { // The service does not implement the requested interface throw new IncompatibleRemoteServiceException("Blocked attempt to access interface '" + serviceIntfName + "', which is not implemented by '" + printTypeName(type) + "'; this is either misconfiguration or a hack attempt"); } } SerializationPolicy serializationPolicy = streamReader.getSerializationPolicy(); Class<?> serviceIntf; try { serviceIntf = getClassFromSerializedName(serviceIntfName, classLoader); if (!RemoteService.class.isAssignableFrom(serviceIntf)) { // The requested interface is not a RemoteService interface throw new IncompatibleRemoteServiceException("Blocked attempt to access interface '" + printTypeName(serviceIntf) + "', which doesn't extend RemoteService; this is either misconfiguration or a hack attempt"); } } catch (ClassNotFoundException e) { throw new IncompatibleRemoteServiceException( "Could not locate requested interface '" + serviceIntfName + "' in default classloader", e); } String serviceMethodName = streamReader.readString(); int paramCount = streamReader.readInt(); if (paramCount > streamReader.getNumberOfTokens()) { throw new IncompatibleRemoteServiceException("Invalid number of parameters"); } Class<?>[] parameterTypes = new Class[paramCount]; for (int i = 0; i < parameterTypes.length; i++) { String paramClassName = maybeDeobfuscate(streamReader, streamReader.readString()); try { parameterTypes[i] = getClassFromSerializedName(paramClassName, classLoader); } catch (ClassNotFoundException e) { throw new IncompatibleRemoteServiceException( "Parameter " + i + " of is of an unknown type '" + paramClassName + "'", e); } } try { Method method = serviceIntf.getMethod(serviceMethodName, parameterTypes); Object[] parameterValues = new Object[parameterTypes.length]; for (int i = 0; i < parameterValues.length; i++) { parameterValues[i] = streamReader.deserializeValue(parameterTypes[i]); } return new RPCRequest(method, parameterValues, rpcToken, serializationPolicy, streamReader.getFlags()); } catch (NoSuchMethodException e) { throw new IncompatibleRemoteServiceException( formatMethodNotFoundErrorMessage(serviceIntf, serviceMethodName, parameterTypes)); } } catch (SerializationException ex) { throw new IncompatibleRemoteServiceException(ex.getMessage(), ex); } }
From source file:com.brightedu.server.util.MyRPC.java
License:Apache License
/** * Given a type identifier in the stream, attempt to deobfuscate it. Retuns * the original identifier if deobfuscation is unnecessary or no mapping is * known.//from w ww . ja v a 2s.c o m */ private static String maybeDeobfuscate(ServerSerializationStreamReader streamReader, String name) throws SerializationException { int index; if (streamReader.hasFlags(AbstractSerializationStream.FLAG_ELIDE_TYPE_NAMES)) { SerializationPolicy serializationPolicy = streamReader.getSerializationPolicy(); if (!(serializationPolicy instanceof TypeNameObfuscator)) { throw new IncompatibleRemoteServiceException("RPC request was encoded with obfuscated type names, " + "but the SerializationPolicy in use does not implement " + TypeNameObfuscator.class.getName()); } String maybe = ((TypeNameObfuscator) serializationPolicy).getClassNameForTypeId(name); if (maybe != null) { return maybe; } } else if ((index = name.indexOf('/')) != -1) { return name.substring(0, index); } return name; }
From source file:com.dotspots.rpcplus.client.flexiblerpc.impl.ClientSerializationStreamReader.java
License:Apache License
@Override public void prepareToRead(String encoded) throws SerializationException { results = eval(encoded);//from w w w .j a v a 2s.co m index = getLength(results); super.prepareToRead(encoded); if (getVersion() != SERIALIZATION_STREAM_VERSION) { throw new IncompatibleRemoteServiceException("Expecting version " + SERIALIZATION_STREAM_VERSION + " from server, got " + getVersion() + "."); } stringTable = readJavaScriptObject(); // TODO: // popTimingData(stringTable); }
From source file:com.gdevelop.gwt.syncrpc.SyncClientSerializationStreamReader.java
License:Apache License
@Override public void prepareToRead(String encoded) throws SerializationException { parse(encoded);/*from ww w . ja v a 2 s . c o m*/ index = results.size(); super.prepareToRead(encoded); if (getVersion() != SERIALIZATION_STREAM_VERSION) { throw new IncompatibleRemoteServiceException("Expecting version " + SERIALIZATION_STREAM_VERSION + " from server, got " + getVersion() + "."); } buildStringTable(); }
From source file:com.google.gwt.sample.dynatable.utils.RPC_2_0_1.java
/** * Returns an {@link RPCRequest} that is built by decoding the contents of an * encoded RPC request and optionally validating that type can handle the * request. If the type parameter is not <code>null</code>, the implementation * checks that the type is assignable to the {@link com.google.gwt.user.client.rpc.RemoteService} interface * requested in the encoded request string. * <p/>//from w w w .j av a2 s. co m * <p> * If the serializationPolicyProvider parameter is not <code>null</code>, it * is asked for a {@link com.google.gwt.user.server.rpc.SerializationPolicy} to use to restrict the set of * types that can be decoded from the request. 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 can be decoded. * </p> * <p/> * <p> * Invoking this method with <code>null</code> for the type parameter, * <code>decodeRequest(encodedRequest, null)</code>, is equivalent to calling * <code>decodeRequest(encodedRequest)</code>. * </p> * * @param encodedRequest a string that encodes the {@link com.google.gwt.user.client.rpc.RemoteService} * interface, the service method, and the arguments to pass to the * service method * @param type if not <code>null</code>, the implementation checks that the * type is assignable to the {@link com.google.gwt.user.client.rpc.RemoteService} interface encoded * in the encoded request string. * @param serializationPolicyProvider if not <code>null</code>, the * implementation asks this provider for a * {@link com.google.gwt.user.server.rpc.SerializationPolicy} which will be used to restrict the set * of types that can be decoded from this request * @return an {@link RPCRequest} instance * @throws NullPointerException if the encodedRequest is <code>null</code> * @throws IllegalArgumentException if the encodedRequest is an empty string * @throws com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException * if any of the following * conditions apply: * <ul> * <li>if the types in the encoded request cannot be deserialized</li> * <li>if the {@link ClassLoader} acquired from * <code>Thread.currentThread().getContextClassLoader()</code> * cannot load the service interface or any of the types specified * in the encodedRequest</li> * <li>the requested interface is not assignable to * {@link com.google.gwt.user.client.rpc.RemoteService}</li> * <li>the service method requested in the encodedRequest is not a * member of the requested service interface</li> * <li>the type parameter is not <code>null</code> and is not * assignable to the requested {@link com.google.gwt.user.client.rpc.RemoteService} interface * </ul> */ public static RPCRequest decodeRequest(String encodedRequest, Class<?> type, SerializationPolicyProvider serializationPolicyProvider) { if (encodedRequest == null) { throw new NullPointerException("encodedRequest cannot be null"); } if (encodedRequest.length() == 0) { throw new IllegalArgumentException("encodedRequest cannot be empty"); } ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try { ServerSerializationStreamReader streamReader = new ServerSerializationStreamReader(classLoader, serializationPolicyProvider); streamReader.prepareToRead(encodedRequest); // Read the name of the RemoteService interface String serviceIntfName = maybeDeobfuscate(streamReader, streamReader.readString()); if (type != null) { if (!implementsInterface(type, serviceIntfName)) { // The service does not implement the requested interface throw new IncompatibleRemoteServiceException("Blocked attempt to access interface '" + serviceIntfName + "', which is not implemented by '" + printTypeName(type) + "'; this is either misconfiguration or a hack attempt"); } } SerializationPolicy serializationPolicy = streamReader.getSerializationPolicy(); Class<?> serviceIntf; try { serviceIntf = getClassFromSerializedName(serviceIntfName, classLoader); if (!RemoteService.class.isAssignableFrom(serviceIntf)) { // The requested interface is not a RemoteService interface throw new IncompatibleRemoteServiceException("Blocked attempt to access interface '" + printTypeName(serviceIntf) + "', which doesn't extend RemoteService; this is either misconfiguration or a hack attempt"); } } catch (ClassNotFoundException e) { throw new IncompatibleRemoteServiceException( "Could not locate requested interface '" + serviceIntfName + "' in default classloader", e); } String serviceMethodName = streamReader.readString(); int paramCount = streamReader.readInt(); if (paramCount > streamReader.getNumberOfTokens()) { throw new IncompatibleRemoteServiceException("Invalid number of parameters"); } Class<?>[] parameterTypes = new Class[paramCount]; for (int i = 0; i < parameterTypes.length; i++) { String paramClassName = maybeDeobfuscate(streamReader, streamReader.readString()); try { parameterTypes[i] = getClassFromSerializedName(paramClassName, classLoader); } catch (ClassNotFoundException e) { throw new IncompatibleRemoteServiceException( "Parameter " + i + " of is of an unknown type '" + paramClassName + "'", e); } } try { Method method = serviceIntf.getMethod(serviceMethodName, parameterTypes); Object[] parameterValues = new Object[parameterTypes.length]; for (int i = 0; i < parameterValues.length; i++) { parameterValues[i] = streamReader.deserializeValue(parameterTypes[i]); } return new RPCRequest(method, parameterValues, serializationPolicy, streamReader.getFlags()); } catch (NoSuchMethodException e) { throw new IncompatibleRemoteServiceException( formatMethodNotFoundErrorMessage(serviceIntf, serviceMethodName, parameterTypes)); } } catch (SerializationException ex) { throw new IncompatibleRemoteServiceException(ex.getMessage(), ex); } }
From source file:de.itsvs.cwtrpc.core.DefaultExtendedSerializationPolicyProvider.java
License:Apache License
protected SerializationPolicy loadSerializationPolicy(HttpServletRequest request, String moduleBasePath, String strongName) throws IncompatibleRemoteServiceException, CwtRpcException { final String relativeModuleBasePath; final String policyFilePath; final InputStream is; final SerializationPolicy serializationPolicy; if (log.isDebugEnabled()) { log.debug("Trying to load serialization policy " + "for module base path '" + moduleBasePath + "' with strong name '" + strongName + "'"); }// w w w . j a v a 2s . c o m relativeModuleBasePath = getRelativeModuleBasePath(request, moduleBasePath); policyFilePath = getPolicyPath(relativeModuleBasePath, strongName); if (log.isDebugEnabled()) { log.debug("Trying to load policy file '" + policyFilePath + "' from servlet context"); } is = getServletContext().getResourceAsStream(policyFilePath); try { if (is != null) { try { serializationPolicy = SerializationPolicyLoader.loadFromStream(is, null); } catch (ParseException e) { log.error("Failed to parse policy file '" + policyFilePath + "'", e); throw new CwtRpcException("System error while initializing serialization"); } catch (IOException e) { log.error("Error while reading policy file '" + policyFilePath + "'", e); throw new CwtRpcException("System error while initializing serialization"); } } else { if (log.isWarnEnabled()) { log.warn("Requested policy file '" + policyFilePath + "' does not exist"); } throw new IncompatibleRemoteServiceException( "Strong name '" + strongName + "' seems to be invalid"); } } finally { try { if (is != null) { is.close(); } } catch (IOException e) { log.error("Error while closing servlet context resource '" + policyFilePath + "'", e); } } return serializationPolicy; }
From source file:de.itsvs.cwtrpc.core.DefaultExtendedSerializationPolicyProvider.java
License:Apache License
protected String getModuleBasePath(HttpServletRequest request, String moduleBaseUrl) throws IncompatibleRemoteServiceException, SecurityException { final String path; try {/* ww w . jav a 2 s .c om*/ path = new URL(moduleBaseUrl).getPath(); } catch (MalformedURLException e) { if (log.isWarnEnabled()) { log.warn("Received module base Url is invalid: " + moduleBaseUrl); } throw new IncompatibleRemoteServiceException("Module base Url is invalid"); } return path; }
From source file:de.itsvs.cwtrpc.core.DefaultExtendedSerializationPolicyProvider.java
License:Apache License
protected String getRelativeModuleBasePath(HttpServletRequest request, String moduleBasePath) throws IncompatibleRemoteServiceException, SecurityException { final String contextPath; final String relativeModuleBasePath; contextPath = request.getContextPath(); if (!moduleBasePath.startsWith(contextPath)) { throw new IncompatibleRemoteServiceException( "Module base URL is invalid " + "(does not start with context path)"); }//from ww w .ja v a2s . co m relativeModuleBasePath = moduleBasePath.substring(contextPath.length()); if (!relativeModuleBasePath.startsWith("/") || !relativeModuleBasePath.endsWith("/")) { throw new IncompatibleRemoteServiceException( "Module base URL is invalid (must start and end with slash)"); } if (relativeModuleBasePath.contains("/..")) { throw new SecurityException( "Specified module base URL contains " + "relative path to sub directory: " + moduleBasePath); } return relativeModuleBasePath; }
From source file:net.officefloor.plugin.gwt.service.GwtServiceTask.java
License:Open Source License
@Override public Object doTask(TaskContext<GwtServiceTask, Dependencies, Indexed> context) throws Throwable { // Obtain the request ServerGwtRpcConnection<?> connection = (ServerGwtRpcConnection<?>) context .getObject(Dependencies.SERVER_GWT_RPC_CONNECTION); // Obtain the GWT request RPCRequest rpc = connection.getRpcRequest(); // Obtain the flow index String methodName = rpc.getMethod().getName(); Integer flowIndex = this.methodToFlow.get(methodName); if (flowIndex == null) { // Indicate unknown GWT service method connection.onFailure(/*from ww w . j a v a2 s .co m*/ new IncompatibleRemoteServiceException("Unknown service method '" + methodName + "(...)'")); return null; // No further processing } // Obtain the parameter value Object[] parameters = rpc.getParameters(); Object parameter = (parameters.length == 0 ? null : parameters[0]); // Invoke flow to service request context.doFlow(flowIndex.intValue(), parameter); // Processing by flows return null; }