No need for Web Application Server Java to implement WebServices

Source: Internet
Author: User

Recently, I browsed some posts about Java to implement WebServives in the community, and found that more than 90% of them have such one operation:

In fact, this method is correct, but it kills many advantages of WebServices. So let's take a look at what is WebServices from the beginning.

Baidu encyclopedia wrote:

Web Services are online application Services released by enterprises to meet their specific business needs. Other companies or application software can access and use this online service over the Internet. It is a universal model for building applications and can be run in any operating system that supports network communication. It is a new web Application Branch, it is a self-contained, self-describing, and modular application that can be released, located, and called through the web.

Web Service is an application component that logically provides data and services for other applications. each application accesses the Web Service through the network protocol and some standard data formats Http, XML, and Soap. The results are obtained through the internal execution of the Web Service. web services can execute any function from simple requests to complex business processing. After deployment, other Web Service applications can discover and call the services deployed by the application.

The following key technologies and rules are used to build and use Web services:

1. XML: Standard Method for describing data.

2. SOAP: indicates the Information Exchange Protocol.

3. WSDL: Web Service Description Language.

4. UDDI (Universal Description, Discovery and Integration): Universal Description, Discovery, and Integration. It is a platform-independent, XML-based protocol used to describe commerce on the Internet. In fact, the main goal of WebService is cross-platform interoperability. To achieve this goal, WebService is fully based on XML eXtensible Markup Language), XSDXMLSchema, and other standards independent of platforms and software vendors, is a new platform for creating interoperable and distributed applications.

Persistent Item 1: Cross-firewall communication.

Long term 2: Application Integration.

Item 3: B2B Integration.

Back to the Title I mentioned, do WebServices really need any Jar packages? Do I need a plug-in? In fact, there are many ways to implement webservice, such as the axis framework and xfire framework, which can be used to publish the wsdl interface or implement the webservice client. Currently, eclipse has integrated plug-ins, you can generate a webservice client to call the interface according to the wsdl file. However, in this case, you must rely on the jar package of the Framework. Sometimes, due to environment and other reasons, we only need one interface in the wsdl, at this time, xml data can be directly generated through the http interface or socket interface to call the webservice Service on the server. In fact, the bottom layer of webservice still sends xml data, the framework encapsulates the serialization and deserialization of xml data. The following two simple examples describe the http and socket methods. Example 1: http webservice Interface call example:

 
 
  1. Import java. io. BufferedReader;
  2. Import java. io. IOException;
  3. Import java. io. InputStreamReader;
  4. Import java. io. OutputStreamWriter;
  5. Import java. io. UnsupportedEncodingException;
  6. Import java.net. MalformedURLException;
  7. Import java.net. URL;
  8. Import java.net. URLConnection;
  9. Public class HttpPostTest {
  10. Void testPost (String urlStr ){
  11. Try {
  12. URL url = new URL (urlStr );
  13. URLConnection con = url. openConnection ();
  14. Con. setDoOutput (true );
  15. Con. setRequestProperty ("Pragma:", "no-cache ");
  16. Con. setRequestProperty ("Cache-Control", "no-cache ");
  17. Con. setRequestProperty ("Content-Type", "text/xml ");
  18. OutputStreamWriter out = new OutputStreamWriter (con. getOutputStream ());
  19. String xmlInfo = getXmlInfo ();
  20. Out. write (new String (xmlInfo ));
  21. Out. flush ();
  22. Out. close ();
  23. BufferedReader br = new BufferedReader (new InputStreamReader (con. getInputStream ()));
  24. String line = "";
  25. StringBuffer buf = new StringBuffer ();
  26. For (line = br. readLine (); line! = Null; line = br. readLine ()){
  27. Buf. append (new String (line. getBytes (), "UTF-8 "));
  28. }
  29. System. out. println (buf. toString ());
  30. } Catch (MalformedURLException e ){
  31. E. printStackTrace ();
  32. } Catch (IOException e ){
  33. E. printStackTrace ();
  34. }
  35. }
  36. Private String getXmlInfo (){
  37. // You can view the interface xml format data through the wsdl file to construct the xml data of the calling interface.
  38. String xml = "<SOAP-ENV: Envelope xmlns: SOAP-ENV = \" extensions "xmlns: SOAP-ENC = \" extensions "xmlns: xsi = \" http://www.w3.org/2001/XMLSchema-instance\ "xmlns: xsd = \ "http://www.w3.org/2001/XMLSchema\">"
  39. + "<SOAP-ENV: Body>"
  40. + "<M: getItemDetailSingle xmlns: m = \" http: xxxxxxxxxxxxxxxx/\ ">"
  41. + "<ItemMo>"
  42. + "<Category> government domain name </category>"
  43. + "<City> beili, xiba River, Beijing </city>"
  44. + "<Flag> 3 </flag>"
  45. + "<ItemId> 10 </itemId>"
  46. + "<ItemIndex> 22 </itemIndex>"
  47. + "<Keyword> Chaoyang District </keyword>"
  48. + "<Mobile> 139-0111-1111 </mobile>"
  49. + "<Password> iteyePl </password>"
  50. + "<UserName> hwak </userName>"
  51. + "</ItemMo>"
  52. + "</M: getItemDetailSingle>"
  53. + "</SOAP-ENV: Body>"
  54. + "</SOAP-ENV: Envelope> ";
  55. Return xml;
  56. }
  57. Public static void main (String [] args) throws UnsupportedEncodingException {
  58. String url = "http: // localhost: 9999/dataService/services/Job ";
  59. New HttpPostTest (). testPost (url );
  60. }
  61. } </PRE>

We can see from the above two examples that Web application servers are not necessary when Java is used to implement WebServices. We hope that you can make good use of the advantages provided by WebServices according to local conditions, be good at doing it!

Recommended Editing:

Related Article

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.