Java Code Examples for org.apache.axis2.client.Options#setAction()
The following examples show how to use
org.apache.axis2.client.Options#setAction() .
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: AxisOperationClient.java From product-ei with Apache License 2.0 | 6 votes |
/** * creating the message context of the soap message * * @param addUrl * @param trpUrl * @param action */ private void setMessageContext(String addUrl, String trpUrl, String action) { outMsgCtx = new MessageContext(); //assigning message context’s option object into instance variable Options options = outMsgCtx.getOptions(); //setting properties into option if (trpUrl != null && !"null".equals(trpUrl)) { options.setProperty(Constants.Configuration.TRANSPORT_URL, trpUrl); } if (addUrl != null && !"null".equals(addUrl)) { options.setTo(new EndpointReference(addUrl)); } if(action != null && !"null".equals(action)) { options.setAction(action); } }
Example 2
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 3
Source File: CallOutMediatorWithMTOMTestCase.java From product-ei with Apache License 2.0 | 6 votes |
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 4
Source File: SOAPClient.java From product-ei with Apache License 2.0 | 6 votes |
/** * 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 5
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 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: 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 8
Source File: Sample700TestCase.java From product-ei with Apache License 2.0 | 6 votes |
@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 9
Source File: Sample700TestCase.java From micro-integrator with Apache License 2.0 | 6 votes |
@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 10
Source File: XdsTest.java From openxds with Apache License 2.0 | 6 votes |
protected Options getOptions(String action, boolean enableMTOM, String url) { Options options = new Options(); options.setAction(action); options.setProperty(WSDL2Constants.ATTRIBUTE_MUST_UNDERSTAND,"1"); options.setTo( new EndpointReference(url) ); options.setTransportInProtocol(Constants.TRANSPORT_HTTP); // try { // String from = InetAddress.getLocalHost().getHostAddress(); // options.setFrom(new EndpointReference(from)); // }catch(UnknownHostException e) { // //ignore From // } if (enableMTOM) options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE); else options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_FALSE); //use SOAP12, options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI); return options; }
Example 11
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 12
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 13
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 14
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, String clientTimeoutInMilliSeconds) 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", clientTimeoutInMilliSeconds)); 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 15
Source File: UserSignUpWSWorkflowExecutor.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 16
Source File: LoadBalanceSessionFullClient.java From micro-integrator with Apache License 2.0 | 5 votes |
private void updateServiceClientOptions(String trpUrl, String addUrl, String prxUrl) throws AxisFault { Options options = new Options(); options.setTo(new EndpointReference(trpUrl)); options.setAction("urn:sampleOperation"); options.setTimeOutInMilliSeconds(10000000); // set addressing, transport and proxy url if (addUrl != null && !"null".equals(addUrl)) { serviceClient.engageModule("addressing"); options.setTo(new EndpointReference(addUrl)); } if (trpUrl != null && !"null".equals(trpUrl)) { options.setProperty(Constants.Configuration.TRANSPORT_URL, trpUrl); } else { serviceClient.engageModule("addressing"); } serviceClient.engageModule("addressing"); if (prxUrl != null && !"null".equals(prxUrl)) { HttpTransportProperties.ProxyProperties proxyProperties = new HttpTransportProperties.ProxyProperties(); try { URL url = new URL(prxUrl); proxyProperties.setProxyName(url.getHost()); proxyProperties.setProxyPort(url.getPort()); proxyProperties.setUserName(""); proxyProperties.setPassWord(""); proxyProperties.setDomain(""); options.setProperty(HTTPConstants.PROXY, proxyProperties); } catch (MalformedURLException e) { String msg = "Error while creating proxy URL"; log.error(msg, e); throw new AxisFault(msg, e); } } serviceClient.setOptions(options); }
Example 17
Source File: TcpClient.java From product-ei with Apache License 2.0 | 4 votes |
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 18
Source File: SecurityWithServiceDescriptorTest.java From product-ei with Apache License 2.0 | 4 votes |
@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")); }
Example 19
Source File: TestUtils.java From micro-integrator with Apache License 2.0 | 3 votes |
/** * Calls an operation of a target web service with the given parameters and * returns the result, support array types. * * @param epr * End point reference of the service * @param opName * Operation to be called in the service * @param params * Parameters of the service call * @return Service results * @throws AxisFault */ public static OMElement callOperationWithArray(String epr, String opName, List<List<String>> params) throws AxisFault { EndpointReference targetEPR = new EndpointReference(epr); OMElement payload = getPayload(opName, params); Options options = new Options(); options.setTo(targetEPR); options.setAction("urn:" + opName); ServiceClient sender = new ServiceClient(); sender.setOptions(options); OMElement result = sender.sendReceive(payload); return result; }
Example 20
Source File: TestUtils.java From micro-integrator with Apache License 2.0 | 3 votes |
/** * Calls an operation of a target web service with the given parameters and * returns the result. * * @param epr * End point reference of the service * @param opName * Operation to be called in the service * @param params * Parameters of the service call * @return Service results * @throws AxisFault */ public static OMElement callOperation(String epr, String opName, Map<String, String> params) throws AxisFault { EndpointReference targetEPR = new EndpointReference(epr); OMElement payload = getPayload(opName, params); Options options = new Options(); options.setTo(targetEPR); options.setAction("urn:" + opName); ServiceClient sender = new ServiceClient(); sender.setOptions(options); OMElement result = sender.sendReceive(payload); return result; }