Search in sources :

Example 1 with BareOutInterceptor

use of org.apache.cxf.wsdl.interceptors.BareOutInterceptor in project cxf by apache.

the class XMLMessageOutInterceptor method handleMessage.

public void handleMessage(Message message) throws Fault {
    BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();
    MessageInfo mi;
    BindingMessageInfo bmi;
    if (isRequestor(message)) {
        mi = boi.getOperationInfo().getInput();
        bmi = boi.getInput();
    } else {
        mi = boi.getOperationInfo().getOutput();
        bmi = boi.getOutput();
    }
    XMLBindingMessageFormat xmf = bmi.getExtensor(XMLBindingMessageFormat.class);
    QName rootInModel = null;
    if (xmf != null) {
        rootInModel = xmf.getRootNode();
    }
    final int mpn = mi.getMessagePartsNumber();
    if (boi.isUnwrapped() || mpn == 1) {
        // wrapper out interceptor created the wrapper
        // or if bare-one-param
        new BareOutInterceptor().handleMessage(message);
    } else {
        if (rootInModel == null) {
            rootInModel = boi.getName();
        }
        if (mpn == 0 && !boi.isUnwrapped()) {
            // write empty operation qname
            writeMessage(message, rootInModel, false);
        } else {
            // multi param, bare mode, needs write root node
            writeMessage(message, rootInModel, true);
        }
    }
    // in the end we do flush ;)
    XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
    try {
        writer.flush();
    } catch (XMLStreamException e) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE, e));
    }
}
Also used : BareOutInterceptor(org.apache.cxf.wsdl.interceptors.BareOutInterceptor) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.message.Message) QName(javax.xml.namespace.QName) Fault(org.apache.cxf.interceptor.Fault) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) XMLStreamException(javax.xml.stream.XMLStreamException) XMLBindingMessageFormat(org.apache.cxf.bindings.xformat.XMLBindingMessageFormat) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 2 with BareOutInterceptor

use of org.apache.cxf.wsdl.interceptors.BareOutInterceptor in project cxf by apache.

the class CorbaBindingFactory method createBinding.

public Binding createBinding(BindingInfo bindingInfo) {
    CorbaBinding binding = new CorbaBinding();
    binding.getInFaultInterceptors().add(new CorbaStreamFaultInInterceptor());
    binding.getOutFaultInterceptors().add(new CorbaStreamFaultOutInterceptor());
    binding.getOutInterceptors().add(new BareOutInterceptor());
    binding.getOutInterceptors().add(new CorbaStreamOutInterceptor());
    binding.getInInterceptors().add(new BareInInterceptor());
    binding.getInInterceptors().add(new CorbaStreamInInterceptor());
    binding.setBindingInfo(bindingInfo);
    return binding;
}
Also used : BareOutInterceptor(org.apache.cxf.wsdl.interceptors.BareOutInterceptor) CorbaStreamInInterceptor(org.apache.cxf.binding.corba.interceptors.CorbaStreamInInterceptor) CorbaStreamFaultInInterceptor(org.apache.cxf.binding.corba.interceptors.CorbaStreamFaultInInterceptor) CorbaStreamFaultOutInterceptor(org.apache.cxf.binding.corba.interceptors.CorbaStreamFaultOutInterceptor) CorbaStreamOutInterceptor(org.apache.cxf.binding.corba.interceptors.CorbaStreamOutInterceptor) BareInInterceptor(org.apache.cxf.wsdl.interceptors.BareInInterceptor)

Example 3 with BareOutInterceptor

use of org.apache.cxf.wsdl.interceptors.BareOutInterceptor in project cxf by apache.

the class SoapBindingFactory method createBinding.

public Binding createBinding(BindingInfo binding) {
    // The default style should be doc-lit wrapped.
    String parameterStyle = SoapBindingConstants.PARAMETER_STYLE_WRAPPED;
    String bindingStyle = SoapBindingConstants.BINDING_STYLE_DOC;
    boolean hasWrapped = false;
    final org.apache.cxf.binding.soap.SoapBinding sb;
    final SoapVersion version;
    if (binding instanceof SoapBindingInfo) {
        SoapBindingInfo sbi = (SoapBindingInfo) binding;
        version = sbi.getSoapVersion();
        sb = new org.apache.cxf.binding.soap.SoapBinding(binding, version);
        // Service wide style
        if (!StringUtils.isEmpty(sbi.getStyle())) {
            bindingStyle = sbi.getStyle();
        }
        boolean hasRPC = false;
        boolean hasDoc = false;
        // Operation wide style, what to do with the mixed style/use?
        for (BindingOperationInfo boi : sbi.getOperations()) {
            String st = sbi.getStyle(boi.getOperationInfo());
            if (st != null) {
                bindingStyle = st;
                if (SoapBindingConstants.BINDING_STYLE_RPC.equalsIgnoreCase(st)) {
                    hasRPC = true;
                } else {
                    hasDoc = true;
                }
            }
            if (boi.getUnwrappedOperation() == null) {
                parameterStyle = SoapBindingConstants.PARAMETER_STYLE_BARE;
            } else {
                hasWrapped = true;
            }
        }
        if (Boolean.TRUE.equals(binding.getService().getProperty("soap.force.doclit.bare"))) {
            hasDoc = true;
            hasRPC = false;
            parameterStyle = SoapBindingConstants.PARAMETER_STYLE_BARE;
            bindingStyle = SoapBindingConstants.BINDING_STYLE_DOC;
        }
        if (hasRPC && hasDoc) {
            throw new RuntimeException("WSI-BP prohibits RPC and Document style " + "operations in same service.");
        }
        // jms
        if (sbi.getTransportURI().equals(SoapJMSConstants.SOAP_JMS_SPECIFICIATION_TRANSPORTID)) {
            sb.getInInterceptors().add(new SoapJMSInInterceptor());
        }
    } else {
        throw new RuntimeException("Can not initialize SoapBinding, BindingInfo is not SoapBindingInfo");
    }
    sb.getOutFaultInterceptors().add(new StaxOutInterceptor());
    sb.getOutFaultInterceptors().add(new SoapOutInterceptor(getBus()));
    sb.getOutFaultInterceptors().add(new AttachmentOutInterceptor());
    sb.getInInterceptors().add(new AttachmentInInterceptor());
    sb.getInInterceptors().add(new StaxInInterceptor());
    sb.getInInterceptors().add(new SoapActionInInterceptor());
    sb.getOutInterceptors().add(new AttachmentOutInterceptor());
    sb.getOutInterceptors().add(new StaxOutInterceptor());
    sb.getOutInterceptors().add(SoapHeaderOutFilterInterceptor.INSTANCE);
    if (SoapBindingConstants.BINDING_STYLE_RPC.equalsIgnoreCase(bindingStyle)) {
        sb.getInInterceptors().add(new RPCInInterceptor());
        sb.getOutInterceptors().add(new RPCOutInterceptor());
    } else if (SoapBindingConstants.BINDING_STYLE_DOC.equalsIgnoreCase(bindingStyle) && SoapBindingConstants.PARAMETER_STYLE_BARE.equalsIgnoreCase(parameterStyle)) {
        // sb.getInInterceptors().add(new BareInInterceptor());
        sb.getInInterceptors().add(new DocLiteralInInterceptor());
        if (hasWrapped) {
            sb.getOutInterceptors().add(new WrappedOutInterceptor());
        }
        sb.getOutInterceptors().add(new BareOutInterceptor());
    } else {
        // sb.getInInterceptors().add(new WrappedInInterceptor());
        sb.getInInterceptors().add(new DocLiteralInInterceptor());
        sb.getOutInterceptors().add(new WrappedOutInterceptor());
        sb.getOutInterceptors().add(new BareOutInterceptor());
    }
    sb.getInInterceptors().add(new SoapHeaderInterceptor());
    sb.getInInterceptors().add(new ReadHeadersInterceptor(getBus(), version));
    sb.getInInterceptors().add(new StartBodyInterceptor());
    sb.getInInterceptors().add(new CheckFaultInterceptor());
    sb.getInInterceptors().add(new MustUnderstandInterceptor());
    sb.getOutInterceptors().add(new SoapPreProtocolOutInterceptor());
    sb.getOutInterceptors().add(new SoapOutInterceptor(getBus()));
    sb.getOutFaultInterceptors().add(new SoapOutInterceptor(getBus()));
    sb.getOutFaultInterceptors().add(SoapHeaderOutFilterInterceptor.INSTANCE);
    if (version.getVersion() == 1.1) {
        sb.getInFaultInterceptors().add(new Soap11FaultInInterceptor());
        sb.getOutFaultInterceptors().add(new Soap11FaultOutInterceptor());
    } else if (version.getVersion() == 1.2) {
        sb.getInFaultInterceptors().add(new Soap12FaultInInterceptor());
        sb.getOutFaultInterceptors().add(new Soap12FaultOutInterceptor());
    }
    if (binding.getService() != null) {
        for (EndpointInfo ei : binding.getService().getEndpoints()) {
            if (ei.getAddress() != null && ei.getAddress().startsWith("soap.udp")) {
                setupUDP(sb, ei);
            }
        }
    }
    return sb;
}
Also used : BareOutInterceptor(org.apache.cxf.wsdl.interceptors.BareOutInterceptor) ReadHeadersInterceptor(org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor) CheckFaultInterceptor(org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor) StaxOutInterceptor(org.apache.cxf.interceptor.StaxOutInterceptor) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapHeaderInterceptor(org.apache.cxf.binding.soap.interceptor.SoapHeaderInterceptor) RPCOutInterceptor(org.apache.cxf.binding.soap.interceptor.RPCOutInterceptor) Soap12FaultInInterceptor(org.apache.cxf.binding.soap.interceptor.Soap12FaultInInterceptor) WrappedOutInterceptor(org.apache.cxf.wsdl.interceptors.WrappedOutInterceptor) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) AttachmentInInterceptor(org.apache.cxf.interceptor.AttachmentInInterceptor) SoapJMSInInterceptor(org.apache.cxf.binding.soap.jms.interceptor.SoapJMSInInterceptor) DocLiteralInInterceptor(org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor) RPCInInterceptor(org.apache.cxf.binding.soap.interceptor.RPCInInterceptor) Soap11FaultInInterceptor(org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor) SoapOutInterceptor(org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor) SoapPreProtocolOutInterceptor(org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor) StaxInInterceptor(org.apache.cxf.interceptor.StaxInInterceptor) MustUnderstandInterceptor(org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor) Soap12FaultOutInterceptor(org.apache.cxf.binding.soap.interceptor.Soap12FaultOutInterceptor) StartBodyInterceptor(org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor) Soap11FaultOutInterceptor(org.apache.cxf.binding.soap.interceptor.Soap11FaultOutInterceptor) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapActionInInterceptor(org.apache.cxf.binding.soap.interceptor.SoapActionInInterceptor) AttachmentOutInterceptor(org.apache.cxf.interceptor.AttachmentOutInterceptor)

Example 4 with BareOutInterceptor

use of org.apache.cxf.wsdl.interceptors.BareOutInterceptor in project cxf by apache.

the class XMLMessageOutInterceptor method writeMessage.

private void writeMessage(Message message, QName name, boolean executeBare) {
    XMLStreamWriter xmlWriter = message.getContent(XMLStreamWriter.class);
    try {
        String pfx = name.getPrefix();
        if (StringUtils.isEmpty(pfx)) {
            pfx = "ns1";
        }
        StaxUtils.writeStartElement(xmlWriter, pfx, name.getLocalPart(), name.getNamespaceURI());
        if (executeBare) {
            new BareOutInterceptor().handleMessage(message);
        }
        xmlWriter.writeEndElement();
    } catch (XMLStreamException e) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE, e));
    }
}
Also used : BareOutInterceptor(org.apache.cxf.wsdl.interceptors.BareOutInterceptor) XMLStreamException(javax.xml.stream.XMLStreamException) Message(org.apache.cxf.message.Message) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) Fault(org.apache.cxf.interceptor.Fault)

Example 5 with BareOutInterceptor

use of org.apache.cxf.wsdl.interceptors.BareOutInterceptor in project cxf by apache.

the class BareOutInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    interceptor = new BareOutInterceptor();
    baos = new ByteArrayOutputStream();
    writer = getXMLStreamWriter(baos);
    message.setContent(XMLStreamWriter.class, writer);
    message.getExchange().put(BindingOperationInfo.class, operation);
    IMocksControl control = EasyMock.createNiceControl();
    InterceptorChain ic = control.createMock(InterceptorChain.class);
    message.setInterceptorChain(ic);
    control.replay();
}
Also used : BareOutInterceptor(org.apache.cxf.wsdl.interceptors.BareOutInterceptor) IMocksControl(org.easymock.IMocksControl) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Before(org.junit.Before)

Aggregations

BareOutInterceptor (org.apache.cxf.wsdl.interceptors.BareOutInterceptor)5 XMLStreamException (javax.xml.stream.XMLStreamException)2 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)2 Fault (org.apache.cxf.interceptor.Fault)2 Message (org.apache.cxf.message.Message)2 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 QName (javax.xml.namespace.QName)1 CorbaStreamFaultInInterceptor (org.apache.cxf.binding.corba.interceptors.CorbaStreamFaultInInterceptor)1 CorbaStreamFaultOutInterceptor (org.apache.cxf.binding.corba.interceptors.CorbaStreamFaultOutInterceptor)1 CorbaStreamInInterceptor (org.apache.cxf.binding.corba.interceptors.CorbaStreamInInterceptor)1 CorbaStreamOutInterceptor (org.apache.cxf.binding.corba.interceptors.CorbaStreamOutInterceptor)1 CheckFaultInterceptor (org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor)1 MustUnderstandInterceptor (org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor)1 RPCInInterceptor (org.apache.cxf.binding.soap.interceptor.RPCInInterceptor)1 RPCOutInterceptor (org.apache.cxf.binding.soap.interceptor.RPCOutInterceptor)1 ReadHeadersInterceptor (org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor)1 Soap11FaultInInterceptor (org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor)1 Soap11FaultOutInterceptor (org.apache.cxf.binding.soap.interceptor.Soap11FaultOutInterceptor)1 Soap12FaultInInterceptor (org.apache.cxf.binding.soap.interceptor.Soap12FaultInInterceptor)1