1 22 package org.jboss.test.webservice.header; 23 24 import org.jboss.logging.Logger; 25 26 import javax.xml.rpc.ServiceException ; 27 import javax.xml.rpc.handler.soap.SOAPMessageContext ; 28 import javax.xml.rpc.server.ServiceLifecycle ; 29 import javax.xml.rpc.server.ServletEndpointContext ; 30 import javax.xml.soap.Name ; 31 import javax.xml.soap.SOAPElement ; 32 import javax.xml.soap.SOAPException ; 33 import javax.xml.soap.SOAPFactory ; 34 import javax.xml.soap.SOAPHeader ; 35 import javax.xml.soap.SOAPHeaderElement ; 36 import javax.xml.soap.SOAPMessage ; 37 import java.rmi.RemoteException ; 38 import java.util.Iterator ; 39 40 44 public class ImplicitHeaderEndpointImpl implements ImplicitHeaderEndpoint, ServiceLifecycle 45 { 46 private final Logger log = Logger.getLogger(ImplicitHeaderEndpointImpl.class); 48 49 private static final String NAMESPACE_URI = ImplicitHeaderEndpoint.NAMESPACE_URI; 50 private static final String PREFIX = ImplicitHeaderEndpoint.PREFIX; 51 52 private ServletEndpointContext context; 53 54 public boolean doStuff(String parameter) throws RemoteException 55 { 56 if (parameter == null) 57 throw new IllegalArgumentException ("Null parameter"); 58 59 try 60 { 61 SOAPFactory factory = SOAPFactory.newInstance(); 62 63 SOAPMessageContext msgContext = (SOAPMessageContext )context.getMessageContext(); 64 SOAPMessage soapMessage = msgContext.getMessage(); 65 SOAPHeader soapHeader = soapMessage.getSOAPHeader(); 66 Iterator it = soapHeader.extractAllHeaderElements(); 67 if (it.hasNext() == false) 68 throw new IllegalArgumentException ("No header elements"); 69 70 SOAPHeaderElement headerElement = (SOAPHeaderElement )it.next(); 71 Name usernameName = factory.createName("username", PREFIX, NAMESPACE_URI); 72 SOAPElement usrElement = (SOAPElement )headerElement.getChildElements(usernameName).next(); 73 String username = usrElement.getValue(); 74 75 Name sessionIDName = factory.createName("sessionID", PREFIX, NAMESPACE_URI); 76 SOAPElement seElement = (SOAPElement )headerElement.getChildElements(sessionIDName).next(); 77 String sessionID = seElement.getValue(); 78 79 log.info("username: " + username); 80 log.info("sessionID: " + sessionID); 81 82 return true; 83 } 84 catch (SOAPException e) 85 { 86 log.error(e); 87 return false; 88 } 89 } 90 91 public void init(Object context) throws ServiceException 92 { 93 log.info("init: " + context); 94 this.context = (ServletEndpointContext )context; 95 } 96 97 public void destroy() 98 { 99 log.info("destroy: " + context); 100 } 101 } 102 | Popular Tags |