Generate the server-side code

Next the WSDL is put through the Axis2 tool to generate the server code. This server code contains logic to receive XML from the HTTP server using SOAP (which contains the input data), parse it, and create the types to pass to the main application. It also contains code to turn these types back to XML and return to the Web server, which returns a SOAP response.

You must start the JBoss EAP 7.1 server before generating the server-side code:

  1. Click Window > Show View > Servers.
  2. Right-click in the Servers tab, and then click New > Server.

    This opens the New Server dialog box.

  3. Click Red Hat JBoss Middleware > Red Hat JBoss Enterprise Application Platform 7.1.
  4. Click Next.
  5. Click Finish.
  6. Right-click Red Hat JBoss EAP 7.1 on the Server tab.
  7. Click Start.
    You must wait till the server has started before continuing with the steps to generate the server-side code.
    Tip: You can check that the server has started successfully by looking in the console tab.

To generate the server-side code:

  1. In Project Explorer, right-click BookLegacy.wsdl.
  2. Click New > Other.
  3. Expand Web Services, and then click Web Service.
  4. Click Next.
    This opens the Web Service dialog box.
    Note: If the Web service runtime was correctly configured then it displays Apache Axis2. If it does not click on the link it to change it. This opens the Service Deployment Configuration dialog box. Click Apache Axis2, and then click OK. By default, the Web services type field should be set to Top down Java bean Web Service and the Service definition field should be set to /wsdl/BookLegacy.wsdl.
  5. Click Finish.

    A progress bar might appear while it generates the code.

    Important: When using Axis2 1.7 and onwards, you might generate the following exception:
    Exception occurred during code generation for the WSDL  : java.lang.NoClassDefFoundError:

    This is because Eclipse does not copy the xmlschema-core-n.n.n.jar file to your dynamic Web project. To avoid this exception, copy the xmlschema-core-n.n.n.jar file located in your $AXIS2_HOME/lib folder to the DynWebTest1/WebContent/WEB-INF/lib folder. You need to restart Eclipse before attempting to run the server-side code generation steps again.

  6. Once the code is generated the file BookLegacySkeleton.java should appear in an editor pane.
  7. It is a good idea to reformat the source code at this point. Right-click in the editor pane, select Source > Format.
  8. Click File > Save.

Comments

The classes BookDetails, BookReturn, BookReturnE, NewBook, and StockNo hold instances of the types represented in the WSDL.

In the outline view for BookLegacySkeleton.java are four methods, nextBook(), readBook(), deleteBook(), and addBook(). These are the methods that are called by the web service for the operations that were defined and is where you place your code.

Because you might want to regenerate this code, it is a good idea to keep the user code in this file to a minimum and have all the logic in a separate class. Each of these methods contain one line to invoke an appropriate method in a new class called BookOperation. The next step is to create this class which interfaces between the Web service and the COBOL application.