Search in sources :

Example 86 with InvocationHandler

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

the class MdbProxy method newProxyInstance.

@SuppressWarnings({ "unchecked" })
public static <T> T newProxyInstance(final Class<T> type, final ConnectionFactory connectionFactory, final String requestQueueName) throws JMSException {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    if (classLoader == null)
        classLoader = type.getClassLoader();
    if (classLoader == null)
        classLoader = ClassLoader.getSystemClassLoader();
    final InvocationHandler invocationHandler = new MdbInvocationHandler(connectionFactory, requestQueueName);
    final Object proxy = Proxy.newProxyInstance(classLoader, new Class[] { type }, invocationHandler);
    return (T) proxy;
}
Also used : InvocationHandler(java.lang.reflect.InvocationHandler)

Example 87 with InvocationHandler

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

the class MultiplexHttpAddressClientServerTest method testWithManualMultiplexEprCreation.

@Test
public void testWithManualMultiplexEprCreation() throws Exception {
    Service numService = Service.create(NumberFactoryImpl.NUMBER_SERVICE_QNAME);
    Number num = numService.getPort(Number.class);
    InvocationHandler handler = Proxy.getInvocationHandler(num);
    BindingProvider bp = (BindingProvider) handler;
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, NUMBER_SERVANT_ADDRESS_ROOT + "103");
    IsEvenResponse numResp = num.isEven();
    assertTrue("103 is not even", Boolean.FALSE.equals(numResp.isEven()));
}
Also used : Number(org.apache.cxf.factory_pattern.Number) Service(javax.xml.ws.Service) NumberService(org.apache.cxf.factory_pattern.NumberService) NumberFactoryService(org.apache.cxf.factory_pattern.NumberFactoryService) BindingProvider(javax.xml.ws.BindingProvider) IsEvenResponse(org.apache.cxf.factory_pattern.IsEvenResponse) InvocationHandler(java.lang.reflect.InvocationHandler) Test(org.junit.Test)

Example 88 with InvocationHandler

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

the class ClientMtomXopTest method createPort.

private <T> T createPort(QName serviceName, QName portName, Class<T> serviceEndpointInterface, boolean enableMTOM, boolean installInterceptors) throws Exception {
    ReflectionServiceFactoryBean serviceFactory = new JaxWsServiceFactoryBean();
    Bus bus = getStaticBus();
    serviceFactory.setBus(bus);
    serviceFactory.setServiceName(serviceName);
    serviceFactory.setServiceClass(serviceEndpointInterface);
    serviceFactory.setWsdlURL(ClientMtomXopTest.class.getResource("/wsdl/mtom_xop.wsdl"));
    Service service = serviceFactory.create();
    EndpointInfo ei = service.getEndpointInfo(portName);
    JaxWsEndpointImpl jaxwsEndpoint = new JaxWsEndpointImpl(bus, service, ei);
    SOAPBinding jaxWsSoapBinding = new SOAPBindingImpl(ei.getBinding(), jaxwsEndpoint);
    jaxWsSoapBinding.setMTOMEnabled(enableMTOM);
    if (installInterceptors) {
        // jaxwsEndpoint.getBinding().getInInterceptors().add(new TestMultipartMessageInterceptor());
        jaxwsEndpoint.getBinding().getOutInterceptors().add(new TestAttachmentOutInterceptor());
    }
    jaxwsEndpoint.getBinding().getInInterceptors().add(new LoggingInInterceptor());
    jaxwsEndpoint.getBinding().getOutInterceptors().add(new LoggingOutInterceptor());
    Client client = new ClientImpl(bus, jaxwsEndpoint);
    InvocationHandler ih = new JaxWsClientProxy(client, jaxwsEndpoint.getJaxwsBinding());
    Object obj = Proxy.newProxyInstance(serviceEndpointInterface.getClassLoader(), new Class[] { serviceEndpointInterface, BindingProvider.class }, ih);
    updateAddressPort(obj, PORT);
    return serviceEndpointInterface.cast(obj);
}
Also used : Bus(org.apache.cxf.Bus) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) Service(org.apache.cxf.service.Service) SOAPBinding(javax.xml.ws.soap.SOAPBinding) ClientImpl(org.apache.cxf.endpoint.ClientImpl) InvocationHandler(java.lang.reflect.InvocationHandler) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) JaxWsClientProxy(org.apache.cxf.jaxws.JaxWsClientProxy) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) SOAPBindingImpl(org.apache.cxf.jaxws.binding.soap.SOAPBindingImpl) Client(org.apache.cxf.endpoint.Client) ReflectionServiceFactoryBean(org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean)

Example 89 with InvocationHandler

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

the class OOBHeaderTest method addOutOfBoundHeader.

private void addOutOfBoundHeader(PutLastTradedPricePortType portType, boolean invalid, boolean mu) {
    InvocationHandler handler = Proxy.getInvocationHandler(portType);
    BindingProvider bp = null;
    try {
        if (handler instanceof BindingProvider) {
            bp = (BindingProvider) handler;
            Map<String, Object> requestContext = bp.getRequestContext();
            OutofBandHeader ob = new OutofBandHeader();
            ob.setName("testOobHeader");
            ob.setValue("testOobHeaderValue");
            ob.setHdrAttribute(invalid ? "dontProcess" : "testHdrAttribute");
            SoapHeader hdr = new SoapHeader(new QName(TEST_HDR_NS, TEST_HDR_REQUEST_ELEM), ob, new JAXBDataBinding(ob.getClass()));
            hdr.setMustUnderstand(mu);
            List<Header> holder = new ArrayList<>();
            holder.add(hdr);
            // Add List of headerHolders to requestContext.
            requestContext.put(Header.HEADER_LIST, holder);
        }
    } catch (JAXBException ex) {
    // System.out.println("failed to insert header into request context :" + ex);
    }
}
Also used : QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) BindingProvider(javax.xml.ws.BindingProvider) InvocationHandler(java.lang.reflect.InvocationHandler) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) Header(org.apache.cxf.headers.Header) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding)

Example 90 with InvocationHandler

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

the class SOAPJMSTestSuiteTest method oneWayTest.

private void oneWayTest(TestCaseType testcase, JMSSimplePortType port) throws Exception {
    closeable = (java.io.Closeable) port;
    InvocationHandler handler = Proxy.getInvocationHandler(port);
    BindingProvider bp = (BindingProvider) handler;
    Map<String, Object> requestContext = bp.getRequestContext();
    JMSMessageHeadersType requestHeader = new JMSMessageHeadersType();
    requestContext.put(JMSConstants.JMS_CLIENT_REQUEST_HEADERS, requestHeader);
    Exception e = null;
    try {
        port.ping("test");
    } catch (Exception e1) {
        e = e1;
    }
    checkJMSProperties(testcase, requestHeader);
    if (e != null) {
        throw e;
    }
}
Also used : JMSMessageHeadersType(org.apache.cxf.transport.jms.JMSMessageHeadersType) BindingProvider(javax.xml.ws.BindingProvider) InvocationHandler(java.lang.reflect.InvocationHandler) JMSException(javax.jms.JMSException) WebServiceException(javax.xml.ws.WebServiceException)

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