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:com.identityauth.util.NciicClient.java

public String executeClient(String serviceName, String license, String condition) throws MalformedURLException {
    ProtocolSocketFactory easy = new EasySSLProtocolSocketFactory();
    Protocol protocol = new Protocol("https", easy, 443);
    Protocol.registerProtocol("https", protocol);
    Service serviceModel = new ObjectServiceFactory().create(ServiceInf.class, "NciicServices", null, null);
    ServiceInf service = (ServiceInf) new XFireProxyFactory().create(serviceModel, SERVICE_URL + serviceName);
    Client client = ((XFireProxy) Proxy.getInvocationHandler(service)).getClient();
    client.addOutHandler(new DOMOutHandler());

    // /*from   ww w . ja  v  a2 s .c o  m*/
    client.setProperty(CommonsHttpMessageSender.GZIP_ENABLED, Boolean.TRUE);
    // 
    client.setProperty(CommonsHttpMessageSender.DISABLE_EXPECT_CONTINUE, "1");
    client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, "0");
    /**
     * 
     */
    String licensecode = null;
    String result = null;
    BufferedReader in;

    try {
        InputStream is = this.getClass().getResourceAsStream("/" + license + ".txt");
        InputStreamReader isr = new InputStreamReader(is);
        in = new BufferedReader(isr);
        licensecode = in.readLine();
        // 
        result = service.nciicCheck(licensecode, condition);
        // 
        // result = service.nciicGetCondition(licensecode);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return result;
}

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

private void addOutHandlers(Object service) {
    Properties properties = new Properties();
    // NOTE: The ACTION is also set in the WSSAcegiPropagationAdvice
    properties.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    properties.setProperty(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);

    Client client = ((XFireProxy) Proxy.getInvocationHandler(service)).getClient();
    client.addOutHandler(new DOMOutHandler());
    client.addOutHandler(new WSS4JOutHandler(properties));

    // NOTE: WSHandlerConstants.USER and WSHandlerConstants.PW_CALLBACK_CLASS 
    // are not set here, but "per-call" in the WSSAcegiPropagationAdvice.
}

From source file:com.sworddance.util.WeakProxy.java

/**
 *
 * @param <T>/* w w  w .  j a  v  a2 s. c  o m*/
 * @param proxy
 * @return the actual object that is wrapped by {@link Reference} and {@link #newProxyInstance(Object, Class...)} created
 * objects.
 */
@SuppressWarnings("unchecked")
public static <T> T getActual(Object proxy) {
    Object actual = proxy;
    while (actual != null) {
        if (Proxy.isProxyClass(actual.getClass())) {
            InvocationHandler invocationHandler = Proxy.getInvocationHandler(actual);
            if (invocationHandler instanceof ProxyInvocationHandler<?>) {
                actual = ((ProxyInvocationHandler<?>) invocationHandler).getActual();
            } else {
                break;
            }
        } else if (actual instanceof Reference<?>) {
            actual = getActual(getReferent((Reference<T>) actual));
        } else {
            break;
        }
    }
    return (T) actual;
}

From source file:com.alibaba.wasp.ipc.ProtobufRpcEngine.java

@Override
public void stopProxy(VersionedProtocol proxy) {
    if (proxy != null) {
        ((Invoker) Proxy.getInvocationHandler(proxy)).close();
    }
}

From source file:org.resthub.rpc.AMQPHessianProxy.java

/**
 * Handles the object invocation.//from   ww  w.  j  a v  a  2s  . c o m
 *
 * @param proxy  the proxy object to invoke
 * @param method the method to call
 * @param args   the arguments to the proxy object
 */
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    String methodName = method.getName();
    Class<?>[] params = method.getParameterTypes();

    // equals and hashCode are special cased
    if (methodName.equals("equals") && params.length == 1 && params[0].equals(Object.class)) {
        Object value = args[0];
        if (value == null || !Proxy.isProxyClass(value.getClass())) {
            return Boolean.FALSE;
        }

        AMQPHessianProxy handler = (AMQPHessianProxy) Proxy.getInvocationHandler(value);

        return _factory.equals(handler._factory);
    } else if (methodName.equals("hashCode") && params.length == 0) {
        return _factory.hashCode();
    } else if (methodName.equals("toString") && params.length == 0) {
        return "[HessianProxy " + proxy.getClass() + "]";
    }

    ConnectionFactory connectionFactory = _factory.getConnectionFactory();

    try {
        Message response = sendRequest(connectionFactory, method, args);

        if (response == null) {
            throw new TimeoutException();
        }

        MessageProperties props = response.getMessageProperties();
        boolean compressed = "deflate".equals(props.getContentEncoding());

        AbstractHessianInput in;

        InputStream is = new ByteArrayInputStream(response.getBody());
        if (compressed) {
            is = new InflaterInputStream(is, new Inflater(true));
        }

        int code = is.read();

        if (code == 'H') {
            int major = is.read();
            int minor = is.read();

            in = _factory.getHessian2Input(is);

            return in.readReply(method.getReturnType());
        } else if (code == 'r') {
            int major = is.read();
            int minor = is.read();

            in = _factory.getHessianInput(is);

            in.startReplyBody();

            Object value = in.readObject(method.getReturnType());

            in.completeReply();

            return value;
        } else {
            throw new HessianProtocolException("'" + (char) code + "' is an unknown code");
        }
    } catch (HessianProtocolException e) {
        throw new HessianRuntimeException(e);
    }
}

From source file:com.healthmarketscience.rmiio.RemoteWrapper.java

/**
 * Gets the wrapper underlying a proxy created by a call to {@link #wrap}.
 */// w w  w  .ja  v  a 2s  .c o m
public static RemoteWrapper<?> getWrapper(Object proxy) {
    return (RemoteWrapper<?>) Proxy.getInvocationHandler(proxy);
}

From source file:org.mybatis.spring.asyncsynchronization.AsyncAfterCompletionHelper.java

/**
 * Creates proxy that performs afterCompletion call on a separate thread
 * /*from   w ww.j  a v  a 2s . c  o  m*/
 * @param synchronization
 * @return
 */
public TransactionSynchronization createSynchronizationWithAsyncAfterComplete(
        TransactionSynchronization synchronization) {
    if (Proxy.isProxyClass(synchronization.getClass())
            && Proxy.getInvocationHandler(synchronization) instanceof AsynchAfterCompletionInvocationHandler) {
        // avoiding double wrapping just in case
        return synchronization;
    }
    Class<?>[] interfaces = { TransactionSynchronization.class };
    return (TransactionSynchronization) Proxy.newProxyInstance(synchronization.getClass().getClassLoader(),
            interfaces, new AsynchAfterCompletionInvocationHandler(synchronization));

}

From source file:org.apache.hadoop.yarn.ipc.ProtoOverHadoopRpcEngine.java

@Override
public void stopProxy(Object proxy) {
    try {//  w w w  .j a  va 2 s .com
        ((Invoker) Proxy.getInvocationHandler(proxy)).close();
    } catch (IOException e) {
        LOG.warn("Error while stopping " + proxy, e);
    }
}

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

protected Client checkClient(String name, Boolean async) {
    Client client;//from   w  ww. ja  v  a  2s  .  c om

    if (name != null) {
        client = ctx.getBean(name, Client.class);
    } else {
        client = ctx.getBean(Client.class);
    }
    if (async != null) {
        if (async) {
            assertThat(client, instanceOf(Advised.class));
            assertThat(((Advised) client).getAdvisors()[0].getAdvice(),
                    instanceOf(GenericInvocationHandler.class));
        } else {
            try {
                Proxy.getInvocationHandler(client);
                fail("Must not be proxyfied");
            } catch (IllegalArgumentException e) {
                // We expect that
            }
        }
    }
    assertThat(client, not(nullValue()));
    return client;
}

From source file:fr.pilato.spring.elasticsearch.it.xml.AbstractXmlContextModel.java

Client checkClient(String name, Boolean async) {
    Client client;/*w  w w .j  a v a  2 s  .  c  om*/

    if (name != null) {
        client = ctx.getBean(name, Client.class);
    } else {
        client = ctx.getBean(Client.class);
    }
    if (async != null) {
        if (async) {
            assertThat(client, instanceOf(Advised.class));
            assertThat(((Advised) client).getAdvisors()[0].getAdvice(),
                    instanceOf(GenericInvocationHandler.class));
        } else {
            try {
                Proxy.getInvocationHandler(client);
                fail("Must not be proxyfied");
            } catch (IllegalArgumentException e) {
                // We expect that
            }
        }
    }
    assertThat(client, not(nullValue()));
    return client;
}