use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class AbstractTransportSender method createResponseMessageContext.
/**
* Create a new axis MessageContext for an incoming response message
* through this transport, for the given outgoing message
*
* @param outMsgCtx the outgoing message
* @return the newly created message context
*/
public MessageContext createResponseMessageContext(MessageContext outMsgCtx) {
MessageContext responseMsgCtx = null;
try {
responseMsgCtx = outMsgCtx.getOperationContext().getMessageContext(WSDL2Constants.MESSAGE_LABEL_IN);
} catch (AxisFault af) {
log.error("Error getting IN message context from the operation context", af);
}
if (responseMsgCtx == null) {
responseMsgCtx = new MessageContext();
responseMsgCtx.setOperationContext(outMsgCtx.getOperationContext());
}
responseMsgCtx.setIncomingTransportName(getTransportName());
responseMsgCtx.setTransportOut(transportOut);
responseMsgCtx.setTransportIn(transportIn);
responseMsgCtx.setMessageID(UUIDGenerator.getUUID());
responseMsgCtx.setDoingREST(outMsgCtx.isDoingREST());
responseMsgCtx.setProperty(MessageContext.TRANSPORT_IN, outMsgCtx.getProperty(MessageContext.TRANSPORT_IN));
responseMsgCtx.setAxisMessage(outMsgCtx.getOperationContext().getAxisOperation().getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE));
responseMsgCtx.setTo(null);
return responseMsgCtx;
}
use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class ProtocolEndpoint method createMessageContext.
public MessageContext createMessageContext() throws AxisFault {
MessageContext msgContext = listener.createMessageContext();
if (service != null) {
msgContext.setAxisService(service);
// find the operation for the message, or default to one
Parameter operationParam = service.getParameter(BaseConstants.OPERATION_PARAM);
QName operationQName = (operationParam != null ? BaseUtils.getQNameFromString(operationParam.getValue()) : BaseConstants.DEFAULT_OPERATION);
AxisOperation operation = service.getOperation(operationQName);
if (operation != null) {
msgContext.setAxisOperation(operation);
msgContext.setAxisMessage(operation.getMessage(WSDL2Constants.MESSAGE_LABEL_IN));
msgContext.setSoapAction("urn:" + operation.getName().getLocalPart());
}
}
return msgContext;
}
use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class MinConcurrencyTest method runTest.
@Override
protected void runTest() throws Throwable {
int endpointCount = channels.length;
int expectedConcurrency = endpointCount * messages;
final MessageReceiver messageReceiver = new MessageReceiver() {
public void receive(MessageContext msgContext) throws AxisFault {
synchronized (concurrencyReachedLock) {
concurrencyReached++;
concurrencyReachedLock.notifyAll();
}
try {
synchronized (shutdownAwaitLock) {
shutdownAwaitLock.wait();
}
} catch (InterruptedException ex) {
}
}
};
TestResourceSet[] clientResourceSets = new TestResourceSet[endpointCount];
TestResourceSet[] endpointResourceSets = new TestResourceSet[endpointCount];
try {
for (int i = 0; i < endpointCount; i++) {
TestResourceSet clientResourceSet = new TestResourceSet(getResourceSet());
AsyncChannel channel = channels[i];
clientResourceSet.addResource(channel);
AxisAsyncTestClient client = new AxisAsyncTestClient(false);
clientResourceSet.addResource(client);
clientResourceSet.setUp();
clientResourceSets[i] = clientResourceSet;
TestResourceSet endpointResourceSet = new TestResourceSet(clientResourceSet);
endpointResourceSet.addResource(new AxisTestEndpoint() {
@Override
protected AxisOperation createOperation() {
AxisOperation operation = new InOnlyAxisOperation(new QName("in"));
operation.setMessageReceiver(messageReceiver);
return operation;
}
@Override
protected void onTransportError(Throwable ex) {
// TODO Auto-generated method stub
}
});
if (!preloadMessages) {
endpointResourceSet.setUp();
endpointResourceSets[i] = endpointResourceSet;
}
for (int j = 0; j < messages; j++) {
ClientOptions options = new ClientOptions(client, new ContentType(SOAP11Constants.SOAP_11_CONTENT_TYPE), "UTF-8");
AxisMessage message = new AxisMessage();
message.setMessageType(SOAP11Constants.SOAP_11_CONTENT_TYPE);
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = factory.getDefaultEnvelope();
message.setEnvelope(envelope);
client.sendMessage(options, new ContentType(message.getMessageType()), message);
}
if (preloadMessages) {
endpointResourceSet.setUp();
endpointResourceSets[i] = endpointResourceSet;
}
}
long startTime = System.currentTimeMillis();
while (concurrencyReached < expectedConcurrency && System.currentTimeMillis() < (startTime + 5000)) {
synchronized (concurrencyReachedLock) {
concurrencyReachedLock.wait(5000);
}
}
synchronized (shutdownAwaitLock) {
shutdownAwaitLock.notifyAll();
}
if (concurrencyReached < expectedConcurrency) {
fail("Concurrency reached is " + concurrencyReached + ", but expected " + expectedConcurrency);
}
} finally {
for (int i = 0; i < endpointCount; i++) {
if (endpointResourceSets[i] != null) {
endpointResourceSets[i].tearDown();
}
if (clientResourceSets[i] != null) {
clientResourceSets[i].tearDown();
}
}
}
}
use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class XMPPListener method start.
/**
* Start a pool of Workers. For each connection in connectionFactories,
* assign a packer listener. This packet listener will trigger when a
* message arrives.
*/
public void start() throws AxisFault {
// create thread pool of workers
ExecutorService workerPool = new ThreadPoolExecutor(1, WORKERS_MAX_THREADS, WORKER_KEEP_ALIVE, TIME_UNIT, new LinkedBlockingQueue(), new org.apache.axis2.util.threadpool.DefaultThreadFactory(new ThreadGroup("XMPP Worker thread group"), "XMPPWorker"));
Iterator iter = connectionFactories.values().iterator();
while (iter.hasNext()) {
XMPPConnectionFactory connectionFactory = (XMPPConnectionFactory) iter.next();
XMPPPacketListener xmppPacketListener = new XMPPPacketListener(connectionFactory, this.configurationContext, workerPool);
connectionFactory.listen(xmppPacketListener);
}
}
use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class XMPPClientConnectionFactory method connect.
/**
* Connects to a XMPP server based on the details available in serverCredentials object
* @param serverCredentials
* @throws XMPPException
*/
public XMPPConnection connect(final XMPPServerCredentials serverCredentials) throws AxisFault {
// XMPPConnection.DEBUG_ENABLED = true;
if (XMPPConstants.XMPP_SERVER_TYPE_JABBER.equals(serverCredentials.getServerType())) {
xmppConnection = new XMPPConnection(serverCredentials.getServerUrl());
try {
xmppConnection.connect();
} catch (XMPPException e) {
log.error("Failed to connect to server :" + serverCredentials.getServerUrl(), e);
throw new AxisFault("Failed to connect to server :" + serverCredentials.getServerUrl());
}
// This prevents random ssl exception from Smack API
try {
Thread.sleep(100);
} catch (InterruptedException e5) {
log.debug("Sleep interrupted ", e5);
}
if (xmppConnection.isConnected()) {
String resource = serverCredentials.getResource() + new Object().hashCode();
if (!xmppConnection.isAuthenticated()) {
try {
// xmppConnection.login(serverCredentials.getAccountName()+"@"+
// serverCredentials.getServerUrl(),
xmppConnection.login(serverCredentials.getAccountName(), serverCredentials.getPassword(), resource, true);
} catch (XMPPException e) {
try {
log.error("Login failed for " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl() + ".Retrying in 2 secs", e);
Thread.sleep(2000);
// xmppConnection.login(serverCredentials.getAccountName()+"@"+
// serverCredentials.getServerUrl(),
xmppConnection.login(serverCredentials.getAccountName(), serverCredentials.getPassword(), resource, true);
} catch (InterruptedException e1) {
log.error("Sleep interrupted.", e1);
} catch (XMPPException e2) {
log.error("Login failed for : " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl(), e2);
throw new AxisFault("Login failed for : " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl());
}
}
// Listen for Message type packets from specified server url
// packetFilter = new AndFilter(new PacketTypeFilter(Message.class),
// new FromContainsFilter(serverCredentials.getServerUrl()));
packetFilter = new FromContainsFilter(serverCredentials.getServerUrl());
}
}
} else if (XMPPConstants.XMPP_SERVER_TYPE_GOOGLETALK.equals(serverCredentials.getServerType())) {
ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(XMPPConstants.GOOGLETALK_URL, XMPPConstants.GOOGLETALK_PORT, XMPPConstants.GOOGLETALK_SERVICE_NAME);
xmppConnection = new XMPPConnection(connectionConfiguration);
try {
xmppConnection.connect();
xmppConnection.login(serverCredentials.getAccountName(), serverCredentials.getPassword(), serverCredentials.getResource(), true);
// packetFilter = new AndFilter(new PacketTypeFilter(Message.class),
// new FromContainsFilter(XMPPConstants.GOOGLETALK_FROM));
// packetFilter = new FromContainsFilter(XMPPConstants.GOOGLETALK_FROM);
packetFilter = new ToContainsFilter("@gmail.com");
} catch (XMPPException e1) {
log.error("Error occured while connecting to Googletalk server.", e1);
throw new AxisFault("Error occured while connecting to Googletalk server.");
}
}
ConnectionListener connectionListener = null;
connectionListener = new ConnectionListener() {
public void connectionClosed() {
log.debug("Connection closed normally");
}
public void connectionClosedOnError(Exception e1) {
log.error("Connection to " + serverCredentials.getServerUrl() + " closed with error.", e1);
}
public void reconnectingIn(int seconds) {
log.error("Connection to " + serverCredentials.getServerUrl() + " failed. Reconnecting in " + seconds + "s");
}
public void reconnectionFailed(Exception e) {
log.error("Reconnection to " + serverCredentials.getServerUrl() + " failed.", e);
}
public void reconnectionSuccessful() {
log.debug("Reconnection to " + serverCredentials.getServerUrl() + " successful.");
}
};
if (xmppConnection != null && xmppConnection.isConnected()) {
xmppConnection.addConnectionListener(connectionListener);
log.info("Connected to " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl() + "/" + serverCredentials.getResource());
} else {
log.warn(" Not Connected to " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl() + "/" + serverCredentials.getResource());
}
return xmppConnection;
}
Aggregations