Beispiel #1
0
 /**
  * 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 MappedMethod serviceMethod the method that threw the exception, may be
  *          <code>null</code>
  * @param Exception cause the {@link Throwable} that was thrown
  * @param SerializationPolicy serializationPolicy determines the serialization policy to be used
  * @return a string that encodes the exception
  *
  * @throws NullPointerException if the 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 function encodeResponseForFailure(MappedMethod $serviceMethod = null, Exception $cause, SerializationPolicy $serializationPolicy = null, MappedClassLoader $mappedClassLoader)
 {
     if ($cause === null) {
         throw new NullPointerException("cause cannot be null");
     }
     if ($serializationPolicy === null) {
         $serializationPolicy = RPC::getDefaultSerializationPolicy();
         //throw new NullPointerException("serializationPolicy");
     }
     if ($serviceMethod != null && !RPC::isExpectedException($serviceMethod, $cause)) {
         class_exists('UnexpectedException') || (require GWTPHP_DIR . '/exceptions/UnexpectedException.class.php');
         throw new UnexpectedException("Service method '" . RPC::getSourceRepresentation($serviceMethod) . "' threw an unexpected exception: " . $cause->__toString(), $cause);
     }
     //class_exists('UnimplementedOperationException') || require(GWTPHP_DIR.'/exceptions/UnimplementedOperationException.class.php');
     //throw new UnimplementedOperationException("Exception serialization not implemented yet! " . print_r($cause,true));
     //ArrayMappedClassLoader::loadMappedClass('pl.rmalinowski.gwtphp.client.dto.SimpleException');
     $couseClass = $mappedClassLoader->findMappedClassByReflectionClass(new ReflectionObject($cause));
     return RPC::encodeResponse($couseClass, $cause, true, $serializationPolicy);
     // return RPC::encodeResponse($cause.getClass(), $cause, true, $serializationPolicy);
 }