1

I am new to Axis2 Web services, and I tried to implement Axis2 from some simple tutorials. My code runs well in JavaEE with Tomcat server 7.0+, however I still haven't fully understood how client and server connect together. For that reason, I have a several general questions regarding to Axis2:

  1. What is the functions of the Stub.java file that is automatically generated in client side? I don't know how it functions, but it seems to handle the requests of the client side. Here is the code I need to implement to run from the client side:

    public static String getData(int code) throws RemoteException, MylittleShopParserConfigurationExceptionException, MylittleShopIOExceptionException, MylittleShopSAXExceptionException  {
    //When creating client web service, importing http://localhost:8080/Server/services/MylittleShop?wsdl (this is the xml file for
    //describing server-web service, it will tell the client how to compose a web service request and the interface that is
    // provided by the server ,all of thing contained in MylittleShopStub class.
    MylittleShopStub ser = new MylittleShopStub();
    GetData setCode =  new GetData();
    setCode.setCode(code);
    GetData1Response getCode = null;
    getCode = ser.getData1(setCode);
    return getCode.get_return();
    

    }

My service is simply to send a code (id) to the server to retrieve a dataset from the database.

  1. What I need to write in the client side is the function that is auto-generated based on the function I have in the server side. However, I only need to pass the necessary parameters then send back to the server to get the response. So how do the parameters in client side are handled uppon sending requests to the server?
  2. Do client and server communicate via HTTP?

Thank you in advance!

WKuro
  • 175
  • 2
  • 16
  • It would be best to provide the link to the tutorial you follow and the Stub.java code for more detailed answers. – Spyros K May 09 '18 at 10:14
  • 1
    I already updated the code I wrote to use the Stub file to invoke the server. The Stub.java file is auto-generated and it is very long. – WKuro May 09 '18 at 11:03
  • OK. So if I understand correctly that MylittleShopStub.java is the Stub.java you mention? – Spyros K May 09 '18 at 12:16
  • Yes, and it is generated based on the file MyLittleShop.java which stored the services I created. – WKuro May 09 '18 at 12:20

1 Answers1

0
  1. MylittleShopStub.java is a java client model of the service. Practically what it does is what is mentioned in point 2. It converts the Java objects that model the client request to the appropriate XML, sends them to the server endpoint defined. Then receives the server response in XML format, creates the server response java object and returns it to the caller. The following quote might also help.

Using the service is simply a matter of creating and populating the appropriate type of request using the names defined in the WSDL file, and then using the stub to actually send the request to the appropriate method.

Axis 2 Creating Clients

  1. A WSDL Service understands and responds to XML documents that are submitted to the server. These XML should follow a specific XSD. At first the client encodes all the parameters in XML,and sends them to the server. Then the server parses the XML, it performs the defined operations and returns an XML to the client. The java client parses the XML and returns the result as a java object.

  2. Client and server can communicate over HTTP and HTTPS. Normally since you follow simple tutorials you use HTTP.

About WSDL services WSDL (Web Services Description Language) is an XML language for describing Web services. So by definition WSDL web services are the web services that are describe and conform to the WSDL standard. A web service is in a sense a remote procedure call. A client program asks a server program to do "something" and (in most cases) return a result. WSDL defines an XML format that is used by client and server to communicate in a neutral, programming language independent, format. So basically the client and server programs send back and forth XML documents that describe the customer request and server response.

Spyros K
  • 2,480
  • 1
  • 20
  • 37
  • Thank you! the last two questions are clear to me now! Also I just updated my code for using Stub to retrieve the data. – WKuro May 09 '18 at 11:03
  • And also, could you mind explaining me simply about WSDL Service? I looked up some definitions and it's still a bit confusing to me. – WKuro May 09 '18 at 11:17
  • I updated the response based on the feedback and answers in the comments. – Spyros K May 09 '18 at 12:29
  • 1
    That clarifies all my questions at the moment. Thank you so much! – WKuro May 10 '18 at 01:00
  • 1
    Haha yes it is truly useful for beginner like me! I cannot use the up-vote yet because I still need 15 reputations to do that! – WKuro May 10 '18 at 15:04
  • By the way, I have an additional question: what do you think about the advantages and drawbacks of using Axis2 web service? And does Axis2 by default exchange SOAP messages? – WKuro May 14 '18 at 08:27
  • This is a question that can have a big answer, but I will try to answer briefly. Axis2 can be used for SOAP and WSDL, see here for more info regarding SOAP and WSDL: https://stackoverflow.com/questions/14541066/difference-between-a-soap-message-and-a-wsdl Regarding pros and cons: If you plan to use WSDL then Axis2 is a good implementation so you can use it with confidence. Comparing different WSDL implementations would be a long and potentially subjective topic. If you are wondering about WSDL vs REST see here: https://stackoverflow.com/questions/840653/wsdl-vs-rest-pros-and-cons. – Spyros K May 14 '18 at 08:34
  • Thanks! One more thing is that I already finished running the project locally. Now I want to put my web services on the server. I tried to search for many sources but I couldnt find a solution to deploy axis2 on the internet. For example, when I tried to bring Axis2 to AwS, I don't know how to create my client web service again to handle the WSDL (usually it is generated locally) on the internet. Do you have any suggestion that I can try to deploy my axis2 web service over the internet so that I can access it from anywhere using client desktop application? – WKuro May 18 '18 at 07:09
  • You need to find a provider that can offer java hosting. Then the core process would be similar to what you do locally but you would have to do it remotely. One short tip would be that the auto-generated clients some times have the IP and PORT of the WSDL endpoint hardcoded so you might need to change that. – Spyros K May 18 '18 at 07:28
  • Point is whenever I create web service on the server, WSDL is auto-generated locally. For example: http://localhost:8080/Server/services/MylittleShop?wsdl. Is WSDL generated according to the host of the tomcat server? And how do I change it if I deploy it online? – WKuro May 18 '18 at 07:44
  • You need to export the project as a war file and deploy it. You can do it also locally. The war file should contain the autocreated service description. – Spyros K May 18 '18 at 15:26