Web services 带附件的mule esb代理web服务请求

Web services 带附件的mule esb代理web服务请求,web-services,xslt,cxf,mule,alfresco,Web Services,Xslt,Cxf,Mule,Alfresco,我希望做以下工作: 使用带有附件的web请求 转换请求如果需要从请求中设置contentstream,转换请求如下所示: <ns:contentStream> <!--Optional:--> <ns:length>?</ns:length> <!--Optional:--> <ns:mimeType>?</ns:mimeType>

我希望做以下工作:

使用带有附件的web请求

转换请求如果需要从请求中设置contentstream,转换请求如下所示:

 <ns:contentStream>
        <!--Optional:-->
        <ns:length>?</ns:length>
        <!--Optional:-->
        <ns:mimeType>?</ns:mimeType>
        <!--Optional:-->
        <ns:filename>?</ns:filename>
        <ns:stream>cid:96497346318</ns:stream>
        <!--You may enter ANY elements at this point-->
   </ns:contentStream>
    <flow name="SOAP2SOAPFlow2" doc:name="SOAP-2-SOAP proxy using CXF">
    <http:inbound-endpoint exchange-pattern="request-response" 
        host="localhost" port="8081" path="cc" doc:name="HTTP"/>
    <cxf:proxy-service namespace="urn:greeter:GreeterResponder:1" 
        service="GreeterResponderService" payload="body" 
        wsdlLocation="schemas/interactions/GreeterInteraction/GreeterInteraction_1.0.wsdl" 
        enableMuleSoapHeaders="false" doc:name="SOAP"/>        
<mulexml:xslt-transformer 
        maxIdleTransformers="2" maxActiveTransformers="5" 
        outputEncoding="UTF-8" doc:name="Transform from outer to inner" 
        xsl-file="transform-outer2inner.xslt" encoding="UTF-8" 
        returnClass="java.lang.String"/>
<cxf:proxy-client payload="body" enableMuleSoapHeaders="true"/ >
    <http:outbound-endpoint exchange-pattern="request-response" 
        address="http://localhost:8080/alfresco/cmisws/ObjectService" doc:name="HTTP" />
</flow>
然后向alfresco发送创建文档的请求

我的流程如下所示:

 <ns:contentStream>
        <!--Optional:-->
        <ns:length>?</ns:length>
        <!--Optional:-->
        <ns:mimeType>?</ns:mimeType>
        <!--Optional:-->
        <ns:filename>?</ns:filename>
        <ns:stream>cid:96497346318</ns:stream>
        <!--You may enter ANY elements at this point-->
   </ns:contentStream>
    <flow name="SOAP2SOAPFlow2" doc:name="SOAP-2-SOAP proxy using CXF">
    <http:inbound-endpoint exchange-pattern="request-response" 
        host="localhost" port="8081" path="cc" doc:name="HTTP"/>
    <cxf:proxy-service namespace="urn:greeter:GreeterResponder:1" 
        service="GreeterResponderService" payload="body" 
        wsdlLocation="schemas/interactions/GreeterInteraction/GreeterInteraction_1.0.wsdl" 
        enableMuleSoapHeaders="false" doc:name="SOAP"/>        
<mulexml:xslt-transformer 
        maxIdleTransformers="2" maxActiveTransformers="5" 
        outputEncoding="UTF-8" doc:name="Transform from outer to inner" 
        xsl-file="transform-outer2inner.xslt" encoding="UTF-8" 
        returnClass="java.lang.String"/>
<cxf:proxy-client payload="body" enableMuleSoapHeaders="true"/ >
    <http:outbound-endpoint exchange-pattern="request-response" 
        address="http://localhost:8080/alfresco/cmisws/ObjectService" doc:name="HTTP" />
</flow>
那么,在向Alfresco发送createDocument请求时,如何向负载添加附件呢


提前谢谢

您可以使用Java类添加附件。。。您需要在CXF代理服务和调用Java类之前添加一个自定义处理器。 下一步是在cxf-roxy服务中添加一个cxf:outInterceptors Mule配置如下所示:-

<flow name="SOAP2SOAPFlow2" doc:name="SOAP-2-SOAP proxy using CXF">
    <http:inbound-endpoint exchange-pattern="request-response" 
        host="localhost" port="8081" path="cc" doc:name="HTTP"/>
   <custom-processor class="com.test.services.schema.SOAPOptionalData.AddAttachmentMessageProcessor" doc:name="Custom Processor"/>       

 <cxf:proxy-service namespace="urn:greeter:GreeterResponder:1" 
        service="GreeterResponderService" payload="body" 
        wsdlLocation="schemas/interactions/GreeterInteraction/GreeterInteraction_1.0.wsdl" 
        enableMuleSoapHeaders="false" doc:name="SOAP">   


 <cxf:outInterceptors>
<spring:bean id ="copyAttachment" class="org.mule.module.cxf.support.CopyAttachmentOutInterceptor"/> <!-- SOAP Attachment -->

 </cxf:outInterceptors>
 </cxf:proxy-service>


<mulexml:xslt-transformer 
        maxIdleTransformers="2" maxActiveTransformers="5" 
        outputEncoding="UTF-8" doc:name="Transform from outer to inner" 
        xsl-file="transform-outer2inner.xslt" encoding="UTF-8" 
        returnClass="java.lang.String"/>
<cxf:proxy-client payload="body" enableMuleSoapHeaders="true"/ >
    <http:outbound-endpoint exchange-pattern="request-response" 
        address="http://localhost:8080/alfresco/cmisws/ObjectService" doc:name="HTTP" />
</flow>
java类如下所示,它从属性文件获取附件路径:-

package com.test.services.schema.SOAPOptionalData;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Properties;

import javax.activation.DataSource;

    import org.apache.axiom.attachments.ConfigurableDataHandler;
    import org.apache.cxf.attachment.*;
    import org.apache.cxf.message.Attachment;
    import org.mule.api.MuleEvent;
    import org.mule.api.MuleException;
    import org.mule.api.processor.MessageProcessor;
    import org.mule.module.cxf.CxfConstants;
    import org.mule.util.IOUtils;

    import com.sun.istack.ByteArrayDataSource;
    import com.test.services.schema.maindata.v1.Impl.MainDataImpl;

    public class AddAttachmentMessageProcessor implements MessageProcessor
    {

        Properties prop = new Properties(); //Creating property file object read File attachment path from property file
        InputStream input = null; // To read property file path

        @Override
        public MuleEvent process(MuleEvent event) throws MuleException
        {




            Collection<Attachment> attachments = new ArrayList<Attachment>();

            AttachmentImpl attachment = new AttachmentImpl("1");
            String attachmentXML = "";

            try
            {

              input = getClass().getResourceAsStream("/conf/DBConnectionProp.properties"); // Property file path in classpath
              prop.load(input); // get and load the property file

                attachmentXML = IOUtils.getResourceAsString(prop.getProperty("Attachment_File"), this.getClass());
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }

            DataSource source = new ByteArrayDataSource(attachmentXML.getBytes(), "text/xml");

            attachment.setDataHandler(new ConfigurableDataHandler(source));

            attachments.add(attachment);


            event.getMessage().setInvocationProperty(CxfConstants.ATTACHMENTS, attachments);
            return event;
        }


    }
注意:-请记住根据它修改您的响应XSLT。。。当您在SOAPUI中测试时,您将在响应中找到附件文件