Example usage for java.lang.reflect Proxy getInvocationHandler

List of usage examples for java.lang.reflect Proxy getInvocationHandler

Introduction

In this page you can find the example usage for java.lang.reflect Proxy getInvocationHandler.

Prototype

@CallerSensitive
public static InvocationHandler getInvocationHandler(Object proxy) throws IllegalArgumentException 

Source Link

Document

Returns the invocation handler for the specified proxy instance.

Usage

From source file:org.atemsource.atem.impl.jpa.SessionFactoryFactoryBean.java

public void afterPropertiesSet() throws Exception {
    Object o = Proxy.getInvocationHandler(entityManagerFactory);
    Field field = null;//from  w w  w . ja  va2 s .co m
    try {
        field = o.getClass().getDeclaredField("targetEntityManagerFactory");
        if (!field.isAccessible()) {
            field.setAccessible(true);
        }
        sessionFactory = ((EntityManagerFactoryImpl) field.get(o)).getSessionFactory();
    } catch (NoSuchFieldException e) {
        field = o.getClass().getDeclaredField("entityManagerFactoryBean");
        if (!field.isAccessible()) {
            field.setAccessible(true);
        }
        AbstractEntityManagerFactoryBean factory = (AbstractEntityManagerFactoryBean) field.get(o);
        sessionFactory = ((EntityManagerFactoryImpl) factory.nativeEntityManagerFactory).getSessionFactory();
    }

}

From source file:net.heartsome.license.webservice.ServiceUtil.java

public static IService getService() throws MalformedURLException {
    //      Service srvcModel = new ObjectServiceFactory().create(IService.class);
    //      XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
    //            .newInstance().getXFire());
    ///*from   ww  w  .  j  av a 2  s .com*/
    //      IService srvc = (IService) factory.create(srvcModel, Constants.CONNECT_URL);
    //      return srvc;

    ProtocolSocketFactory easy = new EasySSLProtocolSocketFactory();
    Protocol protocol = new Protocol(HTTP_TYPE, easy, PORT);
    Protocol.registerProtocol(HTTP_TYPE, protocol);
    Service serviceModel = new ObjectServiceFactory().create(IService.class, SERVICE_NAME, SERVICE_NAMESPACE,
            null);

    IService service = (IService) new XFireProxyFactory().create(serviceModel, SERVICE_URL);
    Client client = ((XFireProxy) Proxy.getInvocationHandler(service)).getClient();
    client.addOutHandler(new DOMOutHandler());
    client.setProperty(CommonsHttpMessageSender.GZIP_ENABLED, Boolean.FALSE);
    client.setProperty(CommonsHttpMessageSender.DISABLE_EXPECT_CONTINUE, "1");
    client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, "0");

    return service;
}

From source file:cat.albirar.framework.dynabean.impl.DynaBeanFactoryUtils.java

/**
 * Check if the object is a {@link DynaBeanImpl} or a Proxy with a {@link DynaBeanImpl} as a {@link Proxy#getInvocationHandler(Object) invocation handler}.
 * @param object The object (or proxy)// w  w w  .j  av  a2  s. c om
 * @return true if the object is a {@link DynaBeanImpl} instance or a {@link Proxy} with a {@link DynaBeanImpl} as an invocation handler. Return false otherwise ever if object is null 
 */
public static boolean checkDynaBean(Object object) {
    if (object != null) {
        return ((Proxy.isProxyClass(object.getClass())
                && DynaBeanImpl.class.isAssignableFrom(Proxy.getInvocationHandler(object).getClass()))
                || DynaBeanImpl.class.isAssignableFrom(object.getClass()));
    }
    return false;
}

From source file:org.apache.openejb.assembler.classic.LazyValidatorTest.java

@Test
public void serialize() {
    final Serializable obj = Serializable.class.cast(Proxy.newProxyInstance(
            Thread.currentThread().getContextClassLoader(), new Class<?>[] { ValidatorFactory.class },
            new LazyValidator(Validation.buildDefaultValidatorFactory())));
    final LazyValidator deserialized = LazyValidator.class.cast(
            Proxy.getInvocationHandler(SerializationUtils.deserialize(SerializationUtils.serialize(obj))));
    final Validator validator = deserialized.getValidator();
    assertNotNull(validator);//w  ww  . j  av  a2s .  c  o m
}

From source file:fr.pilato.spring.elasticsearch.xml.AsyncNodeClientTest.java

@Test
public void test_node_client() throws ExecutionException, InterruptedException {
    Node node = ctx.getBean(Node.class);
    Assert.assertTrue(AopUtils.isAopProxy(node));
    Client client = checkClient("testNodeClient");
    Assert.assertNotNull(Proxy.getInvocationHandler(client));
    client.admin().cluster().prepareState().execute().get();
}

From source file:io.dyn.core.handler.HandlerMethod.java

public HandlerMethod(Method method, HandlerMethodArgument[] arguments, Guard guard) {
    this.method = method;
    ReflectionUtils.makeAccessible(method);
    this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
    ReflectionUtils.makeAccessible(bridgedMethod);
    this.arguments = arguments;
    this.guard = guard;
    this.invocationHandler = (Proxy.isProxyClass(method.getDeclaringClass())
            ? Proxy.getInvocationHandler(method.getDeclaringClass())
            : null);/*w  ww.j  a  v a  2 s. c om*/
}

From source file:fr.pilato.spring.elasticsearch.xml.AsyncNode4ClientsTest.java

@Test
public void test_node_client() throws Exception {
    Node node = ctx.getBean(Node.class);
    Assert.assertTrue(AopUtils.isAopProxy(node));

    Map<String, Client> clientMap = ctx.getBeansOfType(Client.class);

    for (Map.Entry<String, Client> entry : clientMap.entrySet()) {
        if (entry.getKey().contains("async")) {
            Assert.assertNotNull(Proxy.getInvocationHandler(entry.getValue()));
        } else {/* w  ww .  ja va2s .  co m*/
            try {
                Proxy.getInvocationHandler(entry.getValue());
                throw new Exception("Must not be proxyfied");
            } catch (IllegalArgumentException e) {
            }
        }
    }
    //wait
    node.isClosed();
}

From source file:org.bytesoft.openjtcc.supports.marshall.TerminatorMarshallerImpl.java

@Override
public TerminatorInfo marshallTerminator(RemoteTerminator terminator) throws IOException {
    if (Proxy.isProxyClass(terminator.getClass())) {
        InvocationHandler obj = Proxy.getInvocationHandler(terminator);
        if (RemoteTerminatorHandler.class.isInstance(obj)) {
            RemoteTerminatorHandler handler = (RemoteTerminatorHandler) obj;
            return handler.getRemoteTerminatorInfo();
        }/* www .  j  a  v a 2s  .  com*/
    }
    return null;
}

From source file:no.abakus.bedcard.storage.ws.WSSAcegiPropagationAdvice.java

public void before(Method m, Object[] args, Object target) throws Throwable {
    WSS4JOutHandler wssHandler = null;/* w w w. ja va  2s. c om*/
    Client client = ((XFireProxy) Proxy.getInvocationHandler(target)).getClient();
    Iterator handlerIterator = client.getOutHandlers().iterator();
    while (handlerIterator.hasNext()) {
        Handler aHandler = (Handler) handlerIterator.next();
        if (aHandler instanceof WSS4JOutHandler) {
            wssHandler = (WSS4JOutHandler) aHandler;
            break;
        }
    }
    if (wssHandler == null) {
        throw new Exception("No WSS4JOutHandler configured for this service client");
    }

    if (username == null || password == null) {
        // If consumer code has not set any Authentication, there is nothing to propagate!
        wssHandler.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.NO_SECURITY);
    } else {
        wssHandler.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
        wssHandler.setProperty(WSHandlerConstants.USER, username);
        ThreadLocalCallbackHandler
                .setThreadLocalCallbackHandler(new SinglePasswordCallbackHandler(username, password));
        wssHandler.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS,
                ThreadLocalCallbackHandler.class.getName());

        // TODO This should also work, and is maybe better: properties.setProperty(WSHandlerConstants.PW_CALLBACK_REF, new SinglePasswordCallbackHandler(username, password));
        // See Email "Re: [xfire-user] Password CallbackHandler wiring with WS-Security"
    }
}

From source file:org.qi4j.runtime.value.ValueInstance.java

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }//from  w ww .ja  v  a  2  s  .  c  o  m
    if (o == null || !Proxy.isProxyClass(o.getClass())) {
        return false;
    }

    try {
        ValueInstance that = (ValueInstance) Proxy.getInvocationHandler(o);
        return state.equals(that.state);
    } catch (ClassCastException e) {
        return false;
    }
}