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

The following examples show how to use org.apache.axis2.client.Options#setCallTransportCleanup() . 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: 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 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: 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: CallOutMediatorWithMTOMTestCase.java    From product-ei 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 6
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 7
Source File: BasicAuthCredentialValidator.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the validator with the synapse environment.
 *
 * @throws APISecurityException If an authentication failure or some other error occurs
 */
BasicAuthCredentialValidator() throws APISecurityException {
    this.gatewayKeyCacheEnabled = isGatewayTokenCacheEnabled();
    this.getGatewayUsernameCache();

    ConfigurationContext configurationContext = ServiceReferenceHolder.getInstance().getAxis2ConfigurationContext();
    APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfiguration();
    String username = config.getFirstProperty(APIConstants.API_KEY_VALIDATOR_USERNAME);
    String password = config.getFirstProperty(APIConstants.API_KEY_VALIDATOR_PASSWORD);
    String url = config.getFirstProperty(APIConstants.API_KEY_VALIDATOR_URL);
    if (url == null) {
        throw new APISecurityException(APISecurityConstants.API_AUTH_GENERAL_ERROR,
                "API key manager URL unspecified");
    }

    try {
        apiKeyMgtRemoteUserStoreMgtServiceStub = new APIKeyMgtRemoteUserStoreMgtServiceStub(configurationContext, url +
                "APIKeyMgtRemoteUserStoreMgtService");
        ServiceClient client = apiKeyMgtRemoteUserStoreMgtServiceStub._getServiceClient();
        Options options = client.getOptions();
        options.setCallTransportCleanup(true);
        options.setManageSession(true);
        CarbonUtils.setBasicAccessSecurityHeaders(username, password, client);
    } catch (AxisFault axisFault) {
        throw new APISecurityException(APISecurityConstants.API_AUTH_GENERAL_ERROR, axisFault.getMessage(), axisFault);
    }
}
 
Example 8
Source File: RemoteAuthorizationManagerClient.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public RemoteAuthorizationManagerClient() {
    APIManagerConfiguration config = ServiceReferenceHolder.getInstance().
            getAPIManagerConfigurationService().getAPIManagerConfiguration();
    String serviceURL = config.getFirstProperty(APIConstants.AUTH_MANAGER_URL);
    username = config.getFirstProperty(APIConstants.AUTH_MANAGER_USERNAME);
    password = config.getFirstProperty(APIConstants.AUTH_MANAGER_PASSWORD);
    if (serviceURL == null || username == null || password == null) {
        throw new IllegalArgumentException("Required connection details for authentication " +
                "manager not provided");
    }

    try {
        authorizationManager = new RemoteAuthorizationManagerServiceStub(null, serviceURL +
                "RemoteAuthorizationManagerService");
        userStoreManager = new RemoteUserStoreManagerServiceStub(null, serviceURL +
                "RemoteUserStoreManagerService");
        for (ServiceClient client : new ServiceClient[] {
                authorizationManager._getServiceClient(),
                userStoreManager._getServiceClient()}) {
            Options options = client.getOptions();
            options.setTimeOutInMilliSeconds(TIMEOUT_IN_MILLIS);
            options.setProperty(HTTPConstants.SO_TIMEOUT, TIMEOUT_IN_MILLIS);
            options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, TIMEOUT_IN_MILLIS);
            options.setCallTransportCleanup(true);
            options.setManageSession(true);
        }
    } catch (AxisFault axisFault) {
        throw new IllegalArgumentException("Error while initializing the user management stubs. " +
                "Invalid parameter values passed into initializing the corresponding service clients might " +
                "potentially have been the issue", axisFault);
    }
}
 
Example 9
Source File: RemoteUserManagerClient.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public RemoteUserManagerClient(String cookie) throws APIManagementException {

		APIManagerConfiguration config = ServiceReferenceHolder.getInstance()
		                                                       .getAPIManagerConfigurationService()
		                                                       .getAPIManagerConfiguration();
		String serviceURL = config.getFirstProperty(APIConstants.AUTH_MANAGER_URL);
		String username = config.getFirstProperty(APIConstants.AUTH_MANAGER_USERNAME);
		String password = config.getFirstProperty(APIConstants.AUTH_MANAGER_PASSWORD);
		if (serviceURL == null || username == null || password == null) {
			throw new APIManagementException("Required connection details for authentication");
		}
		
		try {

			String clientRepo = CarbonUtils.getCarbonHome() + File.separator + "repository" +
                    File.separator + "deployment" + File.separator + "client";
			String clientAxisConf = CarbonUtils.getCarbonHome() + File.separator + "repository" +
                    File.separator + "conf" + File.separator + "axis2"+ File.separator +"axis2_client.xml";
			
			ConfigurationContext configContext = ConfigurationContextFactory. createConfigurationContextFromFileSystem(clientRepo,clientAxisConf);
			userStoreManagerStub = new RemoteUserStoreManagerServiceStub(configContext, serviceURL +
			                                                                   "RemoteUserStoreManagerService");
			ServiceClient svcClient = userStoreManagerStub._getServiceClient();
			CarbonUtils.setBasicAccessSecurityHeaders(username, password, svcClient);
			Options options = svcClient.getOptions();
			options.setTimeOutInMilliSeconds(TIMEOUT_IN_MILLIS);
			options.setProperty(HTTPConstants.SO_TIMEOUT, TIMEOUT_IN_MILLIS);
			options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, TIMEOUT_IN_MILLIS);
			options.setCallTransportCleanup(true);
			options.setManageSession(true);		
			options.setProperty(HTTPConstants.COOKIE_STRING, cookie);	
		
		} catch (AxisFault axisFault) {
			throw new APIManagementException(
			                                 "Error while initializing the remote user store manager stub",
			                                 axisFault);
		}
	}