我希望做到以下几点:
使用带附件的网络请求
转换请求从请求设置内容流所需的请求,转换请求如下所示:
<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>
然后向alfresco发送请求以创建文档。
我的流程看起来像这样:
<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请求时如何向有效负载添加附件?
提前致谢!
答案 0 :(得分:0)
您可以使用Java类添加附件...您需要在 CXF代理服务之前添加自定义处理器并调用Java类。 下一步是在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>
和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 ...当您在SOAP UI中测试时,您会在响应中找到附件文件