Cliente Hola Mundo del Java Web Service JAX WS
El objetivo del ejercicio crear un cliente del HolaMundo Web
Service de suma creado en el ejercicio anterior.
Partimos de la URL del WSDL:
1.- Mismo tipo de proyecto maven java application
2.- Agregar un plugin jax-ws y la url del wsdl e el pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>mx.com.gm</groupId>
<artifactId>ClienteSumaWS</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<vmArgs>
<vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
</vmArgs>
</configuration>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlUrls>
<wsdlUrl>http://desktop-322kafb:9090/ServicioSumarImplService/ServicioSumarImpl?wsdl</wsdlUrl>
</wsdlUrls>
<packageName>clientews.servicio</packageName>
<sourceDestDir>${basedir}/src/main/java</sourceDestDir>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
3.- Para netbeans click derecho al pom.xml select run maven ---> Goals y posterirmente ejecutar en la ventanilla generate-sources en la opcion de goals. Esto nos generara el codigo fuente, cade destacar que el app server debe estar corriendo junto con el jar.
4.- Generamos la clase de prueba:
package clientews.servicio;
import clientews.servicio.ServicioSumarImplService;
import clientews.servicio.ServicioSumarWS;
public class TestServicioSumarWS {
public static void main(String[] args) {
ServicioSumarWS servicioSumar = new ServicioSumarImplService().getServicioSumarImplPort();
System.out.println("Ejecutando Servicio Sumar WS");
int x = 1;
int y = 2;
System.out.println("Sumar:" + "x: " + x + " y: " + y);
System.out.println("Resultado: " + servicioSumar.sumar(x, y));
System.out.println("Fin Servicio Sumar WS");
}
}
Opcionalmente se puede hacer la prueba en SOAP UI por ejemplo:
Codigo fuente del proyecto
Partimos de la URL del WSDL:
1.- Mismo tipo de proyecto maven java application
2.- Agregar un plugin jax-ws y la url del wsdl e el pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>mx.com.gm</groupId>
<artifactId>ClienteSumaWS</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<vmArgs>
<vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
</vmArgs>
</configuration>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlUrls>
<wsdlUrl>http://desktop-322kafb:9090/ServicioSumarImplService/ServicioSumarImpl?wsdl</wsdlUrl>
</wsdlUrls>
<packageName>clientews.servicio</packageName>
<sourceDestDir>${basedir}/src/main/java</sourceDestDir>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
3.- Para netbeans click derecho al pom.xml select run maven ---> Goals y posterirmente ejecutar en la ventanilla generate-sources en la opcion de goals. Esto nos generara el codigo fuente, cade destacar que el app server debe estar corriendo junto con el jar.
4.- Generamos la clase de prueba:
package clientews.servicio;
import clientews.servicio.ServicioSumarImplService;
import clientews.servicio.ServicioSumarWS;
public class TestServicioSumarWS {
public static void main(String[] args) {
ServicioSumarWS servicioSumar = new ServicioSumarImplService().getServicioSumarImplPort();
System.out.println("Ejecutando Servicio Sumar WS");
int x = 1;
int y = 2;
System.out.println("Sumar:" + "x: " + x + " y: " + y);
System.out.println("Resultado: " + servicioSumar.sumar(x, y));
System.out.println("Fin Servicio Sumar WS");
}
}
Opcionalmente se puede hacer la prueba en SOAP UI por ejemplo:
Codigo fuente del proyecto
No hay comentarios.