Java Code Examples for org.apache.axis2.client.Options#setProperty()

The following examples show how to use org.apache.axis2.client.Options#setProperty() . 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: ApplicationManagementServiceClient.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @param cookie
 * @param backendServerURL
 * @param configCtx
 * @throws AxisFault
 */
public ApplicationManagementServiceClient(String cookie, String backendServerURL,
                                          ConfigurationContext configCtx) throws AxisFault {

    String serviceURL = backendServerURL + "IdentityApplicationManagementService";
    String userAdminServiceURL = backendServerURL + "UserAdmin";
    stub = new IdentityApplicationManagementServiceStub(configCtx, serviceURL);
    userAdminStub = new UserAdminStub(configCtx, userAdminServiceURL);

    ServiceClient client = stub._getServiceClient();
    Options option = client.getOptions();
    option.setManageSession(true);
    option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);

    ServiceClient userAdminClient = userAdminStub._getServiceClient();
    Options userAdminOptions = userAdminClient.getOptions();
    userAdminOptions.setManageSession(true);
    userAdminOptions.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);

    if (debugEnabled) {
        log.debug("Invoking service " + serviceURL);
    }

}
 
Example 2
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 3
Source File: Sample700TestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Test(groups = { "wso2.esb" }, description = "Introduction to Message Store test case ")
public void messageStoringTest() throws Exception {
    // The count should be 0 as soon as the message store is created
    Assert.assertTrue(messageStoreAdminClient.getMessageCount(MESSAGE_STORE_NAME) == 0,
            "Message store should be initially empty");
    // refer within a sequence through a store mediator, mediate messages
    // and verify the messages are stored correctly in the store.

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(getBackEndServiceUrl("SimpleStockQuoteService")));
    options.setAction("urn:placeOrder");
    options.setProperty(Constants.Configuration.TRANSPORT_URL, getMainSequenceURL());
    serviceClient.setOptions(options);
    serviceClient.sendRobust(createPayload());

    Thread.sleep(30000);
    Assert.assertTrue(messageStoreAdminClient.getMessageCount(MESSAGE_STORE_NAME) == 1,
            "Messages are missing or repeated");

}
 
Example 4
Source File: ServiceAuthenticator.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public void authenticate(ServiceClient client) throws AuthenticationException {

        if (accessUsername != null && accessPassword != null) {
            Options option = client.getOptions();
            HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
            auth.setUsername(accessUsername);
            auth.setPassword(accessPassword);
            auth.setPreemptiveAuthentication(true);
            option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
            option.setManageSession(true);

        } else {
            throw new AuthenticationException("Authentication username or password not set");
        }
    }
 
Example 5
Source File: SubscriptionUpdateWSWorkflowExecutor.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(HTTPConstants.AUTHENTICATE, auth);
        options.setManageSession(true);
    }
    client.setOptions(options);
    return client;
}
 
Example 6
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 7
Source File: FunctionLibraryManagementServiceClient.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates FunctionLibraryManagementServiceClient.
 *
 * @param cookie           For session management
 * @param backendServerURL URL of the back end server where FunctionLibraryManagementAdminServiceStub is running
 * @param configCtx        ConfigurationContext
 * @throws AxisFault
 */
public FunctionLibraryManagementServiceClient(String cookie, String backendServerURL,
                                              ConfigurationContext configCtx) throws AxisFault {

    String serviceURL = backendServerURL + FUNCTION_LIBRARY_MANAGEMENT_SERVICE;
    stub = new FunctionLibraryManagementAdminServiceStub(configCtx, serviceURL);

    ServiceClient client = stub._getServiceClient();
    Options option = client.getOptions();
    option.setManageSession(true);
    option.setProperty(HTTPConstants.COOKIE_STRING, cookie);
}
 
Example 8
Source File: ClaimMetadataMgtServiceClient.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates ClaimMetadataMgtServiceClient
 *
 * @param cookie           For session management
 * @param backendServerURL URL of the back end server where ClaimManagementServiceStub is running.
 * @param configCtx        ConfigurationContext
 * @throws                 AxisFault if error occurs when instantiating the stub
 */
public ClaimMetadataMgtServiceClient(String cookie, String backendServerURL, ConfigurationContext configCtx)
        throws AxisFault {

    String serviceURL = backendServerURL + "ClaimMetadataManagementService";
    stub = new ClaimMetadataManagementServiceStub(configCtx, serviceURL);
    ServiceClient client = stub._getServiceClient();
    Options option = client.getOptions();
    option.setManageSession(true);
    option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
}
 
Example 9
Source File: ReportTemplateClient.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public ReportTemplateClient(ConfigurationContext configCtx, String backendServerURL, String cookie) throws Exception{
	String serviceURL = backendServerURL + "ReportTemplateAdmin";
       stub = new ReportTemplateAdminStub(configCtx, serviceURL);
       ServiceClient client = stub._getServiceClient();
       Options options = client.getOptions();
       options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
       options.setManageSession(true);
       options.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);

}
 
Example 10
Source File: ClaimAdminClient.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates ClaimAdminClient
 *
 * @param cookie           For session management
 * @param backendServerURL URL of the back end server where ClaimManagementServiceStub is
 *                         running.
 * @param configCtx        ConfigurationContext
 * @throws org.apache.axis2.AxisFault if error occurs when instantiating the stub
 */
public ClaimAdminClient(String cookie, String backendServerURL,
                        ConfigurationContext configCtx) throws AxisFault {
    String serviceURL = backendServerURL + "ClaimManagementService";
    stub = new ClaimManagementServiceStub(configCtx, serviceURL);
    ServiceClient client = stub._getServiceClient();
    Options option = client.getOptions();
    option.setManageSession(true);

    option.setProperty(
            org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING,
            cookie);
}
 
Example 11
Source File: ServiceAuthenticator.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
public void authenticate(ServiceClient client) throws ApplicationManagementException {
    Options option = client.getOptions();
    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
    auth.setUsername(username);
    auth.setPassword(password);
    auth.setPreemptiveAuthentication(true);
    option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
    option.setManageSession(true);
}
 
Example 12
Source File: IdentityGovernanceAdminClient.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
public IdentityGovernanceAdminClient(String cookie, String backendServerURL,
                                     ConfigurationContext configContext)
        throws Exception {

    try {
        stub = new IdentityGovernanceAdminServiceStub(configContext,
                backendServerURL + IDENTITY_MGT_ADMIN_SERVICE_URL);
        ServiceClient client = stub._getServiceClient();
        Options option = client.getOptions();
        option.setManageSession(true);
        option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
    } catch (Exception e) {
        throw new Exception("Error occurred while creating TenantIdentityMgtClient Object", e);
    }
}
 
Example 13
Source File: EventingAdminClient.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param cookie
 * @param backendServerURL
 * @param configCtx
 * @throws AxisFault
 */
public EventingAdminClient(String cookie, String backendServerURL,
		ConfigurationContext configCtx) throws AxisFault {
	String serviceURL = backendServerURL + "EventingAdminService";
	stub = new EventingAdminServiceStub(configCtx, serviceURL);
	ServiceClient client = stub._getServiceClient();
	Options option = client.getOptions();
	option.setManageSession(true);
	option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
}
 
Example 14
Source File: IdentityManagementAdminClient.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
public IdentityManagementAdminClient(String cookie, String url, ConfigurationContext configContext)
        throws Exception {
    try {
        stub = new UserIdentityManagementAdminServiceStub(configContext, url + "UserIdentityManagementAdminService");
        ServiceClient client = stub._getServiceClient();
        Options option = client.getOptions();
        option.setManageSession(true);
        option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
    } catch (Exception e) {
        handleException(e.getMessage(), e);
    }
}
 
Example 15
Source File: DefaultAuthenticationSeqMgtServiceClient.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
public DefaultAuthenticationSeqMgtServiceClient(String cookie, String backendServerURL,
                                                ConfigurationContext configCtx) throws Exception {

    String serviceURL = backendServerURL + "IdentityDefaultSeqManagementService";
    stub = new IdentityDefaultSeqManagementServiceStub(configCtx, serviceURL);

    ServiceClient client = stub._getServiceClient();
    Options option = client.getOptions();
    option.setManageSession(true);
    option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);

    if (log.isDebugEnabled()) {
        log.debug("Invoking service " + serviceURL);
    }
}
 
Example 16
Source File: GlobalThrottleEngineClient.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * 1. Check validity of execution plan
 * 2. If execution plan exist with same name edit it
 * 3. Else deploy new execution plan
 *
 * @param executionPlan execution query plan
 * @param sessionCookie session cookie to use established connection
 * @throws RemoteException
 */
private void deploy(String executionPlan, String sessionCookie) throws RemoteException {
    ServiceClient serviceClient;
    Options options;

    EventProcessorAdminServiceStub eventProcessorAdminServiceStub = getEventProcessorAdminServiceStub();
    serviceClient = eventProcessorAdminServiceStub._getServiceClient();
    options = serviceClient.getOptions();
    options.setManageSession(true);
    options.setProperty(HTTPConstants.COOKIE_STRING, sessionCookie);
    eventProcessorAdminServiceStub.deployExecutionPlan(executionPlan);
}
 
Example 17
Source File: TopicAdminClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private void configureCookie(ServiceClient client) throws AxisFault {
    if (SessionCookie != null) {
        Options option = client.getOptions();
        option.setManageSession(true);
        option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, SessionCookie);
    }
}
 
Example 18
Source File: TcpClient.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
public OMElement send12(String trpUrl, String action, OMElement payload, String contentType) throws AxisFault {

        Options options = new Options();
        options.setTo(new EndpointReference(trpUrl));
        options.setTransportInProtocol(Constants.TRANSPORT_TCP);
        options.setAction("urn:" + action);

        options.setProperty(Constants.Configuration.MESSAGE_TYPE, contentType);
        options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);

        serviceClient.engageModule(Constants.MODULE_ADDRESSING);

        serviceClient.setOptions(options);

        OMElement result = serviceClient.sendReceive(payload);

        return result;

    }
 
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: 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;
    }