1 package test.wsdl.jaxrpchandler; 2 3 import javax.xml.namespace.QName ; 4 import javax.xml.rpc.handler.Handler ; 5 import javax.xml.rpc.handler.HandlerInfo ; 6 import javax.xml.rpc.handler.MessageContext ; 7 import javax.xml.rpc.handler.soap.SOAPMessageContext ; 8 import javax.xml.soap.Name ; 9 import javax.xml.soap.SOAPEnvelope ; 10 import javax.xml.soap.SOAPHeader ; 11 import javax.xml.soap.SOAPHeaderElement ; 12 import javax.xml.soap.SOAPMessage ; 13 import javax.xml.soap.SOAPPart ; 14 import java.util.Iterator ; 15 16 18 public class ServerHandler implements Handler { 19 20 private int _counter = 0; 21 private int _faultCounter = 0; 22 23 public final static String _actorURI = "myActorURI"; 24 25 28 public ServerHandler() { 29 super(); 30 } 31 32 35 public boolean handleRequest(MessageContext context) { 36 System.out.println("Hey - in Handle request"); 37 try { 38 SOAPMessageContext smc = (SOAPMessageContext ) context; 39 SOAPMessage msg = smc.getMessage(); 40 SOAPPart sp = msg.getSOAPPart(); 41 SOAPEnvelope se = sp.getEnvelope(); 42 SOAPHeader sh = se.getHeader(); 43 Name name = se.createName("HeaderTest", "AXIS", 44 "http://xml.apache.org/axis"); 45 Iterator iter = sh.extractHeaderElements(_actorURI); 46 while (iter.hasNext()) { 47 SOAPHeaderElement she = (SOAPHeaderElement ) iter.next(); 48 String counter = she.getAttributeValue(se.createName("counter","","")); 49 _counter = Integer.parseInt(counter) + 1; 50 51 String faultCounter = she.getAttributeValue(se.createName("faultCounter","","")); 52 _faultCounter = Integer.parseInt(faultCounter) + 1; } 54 } catch (Exception e) { 55 e.printStackTrace(); 56 } 57 58 return true; 59 } 60 61 64 public boolean handleResponse(MessageContext context) { 65 66 System.out.println("Hey - in Handle response"); 67 try { 68 SOAPMessageContext smc = (SOAPMessageContext ) context; 69 SOAPMessage msg = smc.getMessage(); 70 SOAPPart sp = msg.getSOAPPart(); 71 SOAPEnvelope se = sp.getEnvelope(); 72 SOAPHeader sh = se.getHeader(); 73 Name name = se.createName("HeaderTest", "AXIS", 74 "http://xml.apache.org/axis"); 75 SOAPHeaderElement she = sh.addHeaderElement(name); 76 she.addAttribute(se.createName("counter","",""), new Integer (_counter +1).toString()); 77 she.setActor(_actorURI); 78 } catch (Exception e) { 79 e.printStackTrace(); 80 } 81 return true; 82 } 83 84 87 public boolean handleFault(MessageContext context) { 88 try { 89 SOAPMessageContext smc = (SOAPMessageContext ) context; 90 SOAPMessage msg = smc.getMessage(); 91 SOAPPart sp = msg.getSOAPPart(); 92 SOAPEnvelope se = sp.getEnvelope(); 93 SOAPHeader sh = se.getHeader(); 94 Name name = se.createName("HeaderTest", "AXIS", 95 "http://xml.apache.org/axis"); 96 SOAPHeaderElement she = sh.addHeaderElement(name); 97 98 she.addAttribute(se.createName("faultCounter","",""), new Integer (_faultCounter +1).toString()); 99 she.setActor(_actorURI); 100 } catch (Exception e) { 101 e.printStackTrace(); 102 } 103 104 return true; 105 } 106 107 110 public void init(HandlerInfo config) { 111 } 112 113 116 public void destroy() { 117 } 118 119 122 public QName [] getHeaders() { 123 return null; 124 } 125 126 } 127 | Popular Tags |