You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by as...@apache.org on 2007/08/24 10:28:54 UTC
svn commit: r569292 - in
/webservices/synapse/trunk/java/modules/transports/src:
main/java/org/apache/axis2/transport/base/
main/java/org/apache/axis2/transport/vfs/ test/ test/java/ test/java/org/
test/java/org/apache/ test/java/org/apache/axis2/ test...
Author: asankha
Date: Fri Aug 24 01:28:53 2007
New Revision: 569292
URL: http://svn.apache.org/viewvc?rev=569292&view=rev
Log:
add unit tests to VFS transport.. more to follow
Added:
webservices/synapse/trunk/java/modules/transports/src/test/
webservices/synapse/trunk/java/modules/transports/src/test/java/
webservices/synapse/trunk/java/modules/transports/src/test/java/org/
webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/
webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/
webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/
webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/AbstractTransportTest.java
webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/Echo.java
webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/UtilsTransportServer.java
webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/vfs/
webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/vfs/UtilsVFSServer.java
webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/vfs/VFSEchoRawXMLTest.java
webservices/synapse/trunk/java/modules/transports/src/test/resources/
Modified:
webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/base/BaseUtils.java
webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/PollTableEntry.java
webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSConstants.java
webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSOutTransportInfo.java
webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSTransportListener.java
webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSTransportSender.java
webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSUtils.java
Modified: webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/base/BaseUtils.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/base/BaseUtils.java?rev=569292&r1=569291&r2=569292&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/base/BaseUtils.java (original)
+++ webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/base/BaseUtils.java Fri Aug 24 01:28:53 2007
@@ -338,13 +338,22 @@
return (str != null && str.trim().length() > 0);
}
- public static String getServiceParam(AxisService service, String paramName) throws AxisFault {
+ public static String getRequiredServiceParam(AxisService service, String paramName) throws AxisFault {
Parameter param = service.getParameter(paramName);
if (param != null && param.getValue() != null && param.getValue() instanceof String) {
return (String) param.getValue();
} else {
throw new AxisFault("Cannot find parameter : " + paramName +
" for service : " + service.getName());
+ }
+ }
+
+ public static String getOptionalServiceParam(AxisService service, String paramName) throws AxisFault {
+ Parameter param = service.getParameter(paramName);
+ if (param != null && param.getValue() != null && param.getValue() instanceof String) {
+ return (String) param.getValue();
+ } else {
+ return null;
}
}
Modified: webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/PollTableEntry.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/PollTableEntry.java?rev=569292&r1=569291&r2=569292&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/PollTableEntry.java (original)
+++ webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/PollTableEntry.java Fri Aug 24 01:28:53 2007
@@ -78,7 +78,11 @@
}
public void setFileURI(String fileURI) {
- this.fileURI = fileURI;
+ if (fileURI.startsWith(VFSConstants.VFS_PREFIX)) {
+ this.fileURI = fileURI.substring(VFSConstants.VFS_PREFIX.length());
+ } else {
+ this.fileURI = fileURI;
+ }
}
public String getFileNamePattern() {
Modified: webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSConstants.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSConstants.java?rev=569292&r1=569291&r2=569292&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSConstants.java (original)
+++ webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSConstants.java Fri Aug 24 01:28:53 2007
@@ -20,6 +20,9 @@
package org.apache.axis2.transport.vfs;
public class VFSConstants {
+ // vfs transport prefix (e.g. used in an out EPR etc)
+ public static final String VFS_PREFIX = "vfs:";
+
public static final String TRANSPORT_FILE_ACTION_AFTER_PROCESS = "transport.vfs.ActionAfterProcess";
public static final String TRANSPORT_FILE_ACTION_AFTER_ERRORS = "transport.vfs.ActionAfterErrors";
public static final String TRANSPORT_FILE_ACTION_AFTER_FAILURE = "transport.vfs.ActionAfterFailure";
Modified: webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSOutTransportInfo.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSOutTransportInfo.java?rev=569292&r1=569291&r2=569292&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSOutTransportInfo.java (original)
+++ webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSOutTransportInfo.java Fri Aug 24 01:28:53 2007
@@ -32,23 +32,27 @@
private static final Log log = LogFactory.getLog(VFSOutTransportInfo.class);
- private String replyFileURI = null;
- private String replyFileName = null;
+ private String outFileURI = null;
+ private String outFileName = null;
private String contentType = null;
- VFSOutTransportInfo(String replyFileURI) {
- this.replyFileURI = replyFileURI;
+ VFSOutTransportInfo(String outFileURI) {
+ if (outFileURI.startsWith(VFSConstants.VFS_PREFIX)) {
+ this.outFileURI = outFileURI.substring(VFSConstants.VFS_PREFIX.length());
+ } else {
+ this.outFileURI = outFileURI;
+ }
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
- public String getReplyFileURI() {
- return replyFileURI;
+ public String getOutFileURI() {
+ return outFileURI;
}
- public String getReplyFileName() {
- return replyFileName;
+ public String getOutFileName() {
+ return outFileName;
}
}
Modified: webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSTransportListener.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSTransportListener.java?rev=569292&r1=569291&r2=569292&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSTransportListener.java (original)
+++ webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSTransportListener.java Fri Aug 24 01:28:53 2007
@@ -18,17 +18,13 @@
*/
package org.apache.axis2.transport.vfs;
-import org.apache.axis2.transport.base.AbstractTransportListener;
import org.apache.axis2.transport.base.BaseConstants;
import org.apache.axis2.transport.base.BaseUtils;
import org.apache.axis2.transport.base.AbstractPollingTransportListener;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
-import org.apache.axis2.description.TransportInDescription;
-import org.apache.axis2.description.Parameter;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.*;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.commons.vfs.*;
@@ -71,16 +67,19 @@
*
* services.xml - service attachment
* required parameters
- * <parameter name="transport.file.FileURI" locked="true">..</parameter>
- * <parameter name="transport.file.FileNamePattern" locked="true">..</parameter>
+ * <parameter name="transport.vfs.FileURI">..</parameter>
+ * <parameter name="transport.vfs.ContentType">..</parameter>
*
* optional parameters
- * <parameter name="transport.file.ContentType" locked="true">..</parameter>
- * <parameter name="transport.PollInterval" locked="true">..</parameter>
+ * <parameter name="transport.vfs.FileNamePattern">..</parameter>
+ * <parameter name="transport.PollInterval">..</parameter>
+ *
+ * <parameter name="transport.vfs.ActionAfterProcess">..</parameter>
+ * <parameter name="transport.vfs.ActionAfterErrors" >..</parameter>
+ * <parameter name="transport.vfs.ActionAfterFailure">..</parameter>
*
- * <parameter name="transport.file.ActionAfterProcess" locked="true">..</parameter>
- * <parameter name="transport.file.ActionAfterErrors" locked="true">..</parameter>
- * <parameter name="transport.file.ActionAfterFailure" locked="true">..</parameter>
+ * <parameter name="transport.vfs.ReplyFileURI" >..</parameter>
+ * <parameter name="transport.vfs.ReplyFileName">..</parameter>
*/
public class VFSTransportListener extends AbstractPollingTransportListener {
@@ -182,7 +181,7 @@
processFile(entry, children[i]);
successCount++;
} catch (Exception e) {
- logException("Error processing file : " + entry.getFileURI(), e);
+ logException("Error processing File URI : " + entry.getFileURI(), e);
failCount++;
}
}
@@ -254,7 +253,25 @@
}
} else {
try {
- fileObject.delete();
+ fileObject.close();
+ if (fileObject.getChildren().length > 0) {
+ if (fileObject.delete(new FileSelector() {
+
+ public boolean includeFile(FileSelectInfo fileSelectInfo) throws Exception {
+ return true;
+ }
+
+ public boolean traverseDescendents(FileSelectInfo fileSelectInfo) throws Exception {
+ return true;
+ }
+ }) == 0) {
+ log.error("Error deleting file : " + fileObject);
+ }
+ } else {
+ if (!fileObject.delete()) {
+ log.error("Error deleting file : " + fileObject);
+ }
+ }
} catch (FileSystemException e) {
log.error("Error deleting file : " + fileObject, e);
}
@@ -355,6 +372,13 @@
} catch (FileSystemException e) {
handleException("Error reading file content or attributes : " + file, e);
+
+ } finally {
+ try {
+ file.close();
+ } catch (FileSystemException warn) {
+ log.warn("Cannot close file after processing : " + file.getName().getPath(), warn);
+ }
}
}
@@ -411,20 +435,20 @@
PollTableEntry entry = new PollTableEntry();
try {
entry.setFileURI(
- BaseUtils.getServiceParam(service, VFSConstants.TRANSPORT_FILE_FILE_URI));
+ BaseUtils.getRequiredServiceParam(service, VFSConstants.TRANSPORT_FILE_FILE_URI));
entry.setFileNamePattern(
- BaseUtils.getServiceParam(service, VFSConstants.TRANSPORT_FILE_FILE_NAME_PATTERN));
+ BaseUtils.getOptionalServiceParam(service, VFSConstants.TRANSPORT_FILE_FILE_NAME_PATTERN));
entry.setContentType(
- BaseUtils.getServiceParam(service, VFSConstants.TRANSPORT_FILE_CONTENT_TYPE));
- String option = BaseUtils.getServiceParam(
+ BaseUtils.getRequiredServiceParam(service, VFSConstants.TRANSPORT_FILE_CONTENT_TYPE));
+ String option = BaseUtils.getOptionalServiceParam(
service, VFSConstants.TRANSPORT_FILE_ACTION_AFTER_PROCESS);
entry.setActionAfterProcess(
MOVE.equals(option) ? PollTableEntry.MOVE : PollTableEntry.DELETE);
- option = BaseUtils.getServiceParam(
+ option = BaseUtils.getOptionalServiceParam(
service, VFSConstants.TRANSPORT_FILE_ACTION_AFTER_ERRORS);
entry.setActionAfterErrors(
MOVE.equals(option) ? PollTableEntry.MOVE : PollTableEntry.DELETE);
- option = BaseUtils.getServiceParam(
+ option = BaseUtils.getOptionalServiceParam(
service, VFSConstants.TRANSPORT_FILE_ACTION_AFTER_FAILURE);
entry.setActionAfterFailure(
MOVE.equals(option) ? PollTableEntry.MOVE : PollTableEntry.DELETE);
Modified: webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSTransportSender.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSTransportSender.java?rev=569292&r1=569291&r2=569292&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSTransportSender.java (original)
+++ webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSTransportSender.java Fri Aug 24 01:28:53 2007
@@ -32,8 +32,6 @@
import org.apache.commons.logging.LogFactory;
import org.apache.axiom.om.OMOutputFormat;
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
import java.io.OutputStream;
public class VFSTransportSender extends AbstractTransportSender {
@@ -78,7 +76,7 @@
VFSOutTransportInfo vfsOutInfo = null;
- if (targetAddress != null) {
+ if (targetAddress != null) {
vfsOutInfo = new VFSOutTransportInfo(targetAddress);
} else if (outTransportInfo != null && outTransportInfo instanceof VFSOutTransportInfo) {
vfsOutInfo = (VFSOutTransportInfo) outTransportInfo;
@@ -86,7 +84,7 @@
if (vfsOutInfo != null) {
try {
- FileObject replyFile = fsManager.resolveFile(vfsOutInfo.getReplyFileURI());
+ FileObject replyFile = fsManager.resolveFile(vfsOutInfo.getOutFileURI());
if (replyFile.exists()) {
if (replyFile.getType() == FileType.FOLDER) {
@@ -103,7 +101,7 @@
} else {
handleException("Unsupported reply file type : " + replyFile.getType() +
- " for file : " + vfsOutInfo.getReplyFileURI());
+ " for file : " + vfsOutInfo.getOutFileURI());
}
} else {
replyFile.createFile();
@@ -111,7 +109,7 @@
}
} catch (FileSystemException e) {
handleException("Error resolving reply file : " +
- vfsOutInfo.getReplyFileURI(), e);
+ vfsOutInfo.getOutFileURI(), e);
}
} else {
handleException("Unable to determine out transport information to send message");
Modified: webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSUtils.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSUtils.java?rev=569292&r1=569291&r2=569292&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSUtils.java (original)
+++ webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/axis2/transport/vfs/VFSUtils.java Fri Aug 24 01:28:53 2007
@@ -109,7 +109,7 @@
// next check if the OutTransportInfo specifies one
if (fileName == null) {
- fileName = vfsOutInfo.getReplyFileName();
+ fileName = vfsOutInfo.getOutFileName();
}
// if none works.. use default
Added: webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/AbstractTransportTest.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/AbstractTransportTest.java?rev=569292&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/AbstractTransportTest.java (added)
+++ webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/AbstractTransportTest.java Fri Aug 24 01:28:53 2007
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axis2.transport;
+
+import junit.framework.TestCase;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.transport.vfs.VFSTransportSender;
+
+public class AbstractTransportTest extends TestCase {
+
+ protected UtilsTransportServer server = null;
+
+ protected void setUp() throws Exception {
+ server.start();
+ }
+
+ protected void tearDown() throws Exception {
+ server.stop();
+ }
+
+ /**
+ * Create the payload for an echoOMElement request
+ * @return
+ */
+ protected OMElement createPayload() {
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ OMNamespace omNs = fac.createOMNamespace("http://localhost/axis2/services/EchoXMLService", "my");
+ OMElement method = fac.createOMElement("echoOMElement", omNs);
+ OMElement value = fac.createOMElement("myValue", omNs);
+ value.addChild(fac.createOMText(value, "omTextValue"));
+ method.addChild(value);
+ return method;
+ }
+
+ /**
+ * Get the default axis2 configuration context for a client
+ * @return
+ * @throws Exception
+ */
+ protected ConfigurationContext getClientCfgCtx() throws Exception {
+ AxisConfiguration axisCfg = new AxisConfiguration();
+ ConfigurationContext cfgCtx = new ConfigurationContext(axisCfg);
+ return cfgCtx;
+ }
+
+}
Added: webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/Echo.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/Echo.java?rev=569292&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/Echo.java (added)
+++ webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/Echo.java Fri Aug 24 01:28:53 2007
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axis2.transport;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMText;
+
+public class Echo {
+
+ private static final Log log = LogFactory.getLog(Echo.class);
+ public static final String SERVICE_NAME = "EchoXMLService";
+ public static final String ECHO_OM_ELEMENT_OP_NAME = "echoOMElement";
+
+ public void echoVoid() {
+ log.info("echo Service Called");
+ }
+
+ public void echoOMElementNoResponse(OMElement omEle) {
+ log.info("echoOMElementNoResponse service called.");
+ }
+
+ public OMElement echoOMElement(OMElement omEle) {
+ omEle.buildWithAttachments();
+ omEle.setLocalName(omEle.getLocalName() + "Response");
+ if (omEle.getFirstElement().getText().trim().startsWith("fault")) {
+ throw new RuntimeException("fault string found in echoOMElement");
+ }
+ return omEle;
+ }
+
+ public OMElement echoOM(OMElement omEle) {
+ return omEle;
+ }
+
+ public String echoString(String in) {
+ return in;
+ }
+
+ public int echoInt(int in) {
+ return in;
+ }
+
+ public OMElement echoMTOMtoBase64(OMElement omEle) {
+ OMText omText = (OMText)(omEle.getFirstElement()).getFirstOMChild();
+ omText.setOptimize(false);
+ return omEle;
+ }
+}
\ No newline at end of file
Added: webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/UtilsTransportServer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/UtilsTransportServer.java?rev=569292&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/UtilsTransportServer.java (added)
+++ webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/UtilsTransportServer.java Fri Aug 24 01:28:53 2007
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axis2.transport;
+
+import org.apache.axis2.description.*;
+import org.apache.axis2.Constants;
+import org.apache.axis2.engine.ListenerManager;
+import org.apache.axis2.transport.vfs.VFSTransportListener;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.axis2.receivers.RawXMLINOutMessageReceiver;
+import org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver;
+
+import javax.xml.namespace.QName;
+import java.io.File;
+import java.util.List;
+import java.util.Iterator;
+
+/**
+ * Base class for transport util servers used in unit testing
+ */
+public abstract class UtilsTransportServer {
+
+ private ListenerManager listnMgr = null;
+ private ConfigurationContext cfgCtx = null;
+
+ public void start(TransportInDescription trpInDesc, TransportOutDescription trpDescOut) throws Exception {
+
+ // create a dummy repository
+ File file = makeCleanPath("target/axis2/repository");
+
+ cfgCtx = ConfigurationContextFactory.
+ createConfigurationContextFromFileSystem(file.getAbsolutePath());
+
+ // remove http transport
+ cfgCtx.getAxisConfiguration().getTransportsIn().remove("http");
+
+ // start given transport
+ listnMgr = new ListenerManager();
+ listnMgr.init(cfgCtx);
+ cfgCtx.setTransportManager(listnMgr);
+ //listnMgr.addListener(trpInDesc, false);
+
+ trpDescOut.getSender().init(cfgCtx, trpDescOut);
+ cfgCtx.getAxisConfiguration().addTransportOut(trpDescOut);
+ //trpInDesc.getReceiver().init(cfgCtx, trpInDesc);
+ listnMgr.addListener(trpInDesc, false);
+ listnMgr.start();
+ }
+
+ public void start() throws Exception {
+ }
+
+ public void stop() throws Exception {
+ listnMgr.stop();
+ }
+
+ /**
+ * Deploy the standard Echo service with the custom parameters passed in
+ * @param name the service name to assign
+ * @param parameters the parameters for the service
+ * @throws Exception
+ */
+ public void deployEchoService(String name, List parameters) throws Exception {
+
+ AxisService service = new AxisService(name);
+ service.setClassLoader(Thread.currentThread().getContextClassLoader());
+ service.addParameter(new Parameter(Constants.SERVICE_CLASS, Echo.class.getName()));
+
+ // add operation echoOMElement
+ AxisOperation axisOp = new InOutAxisOperation(new QName("echoOMElement"));
+ axisOp.setMessageReceiver(new RawXMLINOutMessageReceiver());
+ axisOp.setStyle(WSDLConstants.STYLE_RPC);
+ service.addOperation(axisOp);
+ service.mapActionToOperation(Constants.AXIS2_NAMESPACE_URI + "/echoOMElement", axisOp);
+
+ // add operation echoOMElementNoResponse
+ axisOp = new InOutAxisOperation(new QName("echoOMElementNoResponse"));
+ axisOp.setMessageReceiver(new RawXMLINOnlyMessageReceiver());
+ axisOp.setStyle(WSDLConstants.STYLE_RPC);
+ service.addOperation(axisOp);
+ service.mapActionToOperation(Constants.AXIS2_NAMESPACE_URI + "/echoOMElementNoResponse", axisOp);
+
+ Iterator iter = parameters.iterator();
+ while (iter.hasNext()) {
+ service.addParameter((Parameter) iter.next());
+ }
+
+ cfgCtx.getAxisConfiguration().addService(service);
+ }
+
+ /**
+ * Make sure the given path exists by creating it if required
+ * @param path
+ * @return
+ * @throws Exception
+ */
+ protected File makePath(String path) throws Exception {
+ File file = new File(path);
+ if (!file.exists()) {
+ if (!file.mkdirs()) {
+ throw new Exception("Couldn't create directory : " + file.getPath());
+ }
+ }
+ return file;
+ }
+
+ /**
+ * Delete the path if it exists and, create it
+ * @param path
+ * @return
+ * @throws Exception
+ */
+ protected File makeCleanPath(String path) throws Exception {
+ File file = new File(path);
+ if (!file.exists()) {
+ if (!file.mkdirs()) {
+ throw new Exception("Couldn't create directory : " + file.getPath());
+ }
+ } else {
+ // delete any existing
+ recursivelydelete(file);
+ if (file.exists()) {
+ throw new Exception("Couldn't delete directory : " + file.getPath());
+ }
+ if (!file.mkdirs()) {
+ throw new Exception("Couldn't create directory : " + file.getPath());
+ }
+ }
+ return file;
+ }
+
+ private void recursivelydelete(File file) {
+
+ File[] children = file.listFiles();
+ if (children != null && children.length > 0) {
+ for (int i=0; i<children.length; i++) {
+ recursivelydelete(children[i]);
+ }
+ }
+ file.delete();
+ }
+}
Added: webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/vfs/UtilsVFSServer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/vfs/UtilsVFSServer.java?rev=569292&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/vfs/UtilsVFSServer.java (added)
+++ webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/vfs/UtilsVFSServer.java Fri Aug 24 01:28:53 2007
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axis2.transport.vfs;
+
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.description.TransportInDescription;
+import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.transport.UtilsTransportServer;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.io.File;
+
+/**
+ * A VFS enabled Axis2 server implementation for unit testing
+ */
+public class UtilsVFSServer extends UtilsTransportServer {
+
+ public void start() throws Exception {
+
+ TransportOutDescription trpOutDesc =
+ new TransportOutDescription(VFSTransportListener.TRANSPORT_NAME);
+ trpOutDesc.setSender(new VFSTransportSender());
+
+ TransportInDescription trpInDesc =
+ new TransportInDescription(VFSTransportListener.TRANSPORT_NAME);
+ trpInDesc.setReceiver(new VFSTransportListener());
+ super.start(trpInDesc, trpOutDesc);
+
+ // create a temp directory for us to poll for the sample service
+ makeCleanPath("./target/vfs1/req");
+ makeCleanPath("./target/vfs1/res");
+
+ makeCleanPath("./target/vfs2/req");
+ makeCleanPath("./target/vfs2/res");
+
+ // Service1 - polls target/vfs1/req/request.xml, and writes the response to
+ // target/vfs1/res folder and deletes request on success. Polls every 2 secs
+ List parameters = new ArrayList();
+ parameters.add(new Parameter("transport.vfs.FileURI",
+ "vfs:file://" + new File(".").getAbsolutePath() + File.separator + "target/vfs1/req"));
+ parameters.add(new Parameter("transport.vfs.FileNamePattern", "request.xml"));
+ parameters.add(new Parameter("transport.vfs.ReplyFileURI",
+ "vfs:file://" + new File(".").getAbsolutePath() + File.separator + "target/vfs1/res"));
+ parameters.add(new Parameter("transport.vfs.ContentType", "text/xml"));
+ parameters.add(new Parameter("transport.PollInterval", "2000"));
+
+ parameters.add(new Parameter("transport.vfs.ActionAfterProcess", "DELETE"));
+ deployEchoService("Service1", parameters);
+
+ // Service2 - polls target/vfs2/req/requests.jar, and writes the response to
+ // target/vfs/res folder and deletes request on success. Polls every 2 secs
+ parameters = new ArrayList();
+ parameters.add(new Parameter("transport.vfs.FileURI",
+ "vfs:file://" + new File(".").getAbsolutePath() + File.separator + "target/vfs2/req/requests.jar"));
+ //parameters.add(new Parameter("transport.vfs.FileNamePattern", "request.xml"));
+ parameters.add(new Parameter("transport.vfs.ReplyFileURI",
+ "vfs:file://" + new File(".").getAbsolutePath() + File.separator + "target/vfs2/res"));
+ parameters.add(new Parameter("transport.vfs.ContentType", "text/xml"));
+ parameters.add(new Parameter("transport.PollInterval", "2000"));
+
+ parameters.add(new Parameter("transport.vfs.ActionAfterProcess", "DELETE"));
+ deployEchoService("Service2", parameters);
+ }
+
+}
Added: webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/vfs/VFSEchoRawXMLTest.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/vfs/VFSEchoRawXMLTest.java?rev=569292&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/vfs/VFSEchoRawXMLTest.java (added)
+++ webservices/synapse/trunk/java/modules/transports/src/test/java/org/apache/axis2/transport/vfs/VFSEchoRawXMLTest.java Fri Aug 24 01:28:53 2007
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axis2.transport.vfs;
+
+import org.apache.axis2.Constants;
+import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.transport.AbstractTransportTest;
+import org.apache.commons.vfs.FileSystemManager;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.VFS;
+
+import java.io.File;
+
+public class VFSEchoRawXMLTest extends AbstractTransportTest {
+
+ public VFSEchoRawXMLTest() {
+ server = new UtilsVFSServer();
+ }
+
+ public void testXMLFileInDirectory() throws Exception {
+
+ Options options = new Options();
+ options.setTo(
+ new EndpointReference("vfs:file:" + new File(".").getAbsolutePath() +
+ File.separator + "target/vfs1/req/request.xml"));
+ options.setAction(Constants.AXIS2_NAMESPACE_URI + "/echoOMElementNoResponse");
+
+ ServiceClient sender = new ServiceClient(getClientCfgCtx(), null);
+ sender.setOptions(options);
+ sender.fireAndForget(createPayload());
+
+ Thread.yield();
+ Thread.sleep(1000 * 5);
+
+ File req = new File("./target/vfs1/req/request.xml");
+ if (req.exists()) {
+ fail("Request file still exists. Not processed by service? : " + req.getPath());
+ }
+
+ File res = new File("target/vfs1/res/response.xml");
+ if (!res.exists()) {
+ fail("Response file not created : " + res.getPath());
+ }
+ }
+
+ /*public void testXMLFilesInJAR() throws Exception {
+
+ Options options = new Options();
+ options.setTo(
+ new EndpointReference("vfs:jar:" + new File(".").getAbsolutePath() +
+ File.separator + "target/vfs2/req/requests.jar!request.xml"));
+ options.setAction(Constants.AXIS2_NAMESPACE_URI + "/echoOMElementNoResponse");
+
+ ServiceClient sender = new ServiceClient(getClientCfgCtx(), null);
+ sender.setOptions(options);
+ sender.fireAndForget(createPayload());
+
+ Thread.yield();
+ Thread.sleep(1000 * 5 * 60);
+
+ File req = new File("./target/vfs2/req/requests.jar");
+ if (req.exists()) {
+ fail("Request file still exists. Not processed by service? : " + req.getPath());
+ }
+
+ File res = new File("target/vfs2/res/response.xml");
+ if (!res.exists()) {
+ fail("Response file not created : " + res.getPath());
+ }
+ }*/
+
+ /*public void testVFS() throws Exception {
+ FileSystemManager fsManager = VFS.getManager();
+ FileObject jarFile = fsManager.createFileSystem(
+ fsManager.resolveFile("jar:/tmp/aJarFile.jar"));
+ System.out.println("dc");
+ }*/
+
+ /**
+ * Create a axis2 configuration context that 'knows' about the VFS transport
+ * @return
+ * @throws Exception
+ */
+ public ConfigurationContext getClientCfgCtx() throws Exception {
+ AxisConfiguration axisCfg = new AxisConfiguration();
+ TransportOutDescription trpOutDesc = new TransportOutDescription("vfs");
+ VFSTransportSender trpSender = new VFSTransportSender();
+ trpOutDesc.setSender(trpSender);
+ axisCfg.addTransportOut(trpOutDesc);
+ ConfigurationContext cfgCtx = new ConfigurationContext(axisCfg);
+
+ trpSender.init(cfgCtx, trpOutDesc);
+ return cfgCtx;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org