JAX-WS Handler Chain: Interceptando los mensajes
Aug 29, 10 by Juan Lebrijo about Web Services, Java, blog
Queremos interceptar el WS en la salida y la entrada. Esto puede ser útil para:
  • Hacer log de alguna parte del mensaje
  • Llevar registro de mensajes enviados
  • Controles de seguridad añadidos
  • ....
Hoy vamos a hacer un ejemplo de log de la entrada/salida del WS. Anotamos el WS con el descriptor de la cadena de manejadores:
@WebService
@HandlerChain(file="src/META-INF/handlerChain.xml")
public class Hello {
@WebMethod
    public String sayHello(String name) {
        return "Hello, "+name+".";
    }
}
Que tendrá el contenido siguiente:
  
     
        
         lebrijo.handlers.WSHandler  
        
     
  
La clase WSHandler implementará la interfaz SOAPHandler:
public class WSHandler implements SOAPHandler {  
 
     public Set getHeaders() {  
         return null;  
     }  
  
     public boolean handleFault(SOAPMessageContext context) {  
         logToSystemOut(context);  
         return true;  
     }  
 
     public boolean handleMessage(SOAPMessageContext context) {  
         logToSystemOut(context);  
         return true;  
     }  

     private void logToSystemOut(SOAPMessageContext smc) {  
         Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);  
   
         if (outboundProperty.booleanValue()) {  
             System.out.println("\nOutgoing message:");  
         } else {  
             System.out.println("\nIncoming message:");  
         }  
   
         SOAPMessage message = smc.getMessage();  
         try {  
             message.writeTo(System.out);  
         } catch (Exception e) {  
             System.out.println("Exception in handler: " + e);  
         }  
     }

	public void close(MessageContext context) {
		// TODO Auto-generated method stub
		
	}  
JAX-WS Handler Chain: messages interceptor
Aug 29, 10 by Juan Lebrijo about Web Services, Java, blog
We want to intercept the WS input and output. In order to:
  • Logging any part in the message
  • Registering sent messages
  • Add security controls
  • ....
Here we are going to do a input/output WS example log. We annotate the WS with Handler Chain descriptor:
@WebService
@HandlerChain(file="src/META-INF/handlerChain.xml")
public class Hello {
@WebMethod
    public String sayHello(String name) {
        return "Hello, "+name+".";
    }
}
It will have the following contents:
  
     
        
         lebrijo.handlers.WSHandler  
        
     
  
WSHandler class will implements the SOAPHandler interface:
public class WSHandler implements SOAPHandler {  
 
     public Set getHeaders() {  
         return null;  
     }  
  
     public boolean handleFault(SOAPMessageContext context) {  
         logToSystemOut(context);  
         return true;  
     }  
 
     public boolean handleMessage(SOAPMessageContext context) {  
         logToSystemOut(context);  
         return true;  
     }  

     private void logToSystemOut(SOAPMessageContext smc) {  
         Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);  
   
         if (outboundProperty.booleanValue()) {  
             System.out.println("Outgoing message:");  
         } else {  
             System.out.println("Incoming message:");  
         }  
   
         SOAPMessage message = smc.getMessage();  
         try {  
             message.writeTo(System.out);  
         } catch (Exception e) {  
             System.out.println("Exception in handler: " + e);  
         }  
     }

	public void close(MessageContext context) {
		// TODO Auto-generated method stub
		
	}  
Vista ADF: Maestro/Detalle editable con LOV, y exportado a Excel
Aug 28, 10 by Juan Lebrijo about JDeveloper, blog
Basándonos en un artículo anterior en el que mostrábamos como hacer una pantalla maestro detalle, hoy le vamos a añadir una caja donde se mostrará el detalle donde podremos modificar los datos de los empleados. También es útil saber como se hacen las Listas de Valores con esta tecnología, y veremos un ejemplo de como exportar la tabla detalle a Excel. Aplicación ejemplo en HRApplication.zip. De la  misma manera que en el artículo anterior crearemos:
  • un "ADF Read-only Form" a partir del binding departmentsFindAll en la parte superior.
  • una "ADF table Read-Only" a partir de departmentsFindAll > employeesList. Tabla que rodearemos con un"Panel Collection" para ver más características de ADF.
  • Con un nuevo Panel Spliter, crearemos un cuadro lateral derecho, donde crearemos el form de edición.
Pues eso, arrastramos la departmentsFindAll > employeesList, y seleccionamos "ADF Form" con Submit button:
create_form.png 194 KB
Para que este formulario sea editable arrastramos el método mergeEmployees hacia el botón submit, y diciendole a que altura dl arbol de objetos debe hacer el merge, que esen el employeeList (bindings.employeesListIterator.currentRow.dataProvider):
save_button.png 167 KB
Podemos cambiar el texto del botón por el de "Save"  para que sea más intuitivo. Ahora vamos a crear la lista de valores de Departamentos. Arrastramos el control departamentsFindAll > EmployeesList > departments > departmentId sobre el formulario, y seleccionamos para que cree un "ADF Select One Choice ...":
create_lov.png 178 KB
En la zona "menu" del "Panel collection" vamos a crear un Menú ( que llamaremos File) y un menuItem que llamaremos "Export to Excel". Sobre el que arrastraremos un "Export Collection Action Listener". En el que el tipo será el único que existe "excelHTML", y para el id tendremos que buscar la tabla que queremos exportar:
create_excel.png 140 KB
Guardamos, y con el botón derecho seleccionamos "Run" para probar la pantalla browseEditable.jspx. Veremos como:
  • Se pueden modificar empleados.
  • Podemos desplegar el LOV de Departamentos.
  • Se puede exportar las tablas a excel fácilmente.
page.png 122 KB