Search in sources :

Example 16 with BindingFaultInfo

use of org.apache.cxf.service.model.BindingFaultInfo in project cxf by apache.

the class UniqueBodyValidator method isValidEndpoint.

private boolean isValidEndpoint(EndpointInfo endpoint) {
    BindingInfo binding = endpoint.getBinding();
    Map<QName, QName> uniqueNames = new HashMap<>();
    Map<QName, Set<String>> actions = new HashMap<>();
    Collection<BindingOperationInfo> bos = binding.getOperations();
    for (BindingOperationInfo bo : bos) {
        OperationInfo op = binding.getInterface().getOperation(bo.getName());
        if (op.getInput() != null && op.getInput().getMessagePartsNumber() == 1) {
            MessagePartInfo part = op.getInput().getFirstMessagePart();
            if (part.getElementQName() == null) {
                continue;
            }
            QName mName = part.getElementQName();
            String action = getWSAAction(op.getInput());
            QName opName = uniqueNames.get(mName);
            Set<String> opActions = actions.get(mName);
            if (opName != null && opActions != null && !opActions.contains(action)) {
                opName = null;
            }
            if (opName != null) {
                Message msg = new Message("NON_UNIQUE_BODY", LOG, endpoint.getName(), op.getName(), opName, mName);
                addErrorMessage(msg.toString());
                return false;
            }
            uniqueNames.put(mName, op.getName());
            if (action != null) {
                if (opActions == null) {
                    opActions = new HashSet<>();
                    actions.put(mName, opActions);
                }
                opActions.add(action);
            }
        }
        for (BindingFaultInfo fault : bo.getFaults()) {
            if (fault.getFaultInfo().getMessagePartsNumber() > 1) {
                Message msg = new Message("FAULT_WITH_MULTIPLE_PARTS", LOG, fault.getFaultInfo().getName().getLocalPart());
                addErrorMessage(msg.toString());
                return false;
            }
        }
    }
    return true;
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Set(java.util.Set) HashSet(java.util.HashSet) Message(org.apache.cxf.common.i18n.Message) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 17 with BindingFaultInfo

use of org.apache.cxf.service.model.BindingFaultInfo in project jbossws-cxf by jbossws.

the class PolicySetsAnnotationListener method addPolicies.

private void addPolicies(AbstractServiceFactoryBean factory, Endpoint ep, Class<?> seiCls, Class<?> implCls) {
    EndpointPolicyAttachments epa = null;
    Class<?> cls = seiCls;
    if (ep.getEndpointInfo().getInterface() != null) {
        epa = getEndpointPolicyAttachment(seiCls);
    }
    if (epa == null) {
        cls = implCls;
        epa = getEndpointPolicyAttachment(implCls);
    }
    if (epa != null) {
        final BindingInfo binf = ep.getBinding().getBindingInfo();
        final ServiceInfo si = ep.getService().getServiceInfos().get(0);
        final InterfaceInfo inf = ep.getEndpointInfo().getInterface();
        for (PolicyAttachment pa : epa.getPolicyAttachments(Placement.BINDING)) {
            addPolicy(binf, si, pa, cls, binf.getName().getLocalPart() + "BindingPolicy");
        }
        for (PolicyAttachment pa : epa.getPolicyAttachments(Placement.PORT_TYPE)) {
            addPolicy(inf, si, pa, cls, inf.getName().getLocalPart() + "PortTypePolicy");
        }
        for (PolicyAttachment pa : epa.getPolicyAttachments(Placement.SERVICE)) {
            addPolicy(si, si, pa, cls, si.getName().getLocalPart() + "ServicePolicy");
        }
        for (PolicyAttachment pa : epa.getPolicyAttachments(Placement.SERVICE_PORT)) {
            addPolicy(ep.getEndpointInfo(), si, pa, cls, ep.getEndpointInfo().getName().getLocalPart() + "PortPolicy");
        }
        for (BindingOperationInfo binfo : binf.getOperations()) {
            for (PolicyAttachment pa : epa.getPolicyAttachments(Placement.BINDING_OPERATION)) {
                addPolicy(binfo, si, pa, cls, binfo.getName().getLocalPart() + "BindingOpPolicy");
            }
            for (PolicyAttachment pa : epa.getPolicyAttachments(Placement.BINDING_OPERATION_INPUT)) {
                addPolicy(binfo.getInput(), si, pa, cls, binfo.getName().getLocalPart() + "BindingOpInputPolicy");
            }
            for (PolicyAttachment pa : epa.getPolicyAttachments(Placement.BINDING_OPERATION_OUTPUT)) {
                addPolicy(binfo.getOutput(), si, pa, cls, binfo.getName().getLocalPart() + "BindingOpOutputPolicy");
            }
            for (PolicyAttachment pa : epa.getPolicyAttachments(Placement.BINDING_OPERATION_FAULT)) {
                for (BindingFaultInfo f : binfo.getFaults()) {
                    addPolicy(f, si, pa, cls, f.getFaultInfo().getName().getLocalPart() + "BindingOpFaultPolicy");
                }
            }
        }
    }
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 18 with BindingFaultInfo

use of org.apache.cxf.service.model.BindingFaultInfo in project cxf by apache.

the class SoapBindingFactoryTest method testSoap12Factory.

@Test
public void testSoap12Factory() throws Exception {
    Definition d = createDefinition("/wsdl_soap/hello_world_soap12.wsdl");
    Bus bus = getMockBus();
    BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP12, bus);
    expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bfm);
    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_soap12_http", "SOAPService")).get(0);
    BindingInfo bi = serviceInfo.getBindings().iterator().next();
    assertTrue(bi instanceof SoapBindingInfo);
    SoapBindingInfo sbi = (SoapBindingInfo) bi;
    assertEquals("document", sbi.getStyle());
    assertEquals(WSDLConstants.NS_SOAP_HTTP_TRANSPORT, sbi.getTransportURI());
    assertTrue(sbi.getSoapVersion() instanceof Soap12);
    BindingOperationInfo boi = sbi.getOperation(new QName("http://apache.org/hello_world_soap12_http", "sayHi"));
    SoapOperationInfo sboi = boi.getExtensor(SoapOperationInfo.class);
    assertNotNull(sboi);
    assertEquals("document", sboi.getStyle());
    assertEquals("sayHiAction", 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());
    boi = sbi.getOperation(new QName("http://apache.org/hello_world_soap12_http", "pingMe"));
    sboi = boi.getExtensor(SoapOperationInfo.class);
    assertNotNull(sboi);
    assertEquals("document", sboi.getStyle());
    assertEquals("", sboi.getAction());
    Collection<BindingFaultInfo> faults = boi.getFaults();
    assertEquals(1, faults.size());
    BindingFaultInfo faultInfo = boi.getFault(new QName("http://apache.org/hello_world_soap12_http", "pingMeFault"));
    assertNotNull(faultInfo);
}
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) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo) Test(org.junit.Test)

Example 19 with BindingFaultInfo

use of org.apache.cxf.service.model.BindingFaultInfo in project cxf by apache.

the class JaxWsEndpointImpl method extractWsdlExtensibilities.

private void extractWsdlExtensibilities(EndpointInfo endpoint) {
    List<ExtensibilityElement> portExtensors = getExtensors(endpoint);
    List<ExtensibilityElement> bindingExtensors = getExtensors(endpoint.getBinding());
    // check the extensions under <wsdl:binding>
    checkRespectBindingFeature(bindingExtensors);
    Collection<BindingOperationInfo> bindingOperations = endpoint.getBinding().getOperations();
    if (null != bindingOperations) {
        Iterator<BindingOperationInfo> iterator = bindingOperations.iterator();
        while (iterator.hasNext()) {
            BindingOperationInfo operationInfo = iterator.next();
            BindingMessageInfo inputInfo = operationInfo.getInput();
            BindingMessageInfo outputnfo = operationInfo.getOutput();
            Collection<BindingFaultInfo> faults = operationInfo.getFaults();
            // check the extensions under <wsdl:operation>
            checkRespectBindingFeature(getExtensors(operationInfo));
            // check the extensions under <wsdl:input>
            checkRespectBindingFeature(getExtensors(inputInfo));
            // check the extensions under <wsdl:output>
            checkRespectBindingFeature(getExtensors(outputnfo));
            if (null != faults) {
                Iterator<BindingFaultInfo> faultIterator = faults.iterator();
                while (faultIterator.hasNext()) {
                    BindingFaultInfo faultInfo = faultIterator.next();
                    // check the extensions under <wsdl:fault>
                    checkRespectBindingFeature(getExtensors(faultInfo));
                }
            }
        }
    }
    if (hasUsingAddressing(bindingExtensors) || hasUsingAddressing(portExtensors)) {
        WSAddressingFeature feature = new WSAddressingFeature();
        if (addressingRequired(bindingExtensors) || addressingRequired(portExtensors)) {
            feature.setAddressingRequired(true);
        }
        addAddressingFeature(feature);
    }
    extractWsdlEprs(endpoint);
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) WSAddressingFeature(org.apache.cxf.ws.addressing.WSAddressingFeature) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 20 with BindingFaultInfo

use of org.apache.cxf.service.model.BindingFaultInfo in project cxf by apache.

the class MessageModeOutInterceptor method validateFaultDetail.

private void validateFaultDetail(Element detail, Schema schema, BindingOperationInfo bop) throws Exception {
    if (detail != null) {
        Element el = DOMUtils.getFirstElement(detail);
        while (el != null) {
            QName qn = DOMUtils.getElementQName(el);
            for (BindingFaultInfo bfi : bop.getFaults()) {
                if (bfi.getFaultInfo().getMessagePartByIndex(0).getConcreteName().equals(qn)) {
                    // Found a fault with the correct QName, we can validate it
                    schema.newValidator().validate(new DOMSource(DOMUtils.getDomElement(el)));
                }
            }
            el = DOMUtils.getNextElement(el);
        }
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Aggregations

BindingFaultInfo (org.apache.cxf.service.model.BindingFaultInfo)31 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)15 Test (org.junit.Test)13 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)9 QName (javax.xml.namespace.QName)6 BindingInfo (org.apache.cxf.service.model.BindingInfo)5 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)5 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)5 Method (java.lang.reflect.Method)4 Bus (org.apache.cxf.Bus)4 Message (org.apache.cxf.message.Message)4 FaultInfo (org.apache.cxf.service.model.FaultInfo)4 Policy (org.apache.neethi.Policy)4 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)3 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)3 ArrayList (java.util.ArrayList)2 BindingFault (javax.wsdl.BindingFault)2 UnknownExtensibilityElement (javax.wsdl.extensions.UnknownExtensibilityElement)2 Endpoint (org.apache.cxf.endpoint.Endpoint)2 Interceptor (org.apache.cxf.interceptor.Interceptor)2