use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.
the class AxisEndpoint method calculateEndpointURL.
public String calculateEndpointURL(String hostIP) {
if (transportInDescName != null && parent != null) {
AxisConfiguration axisConfiguration = getAxisConfiguration();
if (axisConfiguration != null) {
try {
String serviceName = ((AxisService) parent).getName();
TransportInDescription in = axisConfiguration.getTransportIn(transportInDescName);
TransportListener listener = in.getReceiver();
String ip;
if (hostIP != null) {
ip = hostIP;
} else {
ip = Utils.getIpAddress(axisConfiguration);
}
// we should pass [serviceName].[endpointName] instead of
// [endpointName]
String sDOTe = serviceName + "." + name;
EndpointReference[] eprsForService = listener.getEPRsForService(sDOTe, ip);
// we consider only the first address return by the listener
if (eprsForService != null && eprsForService.length > 0) {
return eprsForService[0].getAddress();
}
} catch (SocketException e) {
logger.warn(e.getMessage(), e);
} catch (AxisFault e) {
logger.warn(e.getMessage(), e);
}
}
}
return null;
}
use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.
the class OutInAxisOperationClient method sendAsync.
private void sendAsync(boolean useAsync, MessageContext mc) throws AxisFault {
if (log.isDebugEnabled()) {
log.debug("useAsync=" + useAsync + ", seperateListener=" + mc.getOptions().isUseSeparateListener());
}
/**
* We are following the async path. If the user hasn't set a callback object then we must
* block until the whole MEP is complete, as they have no other way to get their reply message.
*/
// THREADSAFE issue: Multiple threads could be trying to initialize the callback receiver
// so it is synchronized. It is not done within the else clause to avoid the
// double-checked lock antipattern.
CallbackReceiver callbackReceiver;
synchronized (axisOp) {
if (axisOp.getMessageReceiver() != null && axisOp.getMessageReceiver() instanceof CallbackReceiver) {
callbackReceiver = (CallbackReceiver) axisOp.getMessageReceiver();
} else {
if (log.isDebugEnabled()) {
log.debug("Creating new callback receiver");
}
callbackReceiver = new CallbackReceiver();
axisOp.setMessageReceiver(callbackReceiver);
if (log.isDebugEnabled())
log.debug("OutInAxisOperation: callbackReceiver " + callbackReceiver + " : " + axisOp);
}
}
SyncCallBack internalCallback = null;
if (axisCallback != null) {
callbackReceiver.addCallback(mc.getMessageID(), axisCallback);
if (log.isDebugEnabled())
log.debug("OutInAxisOperationClient: Creating axis callback");
} else {
if (log.isDebugEnabled()) {
log.debug("Creating internal callback");
}
internalCallback = new SyncCallBack();
callbackReceiver.addCallback(mc.getMessageID(), internalCallback);
if (log.isDebugEnabled())
log.debug("OutInAxisOperationClient: Creating internal callback");
}
/**
* If USE_CUSTOM_LISTENER is set to 'true' the replyTo value will not be replaced and Axis2 will not
* start its internal listner. Some other enntity (e.g. a module) should take care of obtaining the
* response message.
*/
Boolean useCustomListener = (Boolean) options.getProperty(Constants.Configuration.USE_CUSTOM_LISTENER);
if (useAsync) {
useCustomListener = Boolean.TRUE;
}
if (useCustomListener == null || !useCustomListener.booleanValue()) {
EndpointReference replyTo = mc.getReplyTo();
if (replyTo == null || replyTo.hasAnonymousAddress()) {
EndpointReference replyToFromTransport = mc.getConfigurationContext().getListenerManager().getEPRforService(sc.getAxisService().getName(), axisOp.getName().getLocalPart(), mc.getTransportIn().getName());
if (replyTo == null) {
mc.setReplyTo(replyToFromTransport);
} else {
replyTo.setAddress(replyToFromTransport.getAddress());
}
}
}
// if we don't do this , this guy will wait till it gets HTTP 202 in the HTTP case
mc.setProperty(MessageContext.CLIENT_API_NON_BLOCKING, Boolean.TRUE);
mc.getConfigurationContext().registerOperationContext(mc.getMessageID(), oc);
AxisEngine.send(mc);
if (internalCallback != null) {
internalCallback.waitForCompletion(options.getTimeOutInMilliSeconds());
// process the result of the invocation
if (internalCallback.envelope == null) {
if (internalCallback.error == null) {
log.error("Callback had neither error nor response");
}
if (options.isExceptionToBeThrownOnSOAPFault()) {
throw AxisFault.makeFault(internalCallback.error);
}
}
}
}
use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.
the class OutInAxisOperationClient method executeImpl.
/**
* Executes the MEP. What this does depends on the specific MEP client. The
* basic idea is to have the MEP client execute and do something with the
* messages that have been added to it so far. For example, if its an Out-In
* MEP, then if the Out message has been set, then executing the client asks
* it to send the message and get the In message, possibly using a different
* thread.
*
* @param block Indicates whether execution should block or return ASAP. What
* block means is of course a function of the specific MEP
* client. IGNORED BY THIS MEP CLIENT.
* @throws AxisFault if something goes wrong during the execution of the MEP.
*/
public void executeImpl(boolean block) throws AxisFault {
if (log.isDebugEnabled()) {
log.debug("Entry: OutInAxisOperationClient::execute, " + block);
}
if (completed) {
throw new AxisFault(Messages.getMessage("mepiscomplted"));
}
ConfigurationContext cc = sc.getConfigurationContext();
// copy interesting info from options to message context.
MessageContext mc = oc.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
if (mc == null) {
throw new AxisFault(Messages.getMessage("outmsgctxnull"));
}
prepareMessageContext(cc, mc);
if (options.getTransportIn() == null && mc.getTransportIn() == null) {
mc.setTransportIn(ClientUtils.inferInTransport(cc.getAxisConfiguration(), options, mc));
} else if (mc.getTransportIn() == null) {
mc.setTransportIn(options.getTransportIn());
}
/**
* If a module has set the USE_ASYNC_OPERATIONS option then we override the behaviour
* for sync calls, and effectively USE_CUSTOM_LISTENER too. However we leave real
* async calls alone.
*/
boolean useAsync = false;
if (!mc.getOptions().isUseSeparateListener()) {
Boolean useAsyncOption = (Boolean) mc.getProperty(Constants.Configuration.USE_ASYNC_OPERATIONS);
if (log.isDebugEnabled())
log.debug("OutInAxisOperationClient: useAsyncOption " + useAsyncOption);
if (useAsyncOption != null) {
useAsync = useAsyncOption.booleanValue();
}
}
EndpointReference replyTo = mc.getReplyTo();
if (replyTo != null) {
if (replyTo.hasNoneAddress()) {
throw new AxisFault(replyTo.getAddress() + "" + " can not be used with OutInAxisOperationClient , user either " + "fireAndForget or sendRobust)");
} else if (replyTo.isWSAddressingAnonymous() && replyTo.getAllReferenceParameters() != null) {
mc.setProperty(AddressingConstants.INCLUDE_OPTIONAL_HEADERS, Boolean.TRUE);
}
String customReplyTo = (String) options.getProperty(Options.CUSTOM_REPLYTO_ADDRESS);
if (!(Options.CUSTOM_REPLYTO_ADDRESS_TRUE.equals(customReplyTo))) {
if (!replyTo.hasAnonymousAddress()) {
useAsync = true;
}
}
}
if (useAsync || mc.getOptions().isUseSeparateListener()) {
sendAsync(useAsync, mc);
} else {
if (block) {
// Send the SOAP Message and receive a response
send(mc);
completed = true;
} else {
sc.getConfigurationContext().getThreadPool().execute(new NonBlockingInvocationWorker(mc, axisCallback));
}
}
}
use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.
the class XMPPSampleClient method invokeTimeService.
private static void invokeTimeService() {
String endPointUrl = "xmpp://synapse.demo.0@gmail.com/" + "TimeService";
EndpointReference targetEPR = new EndpointReference(endPointUrl);
try {
ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromURIs(XMPPSampleClient.class.getResource("axis2.xml"), null);
OMElement payload = getPayload();
Options options = new Options();
options.setProperty(XMPPConstants.XMPP_SERVER_TYPE, XMPPConstants.XMPP_SERVER_TYPE_GOOGLETALK);
options.setProperty(XMPPConstants.XMPP_SERVER_URL, XMPPConstants.GOOGLETALK_URL);
options.setProperty(XMPPConstants.XMPP_SERVER_USERNAME, "synapse.demo.0");
options.setProperty(XMPPConstants.XMPP_SERVER_PASSWORD, "mailpassword");
options.setTo(targetEPR);
options.setAction("urn:getServerTime");
ServiceClient sender = new ServiceClient(ctx, null);
sender.setOptions(options);
OMElement result = sender.sendReceive(payload);
XMLPrettyPrinter.prettify(result, System.out);
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.
the class XMPPPacketListener method createMessageContext.
/**
* Creates message context using values received in XMPP packet
* @param packet
* @return MessageContext
* @throws AxisFault
*/
private MessageContext createMessageContext(Packet packet) throws AxisFault {
Message message = (Message) packet;
Boolean isServerSide = (Boolean) message.getProperty(XMPPConstants.IS_SERVER_SIDE);
String serviceName = (String) message.getProperty(XMPPConstants.SERVICE_NAME);
String action = (String) message.getProperty(XMPPConstants.ACTION);
MessageContext msgContext = null;
TransportInDescription transportIn = configurationContext.getAxisConfiguration().getTransportIn("xmpp");
TransportOutDescription transportOut = configurationContext.getAxisConfiguration().getTransportOut("xmpp");
if ((transportIn != null) && (transportOut != null)) {
msgContext = configurationContext.createMessageContext();
msgContext.setTransportIn(transportIn);
msgContext.setTransportOut(transportOut);
if (isServerSide != null) {
msgContext.setServerSide(isServerSide.booleanValue());
}
msgContext.setProperty(CONTENT_TYPE, "text/xml");
msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, "UTF-8");
msgContext.setIncomingTransportName("xmpp");
Map services = configurationContext.getAxisConfiguration().getServices();
AxisService axisService = (AxisService) services.get(serviceName);
msgContext.setAxisService(axisService);
msgContext.setSoapAction(action);
// pass the configurationFactory to transport sender
msgContext.setProperty("XMPPConfigurationFactory", this.xmppConnectionFactory);
if (packet.getFrom() != null) {
msgContext.setFrom(new EndpointReference(packet.getFrom()));
}
if (packet.getTo() != null) {
msgContext.setTo(new EndpointReference(packet.getTo()));
}
XMPPOutTransportInfo xmppOutTransportInfo = new XMPPOutTransportInfo();
xmppOutTransportInfo.setConnectionFactory(this.xmppConnectionFactory);
String packetFrom = packet.getFrom();
if (packetFrom != null) {
EndpointReference fromEPR = new EndpointReference(packetFrom);
xmppOutTransportInfo.setFrom(fromEPR);
xmppOutTransportInfo.setDestinationAccount(packetFrom);
}
// Save Message-Id to set as In-Reply-To on reply
String xmppMessageId = packet.getPacketID();
if (xmppMessageId != null) {
xmppOutTransportInfo.setInReplyTo(xmppMessageId);
}
xmppOutTransportInfo.setSequenceID((String) message.getProperty(XMPPConstants.SEQUENCE_ID));
msgContext.setProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO, xmppOutTransportInfo);
buildSOAPEnvelope(packet, msgContext);
} else {
throw new AxisFault("Either transport in or transport out is null");
}
return msgContext;
}
Aggregations