Search in sources :

Example 6 with SoapBindingInfo

use of org.apache.cxf.binding.soap.model.SoapBindingInfo in project cxf by apache.

the class ProviderServiceFactoryTest method testSOAPBindingFromCode.

@Test
public void testSOAPBindingFromCode() throws Exception {
    JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    bean.setServiceClass(SOAPSourcePayloadProvider.class);
    bean.setBus(getBus());
    bean.setInvoker(new JAXWSMethodInvoker(new SOAPSourcePayloadProvider()));
    Service service = bean.create();
    assertEquals("SOAPSourcePayloadProviderService", service.getName().getLocalPart());
    InterfaceInfo intf = service.getServiceInfos().get(0).getInterface();
    assertNotNull(intf);
    assertEquals(1, intf.getOperations().size());
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setBus(getBus());
    svrFactory.setServiceFactory(bean);
    String address = "local://localhost:9000/test";
    svrFactory.setAddress(address);
    ServerImpl server = (ServerImpl) svrFactory.create();
    // See if our endpoint was created correctly
    assertEquals(1, service.getServiceInfos().get(0).getEndpoints().size());
    Endpoint endpoint = server.getEndpoint();
    Binding binding = endpoint.getBinding();
    assertTrue(binding instanceof SoapBinding);
    SoapBindingInfo sb = (SoapBindingInfo) endpoint.getEndpointInfo().getBinding();
    assertEquals("document", sb.getStyle());
    assertEquals(false, bean.isWrapped());
    assertEquals(1, sb.getOperations().size());
    Node res = invoke(address, LocalTransportFactory.TRANSPORT_ID, "/org/apache/cxf/jaxws/sayHi.xml");
    addNamespace("j", "http://service.jaxws.cxf.apache.org/");
    assertValid("/s:Envelope/s:Body/j:sayHi", res);
}
Also used : Binding(org.apache.cxf.binding.Binding) SoapBinding(org.apache.cxf.binding.soap.SoapBinding) XMLBinding(org.apache.cxf.binding.xml.XMLBinding) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) Node(org.w3c.dom.Node) Service(org.apache.cxf.service.Service) JAXWSMethodInvoker(org.apache.cxf.jaxws.JAXWSMethodInvoker) SoapBinding(org.apache.cxf.binding.soap.SoapBinding) ServerImpl(org.apache.cxf.endpoint.ServerImpl) Endpoint(org.apache.cxf.endpoint.Endpoint) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) Test(org.junit.Test) AbstractJaxWsTest(org.apache.cxf.jaxws.AbstractJaxWsTest)

Example 7 with SoapBindingInfo

use of org.apache.cxf.binding.soap.model.SoapBindingInfo in project cxf by apache.

the class ReflectionServiceFactoryTest method testServerFactoryBean.

@Test
public void testServerFactoryBean() throws Exception {
    Service service = createService(true);
    assertEquals("test", service.get("test"));
    ServerFactoryBean svrBean = new ServerFactoryBean();
    svrBean.setAddress("http://localhost/Hello");
    svrBean.setServiceFactory(serviceFactory);
    svrBean.setServiceBean(new HelloServiceImpl());
    svrBean.setBus(getBus());
    Map<String, Object> props = new HashMap<>();
    props.put("test", "test");
    serviceFactory.setProperties(props);
    svrBean.setProperties(props);
    Server server = svrBean.create();
    assertNotNull(server);
    Map<QName, Endpoint> eps = service.getEndpoints();
    assertEquals(1, eps.size());
    Endpoint ep = eps.values().iterator().next();
    EndpointInfo endpointInfo = ep.getEndpointInfo();
    assertEquals("test", ep.get("test"));
    BindingInfo b = endpointInfo.getService().getBindings().iterator().next();
    assertTrue(b instanceof SoapBindingInfo);
    SoapBindingInfo sb = (SoapBindingInfo) b;
    assertEquals("HelloServiceSoapBinding", b.getName().getLocalPart());
    assertEquals("document", sb.getStyle());
    assertEquals(4, b.getOperations().size());
    BindingOperationInfo bop = b.getOperations().iterator().next();
    SoapOperationInfo sop = bop.getExtensor(SoapOperationInfo.class);
    assertNotNull(sop);
    assertEquals("", sop.getAction());
    assertEquals("document", sop.getStyle());
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Server(org.apache.cxf.endpoint.Server) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(org.apache.cxf.service.Service) ServerFactoryBean(org.apache.cxf.frontend.ServerFactoryBean) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) Test(org.junit.Test)

Example 8 with SoapBindingInfo

use of org.apache.cxf.binding.soap.model.SoapBindingInfo in project cxf by apache.

the class ServiceJavascriptBuilder method begin.

@Override
public void begin(ServiceInfo service) {
    code.append("//\n");
    code.append("// Definitions for service: " + service.getName().toString() + "\n");
    code.append("//\n");
    BindingInfo xml = null;
    // one for each.
    for (BindingInfo bindingInfo : service.getBindings()) {
        // there is a JIRA about the confusion / profusion of URLS here.
        if (SoapBindingConstants.SOAP11_BINDING_ID.equals(bindingInfo.getBindingId()) || SoapBindingConstants.SOAP12_BINDING_ID.equals(bindingInfo.getBindingId()) || SoapBindingFactory.SOAP_11_BINDING.equals(bindingInfo.getBindingId()) || SoapBindingFactory.SOAP_12_BINDING.equals(bindingInfo.getBindingId())) {
            SoapBindingInfo sbi = (SoapBindingInfo) bindingInfo;
            if (WSDLConstants.NS_SOAP11_HTTP_TRANSPORT.equals(sbi.getTransportURI()) || WSDLConstants.NS_SOAP12_HTTP_BINDING.equals(sbi.getTransportURI()) || // we do NOT want a dependency on the local transport.
            "http://cxf.apache.org/transports/local".equals(sbi.getTransportURI())) {
                soapBindingInfo = sbi;
                break;
            }
        } else if (WSDLConstants.NS_BINDING_XML.equals(bindingInfo.getBindingId())) {
            xml = bindingInfo;
        }
    }
    // For now, we use soap if its available, and XML if it isn't.\
    if (soapBindingInfo == null && xml == null) {
        unsupportedConstruct("NO_USABLE_BINDING", service.getName());
    }
    if (soapBindingInfo != null) {
        isRPC = WSDLConstants.RPC.equals(soapBindingInfo.getStyle());
    } else if (xml != null) {
        xmlBindingInfo = xml;
    }
}
Also used : BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo)

Example 9 with SoapBindingInfo

use of org.apache.cxf.binding.soap.model.SoapBindingInfo in project cxf by apache.

the class PolicyBasedWSS4JStaxInInterceptor method createPolicyEnforcer.

private PolicyEnforcer createPolicyEnforcer(EndpointInfo endpointInfo, SoapMessage msg) throws WSSPolicyException {
    EffectivePolicy dispatchPolicy = null;
    List<OperationPolicy> operationPolicies = new ArrayList<>();
    Collection<BindingOperationInfo> bindingOperationInfos = endpointInfo.getBinding().getOperations();
    for (Iterator<BindingOperationInfo> bindingOperationInfoIterator = bindingOperationInfos.iterator(); bindingOperationInfoIterator.hasNext(); ) {
        BindingOperationInfo bindingOperationInfo = bindingOperationInfoIterator.next();
        QName operationName = bindingOperationInfo.getName();
        // todo: I'm not sure what the effectivePolicy exactly contains,
        // a) only the operation policy,
        // or b) all policies for the service,
        // or c) all policies which applies for the current operation.
        // c) is that what we need for stax.
        EffectivePolicy policy = (EffectivePolicy) bindingOperationInfo.getProperty("policy-engine-info-serve-request");
        // PolicyEngineImpl.POLICY_INFO_REQUEST_SERVER);
        if (MessageUtils.isRequestor(msg)) {
            policy = (EffectivePolicy) bindingOperationInfo.getProperty("policy-engine-info-client-response");
            // Save the Dispatch Policy as it may be used on another BindingOperationInfo
            if (policy != null && "http://cxf.apache.org/jaxws/dispatch".equals(operationName.getNamespaceURI())) {
                dispatchPolicy = policy;
            }
            if (bindingOperationInfo.getOutput() != null) {
                MessageInfo messageInfo = bindingOperationInfo.getOutput().getMessageInfo();
                operationName = messageInfo.getName();
                if (messageInfo.getMessagePartsNumber() > 0) {
                    QName cn = messageInfo.getFirstMessagePart().getConcreteName();
                    if (cn != null) {
                        operationName = cn;
                    }
                }
            }
        } else {
            if (bindingOperationInfo.getInput() != null) {
                MessageInfo messageInfo = bindingOperationInfo.getInput().getMessageInfo();
                operationName = messageInfo.getName();
                if (messageInfo.getMessagePartsNumber() > 0) {
                    QName cn = messageInfo.getFirstMessagePart().getConcreteName();
                    if (cn != null) {
                        operationName = cn;
                    }
                }
            }
        }
        SoapOperationInfo soapOperationInfo = bindingOperationInfo.getExtensor(SoapOperationInfo.class);
        if (soapOperationInfo != null && policy == null && dispatchPolicy != null) {
            policy = dispatchPolicy;
        }
        if (policy != null && soapOperationInfo != null) {
            String soapNS;
            BindingInfo bindingInfo = bindingOperationInfo.getBinding();
            if (bindingInfo instanceof SoapBindingInfo) {
                soapNS = ((SoapBindingInfo) bindingInfo).getSoapVersion().getNamespace();
            } else {
                // most probably throw an exception:
                throw new IllegalArgumentException("BindingInfo is not an instance of SoapBindingInfo");
            }
            OperationPolicy operationPolicy = new OperationPolicy(operationName);
            operationPolicy.setPolicy(policy.getPolicy());
            operationPolicy.setOperationAction(soapOperationInfo.getAction());
            operationPolicy.setSoapMessageVersionNamespace(soapNS);
            operationPolicies.add(operationPolicy);
        }
    }
    String soapAction = SoapActionInInterceptor.getSoapAction(msg);
    if (soapAction == null) {
        soapAction = "";
    }
    String actor = (String) msg.getContextualProperty(SecurityConstants.ACTOR);
    final Collection<org.apache.cxf.message.Attachment> attachments = msg.getAttachments();
    int attachmentCount = 0;
    if (attachments != null && !attachments.isEmpty()) {
        attachmentCount = attachments.size();
    }
    return new PolicyEnforcer(operationPolicies, soapAction, isRequestor(msg), actor, attachmentCount, new WSS4JPolicyAsserter(msg.get(AssertionInfoMap.class)));
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Endpoint(org.apache.cxf.endpoint.Endpoint) MessageInfo(org.apache.cxf.service.model.MessageInfo) EffectivePolicy(org.apache.cxf.ws.policy.EffectivePolicy) OperationPolicy(org.apache.wss4j.policy.stax.OperationPolicy) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) PolicyEnforcer(org.apache.wss4j.policy.stax.enforcer.PolicyEnforcer)

Example 10 with SoapBindingInfo

use of org.apache.cxf.binding.soap.model.SoapBindingInfo in project cxf by apache.

the class RMEndpointTest method testCreateEndpoint.

@Test
public void testCreateEndpoint() throws NoSuchMethodException, EndpointException {
    Method m = RMEndpoint.class.getDeclaredMethod("getUsingAddressing", new Class[] { EndpointInfo.class });
    Service as = control.createMock(Service.class);
    EndpointInfo aei = new EndpointInfo();
    ae = new EndpointImpl(null, as, aei);
    rme = EasyMock.createMockBuilder(RMEndpoint.class).withConstructor(manager, ae).addMockedMethod(m).createMock(control);
    rme.setAplicationEndpoint(ae);
    rme.setManager(manager);
    SoapBindingInfo bi = control.createMock(SoapBindingInfo.class);
    aei.setBinding(bi);
    SoapVersion sv = Soap11.getInstance();
    EasyMock.expect(bi.getSoapVersion()).andReturn(sv);
    String ns = "http://schemas.xmlsoap.org/wsdl/soap/";
    EasyMock.expect(bi.getBindingId()).andReturn(ns);
    aei.setTransportId(ns);
    String addr = "addr";
    aei.setAddress(addr);
    Object ua = new Object();
    EasyMock.expect(rme.getUsingAddressing(aei)).andReturn(ua);
    control.replay();
    rme.createServices();
    rme.createEndpoints(null);
    Endpoint e = rme.getEndpoint(ProtocolVariation.RM10WSA200408);
    WrappedEndpoint we = (WrappedEndpoint) e;
    assertSame(ae, we.getWrappedEndpoint());
    Service s = rme.getService(ProtocolVariation.RM10WSA200408);
    assertEquals(1, s.getEndpoints().size());
    assertSame(e, s.getEndpoints().get(RM10Constants.PORT_NAME));
}
Also used : SoapVersion(org.apache.cxf.binding.soap.SoapVersion) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) Service(org.apache.cxf.service.Service) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

SoapBindingInfo (org.apache.cxf.binding.soap.model.SoapBindingInfo)23 QName (javax.xml.namespace.QName)11 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)11 BindingInfo (org.apache.cxf.service.model.BindingInfo)10 Endpoint (org.apache.cxf.endpoint.Endpoint)9 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)9 Test (org.junit.Test)9 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)8 Service (org.apache.cxf.service.Service)8 DestinationFactoryManager (org.apache.cxf.transport.DestinationFactoryManager)5 Bus (org.apache.cxf.Bus)4 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)4 Definition (javax.wsdl.Definition)3 BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)3 SoapVersion (org.apache.cxf.binding.soap.SoapVersion)3 SoapBodyInfo (org.apache.cxf.binding.soap.model.SoapBodyInfo)3 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)3 BusException (org.apache.cxf.BusException)2 Binding (org.apache.cxf.binding.Binding)2 SoapBinding (org.apache.cxf.binding.soap.SoapBinding)2