use of org.apache.axis2.description.TransportOutDescription in project carbon-business-process by wso2.
the class PartnerService method invoke.
public void invoke(final PartnerRoleMessageExchange partnerRoleMessageExchange) {
boolean isTwoWay = (partnerRoleMessageExchange.getMessageExchangePattern() == MessageExchange.MessageExchangePattern.REQUEST_RESPONSE);
try {
// Override options are passed to the axis MessageContext so we can
// retrieve them in our session out changeHandler
//
// Below logic is required only if tenant information from the thread local context is required here.
// However,
// it does not seem required, hence commenting out.
String deployer = processConfiguration.getDeployer();
if (log.isDebugEnabled()) {
String msg = "Process Name => " + processConfiguration.getProcessId() + " Deployer =>" + processConfiguration.getDeployer();
log.debug(msg);
}
PrivilegedCarbonContext.startTenantFlow();
// Assuming that deployer should not be null
String domain = BPELServerHolder.getInstance().getRealmService().getTenantManager().getDomain(Integer.parseInt(deployer));
if (domain != null) {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(domain);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(Integer.parseInt(deployer));
} else {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(Integer.parseInt(deployer));
}
final MessageContext mctx = new MessageContext();
BPELMessageContext partnerInvocationContext = BPELMessageContextFactory.createBPELMessageContext(mctx, this);
ExtensibilityElement bindingType = WSDLAwareSOAPProcessor.getBindingExtension(binding);
try {
if (bindingType instanceof HTTPBinding) {
// =========================================================
if (uep.getAddress() == null) {
uep.setAddress(endpointUrl);
}
partnerInvocationContext.setUep(uep);
partnerInvocationContext.setTwoWay(isTwoWay);
partnerInvocationContext.setService(serviceName);
partnerInvocationContext.setPort(portName);
partnerInvocationContext.setCaller(partnerRoleMessageExchange.getCaller().getLocalPart());
partnerInvocationContext.setOperationName(partnerRoleMessageExchange.getOperationName());
SOAPUtils.createSOAPRequest(partnerInvocationContext, partnerRoleMessageExchange);
String mexEndpointUrl = ((MutableEndpoint) partnerRoleMessageExchange.getEndpointReference()).getUrl();
if (!endpointUrl.equals(mexEndpointUrl)) {
uep.setAddress(mexEndpointUrl);
}
if (messageTraceLog.isDebugEnabled()) {
messageTraceLog.debug("Invoking service: MEXId: " + partnerRoleMessageExchange.getMessageExchangeId() + " :: " + serviceName + "." + partnerRoleMessageExchange.getOperationName());
if (messageTraceLog.isTraceEnabled()) {
messageTraceLog.trace("Request message: MEXId: " + partnerRoleMessageExchange.getMessageExchangeId() + " :: " + partnerInvocationContext.getInMessageContext().getEnvelope());
}
}
HTTPBindingHandler httpBindingHandler = new HTTPBindingHandler(clientConfigCtx, serviceName, portName, wsdlDefinition);
HTTPBindingHandler.HTTPBindingResponse response = httpBindingHandler.invoke(partnerRoleMessageExchange, partnerInvocationContext);
if (isTwoWay) {
MessageContext responseMessageContext = response.getReponseMessageContext();
partnerInvocationContext.setOutMessageContext(responseMessageContext);
MessageContext fltMessageContext = response.getFaultMessageContext();
if (messageTraceLog.isTraceEnabled()) {
messageTraceLog.trace("Response message: MEXId: " + partnerRoleMessageExchange.getMessageExchangeId() + " :: " + responseMessageContext.getEnvelope());
}
if (fltMessageContext != null) {
replyHTTP(partnerInvocationContext, partnerRoleMessageExchange, true);
} else {
replyHTTP(partnerInvocationContext, partnerRoleMessageExchange, response.isFault());
}
} else {
/* one-way case */
partnerRoleMessageExchange.replyOneWayOk();
}
} else {
if (uep.getAddress() == null) {
uep.setAddress(endpointUrl);
}
partnerInvocationContext.setUep(uep);
partnerInvocationContext.setTwoWay(isTwoWay);
partnerInvocationContext.setService(serviceName);
partnerInvocationContext.setPort(portName);
partnerInvocationContext.setCaller(partnerRoleMessageExchange.getCaller().getLocalPart());
partnerInvocationContext.setOperationName(partnerRoleMessageExchange.getOperationName());
SOAPUtils.createSOAPRequest(partnerInvocationContext, partnerRoleMessageExchange);
String mexEndpointUrl = ((MutableEndpoint) partnerRoleMessageExchange.getEndpointReference()).getUrl();
if (!endpointUrl.equals(mexEndpointUrl)) {
uep.setAddress(mexEndpointUrl);
}
if (messageTraceLog.isDebugEnabled()) {
messageTraceLog.debug("Invoking service: MEXId: " + partnerRoleMessageExchange.getMessageExchangeId() + " :: " + serviceName + "." + partnerRoleMessageExchange.getOperationName());
if (messageTraceLog.isTraceEnabled()) {
messageTraceLog.trace("Request message: MEXId: " + partnerRoleMessageExchange.getMessageExchangeId() + " :: " + partnerInvocationContext.getInMessageContext().getEnvelope());
}
}
AxisServiceUtils.invokeService(partnerInvocationContext, clientConfigCtx);
if (messageTraceLog.isDebugEnabled()) {
messageTraceLog.debug("Service invocation completed: MEXId: " + partnerRoleMessageExchange.getMessageExchangeId() + " :: " + serviceName + "." + partnerRoleMessageExchange.getOperationName());
}
if (isTwoWay) {
final Operation operation = partnerRoleMessageExchange.getOperation();
MessageContext response = partnerInvocationContext.getOutMessageContext();
MessageContext flt = partnerInvocationContext.getFaultMessageContext();
if (messageTraceLog.isTraceEnabled()) {
messageTraceLog.trace("Response message: MEXId: " + partnerRoleMessageExchange.getMessageExchangeId() + " :: " + response.getEnvelope());
}
if (flt != null) {
reply(partnerInvocationContext, partnerRoleMessageExchange, operation, flt, true);
} else {
reply(partnerInvocationContext, partnerRoleMessageExchange, operation, response, response.isFault());
}
} else {
/* one-way case */
partnerRoleMessageExchange.replyOneWayOk();
}
}
} finally {
// make sure the HTTP connection is released to the pool!
TransportOutDescription out = mctx.getTransportOut();
if (out != null && out.getSender() != null) {
out.getSender().cleanup(mctx);
}
}
} catch (Exception e) {
String errmsg = Messages.msgErrorSendingMessageToAxisForODEMex(partnerRoleMessageExchange.toString());
log.error(errmsg, e);
replyWithFailure(partnerRoleMessageExchange, MessageExchange.FailureType.COMMUNICATION_ERROR, errmsg);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.apache.axis2.description.TransportOutDescription in project carbon-apimgt by wso2.
the class TestUtils method initConfigurationContextService.
/**
* To initialize the (@link {@link ConfigurationContextService}} for testing.
*
* @return initialized configuration context service.
*/
public static ConfigurationContextService initConfigurationContextService(boolean initAPIMConfigurationService) throws XMLStreamException {
ConfigurationContextService configurationContextService = Mockito.mock(ConfigurationContextService.class);
ConfigurationContext configurationContext = Mockito.mock(ConfigurationContext.class);
AxisConfiguration axisConfiguration = Mockito.mock(AxisConfiguration.class);
Mockito.doReturn(axisConfiguration).when(configurationContext).getAxisConfiguration();
TransportInDescription transportInDescription = Mockito.mock(TransportInDescription.class);
Mockito.doReturn(transportInDescription).when(axisConfiguration).getTransportIn(Mockito.anyString());
Parameter dynamicSSLProfilesConfigParameter = Mockito.mock(Parameter.class);
Mockito.when(dynamicSSLProfilesConfigParameter.getParameterElement()).thenReturn(getDynamicSSLElement());
Mockito.when(transportInDescription.getParameter("dynamicSSLProfilesConfig")).thenReturn(dynamicSSLProfilesConfigParameter);
TransportOutDescription transportOutDescription = Mockito.mock(TransportOutDescription.class);
Mockito.doReturn(transportOutDescription).when(axisConfiguration).getTransportOut(Mockito.anyString());
Mockito.when(transportOutDescription.getParameter("dynamicSSLProfilesConfig")).thenReturn(dynamicSSLProfilesConfigParameter);
Mockito.doReturn(configurationContext).when(configurationContextService).getServerConfigContext();
if (initAPIMConfigurationService) {
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
Mockito.doReturn("true").when(apiManagerConfiguration).getFirstProperty(APIConstants.ENABLE_MTLS_FOR_APIS);
Mockito.doReturn(apiManagerConfiguration).when(apiManagerConfigurationService).getAPIManagerConfiguration();
ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(apiManagerConfigurationService);
}
ServiceReferenceHolder.setContextService(configurationContextService);
System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
System.setProperty("javax.net.ssl.trustStore", ".");
return configurationContextService;
}
use of org.apache.axis2.description.TransportOutDescription in project wso2-axis2-transports by wso2.
the class JMSTransportDescriptionFactory method createTransportOutDescription.
public TransportOutDescription createTransportOutDescription() throws Exception {
TransportOutDescription trpOutDesc = new TransportOutDescription(JMSSender.TRANSPORT_NAME);
if (cfOnSender) {
setupTransport(trpOutDesc);
}
trpOutDesc.setSender(new JMSSender());
return trpOutDesc;
}
use of org.apache.axis2.description.TransportOutDescription in project wso2-axis2-transports by wso2.
the class SimpleTransportDescriptionFactory method createTransportOutDescription.
public TransportOutDescription createTransportOutDescription() throws Exception {
TransportOutDescription trpOutDesc = new TransportOutDescription(name);
trpOutDesc.setSender(senderClass.newInstance());
return trpOutDesc;
}
use of org.apache.axis2.description.TransportOutDescription in project wso2-axis2-transports by wso2.
the class AxisTestClientContext method setUp.
@Setup
@SuppressWarnings("unused")
private void setUp(TransportDescriptionFactory tdf, AxisTestClientContextConfigurator[] configurators) throws Exception {
cfgCtx = ConfigurationContextFactory.createConfigurationContext(new CustomAxisConfigurator());
AxisConfiguration axisCfg = cfgCtx.getAxisConfiguration();
TransportOutDescription trpOutDesc = tdf.createTransportOutDescription();
axisCfg.addTransportOut(trpOutDesc);
sender = trpOutDesc.getSender();
sender.init(cfgCtx, trpOutDesc);
boolean useListener = false;
for (AxisTestClientContextConfigurator configurator : configurators) {
if (configurator.isTransportListenerRequired()) {
useListener = true;
break;
}
}
TransportInDescription trpInDesc;
if (useListener) {
trpInDesc = tdf.createTransportInDescription();
} else {
trpInDesc = null;
}
for (AxisTestClientContextConfigurator configurator : configurators) {
configurator.setupTransport(trpInDesc, trpOutDesc);
}
if (useListener) {
listenerManager = new ListenerManager();
listenerManager.init(cfgCtx);
cfgCtx.setTransportManager(listenerManager);
listenerManager.addListener(trpInDesc, false);
listenerManager.start();
}
}
Aggregations