JAVA6 WebService Client Package

Source: Internet
Author: User
Tags wsdl

When developing WebService client applications, the biggest challenge is not knowing where the server is going to be deployed and what the ports are, so the example of Hello World is not suitable for production environments and needs to be further improved. The overall idea of the improvement is to replace the static part with dynamic, that is, to make the IP and port of the service into dynamic parameters, and then flexibly change these configuration parameters according to the deployment of the server. Here is an improvement to the client for the previous example. 1, write WebService service configuration parameter fileConfiguration of the Wscfg.properties#java6ws service
java6ws.wsip=192.168.14.117
java6ws.wsport=8888 2. Write Configuration parameter Acquisition toolSysparamstoolkit.javaimport java.io.IOException;
ImportJava.util.Properties;

/**
* Media Resources System configuration file parameter acquisition tool
*
* @author leizhimin 2009-11-16 15:21:22
*/

Public Final classSysparamstoolkit {
Private StaticProperties prop;

PrivateSysparamstoolkit () {
}

Static{
Reload ();
}

Public Static BooleanReload () {
BooleanFlag =true;
Prop =NewProperties ();
Try{
Prop.load (Sysparamstoolkit.class. getResourceAsStream ("/wscfg.properties"));
Flag =false;
}Catch(IOException e) {
E.printstacktrace ();
}
returnFlag
}

Public StaticProperties getsysproperties () {
returnProp
}

/**
* Gets the specified system property value
*
* @param the name of the property specified by key
* @return The specified system property value
*/
Public StaticString GetProperty (String key) {
returnProp.getproperty (key);
}

/**
* Gets the specified system property value
*
* @param the name of the property specified by key
* @param defaultval Default value
* @return The specified system property value
*/
Public StaticString GetProperty (String key, String defaultval) {
returnProp.getproperty (key, Defaultval);
}

Public Static voidMain (string[] args) {
Properties prop = Getsysproperties ();
}
} 3. Modify the code generated by the Java6 tool, and change the static IP and port to dynamic parameters. This step is the most critical step, the front is the preparation, this step is the substantive work, first you have to find the generated client Code service interface implementation class, here is the Java6wsservice class. Extends Service {
Private Final StaticURL java6wsservice_wsdl_location;
Private Final StaticLogger Logger = Logger.getlogger (lavasoft.wsclient.Java6WSService.class. GetName ());

Static{
String Wsip = Sysparamstoolkit.getproperty ("Wsip","192.168.14.117");
String Wsport = Sysparamstoolkit.getproperty ("Wsport","8888");
URL url =NULL;
Try{
URL BaseUrl;
BASEURL = Lavasoft.wsclient.Java6WSService.class. GetResource (".");
URL =NewURL (BASEURL,"http://"+ Wsip +": "+ wsport +"/java6ws/java6ws?wsdl ");
}Catch(Malformedurlexception e) {
Logger.warning ("Failed to create URL for the WSDL location: '"+"http://" + Wsip + ":" + wsport + "/java6ws/java6ws?wsdl" + "', retrying as a local file");
Logger.warning (E.getmessage ());
}
java6wsservice_wsdl_location = URL;
}

......That's it, your client code has a configurable function. You can no longer worry about how the server is deployed. Run a look:

JAVA6 WebService Client Package

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.