use of org.apache.axis2.transport.OutTransportInfo in project wso2-synapse by wso2.
the class VFSTransportSenderTest method testTransportSenderInitAndSend.
/**
* Test Transport sender initialization and sending a file
* @throws AxisFault
*/
public void testTransportSenderInitAndSend() throws AxisFault, XMLStreamException {
// Clear file holder
MockFileHolder.getInstance().clear();
VFSTransportSender vfsTransportSender = new VFSTransportSender();
ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration());
TransportOutDescription transportOutDescription = new TransportOutDescription("Test");
// Enable Autolock release
transportOutDescription.addParameter(new Parameter(VFSConstants.TRANSPORT_AUTO_LOCK_RELEASE, true));
// Set Autolock release interval with default value
transportOutDescription.addParameter(new Parameter(VFSConstants.TRANSPORT_AUTO_LOCK_RELEASE_INTERVAL, 20000));
transportOutDescription.addParameter(new Parameter(VFSConstants.TRANSPORT_AUTO_LOCK_RELEASE_SAME_NODE, true));
vfsTransportSender.init(configurationContext, transportOutDescription);
// Create message context
org.apache.axis2.context.MessageContext mc = new org.apache.axis2.context.MessageContext();
populateMessageContext(mc);
String filePath = "test1:///foo/bar/test-" + System.currentTimeMillis() + ".ack";
String parameters = "?transport.vfs.MaxRetryCount=0&transport.vfs.ReconnectTimeout=1&" + "transport.vfs.SendFileSynchronously=true&transport.vfs.CreateFolder=true";
String fURI = filePath + parameters;
OutTransportInfo outTransportInfo = new VFSOutTransportInfo(fURI, true);
vfsTransportSender.sendMessage(mc, fURI, outTransportInfo);
MockFileHolder fileHolder = MockFileHolder.getInstance();
Assert.assertNotNull("File creation failed", fileHolder.getFile(filePath));
}
use of org.apache.axis2.transport.OutTransportInfo in project wso2-synapse by wso2.
the class VFSTransportSender method sendMessage.
/**
* Send the given message over the VFS transport
*
* @param msgCtx the axis2 message context
* @throws AxisFault on error
*/
public void sendMessage(MessageContext msgCtx, String targetAddress, OutTransportInfo outTransportInfo) throws AxisFault {
if (waitForSynchronousResponse(msgCtx)) {
throw new AxisFault("The VFS transport doesn't support synchronous responses. " + "Please use the appropriate (out only) message exchange pattern.");
}
VFSOutTransportInfo vfsOutInfo = null;
if (targetAddress != null) {
vfsOutInfo = new VFSOutTransportInfo(targetAddress, globalFileLockingFlag);
} else if (outTransportInfo != null && outTransportInfo instanceof VFSOutTransportInfo) {
vfsOutInfo = (VFSOutTransportInfo) outTransportInfo;
}
WriteLockObject lockObject = null;
String baseUri = null;
if (vfsOutInfo != null) {
if (vfsOutInfo.getSendFileSynchronously()) {
baseUri = getBaseUri(targetAddress);
if (baseUri != null) {
if (!lockingObjects.containsKey(baseUri)) {
lockingObjects.putIfAbsent(baseUri, new WriteLockObject());
log.debug("New locking object created for Synchronous write|MapSize:" + lockingObjects.size());
}
lockObject = lockingObjects.get(baseUri);
lockObject.incrementUsers();
}
}
}
try {
if (lockObject == null) {
writeFile(msgCtx, vfsOutInfo);
} else {
synchronized (lockObject) {
writeFile(msgCtx, vfsOutInfo);
}
}
} finally {
if (lockObject != null && (lockObject.decrementAndGetUsers() == 0)) {
lockingObjects.remove(baseUri);
if (log.isDebugEnabled()) {
log.debug("locking object removed for after Synchronous write|MapSize:" + lockingObjects.size());
}
}
}
}
Aggregations