NB6JAXBSample1
JAXB and Provider API based JAX-WS Web Services.
Java Service Endpoint Interface (SEI) artifacts and stub implementation by Netbeans JAX-WS Wizard gives high level Java centric model for developers.
However there are times when one wants to operate on XML messages level. This is especially the case in Web Services, Application integration and Business integration applications. JAX-WS Provider API provides one to operate at the XML message level in a Web service.
Below example shows one such an example using simple Credit Report Web Service. Later we will show how to use JAXB binding file to customize generated classes.
Credit Report Web Service will consolidate credit report from different sources and inputs in different format.
Softwares needed
- Netebeans 6.0 full distribution.
- Glassfish 9.1 V2
- HTTP SOAP Web Serive client or SOAP UI
Steps
We will follow below steps to create our sample Web Service.
- Create an EJB project using Java EE 5 version.
- Create a JAXB Binding.
- Copy the WSDL files to be packaged with jar file.
- Create Provider API implementation class
- Copy sample XML files to simulate different XML sources.
- Build and deploy the EJB application to Glassfish.
- Use your favorite Web Services client to test the Web Service.
- Customizing generated classes: Importing and editing binding file.
Create an EJB project of Java EE 5 version.
File -> New project
EjbProject_NB6JAXBSample1.PNG
Create a JAXB Binding.
On Project node, New -> JAXB Binding
or New -> Other -> XML -> JAXB Binding
Enter Binding name, Select WSDL which imports Schema file , click finish.
(You need to copy/download both WSDL and Schema files to the same location)
You will notice JAXB binding node being created and compiled.
Also notice in File view generated Java classes in build/generated/addons/jaxb/
Copy the WSDL files to be packaged with jar file.
Select File view tab on Project explorer.
Copy the 'conf/xml-resources/jaxb/CreditCoReportSchema' directory 'conf/wsdl' directory. So that WSDL and Schema files are packaged during Ejb Jar build.
Create Provider API implementation class
Create/copy the 'CreditCoReportProvider' class. CreditCoReportProvider_NB6JAXBSample1.java
Invoke method in ProviderImpl consolidates data from different sources using methods getCreditInfo, getEmploymentInfo etc.
Method getCreditEnquiries and getCreditInfo returns JAXB generated objects created differently. One uses XML source/InputStream other directly instantiates and populates the content.
Copy sample XML files to simulate different XML sources.
Copy the 'addresses_NB6JAXBSample1.xml', 'creditEnquiries_NB6JAXBSample1.xml' and 'employmentInfo_NB6JAXBSample1.xml' files to 'com.creditco.ws.report' package. As we use these to simulate XML data received from other applications.
Build and deploy the EJB application to Glassfish.
Build and deploy the project to Glassfish 9.1 application server. Note the endpoint address.
Use your favorite Web Services client to test the Web Service.
Use your favorite Web Services client. Suffix '?WSDL' to get URL for the Webservice WSDL just deployed.
Customizing generated classes: Importing and editing binding file.
JAXB allows developers to customize generation of Java classes.
In our example, if we want to change the generated class name of 'CreditAccount', we could do the following to change it.
Select the JAXB node 'CreditCoReportSchema' and action 'Change JAXB Options' .
Import binding file 'CreditCoCustomization_NB6JAXBSample1.xjb'
Double click on 'CreditCoCustomization_NB6JAXBSample1.xjb.xml' to edit the binding file.
Change the class name for element 'CreditAccount' to 'CreditCardAccount' .
Click on 'JAXB bindings' node and select 'Regenerate Java Code' action.
You will see editor showing invalid class reference for 'CreditAccount' in CreditCoReportProvider_NB6JAXBSample1.java file.
Replace class reference 'CreditAccount' with 'CreditCardAccount' in CreditCoReportProvider_NB6JAXBSample1.java to use new name.
Attachments
- Media:CreateJAXBBinding3_NB6JAXBSample1.PNG
- Media:CreditCoCustomization_NB6JAXBSample1.xjb
- Media:EjbProject_NB6JAXBSample1.PNG
- Media:CreateJAXBBinding2_NB6JAXBSample1.PNG
- Media:CreateJAXBBinding1_NB6JAXBSample1.PNG
- Media:CreditCoReport_NB6JAXBSample1.xsd
- Media:addresses_NB6JAXBSample1.xml
- Media:CreateJAXBBinding4_NB6JAXBSample1.PNG
- Media:creditEnquiries_NB6JAXBSample1.xml
- Media:employmentInfo_NB6JAXBSample1.xml
- Media:CreditCoReportProvider_NB6JAXBSample1.java
- Media:CreditCoReport_NB6JAXBSample1.wsdl

