Search in sources :

Example 51 with Bus

use of org.apache.cxf.Bus in project cxf by apache.

the class PerRequestFactory method create.

public Object create(Exchange ex) throws Throwable {
    try {
        if (svcClass.isInterface()) {
            throw new Fault(new Message("SVC_CLASS_IS_INTERFACE", BUNDLE, svcClass.getName()));
        }
        if (Modifier.isAbstract(svcClass.getModifiers())) {
            throw new Fault(new Message("SVC_CLASS_IS_ABSTRACT", BUNDLE, svcClass.getName()));
        }
        Object o = svcClass.newInstance();
        Bus b = ex.getBus();
        ResourceManager resourceManager = b.getExtension(ResourceManager.class);
        if (resourceManager != null) {
            ResourceInjector injector = new ResourceInjector(resourceManager);
            injector.inject(o);
            injector.construct(o);
        }
        return o;
    } catch (InstantiationException e) {
        throw new Fault(new Message("COULD_NOT_INSTANTIATE", BUNDLE), e);
    } catch (IllegalAccessException e) {
        throw new Fault(new Message("ILLEGAL_ACCESS", BUNDLE), e);
    }
}
Also used : Bus(org.apache.cxf.Bus) Message(org.apache.cxf.common.i18n.Message) Fault(org.apache.cxf.interceptor.Fault) ResourceManager(org.apache.cxf.resource.ResourceManager) ResourceInjector(org.apache.cxf.common.injection.ResourceInjector)

Example 52 with Bus

use of org.apache.cxf.Bus in project cxf by apache.

the class SAAJInInterceptor method replaceHeaders.

public static void replaceHeaders(SOAPMessage soapMessage, SoapMessage message) throws SOAPException {
    SOAPHeader header = SAAJUtils.getHeader(soapMessage);
    if (header == null) {
        return;
    }
    Element elem = DOMUtils.getFirstElement(header);
    elem = (Element) DOMUtils.getDomElement(elem);
    while (elem != null) {
        Bus b = message.getExchange() == null ? null : message.getExchange().getBus();
        HeaderProcessor p = null;
        if (b != null && b.getExtension(HeaderManager.class) != null) {
            p = b.getExtension(HeaderManager.class).getHeaderProcessor(elem.getNamespaceURI());
        }
        Object obj;
        DataBinding dataBinding = null;
        if (p == null || p.getDataBinding() == null) {
            obj = elem;
        } else {
            dataBinding = p.getDataBinding();
            obj = p.getDataBinding().createReader(Node.class).read(elem);
        }
        SoapHeader shead = new SoapHeader(new QName(elem.getNamespaceURI(), elem.getLocalName()), obj, dataBinding);
        shead.setDirection(SoapHeader.Direction.DIRECTION_IN);
        String mu = elem.getAttributeNS(message.getVersion().getNamespace(), message.getVersion().getAttrNameMustUnderstand());
        String act = elem.getAttributeNS(message.getVersion().getNamespace(), message.getVersion().getAttrNameRole());
        shead.setActor(act);
        shead.setMustUnderstand(Boolean.valueOf(mu) || "1".equals(mu));
        Header oldHdr = message.getHeader(new QName(elem.getNamespaceURI(), elem.getLocalName()));
        if (oldHdr != null) {
            message.getHeaders().remove(oldHdr);
        }
        message.getHeaders().add(shead);
        elem = DOMUtils.getNextElement(elem);
    }
}
Also used : Bus(org.apache.cxf.Bus) SOAPHeader(javax.xml.soap.SOAPHeader) Header(org.apache.cxf.headers.Header) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) HeaderProcessor(org.apache.cxf.headers.HeaderProcessor) QName(javax.xml.namespace.QName) SOAPElement(javax.xml.soap.SOAPElement) Element(org.w3c.dom.Element) DataBinding(org.apache.cxf.databinding.DataBinding) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) SOAPHeader(javax.xml.soap.SOAPHeader)

Example 53 with Bus

use of org.apache.cxf.Bus in project cxf by apache.

the class MustUnderstandInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    Bus bus = BusFactory.getDefaultBus();
    rhi = new ReadHeadersInterceptor(bus, "phase1");
    chain.add(rhi);
    sbi = new StartBodyInterceptor("phase1.5");
    chain.add(sbi);
    mui = new MustUnderstandInterceptor("phase2");
    chain.add(mui);
    dsi = new DummySoapInterceptor("phase3");
    chain.add(dsi);
}
Also used : ReadHeadersInterceptor(org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor) Bus(org.apache.cxf.Bus) MustUnderstandInterceptor(org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor) StartBodyInterceptor(org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor) Before(org.junit.Before)

Example 54 with Bus

use of org.apache.cxf.Bus in project cxf by apache.

the class ServiceModelUtilTest method setUp.

@Before
public void setUp() throws Exception {
    String wsdlUrl = getClass().getResource(WSDL_PATH).toString();
    WSDLFactory wsdlFactory = WSDLFactory.newInstance();
    WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
    wsdlReader.setFeature("javax.wsdl.verbose", false);
    def = wsdlReader.readWSDL(wsdlUrl);
    WSDLServiceBuilder wsdlServiceBuilder = new WSDLServiceBuilder(bus);
    for (Service serv : CastUtils.cast(def.getServices().values(), Service.class)) {
        if (serv != null) {
            service = serv;
            break;
        }
    }
    control = EasyMock.createNiceControl();
    bus = control.createMock(Bus.class);
    bindingFactoryManager = control.createMock(BindingFactoryManager.class);
    wsdlServiceBuilder = new WSDLServiceBuilder(bus);
    EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bindingFactoryManager);
    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);
    control.replay();
    serviceInfo = wsdlServiceBuilder.buildServices(def, service).get(0);
}
Also used : Bus(org.apache.cxf.Bus) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) WSDLFactory(javax.wsdl.factory.WSDLFactory) WSDLServiceBuilder(org.apache.cxf.wsdl11.WSDLServiceBuilder) Service(javax.wsdl.Service) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) WSDLReader(javax.wsdl.xml.WSDLReader) Before(org.junit.Before)

Example 55 with Bus

use of org.apache.cxf.Bus in project cxf by apache.

the class SoapBindingFactoryTest method testFactory.

@Test
public void testFactory() throws Exception {
    Definition d = createDefinition("/wsdl_soap/hello_world.wsdl");
    Bus bus = getMockBus();
    BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP11, bus);
    bus.getExtension(BindingFactoryManager.class);
    expectLastCall().andReturn(bfm).anyTimes();
    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);
    control.replay();
    WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
    ServiceInfo serviceInfo = builder.buildServices(d, new QName("http://apache.org/hello_world_soap_http", "SOAPService")).get(0);
    BindingInfo bi = serviceInfo.getBindings().iterator().next();
    assertTrue(bi instanceof SoapBindingInfo);
    SoapBindingInfo sbi = (SoapBindingInfo) bi;
    assertEquals("document", sbi.getStyle());
    assertTrue(WSDLConstants.NS_SOAP11_HTTP_TRANSPORT.equalsIgnoreCase(sbi.getTransportURI()));
    assertTrue(sbi.getSoapVersion() instanceof Soap11);
    BindingOperationInfo boi = sbi.getOperation(new QName("http://apache.org/hello_world_soap_http", "sayHi"));
    SoapOperationInfo sboi = boi.getExtensor(SoapOperationInfo.class);
    assertNotNull(sboi);
    assertEquals("document", sboi.getStyle());
    assertEquals("", sboi.getAction());
    BindingMessageInfo input = boi.getInput();
    SoapBodyInfo bodyInfo = input.getExtensor(SoapBodyInfo.class);
    assertEquals("literal", bodyInfo.getUse());
    List<MessagePartInfo> parts = bodyInfo.getParts();
    assertNotNull(parts);
    assertEquals(1, parts.size());
}
Also used : Bus(org.apache.cxf.Bus) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapBodyInfo(org.apache.cxf.binding.soap.model.SoapBodyInfo) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) WSDLServiceBuilder(org.apache.cxf.wsdl11.WSDLServiceBuilder) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) Test(org.junit.Test)

Aggregations

Bus (org.apache.cxf.Bus)1144 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)800 URL (java.net.URL)748 QName (javax.xml.namespace.QName)436 Service (javax.xml.ws.Service)400 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)354 Test (org.junit.Test)219 HashMap (java.util.HashMap)63 Message (org.apache.cxf.message.Message)60 WebClient (org.apache.cxf.jaxrs.client.WebClient)50 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)48 Client (org.apache.cxf.endpoint.Client)43 Greeter (org.apache.hello_world.Greeter)42 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)41 SOAPService (org.apache.hello_world.services.SOAPService)41 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)40 Endpoint (org.apache.cxf.endpoint.Endpoint)38 ExtensionManagerBus (org.apache.cxf.bus.extension.ExtensionManagerBus)36 STSClient (org.apache.cxf.ws.security.trust.STSClient)36 Document (org.w3c.dom.Document)36