class Test extends Specification { def 'spec'() { given: def service = new ServiceClient() def order = Mock(Order) order.getProduct() >> 'product1' order.getProfile() >> 'profile1' order.getQuantity() >> 3 service.rh = Mock(RequestHelper) when: service.doCall(order) then: noExceptionThrown() 1 * rh.populateOrderRequestBody('product1',3,'profile1',FACTORY.CreateOrderType) } }
public RemoteServiceManager(ServiceId serviceId, ClientConfig clientConfig, RESTClient restClient, RemoteApplicationManager remoteApplicationManager) { super(serviceId, remoteApplicationManager); this.serviceId = serviceId; this.metricsClient = new MetricsClient(clientConfig, restClient); this.programClient = new ProgramClient(clientConfig, restClient); this.serviceClient = new ServiceClient(clientConfig, restClient); }
ServiceClient client = new ServiceClient(); // build your service client here Options options = new Options(); HttpTransportProperties.ProxyProperties proxyProperties = new HttpTransportProperties.ProxyProperties(); proxyProperties.setDomain(""); proxyProperties.setProxyName(""); proxyProperties.setProxyPort(8000); proxyProperties.setUserName(""); proxyProperties.setPassWord(""); options.setProperty(HTTPConstants.PROXY, proxyProperties); client.setOptions(options);
ServiceClient sc = new ServiceClient(); Options opt= new Options(); //set the target EP opt.setTo(new EndpointReference("http://localhost:8080/axis2/services/CountryService")); opt.setAction("urn:getCountryDetails"); sc.setOptions(opt); sc.sendReceiveNonBlocking(payload, callBack);
public static void main(String[] args) throws Exception { String endPoint = "http://localhost:8080/StudentServiceImplService/StudentServiceImpl"; ServiceClient sc = new ServiceClient(); Options opts = new Options(); opts.setTo(new EndpointReference("http://localhost:8080/StudentServiceImplService/StudentServiceImpl")); sc.setOptions(opts); OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace omNs = fac.createOMNamespace("http://services.tuto.java.com/","ns1"); OMElement method = fac.createOMElement("getStudents", omNs); OMElement res = sc.sendReceive(method); System.out.println(res); Iterator<OMElement> it = res.getChildElements(); while(it.hasNext()) { System.out.println(it.next()); } }
public void serviceClient() throws Exception { // Construct the client used to interact with CDAP ServiceClient serviceClient = new ServiceClient(clientConfig); // Fetch service information using the service in the PurchaseApp example ServiceSpecification serviceSpec = serviceClient.get( NamespaceId.DEFAULT.app("PurchaseApp").service("CatalogLookup")); }
public void uploadFileUsingSwA(String fileName) throws Exception { Options options = new Options(); options.setTo(targetEPR); options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE); options.setTransportInProtocol(Constants.TRANSPORT_HTTP); options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI); options.setTo(targetEPR); ServiceClient sender = new ServiceClient(null,null); sender.setOptions(options); OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP); MessageContext mc = new MessageContext(); mc.setEnvelope(createEnvelope()); FileDataSource fileDataSource = new FileDataSource("test-resources/mtom/test.jpg"); DataHandler dataHandler = new DataHandler(fileDataSource); mc.addAttachment("FirstAttachment",dataHandler); mepClient.addMessageContext(mc); mepClient.execute(true); }
// Set the max connections to 20 and the timeout to 20 seconds MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(20); params.setMaxTotalConnections(20); params.setSoTimeout(20000); params.setConnectionTimeout(20000); multiThreadedHttpConnectionManager.setParams(params); HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager); // Create the service client ServiceClient serviceClient = new ServiceClient(); Options options = new Options(); options.setTo(new EndpointReference(endpoint)); options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE); options.setProperty(Constants.Configuration.HTTP_METHOD, Constants.Configuration.HTTP_METHOD_POST); serviceClient.getServiceContext().getConfigurationContext().setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); serviceClient.setOptions(options); // Blocking call OMElement result = serviceClient.sendReceive(ClientUtils.getRestPayload()); // just a dummy payload <root></root> // Cleanup Transport after each call, this is needed to otherwise the HTTP gets blocked serviceClient.cleanupTransport();