Wednesday, 15 May 2013

java - How to use CXF client in thread safe way -


I created the client stub for service below using the Apache-cxf 'wsdl2java command.


Then I call the following as the getWeatherInformation () method.

  weather season service = new weather (); WeatherSoap weatherSoap = weatherService.getWeatherSoap (); ArrayOfWeatherDescription Results = WeatherOapGetWeeration ();  

I've read that the CXF client threads are safe. But I doubt whether it is safe to use the same WeatherSoap on multiple codes? Or can I use an example of the Weather class in many threads? Thank you.

Edit:


What I do I have exposed a Restrict API to the public and if someone says that I call any other SOAP service the rest of the service. The above code is used to call the SOAP service. What do I want to know, should I execute all the above lines for every remaining request, or do I reuse an example for the fulfillment of all REST requests of or WeatherSoap I can do

Pure Java

  Public class MySoapClient {Personal Static WeatherSoap weatherSoap; Private MySopClient () {} Public stable weather scope getClient () {if (WeatherSoap == null) {weather weather service = new weather (); WeatherSop = Weather Service Gatewayther soap (); } Weather return SOAP; }}  

And I will modify the weather category to get the SOAP url from the property file.

  @WebServiceClient (name = "weather", wsdlLocation = "classpath: weather.wsdl", targetNamespace = "http://ws.cdyne.com/WeatherWS/") public class weather Extension of service {private stationary logger log = logger factory.getLogger (Weather.class); Public Last Fixed URL WSDL_LOCATION; Public Last Fixed QName SERVICE = New QN ("http://ws.cdyne.com/WeatherWS/", "Weather"); Public Last Fixed QName WeatherHttpPost = New QName ("http://ws.cdyne.com/WeatherWS/", "WeatherHttpPost"); Public Last Fixed QName WeatherHttpGet = New QName ("http://ws.cdyne.com/WeatherWS/", "WeatherHttpGet"); Public Last Fixed QName WeatherSoap12 = New QN ("http://ws.cdyne.com/WeatherWS/", "WeatherSoap12"); Public Last Fixed QName WeatherSoap = New QN ("http://ws.cdyne.com/WeatherWS/", "WeatherSpace"); Static {url = null; {Url = New URL (see MyPropertiesUtil.getProperty ("app.weather.url"); } Catch (MalmarmdoorLecepation E) {LOG.error (e.getMessage (), e); } If (url == faucet) {LOG.error ("an issue with your url"); } WSDL_LOCATION = url; } Public Weather (URL wsdl Location) {Super (WSDL Location, Service); } Public Weather (URL wsdl location, QN service service) {super (WSDL location, savannum); } Public Weather () {Super (WSDL_LOCATION, SERVICE); } // All other interface methods}  

Use of Spring

If you are using spring then you can also simplify things You can create, eliminate the class by using the configuration file to end the Weather.java and cxf generates the proxy for you.

  & lt; Jaxws: client id = "weatherSoap" serviceclass = "com.cdyne.ws.weatherws. WeatherSoap" address = "$ {app.weather.url}" />  

and the business class will look down.

  @Component MyBusinessLogic {@Autowired Private WeatherSoap weatherSoap; Public ArrayOfWeatherDescription getOutput () {Return weather SWoap.getWeatherInformation (); }}  

No comments:

Post a Comment