Search in sources :

Example 11 with OutTransportInfo

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));
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) MockFileHolder(org.wso2.carbon.inbound.endpoint.protocol.file.MockFileHolder) VFSOutTransportInfo(org.apache.synapse.commons.vfs.VFSOutTransportInfo) OutTransportInfo(org.apache.axis2.transport.OutTransportInfo) Parameter(org.apache.axis2.description.Parameter) MessageContext(org.apache.axis2.context.MessageContext) MessageContext(org.apache.axis2.context.MessageContext) VFSOutTransportInfo(org.apache.synapse.commons.vfs.VFSOutTransportInfo) TransportOutDescription(org.apache.axis2.description.TransportOutDescription)

Example 12 with OutTransportInfo

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());
            }
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) VFSOutTransportInfo(org.apache.synapse.commons.vfs.VFSOutTransportInfo)

Aggregations

OutTransportInfo (org.apache.axis2.transport.OutTransportInfo)6 AxisFault (org.apache.axis2.AxisFault)5 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)4 MessageContext (org.apache.axis2.context.MessageContext)4 MessageFormatter (org.apache.axis2.transport.MessageFormatter)4 VFSOutTransportInfo (org.apache.synapse.commons.vfs.VFSOutTransportInfo)4 IOException (java.io.IOException)3 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)3 Parameter (org.apache.axis2.description.Parameter)3 TransportOutDescription (org.apache.axis2.description.TransportOutDescription)3 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)3 OutputStream (java.io.OutputStream)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 InterruptedIOException (java.io.InterruptedIOException)1 DatagramPacket (java.net.DatagramPacket)1 DatagramSocket (java.net.DatagramSocket)1 Date (java.util.Date)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 DataHandler (javax.activation.DataHandler)1