Example usage for io.netty.handler.codec.serialization ClassResolver resolve

List of usage examples for io.netty.handler.codec.serialization ClassResolver resolve

Introduction

In this page you can find the example usage for io.netty.handler.codec.serialization ClassResolver resolve.

Prototype

Class<?> resolve(String className) throws ClassNotFoundException;

Source Link

Usage

From source file:org.ow2.petals.bc.gateway.BcGatewayComponent.java

License:Open Source License

/**
 * This constructs a {@link ClassResolver} from the container {@link ClassLoader}.
 * /*from   w  w w . j a  v  a2  s .c om*/
 * This is needed because when we receive a {@link MessageExchange} from the other side, its class was coming from
 * the container on the other side. If we didn't use the container {@link ClassLoader}, then we couldn't unserialize
 * the {@link MessageExchange}.
 */
private ClassResolver newClassResolver() throws PEtALSCDKException {
    final ClassLoader cl;
    try {
        cl = getChannel().createExchangeFactory().createInOnlyExchange().getClass().getClassLoader();
    } catch (final MessagingException e) {
        throw new PEtALSCDKException(e);
    }
    final ClassResolver cr = ClassResolvers.cacheDisabled(cl);
    final ClassResolver mine = ClassResolvers.cacheDisabled(null);
    return new ClassResolver() {
        @Override
        public @Nullable Class<?> resolve(final @Nullable String className) throws ClassNotFoundException {
            try {
                return mine.resolve(className);
            } catch (final ClassNotFoundException e) {
                return cr.resolve(className);
            }
        }
    };
}