Search This Blog

Lets go..

Thursday

Generate soap client from wsdl in Netbeans


By: Md Mahfuj Jia

Introduction: In previous tutorial we have seen, how to create soap web service using SpringWS and Apache CXF. After creating web service we need to consume and make a client for these web services. Your business layer is completely separate from client and main purpose of the client is creating request and get response.  For java, Netbeans is a fantastic tool for creating client from wsdl and in this tutorial we will see how to create client from wsdl and how to consume it.

Projects snapshots:

Image: 1 –This is our wsdl from previous tutorial and we will generate client from this wsdl.

Image: 2-3  -Steps of generating wsdl client.

Image: 4 –Output after generating client.

Image: 5 –Now we see the generated file in Netbeans.

Image: 6-8 –When client will generate, we see the generated source code contains xmlgorgioncalender date format and we need to convert this date format to java.util.date. For conversion, we need external binding file, which makes our client code serializable and convert the desire date format.

Image: 9 –To avoid this error, just clean and build the project in Netbeans.

Image: 10 –This is our main class. Here we will see how to consume service using wsdl client.






























 
Project Source Code:

Happy coding…

Java class to xsd file generation


By: Md Mahfuj Jia

Introduction: Today I will show u how to generate xsd (XML Schema Definition) from pure java class. As we know the data contact first approach is the industry oriented best practice in writing soap based web service so we need to determine data transformation object (dto) in xsd. xsd writing manually is a time consuming for a big enterprise application. We can easily save time by generating entity class to xsd file. xsd to java class (dto) generation will be done by your IDE (Netbeans, Eclipse, xjc compiler) but java class to xsd generation support is rare.

Project snapshots:

Image: 1 –log4j.properties file describes where your xsd file will be saved and set other necessary properties.
Image: 2 –In line number 38, you just give your java class to generate xsd.
























Download source from here:

Happy coding…..

Wednesday

Spring Web Service Complete Tutorial Using Netbeans

By: Md Mahfuj Jia
Introduction:
This tutorial is the 2nd part of service-oriented architecture. In first tutorial (Apache CXF-Spring Integration), we have seen the basic architecture of web-service development, difference between various popular industry-oriented SOA frameworks. In this tutorial I am implementing web service using spring web-service module.

Honestly speaking, spring web-service module is harder than any jax-ws based framework. It requires the knowledge of soap, xml, xml framework, marshaller-unmarshaller etc. But once you get used to programming spring web-services, it will be very easy as coding a jax-ws based framework.

Spring web-service only supports contact first approach, which is the industry oriented best practice and supports automatic wsdl generation. You can easily implement a tight security using spring web-service module.

Prerequisites for this tutorial:
1.Clear concept of object oriented programming and service-oriented architecture.
2.Basic knowledge about spring framework and dependency injection (IoC container).
3.Basic object relational mapping (ORM) knowledge is required.
4.Basic knowledge on soap based web service.
5.Basic knowledge on java xml framework.

Technologies Used:
1.Spring web service module
2.Hibernate
3.MySQL
4.Netbeans
5.Apache Tomcat – 8+
7.JEE 7
8.JDK 7+


  

Image: 1 – Project Architecture

Image: 2-Image: 7 – Here we see how to generate xsd file to data transformation object (dto). There are two files inside xsd folder. user.xsd is for data contact mapping and another is a external binding xml file which gives you java.util.date instead of xmlgorgeoan date format. If you want to edit xsd file and regenerate dto, you just delete the jaxBnUser folder inside the JAXB Bindings folder in Netbeans. You will see Generated Sources (jaxb) in Netbeans is also deleted. Now you do step: 2-7 again.

Image: 8-Image: 11 – Basic spring web service module and data source configuration. If you have more than one xsd file, you just add in image: 10 (inside list value) and must add like 49-53 number line for automatic wsdl generation from your new xsd file.

Image: 12-Image: 13 –Service layer implementation.

Image: 14-Image: 17 –Dao layer implementation.

Image: 18 –Endpoint service implementation.

Image: 19-Image: 21 –Test web service using SOAP-UI.


 
Database Table Description:

CREATE TABLE `users` (

  `user_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

  `user_name` varchar(45) NOT NULL,

  `display_name` varchar(45) NOT NULL,

  `email` varchar(45) NOT NULL,

  `bank_uid` varchar(45) NOT NULL,

  `status` varchar(45) NOT NULL,

  `created_by` varchar(45) DEFAULT NULL,

  `create_date` datetime DEFAULT NULL,

  `creator_ip` varchar(45) DEFAULT NULL,

  `updated_by` varchar(45) DEFAULT NULL,

  `update_date` datetime DEFAULT NULL,

  `updator_ip` varchar(45) DEFAULT NULL,

  PRIMARY KEY (`user_id`)

) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; 




Project Architecture:

Image:1
Image:2
Image:3

Image:4

Image:5

Image:6

Image:7

Image:8

Image:9

Image:10


Image:11
Image:12
Image:13
Image:14
Image:15
Image:16

Image:17
Image:18
Image:19

Image:20

Image:21

Sunday

Apache CXF - Spring Integration using Netbeans

Author:Md Mahfuj Jia

Introduction:
Now days, technologies are changing very rapidly. In an enterprise application integration is the most challenge able part and it is very much necessary to build application with high scalability, reliability, maintainability and testability. Service oriented architecture (SOA) will give you the flexibility to connect with different types of multiple node or language to your business logic layer. For example, you have developed a login service using SOA and you have exposed your wsdl or wadl that any body can consume login service to their own application for login. Apache CXF is one of the most used service oriented architecture (SOA) framework in enterprise application development. I have developed a sample service using Apache CXF and spring integration module with contact first approach. Contact first approach is the industry standard best practice when developing the web service.

Prerequisites for this tutorial:
1.Clear concept of object oriented programming and service-oriented architecture.
2.Basic knowledge about spring framework and dependency injection (IoC container).
3.Basic object relational mapping (ORM) knowledge is required.

Technologies Used:
1.Apache CXF
2.Spring integration module
3.Hibernate
4.MySQL
5.Netbeans
6.Apache Tomcat – 8+
7.JEE-7
8.JDK-7+

Database Table Description:

CREATE TABLE `users` (

  `user_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

  `user_name` varchar(45) NOT NULL,

  `display_name` varchar(45) NOT NULL,

  `email` varchar(45) NOT NULL,

  `bank_uid` varchar(45) NOT NULL,

  `status` varchar(45) NOT NULL,

  `created_by` varchar(45) DEFAULT NULL,

  `create_date` datetime DEFAULT NULL,

  `creator_ip` varchar(45) DEFAULT NULL,

  `updated_by` varchar(45) DEFAULT NULL,

  `update_date` datetime DEFAULT NULL,

  `updator_ip` varchar(45) DEFAULT NULL,

  PRIMARY KEY (`user_id`)

) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; 



Ø  From this article, we see the basic features and comparison of industry oriented soa architecture frameworks.

Framework
Key Positives
Key Concerns
Apache AXIS2
Most Commonly Used, Matured & Stable Web Services Development Framework

Supports Multiple Languages (C++, Java)

Supports both Contract-first & Contract-last Approach

In context of Orchestration & Web Services Transaction (long-running transactions) it supports wide variety of related WS-* specifications:
WS-Atomic Transaction, WS-Business Activity, WS-Coordination, WS-Eventing, WS-Transfer
Compatible with Spring Framework
Comparatively More Code Required/Generated w.r.t. Spring WS/CXF

Is being phased out gradually (mostly by Apache CXF)

It is not fully compliant for JAX-WS JAX-RS
Apache CXF
Most widely used Web Services Standard Now; Improvement over AXIS2, which is now gradually being replaced by Apache CXF

Intuitive & Easy to Use (less coding required as compared to AXIS2)

Clean separation of front-ends, like JAX-WS, from the core code

Fully compliant with JAX-WS, JAX-RS & others

Best Performance across all available framework with minimum computation overhead

Supports wide variety of front-end models

Supports both JAX-WS & JAX-RS (for Restful Services)

Supports JBI & SDO (not supported in AXIS2)

Compatible with Spring Framework
Does not support Orchestration & WS Transactions yet

Does not support WSDL 2.0 yet
Spring WS
Best in terms of supporting Contract-first Web Services Development Approach

Enforces Standards & Best Practices by Framework Constraints (no way out of it & hence limitation as well)

Supports Spring Annotations as well as JAX-WS

Least code from developer’s perspective

Best Aligned with Spring Technology Stack (also similar architectural stack as Spring MVC) including Spring Security
Least number of WS-* Specifications supported (does not fully compliant with JAX-WS)

Spring offers itself as standard & hence other Java-compliant frameworks support better standards support

Only support Contract-first Web Services Development Model



-->



Image:1

Image:2

Image:3

Image:4

Image:5
Image:6

Image:7

Image:8

Image:9

Image:10

Image:11

Image:12

Image:13

Image:14

Image:15

Image:16

Image:17

Image:18

Image:19

Image:20

Image:21

Image:22

Image:23










































































































































Image: 1-Image: 7 – Here we see how to generate xsd file to data transformation object (dto). There are two files inside xsd folder. user.xsd is for data contact mapping and another is a external binding xml file which gives you java.util.date instead of xmlgorgeoan date format. If you want to edit xsd file and regenerate dto, you just delete the jaxBnUser folder inside the JAXB Bindings folder in Netbeans. You will see Generated Sources (jaxb) in Netbeans is also deleted. Now you do step: 2-7 again.

Image: 8-Image: 11 –Apache CXF, Data source and Spring integration configuration file.

Image: 10 –Apache CXF has the flexibility to expose web service both SOAP and Restful.  This one is the cxf configuration file.

Image: 11 -Spring integration setup part. Link endpoint service with business logic layer and object conversion mechanism is configured here. Note that in gateway configuration, there is a service-interface declaration. The main feature of this configuration is that you just declare endpoint-interface according to the endpoint interface package and you do not need the endpoint-interface implementation. You just linked your endpoint-interface to your service layer using chain configuration and setup the object transformation mechanism. Spring integration module is responsible for implementing your end-point interface implementation. Endpoint mapping and request-response object transformation manually is a time consuming issue. I think Apache CXF-Spring integration configuration is a dynamic approach for writing web service.

Image: 12 –Endpoint interface of soap web service.

Image: 13 –Endpoint interface of restful web service.

Image: 14 –Here we see the transformation of objects and UserTransformer class is responsible for this. In this project we have used DozerBeanMapper library to transform dto to service and vice verse. This class talks with image-11 applicationContext-si-cxf.xml file for object transformation.

Image: 15 –Service layer implementation.

Image: 16-Image: 17 –Dao layer implementation.

Image: 18 –Image: 23 –These are our exposed web services and we will test these services using SOAP-UI.


Download Project Source Code
 

Conclusion:
In this tutorial, we have seen that how to write web service using SOA framework in java. Spring web service module is another popular and industry oriented SOA framework. But Spring-WS is comparatively harder than Apache CXF but I am a fan of Spring-WS. In Spring WS you need to explicitly implement endpoint interfaces and Spring-WS support only contact first approach and SOAP based web service. But Apache CXF supports contact first and contact last approach and gives support both Soap and rest based web service.