📄 sampleclient.java
字号:
try { PingServicePortProxy ping = new PingServicePortProxy(wsdlURL); ping._getDescriptor().setEndpoint(endpointURL); System.out.println(">> CLIENT: SEI Ping to " + endpointURL); // Configure SOAPAction properties BindingProvider bp = (BindingProvider) (ping._getDescriptor() .getProxy()); bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL); bp.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE); bp.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, "pingOperation"); // Build the input object PingStringInput pingParm = new ObjectFactory().createPingStringInput(); pingParm.setPingInput(input); // Call the service ping.pingOperation(pingParm); System.out.println(">> CLIENT: SEI Ping SUCCESS."); return true; } catch (Exception e) { System.out.println(">> CLIENT: ERROR: SEI Ping EXCEPTION."); e.printStackTrace(); return false; } } /** * buildEcho * Call the Echo service (Sync) * * @param endpointURL The Service endpoint URL * @param input The message string * @return String from the service */ public String buildEcho(String endpointURL, URL wsdlURL, String input) { String response = "ERROR!:"; try { EchoServicePortProxy echo = new EchoServicePortProxy(wsdlURL); echo._getDescriptor().setEndpoint(endpointURL); // Configure SOAPAction properties BindingProvider bp = (BindingProvider) (echo._getDescriptor() .getProxy()); bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL); bp.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE); bp.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, "echoOperation"); // Build the input object EchoStringInput echoParm = new org.apache.axis2.jaxws.samples.echo.ObjectFactory().createEchoStringInput(); echoParm.setEchoInput(input); System.out.println(">> CLIENT: SEI Echo to " + endpointURL); // Call the service response = echo.echoOperation(echoParm).getEchoResponse(); System.out.println(">> CLIENT: SEI Echo invocation complete."); System.out.println(">> CLIENT: SEI Echo response is: " + response); } catch (Exception e) { System.out.println(">> CLIENT: ERROR: SEI Echo EXCEPTION."); e.printStackTrace(); return response + ">>>ECHO SERVICE EXCEPTION<<< "; } return response; } /** * buildAsync * Call the Echo service (Async) * * @param endpointURL The Service endpoint URL * @param input The message string * @param waiting The Async timeout * @param wireasync true to use Async on the wire * @return String from the service */ public String buildAsync(String endpointURL, URL wsdlURL, String input, int waiting, Boolean wireasync) { String response = "ERROR!:"; try { EchoServicePortProxy echo = new EchoServicePortProxy(wsdlURL); echo._getDescriptor().setEndpoint(endpointURL); // Configure SOAPAction properties BindingProvider bp = (BindingProvider) (echo._getDescriptor() .getProxy()); bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL); bp.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE); bp.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, "echoOperation"); if (wireasync) { bp.getRequestContext().put(org.apache.axis2.jaxws.util.Constants.USE_ASYNC_MEP, Boolean.TRUE); } // Set up the callback handler and create the input object EchoServiceCallbackHandler callbackHandler = new EchoServiceCallbackHandler(); EchoStringInput echoParm = new org.apache.axis2.jaxws.samples.echo.ObjectFactory().createEchoStringInput(); echoParm.setEchoInput(input); System.out.println(">> CLIENT: SEI Async to " + endpointURL); // Call the service Future<?> resp = echo.echoOperationAsync(echoParm, callbackHandler); Thread.sleep(1000); while (!resp.isDone()) { // Check for timeout if (waiting <= 0) { System.out .println(">> CLIENT: ERROR - SEI Async Timeout waiting for reply."); return response + "Async timeout waiting for reply."; } System.out .println(">> CLIENT: SEI Async invocation still not complete"); Thread.sleep(1000 * SLEEPER); waiting -= SLEEPER; } // Get the response and print it, then return EchoStringResponse esr = callbackHandler.getResponse(); System.out.println(">> CLIENT: SEI Async invocation complete."); if (null != esr) { response = esr.getEchoResponse(); if (null != response) { System.out.println(">> CLIENT: SEI Async response is: " + response); } } } catch (Exception e) { System.out.println(">> CLIENT: ERROR: SEI Async EXCEPTION."); e.printStackTrace(); return response + ">>>ASYNC SERVICE EXCEPTION<<<"; } return response; } /** * buildPing12 * Call the ping service * * @param endpointURL The Service endpoint URL * @param input The message string * @return Boolean true if the ping works */ public boolean buildPing12(String endpointURL, URL wsdlURL, String input) { try { PingService12PortProxy ping = new PingService12PortProxy(wsdlURL); ping._getDescriptor().setEndpoint(endpointURL); System.out.println(">> CLIENT: SEI Ping to " + endpointURL); // Build the input object PingStringInput pingParm = new org.apache.axis2.jaxws.samples.ping.ObjectFactory().createPingStringInput(); pingParm.setPingInput(input); // Call the service ping.pingOperation(pingParm); System.out.println(">> CLIENT: SEI Ping SUCCESS."); return true; } catch (Exception e) { System.out.println(">> CLIENT: ERROR: SEI Ping EXCEPTION."); e.printStackTrace(); return false; } } /** * buildEcho12 * Call the Echo service (Sync) * * @param endpointURL The Service endpoint URL * @param input The message string * @return String from the service */ public String buildEcho12(String endpointURL, URL wsdlURL, String input) { String response = "ERROR!:"; try { EchoService12PortProxy echo = new EchoService12PortProxy(wsdlURL); echo._getDescriptor().setEndpoint(endpointURL); // Build the input object EchoStringInput echoParm = new org.apache.axis2.jaxws.samples.echo.ObjectFactory().createEchoStringInput(); echoParm.setEchoInput(input); System.out.println(">> CLIENT: SEI Echo to " + endpointURL); // Call the service response = echo.echoOperation(echoParm).getEchoResponse(); System.out.println(">> CLIENT: SEI Echo invocation complete."); System.out.println(">> CLIENT: SEI Echo response is: " + response); } catch (Exception e) { System.out.println(">> CLIENT: ERROR: SEI Echo EXCEPTION."); e.printStackTrace(); return response + ">>>ECHO SERVICE EXCEPTION<<< "; } return response; } /** * buildAsync12 * Call the Echo service (Async) * * @param endpointURL The Service endpoint URL * @param input The message string * @param waiting The Async timeout * @param wireasync true to use Async on the wire * @return String from the service */ public String buildAsync12(String endpointURL, URL wsdlURL, String input, int waiting, Boolean wireasync) { String response = "ERROR!:"; try { EchoService12PortProxy echo = new EchoService12PortProxy(wsdlURL); echo._getDescriptor().setEndpoint(endpointURL); // Configure over-the-wire async if specified if (wireasync) { BindingProvider bp = (BindingProvider) (echo._getDescriptor() .getProxy()); bp.getRequestContext().put(org.apache.axis2.jaxws.util.Constants.USE_ASYNC_MEP, Boolean.TRUE); } // Set up the callback handler and create the input object EchoServiceCallbackHandler callbackHandler = new EchoServiceCallbackHandler(); EchoStringInput echoParm = new org.apache.axis2.jaxws.samples.echo.ObjectFactory().createEchoStringInput(); echoParm.setEchoInput(input); System.out.println(">> CLIENT: SEI Async to " + endpointURL); // Call the service Future<?> resp = echo.echoOperationAsync(echoParm, callbackHandler); Thread.sleep(1000); while (!resp.isDone()) { // Check for timeout if (waiting <= 0) { System.out .println(">> CLIENT: ERROR - SEI Async Timeout waiting for reply."); return response + "Async timeout waiting for reply."; } System.out .println(">> CLIENT: SEI Async invocation still not complete"); Thread.sleep(1000 * SLEEPER); waiting -= SLEEPER; } // Get the response and print it, then return EchoStringResponse esr = callbackHandler.getResponse(); System.out.println(">> CLIENT: SEI Async invocation complete."); if (null != esr) { response = esr.getEchoResponse(); if (null != response) { System.out.println(">> CLIENT: SEI Async response is: " + response); } } } catch (Exception e) { System.out.println(">> CLIENT: ERROR: SEI Async EXCEPTION."); e.printStackTrace(); return response + ">>>ASYNC SERVICE EXCEPTION<<<"; } return response; } public void setClientConfigurationFactory(ClientConfigurationFactory clientConfigurationFactory) { this.clientConfigurationFactory = clientConfigurationFactory; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -