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();
}
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);
}
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;
}
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();
}
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);
}
}
Aggregations