Java Code Examples for org.apache.axis2.client.Options#setTo()
The following examples show how to use
org.apache.axis2.client.Options#setTo() .
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 |
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: Sample702TestCase.java From micro-integrator with Apache License 2.0 | 6 votes |
@Test(groups = { "wso2.esb" }, description = "Introduction to Message Forwarding Processor " + "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) == 0, "Messages are not forwarded"); }
Example 3
Source File: RetrieveB.java From openxds with Apache License 2.0 | 6 votes |
private OMElement call(OMElement metadata_ele, String endpoint) throws XdsWSException, XdsException, AxisFault { Options options = new Options(); options.setTo(new EndpointReference(endpoint)); // this sets the location of MyService service ServiceClient serviceClient = new ServiceClient(); serviceClient.setOptions(options); OMElement result; Soap soap = new Soap(); soap.setAsync(async); soap.soapCall(metadata_ele, null, //Protocol endpoint, true, // mtom true, // addressing soap12, // soap12 getRequestAction(), getResponseAction()); result = soap.getResult(); return result; }
Example 4
Source File: WSEventDispatcher.java From carbon-commons with Apache License 2.0 | 6 votes |
protected void sendNotification(OMElement topicHeader, 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. ServiceClient serviceClient = new ServiceClient(); Options options = new Options(); options.setTo(new EndpointReference(endpoint)); options.setAction(EventingConstants.WSE_PUBLISH); serviceClient.setOptions(options); serviceClient.addHeader(topicHeader); serviceClient.fireAndForget(payload); }
Example 5
Source File: Sample701TestCase.java From product-ei with Apache License 2.0 | 6 votes |
@Test(groups = { "wso2.esb" }, description = "Introduction to Message Sampling Processor " + "test case") public void messageStoreFIXStoringTest() 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"); ServiceClient serviceClient = new ServiceClient(); Options options = new Options(); options.setTo(new EndpointReference(getBackEndServiceUrl("StockQuoteProxy"))); options.setAction("urn:placeOrder"); options.setProperty(Constants.Configuration.TRANSPORT_URL, getMainSequenceURL()); serviceClient.setOptions(options); for (int i = 0; i < 10; i++) { serviceClient.sendRobust(createPayload()); } Assert.assertTrue(messageStoreAdminClient.getMessageCount(MESSAGE_STORE_NAME) > 0, "Messages are not stored"); }
Example 6
Source File: Sample704TestCase.java From product-ei with Apache License 2.0 | 6 votes |
@Test(groups = { "wso2.esb" }, description = "RESTful Invocations with Message Forwarding" + " Processor test case") public void messageStoreFIXStoringTest() throws Exception { ServiceClient serviceClient = new ServiceClient(); Options options = new Options(); options.setTo(new EndpointReference(getBackEndServiceUrl("StockQuoteProxy"))); options.setAction("urn:placeOrder"); options.setProperty(Constants.Configuration.TRANSPORT_URL, getMainSequenceURL()); serviceClient.setOptions(options); for (int i = 0; i < 10; i++) { serviceClient.sendRobust(createPayload()); } Thread.sleep(2000); Assert.assertTrue(messageStoreAdminClient.getMessageCount(MESSAGE_STORE_NAME) == 0, "Messages are stored"); }
Example 7
Source File: WSXACMLEntitlementServiceClient.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * 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 8
Source File: LoadbalanceFailoverClient.java From product-ei with Apache License 2.0 | 5 votes |
/** * This method is used to send a single request to the load balancing service * @param proxyURL will be the location where load balancing proxy or sequence is defined. * @param serviceURL will be the URL for LBService * @return the response * @throws org.apache.axis2.AxisFault */ public String sendLoadBalanceRequest(String proxyURL,String serviceURL) throws AxisFault { OMFactory fac = OMAbstractFactory.getOMFactory(); OMElement value = fac.createOMElement("Value", null); value.setText("Sample string"); Options options = new Options(); if (proxyURL != null && !"null".equals(proxyURL)) { options.setTo(new EndpointReference(proxyURL)); } options.setAction("urn:sampleOperation"); long timeout = Integer.parseInt(getProperty("timeout", "10000000")); System.out.println("timeout=" + timeout); options.setTimeOutInMilliSeconds(timeout); if (serviceURL != null && !"null".equals(serviceURL)) { // set addressing, transport and proxy url serviceClient.engageModule("addressing"); options.setTo(new EndpointReference(serviceURL)); } serviceClient.setOptions(options); serviceClient.getOptions().setManageSession(true); OMElement responseElement = serviceClient.sendReceive(value); String response = responseElement.getText(); return response; }
Example 9
Source File: ApplicationCreationWSWorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * 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 10
Source File: ApplicationRegistrationWSWorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * 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: ServiceInvoker.java From micro-integrator with Apache License 2.0 | 5 votes |
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 12
Source File: LoadbalanceFailoverClient.java From product-ei with Apache License 2.0 | 5 votes |
public String sessionlessClient() throws AxisFault { OMFactory fac = OMAbstractFactory.getOMFactory(); OMElement value = fac.createOMElement("Value", null); value.setText("Sample string"); Options options = new Options(); options.setTo(new EndpointReference("http://localhost:8480/services/LBService1")); options.setAction("urn:sampleOperation"); long timeout = Integer.parseInt(getProperty("timeout", "10000000")); System.out.println("timeout=" + timeout); options.setTimeOutInMilliSeconds(timeout); // set addressing, transport and proxy url serviceClient.engageModule("addressing"); options.setTo(new EndpointReference("http://localhost:8480")); serviceClient.setOptions(options); String testString = ""; long i = 0; while (i < 100) { serviceClient.getOptions().setManageSession(true); OMElement responseElement = serviceClient.sendReceive(value); String response = responseElement.getText(); i++; System.out.println("Request: " + i + " ==> " + response); testString = testString.concat(":" + i + ">" + response + ":"); } return testString; }
Example 13
Source File: Sample705TestCase.java From product-ei with Apache License 2.0 | 5 votes |
@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 |
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: LoadbalanceFailoverClient.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * This method is used to send a single request to the load balancing service * * @param proxyURL will be the location where load balancing proxy or sequence is defined. * @param serviceURL will be the URL for LBService * @return the response * @throws org.apache.axis2.AxisFault */ public String sendLoadBalanceRequest(String proxyURL, String serviceURL) throws AxisFault { OMFactory fac = OMAbstractFactory.getOMFactory(); OMElement value = fac.createOMElement("Value", null); value.setText("Sample string"); Options options = new Options(); if (proxyURL != null && !"null".equals(proxyURL)) { options.setTo(new EndpointReference(proxyURL)); } options.setAction("urn:sampleOperation"); long timeout = Integer.parseInt(getProperty("timeout", "10000000")); System.out.println("timeout=" + timeout); options.setTimeOutInMilliSeconds(timeout); if (serviceURL != null && !"null".equals(serviceURL)) { // set addressing, transport and proxy url serviceClient.engageModule("addressing"); options.setTo(new EndpointReference(serviceURL)); } serviceClient.setOptions(options); serviceClient.getOptions().setManageSession(true); OMElement responseElement = serviceClient.sendReceive(value); String response = responseElement.getText(); return response; }
Example 16
Source File: AxisServiceClientUtils.java From micro-integrator with Apache License 2.0 | 5 votes |
public static void sendRequestOneWay(String payloadStr, EndpointReference targetEPR) throws XMLStreamException, AxisFault { OMElement payload = AXIOMUtil.stringToOM(payloadStr); Options options = new Options(); options.setTo(targetEPR); //options.setAction("urn:" + operation); //since soapAction = "" //Blocking invocation ServiceClient sender = new ServiceClient(); sender.setOptions(options); sender.fireAndForget(payload); }
Example 17
Source File: SubscriptionUpdateWSWorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * 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 18
Source File: DTPBatchRequestSampleTestcase.java From micro-integrator with Apache License 2.0 | 4 votes |
@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 19
Source File: MTOMSwAClient.java From micro-integrator with Apache License 2.0 | 4 votes |
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 20
Source File: MTOMSwAClient.java From micro-integrator with Apache License 2.0 | 4 votes |
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; }