Search in sources :

Example 6 with MessageContext

use of org.apache.axis2.context.MessageContext 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 7 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.

the class AxisTestClient method send.

protected MessageContext send(ClientOptions options, AxisMessage message, QName operationQName, boolean block, String resultMessageLabel) throws Exception {
    OperationClient mepClient = serviceClient.createClient(operationQName);
    MessageContext mc = new MessageContext();
    mc.setProperty(Constants.Configuration.MESSAGE_TYPE, message.getMessageType());
    mc.setEnvelope(message.getEnvelope());
    Attachments attachments = message.getAttachments();
    if (attachments != null) {
        mc.setAttachmentMap(attachments);
        mc.setDoingSwA(true);
        mc.setProperty(Constants.Configuration.ENABLE_SWA, true);
    }
    for (AxisTestClientConfigurator configurator : configurators) {
        configurator.setupRequestMessageContext(mc);
    }
    mc.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, options.getCharset());
    mc.setServiceContext(serviceClient.getServiceContext());
    if (metrics != null) {
        mc.setProperty(BaseConstants.METRICS_COLLECTOR, metrics);
    }
    mepClient.addMessageContext(mc);
    mepClient.execute(block);
    // mepClient.complete(mc);
    return resultMessageLabel == null ? null : mepClient.getMessageContext(resultMessageLabel);
}
Also used : OperationClient(org.apache.axis2.client.OperationClient) MessageContext(org.apache.axis2.context.MessageContext) Attachments(org.apache.axiom.attachments.Attachments)

Example 8 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.

the class AxisAsyncEndpoint method createOperation.

@Override
protected InOnlyAxisOperation createOperation() {
    InOnlyAxisOperation operation = new InOnlyAxisOperation(new QName("default"));
    operation.setMessageReceiver(new MessageReceiver() {

        public void receive(MessageContext messageCtx) throws AxisFault {
            AxisAsyncEndpoint.this.receive(messageCtx);
        }
    });
    return operation;
}
Also used : InOnlyAxisOperation(org.apache.axis2.description.InOnlyAxisOperation) AxisFault(org.apache.axis2.AxisFault) MessageReceiver(org.apache.axis2.engine.MessageReceiver) QName(javax.xml.namespace.QName) MessageContext(org.apache.axis2.context.MessageContext)

Example 9 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.

the class XMPPSender method prepareOperationList.

/**
 * Prepares a list of service names deployed in current runtime
 * @param msgCtx
 * @return
 */
private static String prepareOperationList(MessageContext msgCtx, String chatMessage) {
    StringBuffer sb = new StringBuffer();
    // extract service name
    String serviceName = chatMessage.replace("getOperations", "");
    serviceName = serviceName.replaceAll(" ", "");
    if (log.isDebugEnabled()) {
        log.debug("Finding operations for service :" + serviceName);
    }
    try {
        AxisService service = msgCtx.getConfigurationContext().getAxisConfiguration().getService(serviceName);
        Iterator itrOperations = service.getOperations();
        int index = 1;
        while (itrOperations.hasNext()) {
            AxisOperation operation = (AxisOperation) itrOperations.next();
            String parameterList = getParameterListForOperation(operation);
            sb.append(index + "." + operation.getName().getLocalPart() + "(" + parameterList + ")" + "\n");
            index++;
        }
    } catch (AxisFault e) {
        log.error("Error occurred while retreiving AxisService : " + serviceName, e);
        sb.append("Error occurred while retrieving operations for service : " + serviceName);
    }
    return sb.toString();
}
Also used : AxisFault(org.apache.axis2.AxisFault) AxisOperation(org.apache.axis2.description.AxisOperation) AxisService(org.apache.axis2.description.AxisService) Iterator(java.util.Iterator)

Example 10 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.

the class XMPPSender method sendChatMessage.

/**
 * Replies to IM clients via a chat message. The reply contains the invocation response as a string.
 * @param msgCtx
 * @param responseMsg
 * @throws AxisFault
 */
private static void sendChatMessage(MessageContext msgCtx, String responseMsg) throws AxisFault {
    XMPPConnection xmppConnection = null;
    XMPPOutTransportInfo xmppOutTransportInfo = null;
    Message message = new Message();
    xmppOutTransportInfo = (XMPPOutTransportInfo) msgCtx.getProperty(Constants.OUT_TRANSPORT_INFO);
    if (xmppOutTransportInfo != null) {
        message.setProperty(XMPPConstants.IN_REPLY_TO, xmppOutTransportInfo.getInReplyTo());
        xmppConnection = xmppOutTransportInfo.getConnectionFactory().getXmppConnection();
        if (xmppConnection == null) {
            handleException("Connection to XMPP Server is not established.");
        }
    } else {
        handleException("Could not find message sender details.");
    }
    // initialize the chat manager using connection
    ChatManager chatManager = xmppConnection.getChatManager();
    Chat chat = chatManager.createChat(xmppOutTransportInfo.getDestinationAccount(), null);
    try {
        message.setProperty(XMPPConstants.SEQUENCE_ID, xmppOutTransportInfo.getSequenceID());
        message.setBody(responseMsg);
        chat.sendMessage(message);
        log.debug("Sent message :" + message.toXML());
    } catch (XMPPException e) {
        XMPPSender.handleException("Error occurred while sending the message : " + message.toXML(), e);
    }
}
Also used : XMPPOutTransportInfo(org.apache.axis2.transport.xmpp.util.XMPPOutTransportInfo) AxisMessage(org.apache.axis2.description.AxisMessage) Message(org.jivesoftware.smack.packet.Message) Chat(org.jivesoftware.smack.Chat) XMPPConnection(org.jivesoftware.smack.XMPPConnection) XMPPException(org.jivesoftware.smack.XMPPException) ChatManager(org.jivesoftware.smack.ChatManager)

Aggregations

MessageContext (org.apache.axis2.context.MessageContext)35 AxisFault (org.apache.axis2.AxisFault)25 OMElement (org.apache.axiom.om.OMElement)13 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)12 IOException (java.io.IOException)11 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)11 XMLStreamException (javax.xml.stream.XMLStreamException)9 QName (javax.xml.namespace.QName)8 MessageFormatter (org.apache.axis2.transport.MessageFormatter)8 AxisOperation (org.apache.axis2.description.AxisOperation)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)5 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)5 SOAPFactory (org.apache.axiom.soap.SOAPFactory)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 OMFactory (org.apache.axiom.om.OMFactory)4 Options (org.apache.axis2.client.Options)4 Message (org.jivesoftware.smack.packet.Message)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OutputStream (java.io.OutputStream)3