1 package test.wsdl.jaxrpchandlereval; 2 3 import javax.xml.rpc.handler.*; 4 import javax.xml.soap.*; 5 import javax.xml.namespace.*; 6 import javax.xml.rpc.handler.soap.SOAPMessageContext ; 7 import javax.xml.rpc.JAXRPCException ; 8 9 10 public class ServiceHandler1 implements javax.xml.rpc.handler.Handler { 11 12 public ServiceHandler1() { 13 System.out.println("ServiceHandler1:Constructor"); 14 } 15 16 public boolean handleRequest(MessageContext context) { 17 System.out.println("ServiceHandler1:handleRequest"); 18 19 try { 20 SOAPMessageContext soapMsgCtx = (SOAPMessageContext )context; 21 SOAPMessage soapMsg = soapMsgCtx.getMessage(); 22 SOAPPart sp = soapMsg.getSOAPPart(); 23 SOAPEnvelope se = sp.getEnvelope(); 24 SOAPBody sb = se.getBody(); 25 SOAPHeader sh = se.getHeader(); 26 27 Name xmlServicesHandler1HdrName = 28 se.createName("ServiceHandler1-handleRequest", "", ""); 29 SOAPHeaderElement xmlServicesHandler1Hdr = 30 sh.addHeaderElement(xmlServicesHandler1HdrName); 31 xmlServicesHandler1Hdr.addTextNode( 32 "Processed by ServiceHandler1Hdr1.handleRequest"); 33 } catch (Exception ex) { 34 throw new JAXRPCException (ex); 35 } 36 return true; 37 } 38 39 public boolean handleResponse(MessageContext context) { 40 System.out.println("ServiceHandler1:handleResponse"); 41 try { 42 SOAPMessageContext soapMsgCtx = (SOAPMessageContext )context; 43 SOAPMessage soapMsg = soapMsgCtx.getMessage(); 44 SOAPPart sp = soapMsg.getSOAPPart(); 45 SOAPEnvelope se = sp.getEnvelope(); 46 SOAPBody sb = se.getBody(); 47 SOAPHeader sh = se.getHeader(); 48 49 Name xmlServicesHandler1HdrName = 50 se.createName("ServiceHandler1-handleResponse", "", ""); 51 SOAPHeaderElement xmlServicesHandler1Hdr = 52 sh.addHeaderElement(xmlServicesHandler1HdrName); 53 xmlServicesHandler1Hdr.addTextNode( 54 "Processed by ServiceHandler1Hdr1.handleResponse"); 55 56 sp.addMimeHeader("MY_MIME_HEADER", "ADDING A NEW HEADER IN SOAPPART"); 57 } catch (Exception ex) { 58 throw new JAXRPCException (ex); 59 } 60 return true; 61 } 62 63 public boolean handleFault(MessageContext context) { 64 System.out.println("\nServiceHandler1:handleFault"); 65 try { 66 SOAPMessageContext soapMsgCtx = (SOAPMessageContext )context; 67 SOAPMessage soapMsg = soapMsgCtx.getMessage(); 68 69 70 SOAPPart sp = soapMsg.getSOAPPart(); 71 SOAPEnvelope se = sp.getEnvelope(); 72 SOAPBody sb = se.getBody(); 73 SOAPHeader sh = se.getHeader(); 74 75 Name xmlServicesHandler1HdrName = 76 se.createName("ServiceHandler1-handleFault", "", ""); 77 SOAPHeaderElement xmlServicesHandler1Hdr = 78 sh.addHeaderElement(xmlServicesHandler1HdrName); 79 xmlServicesHandler1Hdr.addTextNode( 80 "Processed by ServiceHandler1Hdr1.handleFault"); 81 82 soapMsgCtx.setMessage(soapMsg); 83 } catch (Exception ex) { 84 ex.printStackTrace(); 85 } 86 return true; 87 } 88 89 public void init(HandlerInfo config) { 90 System.out.println("ServiceHandler1:init"); 91 } 92 93 public void destroy() { 94 System.out.println("ServiceHandler1:destroy"); 95 } 96 97 public QName[] getHeaders() { 98 System.out.println("ServiceHandler1:getHeaders"); 99 return null; 100 } 101 102 } 103 104 | Popular Tags |