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

The following examples show how to use org.apache.axis2.client.ServiceClient#engageModule() . 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: SecureSample.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    String epr = "https://" + HOST_IP + ":" + HOST_HTTPS_PORT + "/services/samples/SecureDataService";
    System.setProperty("javax.net.ssl.trustStore", (new File(CLIENT_JKS_PATH)).getAbsolutePath());
    ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
    SecureDataServiceStub stub = new SecureDataServiceStub(ctx, epr);
    ServiceClient client = stub._getServiceClient();
    Options options = client.getOptions();
    client.engageModule("rampart");
    options.setUserName("admin");
    options.setPassword("admin");

    options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, loadPolicy(SECURITY_POLICY_PATH));
    Office[] offices = stub.showAllOffices();
    for (Office office : offices) {
        System.out.println("\t-----------------------------");
        System.out.println("\tOffice Code: " + office.getOfficeCode());
        System.out.println("\tPhone: " + office.getPhone());
        System.out.println("\tAddress Line 1: " + office.getAddressLine1());
        System.out.println("\tAddress Line 2: " + office.getAddressLine2());
        System.out.println("\tCity: " + office.getCity());
        System.out.println("\tState: " + office.getState());
        System.out.println("\tPostal Code: " + office.getPostalCode());
        System.out.println("\tCountry: " + office.getCountry());
    }
}
 
Example 2
Source File: SecureSample.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
	String epr = "https://" + HOST_IP + ":" + HOST_HTTPS_PORT + "/services/samples/SecureDataService";
	System.setProperty("javax.net.ssl.trustStore", (new File(CLIENT_JKS_PATH)).getAbsolutePath());
	ConfigurationContext ctx = ConfigurationContextFactory
			.createConfigurationContextFromFileSystem(null, null);
               SecureDataServiceStub stub = new SecureDataServiceStub(ctx, epr);
	ServiceClient client = stub._getServiceClient();
	Options options = client.getOptions();
	client.engageModule("rampart");		
	options.setUserName("admin");
	options.setPassword("admin");

	options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, loadPolicy(SECURITY_POLICY_PATH));
	Office[] offices = stub.showAllOffices();
	for (Office office : offices) {
		System.out.println("\t-----------------------------");
		System.out.println("\tOffice Code: " + office.getOfficeCode());
		System.out.println("\tPhone: " + office.getPhone());
		System.out.println("\tAddress Line 1: " + office.getAddressLine1());
		System.out.println("\tAddress Line 2: " + office.getAddressLine2());
		System.out.println("\tCity: " + office.getCity());			
		System.out.println("\tState: " + office.getState());
		System.out.println("\tPostal Code: " + office.getPostalCode());
		System.out.println("\tCountry: " + office.getCountry());
	}
}
 
Example 3
Source File: SecureSample.java    From product-ei with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
	String epr = "https://" + HOST_IP + ":" + HOST_HTTPS_PORT + "/services/samples/SecureDataService";
	System.setProperty("javax.net.ssl.trustStore", (new File(CLIENT_JKS_PATH)).getAbsolutePath());
	ConfigurationContext ctx = ConfigurationContextFactory
			.createConfigurationContextFromFileSystem(null, null);
               SecureDataServiceStub stub = new SecureDataServiceStub(ctx, epr);
	ServiceClient client = stub._getServiceClient();
	Options options = client.getOptions();
	client.engageModule("rampart");		
	options.setUserName("admin");
	options.setPassword("admin");

	options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, loadPolicy(SECURITY_POLICY_PATH));
	Office[] offices = stub.showAllOffices();
	for (Office office : offices) {
		System.out.println("\t-----------------------------");
		System.out.println("\tOffice Code: " + office.getOfficeCode());
		System.out.println("\tPhone: " + office.getPhone());
		System.out.println("\tAddress Line 1: " + office.getAddressLine1());
		System.out.println("\tAddress Line 2: " + office.getAddressLine2());
		System.out.println("\tCity: " + office.getCity());			
		System.out.println("\tState: " + office.getState());
		System.out.println("\tPostal Code: " + office.getPostalCode());
		System.out.println("\tCountry: " + office.getCountry());
	}
}
 
Example 4
Source File: IWAUIAuthenticator.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @param request
 * @return
 * @throws AxisFault
 */
private IWAAuthenticatorStub getIWAClient(HttpServletRequest request)
        throws AxisFault, IdentityException {

    HttpSession session = request.getSession();
    ServletContext servletContext = session.getServletContext();
    String backendServerURL = request.getParameter("backendURL");
    if (backendServerURL == null) {
        backendServerURL = CarbonUIUtil.getServerURL(servletContext, request.getSession());
    }

    ConfigurationContext configContext = (ConfigurationContext) servletContext
            .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);

    String serviceEPR = backendServerURL + "IWAAuthenticator";
    IWAAuthenticatorStub stub = new IWAAuthenticatorStub(configContext, serviceEPR);
    ServiceClient client = stub._getServiceClient();
    client.engageModule("rampart");
    Policy rampartConfig = IdentityBaseUtil.getDefaultRampartConfig();
    Policy signOnly = IdentityBaseUtil.getSignOnlyPolicy();
    Policy mergedPolicy = signOnly.merge(rampartConfig);
    Options options = client.getOptions();
    options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, mergedPolicy);
    options.setManageSession(true);
    return stub;
}
 
Example 5
Source File: MessageSender.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
private ServiceClient initServiceClient(String epr, int notificationType,
                                        AxisConfiguration axisConf) throws Exception {

    ConfigurationContext cfgCtx = ConfigHolder.getInstance().getClientConfigurationContext();
    ServiceClient serviceClient = new ServiceClient(cfgCtx, null);
    serviceClient.setTargetEPR(new EndpointReference(epr));
    if (notificationType == DiscoveryConstants.NOTIFICATION_TYPE_HELLO) {
        serviceClient.getOptions().setAction(DiscoveryConstants.WS_DISCOVERY_HELLO_ACTION);
    } else {
        serviceClient.getOptions().setAction(DiscoveryConstants.WS_DISCOVERY_BYE_ACTION);
    }

    serviceClient.engageModule("addressing");

    Registry registry = (Registry)PrivilegedCarbonContext.getThreadLocalCarbonContext().getRegistry(
            RegistryType.SYSTEM_CONFIGURATION);
    Policy policy = DiscoveryMgtUtils.getClientSecurityPolicy(registry);
    if (policy != null) {
        serviceClient.engageModule("rampart");
        serviceClient.getOptions().setProperty(
                DiscoveryConstants.KEY_RAMPART_POLICY, policy);
    }

    return serviceClient;
}
 
Example 6
Source File: ServiceInvoker.java    From micro-integrator 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 7
Source File: ServiceInvoker.java    From micro-integrator 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 8
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 9
Source File: XdsTest.java    From openxds with Apache License 2.0 5 votes vote down vote up
protected ServiceClient getRepositoryServiceClient() throws AxisFault {
	ConfigurationContext configctx = getContext();
	ServiceClient sender = new ServiceClient(configctx,null);
	String action = "urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-b";
	boolean enableMTOM = true;
	sender.setOptions(getOptions(action, enableMTOM, repositoryUrl));
	sender.engageModule("addressing");			
	return sender;
}
 
Example 10
Source File: XdsTest.java    From openxds with Apache License 2.0 5 votes vote down vote up
protected ServiceClient getRegistryServiceClient() 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, registryUrl));
	sender.engageModule("addressing");				
	return sender;
}
 
Example 11
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 12
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 13
Source File: XdsTest.java    From openxds with Apache License 2.0 5 votes vote down vote up
protected ServiceClient getRepositoryGateWayClient() throws AxisFault {
       ConfigurationContext configctx = getContext();
	ServiceClient sender = new ServiceClient(configctx,null);
	String action = "urn:ihe:iti:2007:CrossGatewayRetrieve";
	boolean enableMTOM = true;
	sender.setOptions(getOptions(action, enableMTOM, rgUrl));
	sender.engageModule("addressing");				
	return sender;
}
 
Example 14
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 15
Source File: XdsTest.java    From openxds with Apache License 2.0 5 votes vote down vote up
protected ServiceClient getIGRetrieveServiceClient() 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, igUrl));
	sender.engageModule("addressing");
	return sender;
}
 
Example 16
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"));
	}