Search in sources :

Example 1 with OutInAxisOperation

use of org.apache.axis2.description.OutInAxisOperation in project wso2-axis2-transports by wso2.

the class TCPEchoRawXMLTest method testEchoXMLSyncMC.

public void testEchoXMLSyncMC() throws Exception {
    AxisOperation opdesc = new OutInAxisOperation(new QName("echoOMElement"));
    Options options = new Options();
    options.setTo(targetEPR);
    options.setAction(operationName.getLocalPart());
    options.setTransportInProtocol(Constants.TRANSPORT_TCP);
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
    OMElement method = fac.createOMElement("echoOMElement", omNs);
    OMElement value = fac.createOMElement("myValue", omNs);
    value.setText("Isaac Asimov, The Foundation Trilogy");
    method.addChild(value);
    SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope envelope = factory.getDefaultEnvelope();
    envelope.getBody().addChild(method);
    MessageContext requestContext = new MessageContext();
    requestContext.setConfigurationContext(configContext);
    requestContext.setAxisService(clientService);
    requestContext.setAxisOperation(opdesc);
    requestContext.setEnvelope(envelope);
    ServiceClient sender = new ServiceClient(configContext, clientService);
    sender.setOptions(options);
    OperationClient opClient = sender.createClient(new QName("echoOMElement"));
    opClient.addMessageContext(requestContext);
    opClient.setOptions(options);
    opClient.execute(true);
    MessageContext response = opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
    SOAPEnvelope env = response.getEnvelope();
    assertNotNull(env);
    env.getBody().serialize(StAXUtils.createXMLStreamWriter(System.out));
    sender.cleanup();
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) Options(org.apache.axis2.client.Options) OperationClient(org.apache.axis2.client.OperationClient) OMNamespace(org.apache.axiom.om.OMNamespace) OutInAxisOperation(org.apache.axis2.description.OutInAxisOperation) AxisOperation(org.apache.axis2.description.AxisOperation) QName(javax.xml.namespace.QName) ServiceClient(org.apache.axis2.client.ServiceClient) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) MessageContext(org.apache.axis2.context.MessageContext) OutInAxisOperation(org.apache.axis2.description.OutInAxisOperation) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 2 with OutInAxisOperation

use of org.apache.axis2.description.OutInAxisOperation in project wso2-axis2-transports by wso2.

the class UDPSender method waitForReply.

private void waitForReply(MessageContext messageContext, DatagramSocket datagramSocket, String contentType) throws IOException {
    // message context in asnych model
    if (!(messageContext.getAxisOperation() instanceof OutInAxisOperation) && messageContext.getProperty(org.apache.axis2.Constants.PIGGYBACK_MESSAGE) == null) {
        return;
    }
    // TODO set the maximum size parameter
    byte[] inputBuffer = new byte[4096];
    DatagramPacket packet = new DatagramPacket(inputBuffer, inputBuffer.length);
    datagramSocket.receive(packet);
    // create the soap envelope
    try {
        MessageContext respMessageContext = messageContext.getOperationContext().getMessageContext(WSDL2Constants.MESSAGE_LABEL_IN);
        InputStream inputStream = new ByteArrayInputStream(inputBuffer, 0, packet.getLength());
        SOAPEnvelope envelope = TransportUtils.createSOAPMessage(respMessageContext, inputStream, contentType);
        respMessageContext.setEnvelope(envelope);
    } catch (XMLStreamException e) {
        throw new AxisFault("Can not build the soap message ", e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DatagramPacket(java.net.DatagramPacket) MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OutInAxisOperation(org.apache.axis2.description.OutInAxisOperation)

Example 3 with OutInAxisOperation

use of org.apache.axis2.description.OutInAxisOperation in project wso2-axis2-transports by wso2.

the class MailTransportSender method waitForReply.

private void waitForReply(MessageContext msgContext, String mailMessageID) throws AxisFault {
    // message context in asnych model
    if (!(msgContext.getAxisOperation() instanceof OutInAxisOperation) && (msgContext.getProperty(org.apache.axis2.Constants.PIGGYBACK_MESSAGE) == null)) {
        return;
    }
    ConfigurationContext configContext = msgContext.getConfigurationContext();
    // if the mail message listner has not started we need to start it
    if (!configContext.getListenerManager().isListenerRunning(MailConstants.TRANSPORT_NAME)) {
        TransportInDescription mailTo = configContext.getAxisConfiguration().getTransportIn(MailConstants.TRANSPORT_NAME);
        if (mailTo == null) {
            handleException("Could not find the transport receiver for " + MailConstants.TRANSPORT_NAME);
        }
        configContext.getListenerManager().addListener(mailTo, false);
    }
    SynchronousCallback synchronousCallback = new SynchronousCallback(msgContext);
    Map callBackMap = (Map) msgContext.getConfigurationContext().getProperty(BaseConstants.CALLBACK_TABLE);
    callBackMap.put(mailMessageID, synchronousCallback);
    synchronized (synchronousCallback) {
        try {
            synchronousCallback.wait(msgContext.getOptions().getTimeOutInMilliSeconds());
        } catch (InterruptedException e) {
            handleException("Error occured while waiting ..", e);
        }
    }
    if (!synchronousCallback.isComplete()) {
        // when timeout occurs remove this entry.
        callBackMap.remove(mailMessageID);
        handleException("Timeout while waiting for a response");
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 4 with OutInAxisOperation

use of org.apache.axis2.description.OutInAxisOperation in project carbon-business-process by wso2.

the class AnonymousServiceFactory method createAnonymousService.

private static AxisService createAnonymousService(AxisConfiguration axisCfg, String serviceKey) {
    try {
        OutOnlyAxisOperation outOnlyOperation = new OutOnlyAxisOperation(ServiceClient.ANON_OUT_ONLY_OP);
        OutInAxisOperation outInOperation = new OutInAxisOperation(ServiceClient.ANON_OUT_IN_OP);
        AxisService axisAnonymousService = new AxisService(serviceKey);
        axisAnonymousService.addOperation(outOnlyOperation);
        axisAnonymousService.addOperation(outInOperation);
        // set a right default action *after* operations have been added to the service.
        outOnlyOperation.setSoapAction("");
        outInOperation.setSoapAction("");
        if (log.isDebugEnabled()) {
            log.debug("Creating Client Service: " + serviceKey);
        }
        axisAnonymousService.setClientSide(true);
        axisCfg.addService(axisAnonymousService);
        return axisAnonymousService;
    } catch (AxisFault axisFault) {
        handleException("Adding service to axis configuration failed.", axisFault);
    }
    return null;
}
Also used : AxisFault(org.apache.axis2.AxisFault) OutOnlyAxisOperation(org.apache.axis2.description.OutOnlyAxisOperation) AxisService(org.apache.axis2.description.AxisService) OutInAxisOperation(org.apache.axis2.description.OutInAxisOperation)

Example 5 with OutInAxisOperation

use of org.apache.axis2.description.OutInAxisOperation in project carbon-business-process by wso2.

the class AnonymousServiceFactory method createAnonymousService.

private static AxisService createAnonymousService(AxisConfiguration axisCfg, String serviceKey) {
    try {
        OutOnlyAxisOperation outOnlyOperation = new OutOnlyAxisOperation(ServiceClient.ANON_OUT_ONLY_OP);
        OutInAxisOperation outInOperation = new OutInAxisOperation(ServiceClient.ANON_OUT_IN_OP);
        AxisService axisAnonymousService = new AxisService(serviceKey);
        axisAnonymousService.addOperation(outOnlyOperation);
        axisAnonymousService.addOperation(outInOperation);
        // set a right default action *after* operations have been added to the service.
        outOnlyOperation.setSoapAction("");
        outInOperation.setSoapAction("");
        if (log.isDebugEnabled()) {
            log.debug("Creating Client Service: " + serviceKey);
        }
        axisAnonymousService.setClientSide(true);
        axisCfg.addService(axisAnonymousService);
        return axisAnonymousService;
    } catch (AxisFault axisFault) {
        handleException("Adding service to axis configuration failed.", axisFault);
    }
    return null;
}
Also used : AxisFault(org.apache.axis2.AxisFault) OutOnlyAxisOperation(org.apache.axis2.description.OutOnlyAxisOperation) AxisService(org.apache.axis2.description.AxisService) OutInAxisOperation(org.apache.axis2.description.OutInAxisOperation)

Aggregations

OutInAxisOperation (org.apache.axis2.description.OutInAxisOperation)5 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)3 AxisFault (org.apache.axis2.AxisFault)3 MessageContext (org.apache.axis2.context.MessageContext)3 AxisService (org.apache.axis2.description.AxisService)2 OutOnlyAxisOperation (org.apache.axis2.description.OutOnlyAxisOperation)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 DatagramPacket (java.net.DatagramPacket)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 QName (javax.xml.namespace.QName)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 OMElement (org.apache.axiom.om.OMElement)1 OMFactory (org.apache.axiom.om.OMFactory)1 OMNamespace (org.apache.axiom.om.OMNamespace)1 SOAPFactory (org.apache.axiom.soap.SOAPFactory)1 OperationClient (org.apache.axis2.client.OperationClient)1 Options (org.apache.axis2.client.Options)1 ServiceClient (org.apache.axis2.client.ServiceClient)1