Example usage for com.google.gwt.user.server.rpc.impl TypeNameObfuscator SERVICE_INTERFACE_ID

List of usage examples for com.google.gwt.user.server.rpc.impl TypeNameObfuscator SERVICE_INTERFACE_ID

Introduction

In this page you can find the example usage for com.google.gwt.user.server.rpc.impl TypeNameObfuscator SERVICE_INTERFACE_ID.

Prototype

String SERVICE_INTERFACE_ID

To view the source code for com.google.gwt.user.server.rpc.impl TypeNameObfuscator SERVICE_INTERFACE_ID.

Click Source Link

Document

A reserved ID for specifying the identifier for the service interface itself.

Usage

From source file:com.gdevelop.gwt.syncrpc.SerializationPolicyLoader.java

License:Apache License

/**
 * Loads a SerializationPolicy from an input stream and optionally record
 * any {@link ClassNotFoundException}s./*  www.j  a  v  a 2s  .  c om*/
 * 
 * @param inputStream
 *            stream to load the SerializationPolicy from.
 * @param classNotFoundExceptions
 *            if not <code>null</code>, all of the
 *            {@link ClassNotFoundException}s thrown while loading this
 *            serialization policy will be added to this list
 * @return a {@link SerializationPolicy} loaded from the input stream.
 * 
 * @throws IOException
 *             if an error occurs while reading the stream
 * @throws ParseException
 *             if the input stream is not properly formatted
 */
public static SerializationPolicy loadFromStream(InputStream inputStream,
        List<ClassNotFoundException> classNotFoundExceptions) throws IOException, ParseException {

    if (inputStream == null) {
        throw new NullPointerException("inputStream");
    }

    Map<Class<?>, Boolean> whitelistSer = new HashMap<Class<?>, Boolean>();
    Map<Class<?>, Boolean> whitelistDeser = new HashMap<Class<?>, Boolean>();
    Map<Class<?>, String> typeIds = new HashMap<Class<?>, String>();
    Map<Class<?>, Set<String>> clientFields = new HashMap<Class<?>, Set<String>>();

    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();

    InputStreamReader isr = new InputStreamReader(inputStream, SERIALIZATION_POLICY_FILE_ENCODING);
    BufferedReader br = new BufferedReader(isr);

    String line = br.readLine();
    int lineNum = 1;
    while (line != null) {
        line = line.trim();
        if (line.length() > 0) {
            String[] components = line.split(",");

            if (components[0].equals(CLIENT_FIELDS_KEYWORD)) {
                /*
                 * Lines starting with '@ClientFields' list potentially
                 * serializable fields known to client code for classes that
                 * may be enhanced with additional fields on the server. If
                 * additional server fields are found, they will be
                 * serizalized separately from the normal RPC process and
                 * transmitted to the client as an opaque blob of data
                 * stored in a WeakMapping associated with the object
                 * instance.
                 */
                String binaryTypeName = components[1].trim();
                Class<?> clazz;
                try {
                    clazz = Class.forName(binaryTypeName, false, contextClassLoader);
                    HashSet<String> fieldNames = new HashSet<String>();
                    for (int i = 2; i < components.length; i++) {
                        fieldNames.add(components[i]);
                    }
                    clientFields.put(clazz, fieldNames);
                } catch (ClassNotFoundException ex) {
                    // Ignore the error, but add it to the list of errors if
                    // one was
                    // provided.
                    if (classNotFoundExceptions != null) {
                        classNotFoundExceptions.add(ex);
                    }
                }
            } else {
                if (components.length != 2 && components.length != 7) {
                    throw new ParseException(FORMAT_ERROR_MESSAGE, lineNum);
                }

                for (int i = 0; i < components.length; i++) {
                    components[i] = components[i].trim();
                    if (components[i].length() == 0) {
                        throw new ParseException(FORMAT_ERROR_MESSAGE, lineNum);
                    }
                }

                String binaryTypeName = components[0].trim();
                boolean fieldSer;
                boolean instantSer;
                boolean fieldDeser;
                boolean instantDeser;
                String typeId;

                if (components.length == 2) {
                    fieldSer = fieldDeser = true;
                    instantSer = instantDeser = Boolean.valueOf(components[1]);
                    typeId = binaryTypeName;
                } else {
                    int idx = 1;
                    // TODO: Validate the instantiable string better.
                    fieldSer = Boolean.valueOf(components[idx++]);
                    instantSer = Boolean.valueOf(components[idx++]);
                    fieldDeser = Boolean.valueOf(components[idx++]);
                    instantDeser = Boolean.valueOf(components[idx++]);
                    typeId = components[idx++];

                    if (!fieldSer && !fieldDeser && !TypeNameObfuscator.SERVICE_INTERFACE_ID.equals(typeId)) {
                        throw new ParseException("Type " + binaryTypeName
                                + " is neither field serializable, field deserializable "
                                + "nor the service interface", lineNum);
                    }
                }

                try {
                    Class<?> clazz = Class.forName(binaryTypeName, false, contextClassLoader);
                    if (fieldSer) {
                        whitelistSer.put(clazz, instantSer);
                    }
                    if (fieldDeser) {
                        whitelistDeser.put(clazz, instantDeser);
                    }
                    typeIds.put(clazz, typeId);
                } catch (ClassNotFoundException ex) {
                    // Ignore the error, but add it to the list of errors if
                    // one was
                    // provided.
                    if (classNotFoundExceptions != null) {
                        classNotFoundExceptions.add(ex);
                    }
                }
            }
        }

        line = br.readLine();
        lineNum++;
    }
    /****************************************
     * HERE'S THE CHANGE FROM THE ORIGINAL Deser and Ser are swapped because
     * we are the client side
     */
    return new StandardSerializationPolicy(whitelistDeser, whitelistSer, typeIds, clientFields);
}

From source file:de.csenk.gwt.ws.rebind.filter.serialization.GWTSerializerGenerator.java

License:Open Source License

/**
 * @param logger//from  w w  w . java2 s. c o m
 * @param context
 * @param typesSentFromBrowser
 * @param typesSentToBrowser
 * @param serializerInterface
 * @return
 * @throws UnableToCompleteException
 */
private Map<JType, String> generateTypeHandlers(TreeLogger logger, GeneratorContext context,
        SerializableTypeOracle typesSentFromBrowser, SerializableTypeOracle typesSentToBrowser,
        JClassType serializerInterface) throws UnableToCompleteException {
    TypeSerializerCreator tsc = new TypeSerializerCreator(logger, typesSentFromBrowser, typesSentToBrowser,
            context, SerializationUtils.getTypeSerializerQualifiedName(serializerInterface));
    tsc.realize(logger);

    Map<JType, String> typeStrings = new HashMap<JType, String>(tsc.getTypeStrings());
    typeStrings.put(serializerInterface, TypeNameObfuscator.SERVICE_INTERFACE_ID);
    return typeStrings;
}

From source file:org.slim3.gwt.server.rpc.HotSerializationPolicyLoader.java

License:Apache License

/**
 * Loads a SerializationPolicy from an input stream and optionally record
 * any {@link ClassNotFoundException}s./*from w w  w  .j  a  va 2  s .co m*/
 * 
 * @param inputStream
 *            stream to load the SerializationPolicy from.
 * @param classNotFoundExceptions
 *            if not <code>null</code>, all of the
 *            {@link ClassNotFoundException}s thrown while loading this
 *            serialization policy will be added to this list
 * @return a {@link SerializationPolicy} loaded from the input stream.
 * 
 * @throws IOException
 *             if an error occurs while reading the stream
 * @throws ParseException
 *             if the input stream is not properly formatted
 */
public static SerializationPolicy loadFromStream(InputStream inputStream,
        List<ClassNotFoundException> classNotFoundExceptions) throws IOException, ParseException {

    if (inputStream == null) {
        throw new NullPointerException("inputStream");
    }

    Map<String, Boolean> whitelistSer = new HashMap<String, Boolean>();
    Map<String, Boolean> whitelistDeser = new HashMap<String, Boolean>();
    Map<String, String> typeIds = new HashMap<String, String>();
    Map<String, Set<String>> clientFields = new HashMap<String, Set<String>>();

    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();

    InputStreamReader isr = new InputStreamReader(inputStream, SERIALIZATION_POLICY_FILE_ENCODING);
    BufferedReader br = new BufferedReader(isr);

    String line = br.readLine();
    int lineNum = 1;
    while (line != null) {
        line = line.trim();
        if (line.length() > 0) {
            String[] components = line.split(",");

            if (components[0].equals(CLIENT_FIELDS_KEYWORD)) {
                /*
                 * Lines starting with '@ClientFields' list potentially
                 * serializable fields known to client code for classes that
                 * may be enhanced with additional fields on the server. If
                 * additional server fields are found, they will be
                 * serizalized separately from the normal RPC process and
                 * transmitted to the client as an opaque blob of data
                 * stored in a WeakMapping associated with the object
                 * instance.
                 */
                String binaryTypeName = components[1].trim();
                Class<?> clazz;
                try {
                    clazz = Class.forName(binaryTypeName, false, contextClassLoader);
                    HashSet<String> fieldNames = new HashSet<String>();
                    for (int i = 2; i < components.length; i++) {
                        fieldNames.add(components[i]);
                    }
                    clientFields.put(clazz.getName(), fieldNames);
                } catch (ClassNotFoundException ex) {
                    // Ignore the error, but add it to the list of errors if
                    // one was
                    // provided.
                    if (classNotFoundExceptions != null) {
                        classNotFoundExceptions.add(ex);
                    }
                }
            } else {
                if (components.length != 2 && components.length != 7) {
                    throw new ParseException(FORMAT_ERROR_MESSAGE, lineNum);
                }

                for (int i = 0; i < components.length; i++) {
                    components[i] = components[i].trim();
                    if (components[i].length() == 0) {
                        throw new ParseException(FORMAT_ERROR_MESSAGE, lineNum);
                    }
                }

                String binaryTypeName = components[0].trim();
                boolean fieldSer;
                boolean instantSer;
                boolean fieldDeser;
                boolean instantDeser;
                String typeId;

                if (components.length == 2) {
                    fieldSer = fieldDeser = true;
                    instantSer = instantDeser = Boolean.valueOf(components[1]);
                    typeId = binaryTypeName;
                } else {
                    int idx = 1;
                    // TODO: Validate the instantiable string better.
                    fieldSer = Boolean.valueOf(components[idx++]);
                    instantSer = Boolean.valueOf(components[idx++]);
                    fieldDeser = Boolean.valueOf(components[idx++]);
                    instantDeser = Boolean.valueOf(components[idx++]);
                    typeId = components[idx++];

                    if (!fieldSer && !fieldDeser && !TypeNameObfuscator.SERVICE_INTERFACE_ID.equals(typeId)) {
                        throw new ParseException("Type " + binaryTypeName
                                + " is neither field serializable, field deserializable "
                                + "nor the service interface", lineNum);
                    }
                }

                try {
                    Class<?> clazz = Class.forName(binaryTypeName, false, contextClassLoader);
                    if (fieldSer) {
                        whitelistSer.put(clazz.getName(), instantSer);
                    }
                    if (fieldDeser) {
                        whitelistDeser.put(clazz.getName(), instantDeser);
                    }
                    typeIds.put(clazz.getName(), typeId);
                } catch (ClassNotFoundException ex) {
                    // Ignore the error, but add it to the list of errors if
                    // one was
                    // provided.
                    if (classNotFoundExceptions != null) {
                        classNotFoundExceptions.add(ex);
                    }
                }
            }
        }
        line = br.readLine();
        lineNum++;
    }
    return new HotSerializationPolicy(whitelistSer, whitelistDeser, typeIds, clientFields);
}