简体   繁体   English

带附件的Mule ESB代理Web服务请求

[英]mule esb proxy web services request with attachment

I am looking to to do the following: 我希望执行以下操作:

Consume a web request with attachments 使用带有附件的Web请求

transform the request where it requires to set the contentstream from the request, the transformation request looks like this: 在需要根据请求设置内容流的地方转换请求,转换请求如下所示:

 <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>

and then send a request to alfresco to create a document. 然后向露天发送请求以创建文档。

my flow looks something like this: 我的流程看起来像这样:

    <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>

so how do I add attachments to the payload when sending a request to createDocument to Alfresco? 那么在向Alfresco发送cr​​eateDocument请求时,如何向有效负载添加附件?

Thanks in advance! 提前致谢!

You can add Attachment by using Java class ... You need to add add a Custom Processor before CXF proxy-service and calling a Java class. 您可以使用Java类来添加附件。您需要 CXF代理服务和调用Java类之前添加添加自定义处理器。 And next step is to add a cxf:outInterceptors in CXF roxy-service The Mule config is following :- 下一步是在CXF roxy-service中添加一个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>

and the java class is as follows, It takes the attachment path from properties file :- 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;
        }


    }

Note :- just remember to modify your response XSLT according to it ... When you test in SOAP UI , you will find attachment file in response 注意:-只需记住根据它修改您的响应XSLT ...在SOAP UI中进行测试时,您会在响应中找到附件文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM