Search in sources :

Example 6 with BindingFactory

use of org.apache.cxf.binding.BindingFactory in project cxf by apache.

the class WSDLServiceBuilder method buildBinding.

public BindingInfo buildBinding(ServiceInfo service, Binding binding) {
    BindingInfo bi = null;
    StringBuilder ns = new StringBuilder(100);
    BindingFactory factory = WSDLServiceUtils.getBindingFactory(binding, bus, ns);
    if (factory instanceof WSDLBindingFactory) {
        WSDLBindingFactory wFactory = (WSDLBindingFactory) factory;
        bi = wFactory.createBindingInfo(service, binding, ns.toString());
        copyExtensors(bi, binding.getExtensibilityElements());
        copyExtensionAttributes(bi, binding);
    }
    if (bi == null) {
        boolean onlyExtensors = false;
        if (factory instanceof AbstractBindingFactory) {
            bi = ((AbstractBindingFactory) factory).createBindingInfo(service, ns.toString(), null);
            onlyExtensors = true;
        } else {
            bi = new BindingInfo(service, ns.toString());
        }
        bi.setName(binding.getQName());
        copyExtensors(bi, binding.getExtensibilityElements());
        copyExtensionAttributes(bi, binding);
        for (BindingOperation bop : cast(binding.getBindingOperations(), BindingOperation.class)) {
            if (LOG.isLoggable(Level.FINER)) {
                LOG.finer("binding operation name is " + bop.getName());
            }
            String inName = null;
            String outName = null;
            if (bop.getBindingInput() != null) {
                inName = bop.getBindingInput().getName();
            }
            if (bop.getBindingOutput() != null) {
                outName = bop.getBindingOutput().getName();
            }
            final BindingOperationInfo bop2;
            if (onlyExtensors) {
                bop2 = bi.getOperation(new QName(binding.getQName().getNamespaceURI(), bop.getName()));
            } else {
                bop2 = bi.buildOperation(new QName(binding.getQName().getNamespaceURI(), bop.getName()), inName, outName);
                if (bop2 != null) {
                    bi.addOperation(bop2);
                }
            }
            if (bop2 != null) {
                copyExtensors(bop2, bop.getExtensibilityElements());
                copyExtensionAttributes(bop2, bop);
                if (bop.getBindingInput() != null) {
                    copyExtensors(bop2.getInput(), bop.getBindingInput().getExtensibilityElements());
                    copyExtensionAttributes(bop2.getInput(), bop.getBindingInput());
                    handleHeader(bop2.getInput());
                }
                if (bop.getBindingOutput() != null) {
                    copyExtensors(bop2.getOutput(), bop.getBindingOutput().getExtensibilityElements());
                    copyExtensionAttributes(bop2.getOutput(), bop.getBindingOutput());
                    handleHeader(bop2.getOutput());
                }
                for (BindingFault f : cast(bop.getBindingFaults().values(), BindingFault.class)) {
                    BindingFaultInfo bif = bop2.getFault(new QName(service.getTargetNamespace(), f.getName()));
                    copyExtensors(bif, bop.getBindingFault(f.getName()).getExtensibilityElements());
                    copyExtensionAttributes(bif, bop.getBindingFault(f.getName()));
                }
            }
        }
    }
    service.addBinding(bi);
    DescriptionInfo d = service.getDescription();
    if (null != d) {
        d.getDescribed().add(bi);
    }
    return bi;
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingFault(javax.wsdl.BindingFault) QName(javax.xml.namespace.QName) WSDLBindingFactory(org.apache.cxf.wsdl.binding.WSDLBindingFactory) AbstractBindingFactory(org.apache.cxf.binding.AbstractBindingFactory) BindingOperation(javax.wsdl.BindingOperation) BindingInfo(org.apache.cxf.service.model.BindingInfo) DescriptionInfo(org.apache.cxf.service.model.DescriptionInfo) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo) WSDLBindingFactory(org.apache.cxf.wsdl.binding.WSDLBindingFactory) AbstractBindingFactory(org.apache.cxf.binding.AbstractBindingFactory) BindingFactory(org.apache.cxf.binding.BindingFactory)

Example 7 with BindingFactory

use of org.apache.cxf.binding.BindingFactory in project tomee by apache.

the class EndpointImpl method createBinding.

final void createBinding(BindingInfo bi) throws EndpointException {
    if (null != bi) {
        String namespace = bi.getBindingId();
        try {
            final BindingFactory bf = bus.getExtension(BindingFactoryManager.class).getBindingFactory(namespace);
            if (null == bf) {
                Message msg = new Message("NO_BINDING_FACTORY", BUNDLE, namespace);
                throw new EndpointException(msg);
            }
            binding = bf.createBinding(bi);
        } catch (BusException ex) {
            throw new EndpointException(ex);
        }
    }
}
Also used : Message(org.apache.cxf.common.i18n.Message) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) BusException(org.apache.cxf.BusException) BindingFactory(org.apache.cxf.binding.BindingFactory)

Example 8 with BindingFactory

use of org.apache.cxf.binding.BindingFactory in project tomee by apache.

the class CxfUtil method initDefaultBus.

private static Bus initDefaultBus() {
    final ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(CxfUtil.class.getClassLoader());
    try {
        // create the bus reusing cxf logic but skipping factory lookup
        final Bus bus = BusFactory.newInstance(CXFBusFactory.class.getName()).createBus();
        bus.setId(SystemInstance.get().getProperty("openejb.cxf.bus.id", "openejb.cxf.bus"));
        final BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class);
        bindingFactoryMap = (Map<String, BindingFactory>) Reflections.get(bfm, "bindingFactories");
        bus.setExtension(new OpenEJBHttpDestinationFactory(), HttpDestinationFactory.class);
        // ensure client proxies can use app classes
        CXFBusFactory.setDefaultBus(Bus.class.cast(Proxy.newProxyInstance(CxfUtil.class.getClassLoader(), new Class<?>[] { Bus.class }, new ClientAwareBusHandler())));
        bus.setProperty(ClassUnwrapper.class.getName(), new ClassUnwrapper() {

            @Override
            public Class<?> getRealClass(final Object o) {
                final Class<?> aClass = o.getClass();
                Class<?> c = aClass;
                while (c.getName().contains("$$")) {
                    c = c.getSuperclass();
                }
                return c == Object.class ? aClass : c;
            }

            @Override
            public Class<?> getRealClassFromClass(Class<?> aClass) {
                return aClass;
            }

            @Override
            public Object getRealObject(Object o) {
                // straight on the proxy
                if (o instanceof OwbInterceptorProxy) {
                    return getProxiedInstance(o);
                }
                return o;
            }

            private Object getProxiedInstance(Object o) {
                try {
                    final Field field = o.getClass().getDeclaredField(FIELD_INTERCEPTOR_HANDLER);
                    field.setAccessible(true);
                    final Object fieldValue = field.get(o);
                    if (fieldValue instanceof DefaultInterceptorHandler) {
                        final DefaultInterceptorHandler handler = (DefaultInterceptorHandler) fieldValue;
                        return handler.getTarget();
                    } else {
                        throw new IllegalStateException("Expected OwbInterceptorProxy handler to be an instance of Default Interceptor Handler.");
                    }
                } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        SystemInstance.get().addObserver(new LifecycleManager());
        initAuthenticators();
        // we keep as internal the real bus and just expose to cxf the client aware bus to be able to cast it easily
        return bus;
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
}
Also used : Bus(org.apache.cxf.Bus) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) ClassUnwrapper(org.apache.cxf.common.util.ClassUnwrapper) Field(java.lang.reflect.Field) DefaultInterceptorHandler(org.apache.webbeans.intercept.DefaultInterceptorHandler) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) OpenEJBHttpDestinationFactory(org.apache.openejb.server.cxf.transport.OpenEJBHttpDestinationFactory) OwbInterceptorProxy(org.apache.webbeans.proxy.OwbInterceptorProxy) BindingFactory(org.apache.cxf.binding.BindingFactory)

Example 9 with BindingFactory

use of org.apache.cxf.binding.BindingFactory in project cxf by apache.

the class TestBase method setUp.

@Before
public void setUp() throws Exception {
    bus = BusFactory.newInstance().createBus();
    BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class);
    IMocksControl control = createNiceControl();
    BindingFactory bf = control.createMock(BindingFactory.class);
    Binding binding = control.createMock(Binding.class);
    expect(bf.createBinding(null)).andStubReturn(binding);
    expect(binding.getInFaultInterceptors()).andStubReturn(new ArrayList<Interceptor<? extends Message>>());
    expect(binding.getOutFaultInterceptors()).andStubReturn(new ArrayList<Interceptor<? extends Message>>());
    bfm.registerBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/", bf);
    String ns = "http://apache.org/hello_world_soap_http";
    WSDLServiceFactory factory = new WSDLServiceFactory(bus, getClass().getResource("/org/apache/cxf/jaxb/resources/wsdl/hello_world.wsdl").toString(), new QName(ns, "SOAPService"));
    service = factory.create();
    endpointInfo = service.getEndpointInfo(new QName(ns, "SoapPort"));
    endpoint = new EndpointImpl(bus, service, endpointInfo);
    JAXBDataBinding db = new JAXBDataBinding();
    db.setContext(JAXBContext.newInstance(new Class[] { GreetMe.class, GreetMeResponse.class }));
    service.setDataBinding(db);
    operation = endpointInfo.getBinding().getOperation(new QName(ns, "greetMe"));
    operation.getOperationInfo().getInput().getMessagePartByIndex(0).setTypeClass(GreetMe.class);
    operation.getOperationInfo().getOutput().getMessagePartByIndex(0).setTypeClass(GreetMeResponse.class);
    message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    exchange.put(Service.class, service);
    exchange.put(Endpoint.class, endpoint);
    exchange.put(Binding.class, endpoint.getBinding());
}
Also used : Binding(org.apache.cxf.binding.Binding) GreetMe(org.apache.hello_world_soap_http.types.GreetMe) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) Message(org.apache.cxf.message.Message) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) IMocksControl(org.easymock.IMocksControl) Exchange(org.apache.cxf.message.Exchange) Interceptor(org.apache.cxf.interceptor.Interceptor) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) BindingFactory(org.apache.cxf.binding.BindingFactory) Before(org.junit.Before)

Example 10 with BindingFactory

use of org.apache.cxf.binding.BindingFactory in project cxf by apache.

the class DocLiteralInInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    bus = BusFactory.newInstance().createBus();
    BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class);
    IMocksControl control = createNiceControl();
    BindingFactory bf = control.createMock(BindingFactory.class);
    Binding binding = control.createMock(Binding.class);
    expect(bf.createBinding(null)).andStubReturn(binding);
    expect(binding.getInFaultInterceptors()).andStubReturn(new ArrayList<Interceptor<? extends Message>>());
    expect(binding.getOutFaultInterceptors()).andStubReturn(new ArrayList<Interceptor<? extends Message>>());
    bfm.registerBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/", bf);
}
Also used : IMocksControl(org.easymock.IMocksControl) Binding(org.apache.cxf.binding.Binding) Message(org.apache.cxf.message.Message) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) DocLiteralInInterceptor(org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) BindingFactory(org.apache.cxf.binding.BindingFactory) Before(org.junit.Before)

Aggregations

BindingFactory (org.apache.cxf.binding.BindingFactory)13 BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)9 BusException (org.apache.cxf.BusException)7 AbstractBindingFactory (org.apache.cxf.binding.AbstractBindingFactory)4 QName (javax.xml.namespace.QName)3 Binding (org.apache.cxf.binding.Binding)3 ConfiguredBeanLocator (org.apache.cxf.configuration.ConfiguredBeanLocator)3 Interceptor (org.apache.cxf.interceptor.Interceptor)3 Message (org.apache.cxf.message.Message)3 BindingInfo (org.apache.cxf.service.model.BindingInfo)3 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)3 IMocksControl (org.easymock.IMocksControl)3 Before (org.junit.Before)3 Field (java.lang.reflect.Field)2 Message (org.apache.cxf.common.i18n.Message)2 EndpointImpl (org.apache.cxf.endpoint.EndpointImpl)2 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1 BindingFault (javax.wsdl.BindingFault)1 BindingOperation (javax.wsdl.BindingOperation)1