Ir al contenido principal

Primer CodeLab de Web Services con Mule ESB, JAX WS, SOAP, WSDL, Spring

Primer CodeLab de Web Services usando [Mule ESB, JAX WS, SOAP, WSDL, Spring]. en este post no hablaré nada teórico sobre Mule, ya que ello lo pueden encontrar Googleando, será un lab totalmente práctico.

Requisitos:
- JDK  1.6
- MuleStudio
- soapUI

Paso a Paso para crear Web Services con Mule:



1. Crear proyecto Mule (MuleStudio): 




Next > Next > Next > Finish







2.- Crear el Objeto Producto.java
package com.dmotta.mule.labuno.mulelabuno.bo;
import java.io.Serializable;
public class Producto implements Serializable {
private String id;
private String nombre;
private String marca;
private String descripcion;

public Producto() {
}

public Producto(String id, String nombre, String marca, String descripcion) {
this.id=id;
this.nombre=nombre;
this.marca=marca;
this.descripcion=descripcion;
}
//getters/setters
}


3.- Crear la Interface que publicará los métodos listarProductos() y getDetalleProducto() y añadir las anotaciones @WebService, @WebResult para indicar que sera un servicio web.

package com.dmotta.mule.labuno.mulelabuno;
import java.util.List;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

import com.dmotta.mule.labuno.mulelabuno.bo.Producto;

@WebService
public interface ICatalogoService {

@WebResult(name="lista")
public List listarProductos() throws Exception;

@WebResult(name="detalle")
public Producto getDetalleProducto(@WebParam(name="productoId") String productoId) throws Exception;

}


4.- Crear la clase CatalogoServiceImpl.java  que Implementa la Interface ICatalogoService.java

package com.dmotta.mule.labuno.mulelabuno.impl;
import java.util.ArrayList;
import java.util.List;
import javax.jws.WebService;
import com.dmotta.mule.labuno.mulelabuno.ICatalogoService;
import com.dmotta.mule.labuno.mulelabuno.bo.Producto;

@WebService(endpointInterface = "com.dmotta.mule.labuno.mulelabuno.ICatalogoService", serviceName = "productoCatalogService")
public class CatalogoServiceImpl implements ICatalogoService {

 private List listaProducto;

 public CatalogoServiceImpl() {
   listaProducto = new ArrayList();
   listaProducto.add(new Producto("100", "Nexus 4", "LG", " Tablet Google Nexus 4"));
   listaProducto.add(new Producto("101", "Nexus 7", "ASUS", " Tablet Google Nexus 7"));
   listaProducto.add(new Producto("102", "Nexus 10", "SAMSUNG", " Tablet Google Nexus 10"));
 }

 @Override
 public List listarProductos() throws Exception {
   return listaProducto;
 }

 @Override
 public Producto getDetalleProducto(String productoId) throws Exception {
   Producto prod = new Producto();
   for (Producto producto : listaProducto) {
     if (productoId.equals(producto.getId())) {
       prod = producto;
     }
   }
   return prod;
 }

}


5.-  Editar el archivo de configuración de Mule, en este lab se llamará LabUno.xml (por default es mule-config.xml)



6.- Asimismo, Mule genera de manera automatica el archivo mule-deploy.properties

#Mon Feb 25 12:11:42 COT 2013
redeployment.enabled=true
encoding=UTF-8
domain=default
config.resources=LabUno.xml



7.- Finalmente LabUno.mflow, quedaria de la siguiente manera:



8.- Clic derecho : Run As > Mule Application
.
.
INFO  2013-02-25 16:33:37,939 [[labuno].config.change.1.thread.1] org.mule.module.management.agent.JmxAgent: Registered Endpoint Service with name: Mule.labuno:type=Endpoint,service="WebServiceFlow",connector=connector.http.mule.default,name="endpoint.http.localhost.8080.services.ICatalogoService"
INFO  2013-02-25 16:33:37,940 [[labuno].config.change.1.thread.1] org.mule.module.management.agent.JmxAgent: Registered Connector Service with name Mule.labuno:type=Connector,name="connector.http.mule.default.1"
INFO  2013-02-25 16:33:37,941 [[labuno].config.change.1.thread.1] org.mule.DefaultMuleContext:
**********************************************************************
* Application: labuno                                                *
* OS encoding: Cp1252, Mule encoding: UTF-8                          *
*                                                                    *
* Agents Running:                                                    *
*   Clustering Agent                                                 *
*   JMX Agent                                                        *
**********************************************************************
INFO  2013-02-25 16:33:37,942 [[labuno].config.change.1.thread.1] org.mule.module.launcher.DeploymentService:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Started app 'labuno'                                     +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

9.- Consumir el  servicio usando soapUI:



  • Primer Request: getDetalleProducto


  • Segundo Request: listarProductos

Referencias:


Si hay algo que se me paso  no documentarlo, comentar abajo. Espero que sirva de ayuda a los que se estan iniciando  con Mule ESB



Comentarios

  1. Cuando hago la prueba con soapUI solo me aparece el id de los árticulos, no me aparece la descripción ni el nombre, se te ha pasado ponerlo en el código?, un saludo

    ResponderEliminar
  2. Great post i must say and thanks for the information.
    spring boot online training

    ResponderEliminar

Publicar un comentario

Entradas populares de este blog

Java POI HSSFCell : añadir comentario en una celda

POI HSSFComment: Una manera simple de añadir un comentario en una celda de excel usando el metodo cell.setCellComment(). public class ExcelTools { public static void main(String[] args){ //escribirExcel(); //leerExcel(); validarValoresDuplicadosLista(); System.out.println("Ejemplo Finalizado."); } public static void escribirExcel(){ try{ //Se crea el libro Excel HSSFWorkbook wb = new HSSFWorkbook(); //Se crea una nueva hoja dentro del libro HSSFSheet sheet = wb.createSheet("HojaEjemplo"); //Se crea una fila dentro de la hoja HSSFRow row = sheet.createRow((short)0); HSSFPatriarch patr = sheet.createDrawingPatriarch(); //Creamos celdas de varios tipos row.createCell((short)0).setCellValue(1); row.createCell((short)1).setCellValue(1.2); row.createCell((short)2).setCellValue("ejemplo&

Debugging Remoto con Eclipse + WebSphere 7 + Maven

Tienes proyectos java en Maven y no puedes ubicar bugs fácilmente a falta de junit. Sin embargo, existe la alternativa de debugear la aplicación web a través de Java Debugger (jdb). Aquí les muestro una guía de como hacer un debug remoto de la aplicación web en Eclipse y WebSphere 7 a través de Java Debugger (JDB). Eclipse <----> Java Debugger (jdb) <----> WebSphere 7 1. Habilitar el WebSphere en modo Debug. Para esto seguir los siguientes pasos:  1. Servers –> Server Types –> WebSphere application servers 2. Under Server Infrastructure section –> expandir Java and Process Management –> Process definition 3. dentro de la seccion Additional Properties –> click Java Virtual Machine 4. clic en el check “Debug Mode” 5. En texbox Debug arguments, poner este valor:  -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8888 6. Reiniciar el servidor WebSphere. Ahora, WebSphere se inicia en modo debug, y escuchando en el pu

DB2 Error SQL20054N

Ejecutando un alter table me da el  siguiente error: db2 "ALTER TABLE PRG_REC.ESTIMADO_OBJETIVO DROP COLUMN VTA_OBJ_CAMP_FALTA_EXTRANJERA"; Error:  [db2inst1@ibmdb2test]:/home/db2inst1/1223/REQ1223/rollback$ db2 "ALTER TABLE PRG_REC.ESTIMADO_OBJETIVO DROP COLUMN VTA_OBJ_CAMP_FALTA_EXTRANJERA"; DB21034E  The command was processed as an SQL statement because it was not a valid Command Line Processor command.  During SQL processing it returned: SQL20054N  The table "PRG_REC.ESTIMADO_OBJETIVO" is in an invalid state for the operation.  Reason code="23" .  SQLSTATE=55019 Segun IBM la descripcion del error: SQL20054N:  La tabla   nombre-tabla   está en un estado no válido para la operación. Código de razón= código-razón . 23 Se ha realizado el número máximo de modificaciones recomendadas de REORG. Se permite un máximo de tres modificaciones recomendadas de REORG en una tabla antes de que se deba realizar reorg, para actualizar las fila