added Apache Axis2 interop tests (including own SwA service
implementation and deployable service archives for all tests)
This commit is contained in:
38
tests/AxisInterop/SwA/build.xml
Normal file
38
tests/AxisInterop/SwA/build.xml
Normal file
@ -0,0 +1,38 @@
|
||||
<project name="BeSimpleSwaService" default="generate.service">
|
||||
<property environment="env" />
|
||||
<property name="axis2.home" value="C:/axis2" />
|
||||
<property name="axis2.repo" value="${axis2.home}/repository" />
|
||||
<property name="build.dir" value="build" />
|
||||
<property name="filename" value="besimple-swa.aar" />
|
||||
|
||||
<path id="axis.classpath">
|
||||
<fileset dir="${axis2.home}/lib">
|
||||
<include name="*.jar" />
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<target name="generate.service" depends="compile">
|
||||
<jar destfile="${build.dir}/${filename}">
|
||||
<fileset dir="resources/">
|
||||
<include name="META-INF/services.xml" />
|
||||
</fileset>
|
||||
<fileset dir="${build.dir}/classes">
|
||||
<include name="besimple/service/**/*.class" />
|
||||
</fileset>
|
||||
</jar>
|
||||
<copy file="${build.dir}/${filename}" tofile="../axis_services/${filename}" overwrite="true" />
|
||||
<copy file="${build.dir}/${filename}" tofile="${axis2.repo}/services/${filename}" overwrite="true" />
|
||||
<antcall target="clean" />
|
||||
</target>
|
||||
|
||||
<target name="compile">
|
||||
<mkdir dir="${build.dir}/classes" />
|
||||
<javac debug="on" srcdir="src" destdir="${build.dir}/classes">
|
||||
<classpath refid="axis.classpath" />
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="${build.dir}" />
|
||||
</target>
|
||||
</project>
|
15
tests/AxisInterop/SwA/resources/META-INF/services.xml
Normal file
15
tests/AxisInterop/SwA/resources/META-INF/services.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<serviceGroup>
|
||||
<service name="BeSimpleSwaService">
|
||||
<description>BeSimple test service for SwA.</description>
|
||||
<parameter name="enableSwA">true</parameter>
|
||||
<parameter name="ServiceClass" locked="false">besimple.service.BeSimpleSwaService</parameter>
|
||||
<operation name="uploadFile">
|
||||
<actionMapping>urn:uploadFile</actionMapping>
|
||||
<messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
|
||||
</operation>
|
||||
<operation name="downloadFile">
|
||||
<actionMapping>urn:downloadFile</actionMapping>
|
||||
<messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
|
||||
</operation>
|
||||
</service>
|
||||
</serviceGroup>
|
@ -0,0 +1,78 @@
|
||||
package besimple.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.activation.FileDataSource;
|
||||
|
||||
import org.apache.axiom.attachments.Attachments;
|
||||
import org.apache.axiom.om.OMAbstractFactory;
|
||||
import org.apache.axiom.om.OMAttribute;
|
||||
import org.apache.axiom.om.OMElement;
|
||||
import org.apache.axiom.om.OMFactory;
|
||||
import org.apache.axiom.om.OMNamespace;
|
||||
|
||||
import org.apache.axis2.context.MessageContext;
|
||||
import org.apache.axis2.context.OperationContext;
|
||||
import org.apache.axis2.wsdl.WSDLConstants;
|
||||
|
||||
public class BeSimpleSwaService {
|
||||
|
||||
String namespace = "http://service.besimple";
|
||||
|
||||
public OMElement uploadFile(OMElement element) throws Exception {
|
||||
OMElement dataElement = (OMElement)element.getFirstChildWithName(new QName(namespace, "data"));
|
||||
OMAttribute hrefAttribute = dataElement.getAttribute(new QName("href"));
|
||||
|
||||
String contentID = hrefAttribute.getAttributeValue();
|
||||
contentID = contentID.trim();
|
||||
if (contentID.substring(0, 3).equalsIgnoreCase("cid")) {
|
||||
contentID = contentID.substring(4);
|
||||
}
|
||||
OMElement nameElement = (OMElement)element.getFirstChildWithName(new QName(namespace, "name"));
|
||||
String name = nameElement.getText();
|
||||
|
||||
MessageContext msgCtx = MessageContext.getCurrentMessageContext();
|
||||
Attachments attachment = msgCtx.getAttachmentMap();
|
||||
DataHandler dataHandler = attachment.getDataHandler(contentID);
|
||||
|
||||
File file = new File(name);
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(file);
|
||||
dataHandler.writeTo(fileOutputStream);
|
||||
fileOutputStream.flush();
|
||||
fileOutputStream.close();
|
||||
|
||||
OMFactory factory = OMAbstractFactory.getOMFactory();
|
||||
OMNamespace omNs = factory.createOMNamespace(namespace, "swa");
|
||||
OMElement wrapperElement = factory.createOMElement("uploadFileResponse", omNs);
|
||||
OMElement returnElement = factory.createOMElement("return", omNs, wrapperElement);
|
||||
returnElement.setText("File saved succesfully.");
|
||||
|
||||
return wrapperElement;
|
||||
}
|
||||
|
||||
public OMElement downloadFile(OMElement element) throws Exception {
|
||||
OMElement nameElement = (OMElement)element.getFirstChildWithName(new QName(namespace, "name"));
|
||||
String name = nameElement.getText();
|
||||
|
||||
MessageContext msgCtxIn = MessageContext.getCurrentMessageContext();
|
||||
OperationContext operationContext = msgCtxIn.getOperationContext();
|
||||
MessageContext msgCtxOut = operationContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
|
||||
|
||||
FileDataSource fileDataSource = new FileDataSource(name);
|
||||
DataHandler dataHandler = new DataHandler(fileDataSource);
|
||||
|
||||
String contentID = "cid:" + msgCtxOut.addAttachment(dataHandler);
|
||||
|
||||
OMFactory factory = OMAbstractFactory.getOMFactory();
|
||||
OMNamespace omNs = factory.createOMNamespace(namespace, "swa");
|
||||
OMElement wrapperElement = factory.createOMElement("downloadFileResponse", omNs);
|
||||
OMElement dataElement = factory.createOMElement("data", omNs, wrapperElement);
|
||||
dataElement.addAttribute("href", contentID, null);
|
||||
|
||||
return wrapperElement;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user