use of org.apache.axiom.soap.SOAPFactory in project carbon-business-process by wso2.
the class HTCoordinationContextHandler method invokeRegistrationService.
private OMElement invokeRegistrationService(String identifier, String taskProtocolHandlerServiceURL, String registrationService) throws AxisFault {
OMElement payload = SOAPUtils.getRegistrationPayload(identifier, taskProtocolHandlerServiceURL);
SOAPFactory soap11Factory = OMAbstractFactory.getSOAP11Factory();
MessageContext mctx = new MessageContext();
if (mctx.getEnvelope() == null) {
mctx.setEnvelope(soap11Factory.createSOAPEnvelope());
}
if (mctx.getEnvelope().getBody() == null) {
soap11Factory.createSOAPBody(mctx.getEnvelope());
}
if (mctx.getEnvelope().getHeader() == null) {
soap11Factory.createSOAPHeader(mctx.getEnvelope());
}
mctx.getEnvelope().getBody().addChild(payload);
// //Setting basic auth headers. Reading those information using HT server config.
// HumanTaskServerConfiguration serverConfig = HTCoordinationModuleContentHolder.getInstance().getHtServer().getServerConfig();
// String tenantDomain = MultitenantUtils.getTenantDomainFromUrl(registrationService);
// if (registrationService.equals(tenantDomain)) {
// //this is a Super tenant registration service
// if (log.isDebugEnabled()) {
// log.debug("Sending Username" + serverConfig.getRegistrationServiceAuthUsername() + " - " + serverConfig.getRegistrationServiceAuthPassword()); //TODO REMOVE this
// }
// CarbonUtils.setBasicAccessSecurityHeaders(serverConfig.getRegistrationServiceAuthUsername(), serverConfig.getRegistrationServiceAuthPassword(), true, mctx);
// } else {
// if (log.isDebugEnabled()) {
// log.debug("Sending ws-coor Registration request to tenant domain: " + tenantDomain);
// }
// // Tenant's registration service
//
// String username = serverConfig.getRegistrationServiceAuthUsername() + "@" + tenantDomain;
// String pass = serverConfig.getRegistrationServiceAuthPassword();
// if (log.isDebugEnabled()) {
// log.debug("Sending Username" + username + " - " + pass); //TODO REMOVE this
// }
// CarbonUtils.setBasicAccessSecurityHeaders(
// username,
// pass,
// true,
// mctx);
// }
MessageContext responseMsgContext = ServiceUtils.invokeRegistrationService(mctx, registrationService);
if (responseMsgContext.getEnvelope() != null) {
if (responseMsgContext.getEnvelope().getBody() != null) {
return responseMsgContext.getEnvelope().getBody();
}
}
return null;
}
use of org.apache.axiom.soap.SOAPFactory in project carbon-apimgt by wso2.
the class RegularExpressionProtectorTest method testSqlInjectionInBody.
/**
* This is the test case to validate the request body against sql injection attack.
*/
@Test
public void testSqlInjectionInBody() throws AxisFault {
log.info(" Running the test case to validate the request body from sql injection attacks.");
SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
SOAPEnvelope env = fac.createSOAPEnvelope();
fac.createSOAPBody(env);
env.getBody().addChild(fac.createOMElement("test", "Drop database", "testBody"));
Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.ENABLED_CHECK_BODY)).thenReturn(String.valueOf(enabledStatus));
Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.ENABLED_CHECK_HEADERS)).thenReturn(String.valueOf("false"));
Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.ENABLED_CHECK_PATHPARAM)).thenReturn(String.valueOf("false"));
Mockito.when(((Axis2MessageContext) messageContext).getAxis2MessageContext()).thenReturn(axis2MsgContext);
Mockito.doReturn(env).when(axis2MsgContext).getEnvelope();
regularExpressionProtector = new RegularExpressionProtector();
regularExpressionProtector.mediate(messageContext);
}
use of org.apache.axiom.soap.SOAPFactory in project wso2-axis2-transports by wso2.
the class PlainTextFormatterTest method createElementMessageContextElement.
private MessageContext createElementMessageContextElement(String textPayload) throws AxisFault {
try {
MessageContext messageContext = new MessageContext();
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = factory.getDefaultEnvelope();
OMElement textWrapper = factory.createOMElement(BaseConstants.DEFAULT_TEXT_WRAPPER);
OMElement payload = AXIOMUtil.stringToOM(textPayload);
textWrapper.addChild(payload);
envelope.getBody().addChild(textWrapper);
messageContext.setEnvelope(envelope);
return messageContext;
} catch (XMLStreamException e) {
// This is highly unlikely to happen
return null;
}
}
use of org.apache.axiom.soap.SOAPFactory in project wso2-axis2-transports by wso2.
the class PlainTextFormatterTest method createMessageContext.
private MessageContext createMessageContext(String textPayload) throws AxisFault {
MessageContext messageContext = new MessageContext();
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = factory.getDefaultEnvelope();
OMElement textWrapper = factory.createOMElement(BaseConstants.DEFAULT_TEXT_WRAPPER);
textWrapper.setText(textPayload);
envelope.getBody().addChild(textWrapper);
messageContext.setEnvelope(envelope);
return messageContext;
}
use of org.apache.axiom.soap.SOAPFactory 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();
}
}
}
}
Aggregations