JAX-WS Handler Chain: messages interceptor
Aug 29, 10 by Juan Lebrijo about Web Services, blog, Java
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
		
	}  
JAX-WS Handler Chain: Interceptando los mensajes
Aug 29, 10 by Juan Lebrijo about Web Services, blog, Java
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
		
	}  
ADF View: Master/Detail editable with LOVs, and Excel exporting option
Aug 28, 10 by Juan Lebrijo about JDeveloper, blog
Based on an earlier post where show how to make a master detail page, today we will add a box where we will be able to modify the aployee data. It is useful too to know how to make List of Values (combos) with this technology, and see an example of how to export the detail table to Excel. Example application in HRApplication.zip. The same way than the last article we will create:
  • an "ADF Read-only Form" from the departmentsFindAll binding in the top part.
  • an "ADF table Read-Only" from the departmentsFindAll > employeesList. Which surround with a "Panel Collection" component to see more features of ADF.
  • With a new Panel Spliter, create a right side box, where we put the edition form.
So drop the departmentsFindAll > employeesList, and select the "ADF Form" with Submit button:
create_form.png 194 KB
We can meke this form editable dropping the mergeEmployees method to the submit button, and pointing where in the data tree will make the merge:
save_button.png 167 KB
Change the text of the button to "Save" it will be more intuitive. Now we will create the list of values of departments. Drop the control departamentsFindAll > EmployeesList > departments > departmentId over the form, and select the "ADF Select One Choice ...":
create_lov.png 178 KB
In the "menu" zone of the "Panel collection" we will create a Menu (called File) and a menuItem called "Export to Excel". Where we will drop an "Export Collection Action Listener". Of the only existent type "excelHTML", and for the identifier, the table we want to export:
create_excel.png 140 KB
Save, and with right button select "Run" to test the browseEditable.jspx. We can see how:
  • To modify employee data.
  • To select in the Departments LOV.
  • To export to excel datasheets easily.
page.png 122 KB