Search in sources :

Example 1 with BindingFaultInfo

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

the class FaultOutInterceptor method getFaultForClass.

/**
 * Find the correct Fault part for a particular exception.
 *
 * @param op
 * @param class1
 */
public FaultInfo getFaultForClass(BindingOperationInfo op, Class<?> class1) {
    FaultInfo selectedFaultInfo = null;
    Class<?> selectedFaultInfoClass = null;
    for (BindingFaultInfo bfi : op.getFaults()) {
        FaultInfo faultInfo = bfi.getFaultInfo();
        Class<?> c = (Class<?>) faultInfo.getProperty(Class.class.getName());
        if (c != null && c.isAssignableFrom(class1) && (selectedFaultInfo == null || (selectedFaultInfoClass != null && selectedFaultInfoClass.isAssignableFrom(c)))) {
            selectedFaultInfo = faultInfo;
            selectedFaultInfoClass = c;
        }
    }
    return selectedFaultInfo;
}
Also used : BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo) FaultInfo(org.apache.cxf.service.model.FaultInfo) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 2 with BindingFaultInfo

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

the class SoapBindingFactory method createSoapBinding.

private void createSoapBinding(final SoapBindingInfo bi) throws WSDLException {
    boolean isSoap12 = bi.getSoapVersion() instanceof Soap12;
    Bus bs = getBus();
    WSDLManager m = bs.getExtension(WSDLManager.class);
    ExtensionRegistry extensionRegistry = m.getExtensionRegistry();
    SoapBinding soapBinding = SOAPBindingUtil.createSoapBinding(extensionRegistry, isSoap12);
    soapBinding.setStyle(bi.getStyle());
    soapBinding.setTransportURI(bi.getTransportURI());
    bi.addExtensor(soapBinding);
    for (BindingOperationInfo b : bi.getOperations()) {
        for (BindingFaultInfo faultInfo : b.getFaults()) {
            SoapFault soapFault = SOAPBindingUtil.createSoapFault(extensionRegistry, isSoap12);
            soapFault.setUse("literal");
            soapFault.setName(faultInfo.getFaultInfo().getFaultName().getLocalPart());
            faultInfo.addExtensor(soapFault);
        }
        SoapOperationInfo soi = b.getExtensor(SoapOperationInfo.class);
        SoapOperation soapOperation = SOAPBindingUtil.createSoapOperation(extensionRegistry, isSoap12);
        soapOperation.setSoapActionURI(soi.getAction());
        soapOperation.setStyle(soi.getStyle());
        boolean isRpc = "rpc".equals(soapOperation.getStyle());
        b.addExtensor(soapOperation);
        if (b.getInput() != null) {
            List<String> bodyParts = null;
            List<SoapHeaderInfo> headerInfos = b.getInput().getExtensors(SoapHeaderInfo.class);
            if (headerInfos != null && !headerInfos.isEmpty()) {
                bodyParts = new ArrayList<>();
                for (MessagePartInfo part : b.getInput().getMessageParts()) {
                    bodyParts.add(part.getName().getLocalPart());
                }
                for (SoapHeaderInfo headerInfo : headerInfos) {
                    SoapHeader soapHeader = SOAPBindingUtil.createSoapHeader(extensionRegistry, BindingInput.class, isSoap12);
                    soapHeader.setMessage(b.getInput().getMessageInfo().getName());
                    soapHeader.setPart(headerInfo.getPart().getName().getLocalPart());
                    soapHeader.setUse("literal");
                    bodyParts.remove(headerInfo.getPart().getName().getLocalPart());
                    headerInfo.getPart().setProperty(HEADER, true);
                    b.getInput().addExtensor(soapHeader);
                }
            }
            SoapBody body = SOAPBindingUtil.createSoapBody(extensionRegistry, BindingInput.class, isSoap12);
            body.setUse("literal");
            if (isRpc) {
                body.setNamespaceURI(b.getName().getNamespaceURI());
            }
            if (bodyParts != null) {
                body.setParts(bodyParts);
            }
            b.getInput().addExtensor(body);
        }
        if (b.getOutput() != null) {
            List<String> bodyParts = null;
            List<SoapHeaderInfo> headerInfos = b.getOutput().getExtensors(SoapHeaderInfo.class);
            if (headerInfos != null && !headerInfos.isEmpty()) {
                bodyParts = new ArrayList<>();
                for (MessagePartInfo part : b.getOutput().getMessageParts()) {
                    bodyParts.add(part.getName().getLocalPart());
                }
                for (SoapHeaderInfo headerInfo : headerInfos) {
                    SoapHeader soapHeader = SOAPBindingUtil.createSoapHeader(extensionRegistry, BindingOutput.class, isSoap12);
                    soapHeader.setMessage(b.getOutput().getMessageInfo().getName());
                    soapHeader.setPart(headerInfo.getPart().getName().getLocalPart());
                    soapHeader.setUse("literal");
                    bodyParts.remove(headerInfo.getPart().getName().getLocalPart());
                    b.getOutput().addExtensor(soapHeader);
                }
            }
            SoapBody body = SOAPBindingUtil.createSoapBody(extensionRegistry, BindingOutput.class, isSoap12);
            body.setUse("literal");
            if (isRpc) {
                body.setNamespaceURI(b.getName().getNamespaceURI());
            }
            if (bodyParts != null) {
                body.setParts(bodyParts);
            }
            b.getOutput().addExtensor(body);
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapFault(org.apache.cxf.binding.soap.wsdl.extensions.SoapFault) SoapHeaderInfo(org.apache.cxf.binding.soap.model.SoapHeaderInfo) SoapBody(org.apache.cxf.binding.soap.wsdl.extensions.SoapBody) SoapOperation(org.apache.cxf.binding.soap.wsdl.extensions.SoapOperation) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding) ExtensionRegistry(javax.wsdl.extensions.ExtensionRegistry) WSDLManager(org.apache.cxf.wsdl.WSDLManager) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) SoapHeader(org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 3 with BindingFaultInfo

use of org.apache.cxf.service.model.BindingFaultInfo 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 4 with BindingFaultInfo

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

the class ServiceWSDLBuilder method buildBindingFault.

protected void buildBindingFault(Definition def, BindingOperation bindingOperation, Collection<BindingFaultInfo> bindingFaultInfos) {
    for (BindingFaultInfo bindingFaultInfo : bindingFaultInfos) {
        final BindingFault bindingFault = def.createBindingFault();
        addDocumentation(bindingFault, bindingFaultInfo.getDocumentation());
        bindingFault.setName(bindingFaultInfo.getFaultInfo().getFaultName().getLocalPart());
        bindingOperation.addBindingFault(bindingFault);
        addExtensibilityAttributes(def, bindingFault, bindingFaultInfo.getExtensionAttributes());
        addExtensibilityElements(def, bindingFault, getWSDL11Extensors(bindingFaultInfo));
    }
}
Also used : BindingFault(javax.wsdl.BindingFault) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 5 with BindingFaultInfo

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

the class WSDLServiceBuilderTest method assertBindingOperationMessageExtensions.

private void assertBindingOperationMessageExtensions(BindingOperationInfo boi, boolean expectExtensions, boolean hasOutput, QName fault) {
    BindingMessageInfo bmi = boi.getInput();
    if (expectExtensions) {
        // REVISIT: bug in wsdl4j?
        // getExtensionAttributes on binding/operation/input element returns an empty map
        // assertEquals(1, bmi.getExtensionAttributes().size());
        // assertNotNull(bmi.getExtensionAttribute(EXTENSION_ATTR_STRING));
        assertEquals(1, bmi.getExtensors(UnknownExtensibilityElement.class).size());
        assertEquals(EXTENSION_ELEM, bmi.getExtensor(UnknownExtensibilityElement.class).getElementType());
    } else {
        assertNull(bmi.getExtensionAttributes());
        assertNull(bmi.getExtensionAttribute(EXTENSION_ATTR_STRING));
        assertEquals(0, bmi.getExtensors(UnknownExtensibilityElement.class).size());
        assertNull(bmi.getExtensor(UnknownExtensibilityElement.class));
    }
    if (hasOutput) {
        bmi = boi.getOutput();
        if (expectExtensions) {
            // REVISIT: bug in wsdl4j?
            // getExtensionAttributes on binding/operation/output element returns an empty map
            // assertEquals(1, bmi.getExtensionAttributes().size());
            // assertNotNull(bmi.getExtensionAttribute(EXTENSION_ATTR_STRING));
            assertEquals(1, bmi.getExtensors(UnknownExtensibilityElement.class).size());
            assertEquals(EXTENSION_ELEM, bmi.getExtensor(UnknownExtensibilityElement.class).getElementType());
        } else {
            assertNull(bmi.getExtensionAttributes());
            assertNull(bmi.getExtensionAttribute(EXTENSION_ATTR_STRING));
            assertEquals(0, bmi.getExtensors(UnknownExtensibilityElement.class).size());
            assertNull(bmi.getExtensor(UnknownExtensibilityElement.class));
        }
    }
    if (null != fault) {
        BindingFaultInfo bfi = boi.getFault(fault);
        if (expectExtensions) {
            assertEquals(1, bfi.getExtensionAttributes().size());
            assertNotNull(bfi.getExtensionAttribute(EXTENSION_ATTR_STRING));
            assertEquals(1, bfi.getExtensors(UnknownExtensibilityElement.class).size());
            assertEquals(EXTENSION_ELEM, bfi.getExtensor(UnknownExtensibilityElement.class).getElementType());
        } else {
            assertNull(bfi.getExtensionAttributes());
            assertNull(bfi.getExtensionAttribute(EXTENSION_ATTR_STRING));
            assertNull(bfi.getExtensors(UnknownExtensibilityElement.class));
            assertNull(bfi.getExtensor(UnknownExtensibilityElement.class));
        }
    }
}
Also used : BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) 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