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));
}
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);
}
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();
}
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);
}
}
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;
}
Aggregations