Search in sources :

Example 46 with InvocationHandler

use of java.lang.reflect.InvocationHandler in project benchmark by seelunzi.

the class ProxyTest method main.

public static void main(String[] args) {
    UserService userService = new UserServiceImpl();
    InvocationHandler invocationHandler = new MyInvocationHandler(userService);
    UserService userServiceProxy = (UserService) Proxy.newProxyInstance(userService.getClass().getClassLoader(), userService.getClass().getInterfaces(), invocationHandler);
    System.out.println(userServiceProxy.getName(1));
    System.out.println(userServiceProxy.getAge(1));
}
Also used : InvocationHandler(java.lang.reflect.InvocationHandler)

Example 47 with InvocationHandler

use of java.lang.reflect.InvocationHandler in project cxf by apache.

the class DirectDispatchClientTest method invokeService.

private void invokeService(boolean isDirectDispatch) {
    BusFactory.setThreadDefaultBus(staticBus);
    Service service = Service.create(serviceName);
    service.addPort(localPortName, "http://schemas.xmlsoap.org/soap/", "local://Greeter");
    Greeter greeter = service.getPort(localPortName, Greeter.class);
    if (isDirectDispatch) {
        Client client = ClientProxy.getClient(greeter);
        client.getOutInterceptors().add(new GZIPOutInterceptor(50));
        client.getInInterceptors().add(new GZIPInInterceptor());
        InvocationHandler handler = Proxy.getInvocationHandler(greeter);
        BindingProvider bp = null;
        if (handler instanceof BindingProvider) {
            bp = (BindingProvider) handler;
            Map<String, Object> requestContext = bp.getRequestContext();
            requestContext.put(LocalConduit.DIRECT_DISPATCH, true);
        }
    }
    String reply = greeter.greetMe("test");
    assertEquals("Hello test", reply);
    reply = greeter.sayHi();
    assertNotNull("no response received from service", reply);
    assertEquals("Bonjour", reply);
}
Also used : GZIPOutInterceptor(org.apache.cxf.transport.common.gzip.GZIPOutInterceptor) Greeter(org.apache.hello_world_soap_http.Greeter) Service(javax.xml.ws.Service) GZIPInInterceptor(org.apache.cxf.transport.common.gzip.GZIPInInterceptor) BindingProvider(javax.xml.ws.BindingProvider) Client(org.apache.cxf.endpoint.Client) InvocationHandler(java.lang.reflect.InvocationHandler)

Example 48 with InvocationHandler

use of java.lang.reflect.InvocationHandler in project cxf by apache.

the class BusShutdownTest method doWork.

private void doWork(URL wsdlUrl, String address) {
    SOAPService service = new SOAPService(wsdlUrl);
    assertNotNull(service);
    Greeter greeter = service.getSoapPort();
    // overwrite client address
    InvocationHandler handler = Proxy.getInvocationHandler(greeter);
    BindingProvider bp = (BindingProvider) handler;
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
    Client client = ClientProxy.getClient(greeter);
    HTTPConduit c = (HTTPConduit) client.getConduit();
    c.setClient(new HTTPClientPolicy());
    c.getClient().setConnection(ConnectionType.CLOSE);
    // invoke twoway call
    greeter.sayHi();
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) Greeter(org.apache.hello_world_soap_http.Greeter) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) BindingProvider(javax.xml.ws.BindingProvider) Client(org.apache.cxf.endpoint.Client) InvocationHandler(java.lang.reflect.InvocationHandler)

Example 49 with InvocationHandler

use of java.lang.reflect.InvocationHandler in project cxf by apache.

the class TestUtil method setAddress.

// extra methods to help support the dynamic port allocations
public static void setAddress(Object o, String address) {
    if (o instanceof BindingProvider) {
        ((BindingProvider) o).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
    }
    Client c = null;
    if (o instanceof Client) {
        c = (Client) o;
    }
    if (c == null) {
        try {
            InvocationHandler i = Proxy.getInvocationHandler(o);
            c = (Client) i.getClass().getMethod("getClient").invoke(i);
        } catch (Throwable t) {
        // ignore
        }
    }
    if (c == null) {
        try {
            final Method m = o.getClass().getDeclaredMethod("getClient");
            ReflectionUtil.setAccessible(m);
            c = (Client) m.invoke(o);
        } catch (Throwable t) {
        // ignore
        }
    }
    if (c != null) {
        c.getEndpoint().getEndpointInfo().setAddress(address);
    }
}
Also used : BindingProvider(javax.xml.ws.BindingProvider) Method(java.lang.reflect.Method) Client(org.apache.cxf.endpoint.Client) InvocationHandler(java.lang.reflect.InvocationHandler)

Example 50 with InvocationHandler

use of java.lang.reflect.InvocationHandler in project qpid-broker-j by apache.

the class AMQPConnection_0_8Impl method getChannelMethodProcessor.

@Override
public ServerChannelMethodProcessor getChannelMethodProcessor(final int channelId) {
    assertState(ConnectionState.OPEN);
    ServerChannelMethodProcessor channelMethodProcessor = getChannel(channelId);
    if (channelMethodProcessor == null) {
        channelMethodProcessor = (ServerChannelMethodProcessor) Proxy.newProxyInstance(ServerMethodDispatcher.class.getClassLoader(), new Class[] { ServerChannelMethodProcessor.class }, new InvocationHandler() {

            @Override
            public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
                if (method.getName().equals("receiveChannelCloseOk") && channelAwaitingClosure(channelId)) {
                    closeChannelOk(channelId);
                } else if (method.getName().startsWith("receive")) {
                    sendConnectionClose(ErrorCodes.CHANNEL_ERROR, "Unknown channel id: " + channelId, channelId);
                } else if (method.getName().equals("ignoreAllButCloseOk")) {
                    return channelAwaitingClosure(channelId);
                }
                return null;
            }
        });
    }
    return channelMethodProcessor;
}
Also used : Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler)

Aggregations

InvocationHandler (java.lang.reflect.InvocationHandler)411 Method (java.lang.reflect.Method)232 Test (org.junit.Test)70 InvocationTargetException (java.lang.reflect.InvocationTargetException)54 Proxy (java.lang.reflect.Proxy)28 ArrayList (java.util.ArrayList)25 Map (java.util.Map)23 IOException (java.io.IOException)19 Field (java.lang.reflect.Field)19 HashMap (java.util.HashMap)18 AccessibleObject (java.lang.reflect.AccessibleObject)16 List (java.util.List)16 BindingProvider (javax.xml.ws.BindingProvider)14 PersistentClass (org.hibernate.mapping.PersistentClass)12 RootClass (org.hibernate.mapping.RootClass)12 Before (org.junit.Before)10 Connection (java.sql.Connection)9 LinkedHashMap (java.util.LinkedHashMap)9 AbstractQueryFacade (org.jboss.tools.hibernate.runtime.common.AbstractQueryFacade)8 DexMakerTest (com.android.dx.DexMakerTest)7