Creating a WS Client consumer
Creating the client consumer
So I began to google out and find Apache CXF project.
Here are the main steps:
1. Get the URL of the WDSL in my case was an intranet
http://xxx.xxx.xxx.xxx:8080/gexflow/ws/Registro_v2.0?wsdl
where xxx.xxx.xxx.xxx is the IP address (for instance 110.12.3.1)
2. Download Apache CXF.
3. Extract into a folder
3.1. Verify that you have set the variable JAVA_HOME to the folder where the java is installed, now you can use java >9. For instance, you can type in the terminal:
export JAVA_HOME=/usr/java/jdk-13.0.2 //in java version >13 doesn't work using apache cxf 3.3.6 version, but java 17 works in csf version 3.5.4
3.2. Verify that the "bin" directory of the apache-cxf-xxxxx directory is available in the path. For instance, you can type in the terminal:
3.2. Verify that the "bin" directory of the apache-cxf-xxxxx directory is available in the path. For instance, you can type in the terminal:
export PATH=$PATH:/home/ximo/MyPrograms/apache-cxf-3.3.6/bin
4. Open a terminal, go into the generated "bin" folder and execute
wsdl2java -ant -client -d ClientDir http://xxx.xxx.xxx.xxx:8080/gexflow/ws/Registro_v2.0?wsdl
where ClientDir is the name of the folder where java code will be generated
5. Two java packages (that are folders) have been generated. The first one is "com.SERVICE_NAME" and the second is "SERVICE_NAME.BLAH". SERVICE_NAME is the name of the service, in this particular case is "gexflow". BLAH is another internal name of the service, and in this case is "reges". (so I have these 2 packages: "com.gexflow" and "gesflow.reges".
6. These packages have trillions of classes. But there is a class that has a main method that uses all declared services. The name of this class ends with "Port_Client" . In my case is
RegistroV20_RegistroV20ServicesPort_Client
You can execute it to test how to consume the services. You should take into account that by default, the parameters needed to call the services are initialized to null or empty strings, so you should supply the correct values.
7. To use these classes you can create a maven project and use this pom.xml file. Take care that the cxf version is the same as you downloaded!
8. As you can see it is very advisable using lombok jars. When you try to see an object obtained from a service, if you use the @ToString annotation in the definition of the class you can inspect all properties.
9. Here is an image of the eclipse project. Happy WS programming.
wsdl2java -ant -client -d ClientDir http://xxx.xxx.xxx.xxx:8080/gexflow/ws/Registro_v2.0?wsdl
where ClientDir is the name of the folder where java code will be generated
4.1 Optionally, if you have problems accessing the server, can get the wsdl file typing:
wget --no-check-certificate https://xxx.xxx.xxx.xxx:8443/gexflow/ws/RegistroV32.wsdl
now, the wsdl file is in the folder where this action has been executed. Now we go to the bin directory of the apache-cxf folder and execute:
wsdl2java -ant -client -d ClientDir route_to_the_wsdl_file
5. Two java packages (that are folders) have been generated. The first one is "com.SERVICE_NAME" and the second is "SERVICE_NAME.BLAH". SERVICE_NAME is the name of the service, in this particular case is "gexflow". BLAH is another internal name of the service, and in this case is "reges". (so I have these 2 packages: "com.gexflow" and "gesflow.reges".
6. These packages have trillions of classes. But there is a class that has a main method that uses all declared services. The name of this class ends with "Port_Client" . In my case is
RegistroV20_RegistroV20ServicesPort_Client
You can execute it to test how to consume the services. You should take into account that by default, the parameters needed to call the services are initialized to null or empty strings, so you should supply the correct values.
7. To use these classes you can create a maven project and use this pom.xml file. Take care that the cxf version is the same as you downloaded!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.ximodante</groupId> <artifactId>WSClient01</artifactId> <version>0.0.1-SNAPSHOT</version> <name>WSClient01</name> <description>Prova WS Teralco</description> <properties> <cxf.version>3.2.1</cxf.version><!--NEW VERSION 3.3.6 AVAILABLE !!! --> </properties> <dependencies> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>${cxf.version}</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http</artifactId> <version>${cxf.version}</version> </dependency> <!-- Jetty is needed if you're are not using the CXFServlet --> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http-jetty</artifactId> <version>${cxf.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.16.18</version> <scope>provided</scope> </dependency> </dependencies> </project> |
8. As you can see it is very advisable using lombok jars. When you try to see an object obtained from a service, if you use the @ToString annotation in the definition of the class you can inspect all properties.
9. Here is an image of the eclipse project. Happy WS programming.
Comments
Post a Comment