Java Code Examples for org.apache.axis2.client.ServiceClient#setOptions()

The following examples show how to use org.apache.axis2.client.ServiceClient#setOptions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParallelRequestHelper.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * constructor for parallel request helper
 * we can use this for the initial begin boxcarring request as well.(sending sessionCookie null)
 *
 * @param sessionCookie
 * @param operation
 * @param payload
 * @param serviceEndPoint
 * @throws org.apache.axis2.AxisFault
 */
public ParallelRequestHelper(String sessionCookie, String operation, OMElement payload, String serviceEndPoint)
        throws AxisFault {
    this.payload = payload;
    sender = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(serviceEndPoint));
    options.setProperty("__CHUNKED__", Boolean.FALSE);
    options.setTimeOutInMilliSeconds(45000L);
    options.setAction("urn:" + operation);
    sender.setOptions(options);
    if (sessionCookie != null && !sessionCookie.isEmpty()) {
        Header header = new Header("Cookie", sessionCookie);
        ArrayList headers = new ArrayList();
        headers.add(header);
        sender.getOptions().setProperty(HTTPConstants.HTTP_HEADERS, headers);
    }
}
 
Example 2
Source File: SOAPClient.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * Sends a SOAP message with MTOM attachment and returns response as a OMElement.
 *
 * @param fileName   name of file to be sent as an attachment
 * @param targetEPR  service url
 * @param soapAction SOAP Action to set. Specify with "urn:"
 * @return OMElement response from BE service
 * @throws AxisFault in case of an invocation failure
 */
public OMElement sendSOAPMessageWithAttachment(String fileName, String targetEPR, String soapAction) throws AxisFault {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
    OMElement payload = factory.createOMElement("uploadFileUsingMTOM", ns);
    OMElement request = factory.createOMElement("request", ns);
    OMElement image = factory.createOMElement("image", ns);

    FileDataSource fileDataSource = new FileDataSource(new File(fileName));
    DataHandler dataHandler = new DataHandler(fileDataSource);
    OMText textData = factory.createOMText(dataHandler, true);
    image.addChild(textData);
    request.addChild(image);
    payload.addChild(request);

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(targetEPR));
    options.setAction(soapAction);
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
    options.setCallTransportCleanup(true);
    serviceClient.setOptions(options);
    return serviceClient.sendReceive(payload);
}
 
Example 3
Source File: SOAPClient.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Sends a SOAP message with MTOM attachment and returns response as a OMElement.
 *
 * @param fileName   name of file to be sent as an attachment
 * @param targetEPR  service url
 * @param soapAction SOAP Action to set. Specify with "urn:"
 * @return OMElement response from BE service
 * @throws AxisFault in case of an invocation failure
 */
public OMElement sendSOAPMessageWithAttachment(String fileName, String targetEPR, String soapAction) throws AxisFault {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
    OMElement payload = factory.createOMElement("uploadFileUsingMTOM", ns);
    OMElement request = factory.createOMElement("request", ns);
    OMElement image = factory.createOMElement("image", ns);

    FileDataSource fileDataSource = new FileDataSource(new File(fileName));
    DataHandler dataHandler = new DataHandler(fileDataSource);
    OMText textData = factory.createOMText(dataHandler, true);
    image.addChild(textData);
    request.addChild(image);
    payload.addChild(request);

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(targetEPR));
    options.setAction(soapAction);
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
    options.setCallTransportCleanup(true);
    serviceClient.setOptions(options);
    return serviceClient.sendReceive(payload);
}
 
Example 4
Source File: ESBJAVA4909MultipartRelatedTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
public void sendUsingMTOM(String fileName, String targetEPR) throws IOException {
    final String EXPECTED = "<m0:uploadFileUsingMTOMResponse xmlns:m0=\"http://services.samples\"><m0:response>" +
            "<m0:image>PHByb3h5PkFCQzwvcHJveHk+</m0:image></m0:response></m0:uploadFileUsingMTOMResponse>";
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
    OMElement payload = factory.createOMElement("uploadFileUsingMTOM", ns);
    OMElement request = factory.createOMElement("request", ns);
    OMElement image = factory.createOMElement("image", ns);

    FileDataSource fileDataSource = new FileDataSource(new File(fileName));
    DataHandler dataHandler = new DataHandler(fileDataSource);
    OMText textData = factory.createOMText(dataHandler, true);
    image.addChild(textData);
    request.addChild(image);
    payload.addChild(request);

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(targetEPR));
    options.setAction("urn:uploadFileUsingMTOM");
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
    options.setCallTransportCleanup(true);
    serviceClient.setOptions(options);
    OMElement response = serviceClient.sendReceive(payload);
    Assert.assertTrue(response.toString().contains(EXPECTED), "Attachment is missing in the response");
}
 
Example 5
Source File: WSEventDispatcher.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
protected synchronized void sendNotification(OMElement topicHeader,
                                OMElement tenantDomainHeader,
                                OMElement payload,
                                String endpoint)
        throws AxisFault {
    // The parameter args is used as a mechanism to pass any argument into this method, which
    // is used by the implementations that extend the behavior of the default Carbon Event
    // Dispatcher.
    ConfigurationContextService configurationContextService =
            WSEventBrokerHolder.getInstance().getConfigurationContextService();

    ServiceClient serviceClient =
            new ServiceClient(configurationContextService.getClientConfigContext(), null);

    Options options = new Options();
    options.setTo(new EndpointReference(endpoint));
    options.setAction(EventingConstants.WSE_PUBLISH);
    serviceClient.setOptions(options);
    serviceClient.addHeader(topicHeader);

    if (tenantDomainHeader != null){
        serviceClient.addHeader(tenantDomainHeader);
    }

    serviceClient.fireAndForget(payload);
}
 
Example 6
Source File: ESBJAVA4909MultipartRelatedTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public void sendUsingMTOM(String fileName, String targetEPR) throws IOException {
    final String EXPECTED = "<m0:uploadFileUsingMTOMResponse xmlns:m0=\"http://services.samples\"><m0:response>"
            + "<m0:image>PHByb3h5PkFCQzwvcHJveHk+</m0:image></m0:response></m0:uploadFileUsingMTOMResponse>";
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
    OMElement payload = factory.createOMElement("uploadFileUsingMTOM", ns);
    OMElement request = factory.createOMElement("request", ns);
    OMElement image = factory.createOMElement("image", ns);

    FileDataSource fileDataSource = new FileDataSource(new File(fileName));
    DataHandler dataHandler = new DataHandler(fileDataSource);
    OMText textData = factory.createOMText(dataHandler, true);
    image.addChild(textData);
    request.addChild(image);
    payload.addChild(request);

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(targetEPR));
    options.setAction("urn:uploadFileUsingMTOM");
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
    options.setCallTransportCleanup(true);
    serviceClient.setOptions(options);
    OMElement response = serviceClient.sendReceive(payload);
    Assert.assertTrue(response.toString().contains(EXPECTED), "Attachment is missing in the response");
}
 
Example 7
Source File: CallOutMediatorWithMTOMTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public void sendUsingMTOM(String fileName, String targetEPR) throws IOException {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
    OMElement payload = factory.createOMElement("uploadFileUsingMTOM", ns);
    OMElement request = factory.createOMElement("request", ns);
    OMElement image = factory.createOMElement("image", ns);

    FileDataSource fileDataSource = new FileDataSource(new File(fileName));
    DataHandler dataHandler = new DataHandler(fileDataSource);
    OMText textData = factory.createOMText(dataHandler, true);
    image.addChild(textData);
    request.addChild(image);
    payload.addChild(request);

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(targetEPR));
    options.setAction("urn:uploadFileUsingMTOM");
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
    options.setCallTransportCleanup(true);
    serviceClient.setOptions(options);
    OMElement response = serviceClient.sendReceive(payload);
    Assert.assertTrue(response.toString().contains(
            "<m:testMTOM xmlns:m=\"http://services.samples/xsd\">" + "<m:test1>testMTOM</m:test1></m:testMTOM>"));
}
 
Example 8
Source File: WSXACMLEntitlementServiceClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Get decision in a secured manner using the
 * SAML implementation of XACML using X.509 credentials
 *
 * @return decision extracted from the SAMLResponse sent from PDP
 * @throws Exception
 */
@Override
public String getDecision(Attribute[] attributes, String appId) throws Exception {

    String xacmlRequest;
    String xacmlAuthzDecisionQuery;
    OMElement samlResponseElement;
    String samlResponse;
    String result;
    try {
        xacmlRequest = XACMLRequetBuilder.buildXACML3Request(attributes);
        xacmlAuthzDecisionQuery = buildSAMLXACMLAuthzDecisionQuery(xacmlRequest);
        ServiceClient sc = new ServiceClient();
        Options opts = new Options();
        opts.setTo(new EndpointReference(serverUrl + "ws-xacml"));
        opts.setAction("XACMLAuthzDecisionQuery");
        opts.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, authenticator);
        opts.setManageSession(true);
        sc.setOptions(opts);
        samlResponseElement = sc.sendReceive(AXIOMUtil.stringToOM(xacmlAuthzDecisionQuery));
        samlResponse = samlResponseElement.toString();
        result = extractXACMLResponse(samlResponse);
        sc.cleanupTransport();
        return result;
    } catch (Exception e) {
        log.error("Error occurred while getting decision using SAML.", e);
        throw new Exception("Error occurred while getting decision using SAML.", e);
    }
}
 
Example 9
Source File: WSXACMLEntitlementServiceClient.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Get decision in a secured manner using the
 * SAML implementation of XACML using X.509 credentials
 *
 * @return decision extracted from the SAMLResponse sent from PDP
 * @throws Exception
 */
@Override
public String getDecision(Attribute[] attributes, String appId) throws Exception {

    String xacmlRequest;
    String xacmlAuthzDecisionQuery;
    OMElement samlResponseElement;
    String samlResponse;
    String result;
    try {
        xacmlRequest = XACMLRequetBuilder.buildXACML3Request(attributes);
        xacmlAuthzDecisionQuery = buildSAMLXACMLAuthzDecisionQuery(xacmlRequest);
        ServiceClient sc = new ServiceClient();
        Options opts = new Options();
        opts.setTo(new EndpointReference(serverUrl + "ws-xacml"));
        opts.setAction("XACMLAuthzDecisionQuery");
        opts.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, authenticator);
        opts.setManageSession(true);
        sc.setOptions(opts);
        samlResponseElement = sc.sendReceive(AXIOMUtil.stringToOM(xacmlAuthzDecisionQuery));
        samlResponse = samlResponseElement.toString();
        result = extractXACMLResponse(samlResponse);
        sc.cleanupTransport();
        return result;
    } catch (Exception e) {
        log.error("Error occurred while getting decision using SAML.", e);
        throw new Exception("Error occurred while getting decision using SAML.", e);
    }
}
 
Example 10
Source File: ApplicationRegistrationWSWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves configured ServiceClient for communication with external services
 *
 * @param action web service action to use
 * @return configured service client
 * @throws AxisFault
 */
public ServiceClient getClient(String action) throws AxisFault {
    ServiceClient client = new ServiceClient(
            ServiceReferenceHolder.getInstance().getContextService().getClientConfigContext(), null);
    Options options = new Options();
    options.setAction(action);
    options.setTo(new EndpointReference(serviceEndpoint));

    if (contentType != null) {
        options.setProperty(Constants.Configuration.MESSAGE_TYPE, contentType);
    } else {
        options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML);
    }

    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();

    // Assumes authentication is required if username and password is given
    if (username != null && !username.isEmpty() && password != null && password.length != 0) {
        auth.setUsername(username);
        auth.setPassword(String.valueOf(password));
        auth.setPreemptiveAuthentication(true);
        List<String> authSchemes = new ArrayList<String>();
        authSchemes.add(HttpTransportProperties.Authenticator.BASIC);
        auth.setAuthSchemes(authSchemes);

        if (contentType == null) {
            options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML);
        }
        options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
        options.setManageSession(true);
    }
    client.setOptions(options);

    return client;
}
 
Example 11
Source File: XdsTest.java    From openxds with Apache License 2.0 5 votes vote down vote up
protected ServiceClient getRegistryGateWayClient() throws AxisFault {
       ConfigurationContext configctx = getContext();
	ServiceClient sender = new ServiceClient(configctx,null);
	String action = "urn:ihe:iti:2007:CrossGatewayQuery";
	boolean enableMTOM = false;
	sender.setOptions(getOptions(action, enableMTOM, rgUrl));
	sender.engageModule("addressing");				
	return sender;
}
 
Example 12
Source File: XdsTest.java    From openxds with Apache License 2.0 5 votes vote down vote up
protected ServiceClient getRetrieveDocumentServiceClient() throws AxisFault{
	ConfigurationContext configctx = getContext();
	ServiceClient sender = new ServiceClient(configctx,null);
	String action = "urn:ihe:iti:2007:RetrieveDocumentSet";
	boolean enableMTOM = true;
	sender.setOptions(getOptions(action, enableMTOM, repositoryUrl));
	sender.engageModule("addressing");
	return sender;
}
 
Example 13
Source File: Sample705TestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = { "wso2.esb" }, description = "Test forwarding with load balancing")
public void loadBalancingTest() throws Exception {

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(getProxyServiceURLHttp("StockQuoteProxy")));
    options.setAction("urn:placeOrder");
    serviceClient.setOptions(options);

    for (int i = 0; i < 100; i++ ) {
        serviceClient.sendRobust(createPayload());
    }

}
 
Example 14
Source File: ServiceInvoker.java    From product-ei with Apache License 2.0 5 votes vote down vote up
public ServiceInvoker(String epr, String operation) {

        this.operation = operation;

        Options options = new Options();
        options.setTo(new EndpointReference(epr));
        options.setAction(operation);

        try {
            ConfigurationContext configContext = ConfigurationContextFactory.
                    createConfigurationContextFromFileSystem("client_repo", null);

            client = new ServiceClient(configContext, null);
            options.setTimeOutInMilliSeconds(10000000);

            client.setOptions(options);
            client.engageModule("addressing");

        } catch (AxisFault axisFault) {
            axisFault.printStackTrace();
        }

        fac = OMAbstractFactory.getOMFactory();
        msg = fac.createOMElement("SampleMsg", null);

        OMElement load = fac.createOMElement("load", null);
        load.setText("1000");
        msg.addChild(load);
    }
 
Example 15
Source File: ApplicationCreationWSWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves configured ServiceClient for communication with external services
 *
 * @param action web service action to use
 * @return configured service client
 * @throws AxisFault
 */
public ServiceClient getClient(String action) throws AxisFault {
    ServiceClient client = new ServiceClient(
            ServiceReferenceHolder.getInstance().getContextService().getClientConfigContext(), null);
    Options options = new Options();
    options.setAction(action);
    options.setTo(new EndpointReference(serviceEndpoint));

    if (contentType != null) {
        options.setProperty(Constants.Configuration.MESSAGE_TYPE, contentType);
    } else {
        options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML);
    }

    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();

    // Assumes authentication is required if username and password is given
    if (username != null && !username.isEmpty() && password != null && password.length != 0) {
        auth.setUsername(username);
        auth.setPassword(String.valueOf(password));
        auth.setPreemptiveAuthentication(true);
        List<String> authSchemes = new ArrayList<String>();
        authSchemes.add(HttpTransportProperties.Authenticator.BASIC);
        auth.setAuthSchemes(authSchemes);

        if (contentType == null) {
            options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML);
        }
        options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
        options.setManageSession(true);
    }
    client.setOptions(options);

    return client;
}
 
Example 16
Source File: XdsTest.java    From openxds with Apache License 2.0 5 votes vote down vote up
protected ServiceClient getIGQueryServiceClient() throws AxisFault {
       ConfigurationContext configctx = getContext();
	ServiceClient sender = new ServiceClient(configctx,null);
	String action = "urn:ihe:iti:2007:RegistryStoredQuery";
	boolean enableMTOM = false;
	sender.setOptions(getOptions(action, enableMTOM, igUrl));
	sender.engageModule("addressing");				
	return sender;
}
 
Example 17
Source File: SecurityVerificationTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@Test(description = "Ensures that all Admin services are exposed only via HTTPS", enabled = false)
public void verifyAdminServiceSecurity() throws AxisFault, XPathExpressionException {
    ServiceClient client = new ServiceClient(null, null);
    Options opts = new Options();
    String serviceName = "SecurityVerifierService";

    EndpointReference epr = new EndpointReference(getServiceUrlHttp(serviceName));
    opts.setTo(epr);

    client.setOptions(opts);
    client.sendRobust(createPayLoad());   // robust send. Will get reply only if there is a fault
    log.info("sent the message");
}
 
Example 18
Source File: MTOMSwAClient.java    From product-ei with Apache License 2.0 4 votes vote down vote up
public static MessageContext sendUsingSwA(String fileName, String targetEPR) throws IOException {

        Options options = new Options();
        options.setTo(new EndpointReference(targetEPR));
        options.setAction("urn:uploadFileUsingSwA");
        options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE);

        ServiceClient sender = createServiceClient();
        sender.setOptions(options);
        OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP);

        MessageContext mc = new MessageContext();

        System.out.println("Sending file : " + fileName + " as SwA");
        FileDataSource fileDataSource = new FileDataSource(new File(fileName));
        DataHandler dataHandler = new DataHandler(fileDataSource);
        String attachmentID = mc.addAttachment(dataHandler);


        SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
        SOAPEnvelope env = factory.getDefaultEnvelope();
        OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
        OMElement payload = factory.createOMElement("uploadFileUsingSwA", ns);
        OMElement request = factory.createOMElement("request", ns);
        OMElement imageId = factory.createOMElement("imageId", ns);
        imageId.setText(attachmentID);
        request.addChild(imageId);
        payload.addChild(request);
        env.getBody().addChild(payload);
        mc.setEnvelope(env);

        mepClient.addMessageContext(mc);
        mepClient.execute(true);
        MessageContext response = mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);

        SOAPBody body = response.getEnvelope().getBody();
        String imageContentId = body.
                getFirstChildWithName(new QName("http://services.samples", "uploadFileUsingSwAResponse")).
                getFirstChildWithName(new QName("http://services.samples", "response")).
                getFirstChildWithName(new QName("http://services.samples", "imageId")).
                getText();

        Attachments attachment = response.getAttachmentMap();
        dataHandler = attachment.getDataHandler(imageContentId);
        File tempFile = File.createTempFile("swa-", ".gif");
        FileOutputStream fos = new FileOutputStream(tempFile);
        dataHandler.writeTo(fos);
        fos.flush();
        fos.close();

        System.out.println("Saved response to file : " + tempFile.getAbsolutePath());

        return response;
    }
 
Example 19
Source File: DTPBatchRequestSampleTestcase.java    From product-ei with Apache License 2.0 4 votes vote down vote up
@Test(groups = {"wso2.dss"}, dependsOnMethods = "testServiceDeployment")
public void testDTPWithBatchRequests() throws DataServiceFault, RemoteException {
    DTPSampleServiceStub stub = new DTPSampleServiceStub(serverEpr);
    stub._getServiceClient().getOptions().setManageSession(true);
    stub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);

    //Add two accounts to Bank 1
    Entry[] entry1_1 = stub.addAccountToBank1(1000.00);
    Entry[] entry1_2 = stub.addAccountToBank1(1000.00);
    //Add an account to Bank 2
    Entry[] entry2 = stub.addAccountToBank2(2000.00);

    ServiceClient sender = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(serverEpr));
    options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);
    options.setManageSession(true);
    sender.setOptions(options);
    
    options.setAction("urn:" + "begin_boxcar");
    sender.setOptions(options);
    sender.sendRobust(begin_boxcar());
    

    //Send a batch request to Bank 1 to update two accounts
    OMElement payload = createBatchRequestPayload(entry1_1[0].getID().intValue(), entry1_2[0].getID().intValue());
    options.setAction("urn:" + "addToAccountBalanceInBank1_batch_req");
    sender.setOptions(options);
    sender.sendRobust(payload);
             

    //this line will cases dss fault due to service input parameter validation
    payload = createAccountUpdatePayload(entry2[0].getID().intValue());
    options.setAction("urn:" + "addToAccountBalanceInBank2");
    sender.setOptions(options);
    sender.sendRobust(payload);

    try {
    	options.setAction("urn:" + "end_boxcar");
        sender.setOptions(options);
    	sender.sendRobust(end_boxcar());
    } catch (AxisFault dssFault) {
        log.error("DSS fault ignored");
    }

    assertEquals(stub.getAccountBalanceFromBank1(entry1_1[0].getID().intValue()), 1000.00);
    assertEquals(stub.getAccountBalanceFromBank1(entry1_2[0].getID().intValue()), 1000.00);
    assertEquals(stub.getAccountBalanceFromBank2(entry2[0].getID().intValue()), 2000.00);
}
 
Example 20
Source File: SecurityWithServiceDescriptorTest.java    From product-ei with Apache License 2.0 4 votes vote down vote up
@Test(groups = { "wso2.bps",
	                 "wso2.bps.security" }, description = "BPEL security test scenario - secure BPEL process with service.xml file") public void securityWithServiceDescriptorTest()
			throws Exception {
		requestSender.waitForProcessDeployment(backEndUrl + "SWSDPService");
//		FrameworkConstants.start();

		String securityPolicyPath =
				FrameworkPathUtil.getSystemResourceLocation() + BPSTestConstants.DIR_ARTIFACTS +
				File.separator + BPSTestConstants.DIR_POLICY + File.separator + "utpolicy.xml";

		String endpointHttpS = "https://localhost:9645/services/SWSDPService";

		String trustStore =
				CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator +
				"resources" +
				File.separator + "security" + File.separator + "wso2carbon.jks";
		String clientKey = trustStore;
		OMElement result;

		System.setProperty("javax.net.ssl.trustStore", trustStore);
		System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");

		if (log.isDebugEnabled()) {
			log.debug("Carbon Home: " + CarbonUtils.getCarbonHome());
		}
		ConfigurationContext ctx = ConfigurationContextFactory
				.createConfigurationContextFromFileSystem(
						CarbonUtils.getCarbonHome() + File.separator + "repository" +
						File.separator + "deployment" + File.separator + "client", null);
		ServiceClient sc = new ServiceClient(ctx, null);
		sc.engageModule("addressing");
		sc.engageModule("rampart");

		Options opts = new Options();

		opts.setTo(new EndpointReference(endpointHttpS));
		log.info(endpointHttpS);

		opts.setAction("urn:swsdp");

		log.info("SecurityPolicyPath " + securityPolicyPath);
		opts.setProperty(RampartMessageData.KEY_RAMPART_POLICY,
		                 loadPolicy(securityPolicyPath, clientKey, "admin"));
		sc.setOptions(opts);
		result = sc.sendReceive(
				AXIOMUtil.stringToOM("<p:swsdp xmlns:p=\"http://wso2.org/bpel/sample.wsdl\">\n" +
				                     "      <TestPart>ww</TestPart>\n" +
				                     "   </p:swsdp>"));
		log.info(result.getFirstElement().getText());
		Assert.assertFalse("Incorrect Test Result: " + result.toString(),
		                   !result.toString().contains("ww World"));
	}