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.SOAPBody ; 12 import javax.xml.soap.SOAPHeaderElement ; 13 import javax.xml.soap.SOAPMessage ; 14 import javax.xml.soap.SOAPPart ; 15 import java.util.Iterator ; 16 17 19 public class ClientHandler implements Handler { 20 21 private final static String _actorURI = "myActorURI"; 22 25 public ClientHandler() { 26 super(); 27 } 28 29 32 public boolean handleRequest(MessageContext context) { 33 System.out.println("Hey - in Handle request"); 34 try { 35 SOAPMessageContext smc = (SOAPMessageContext ) context; 36 SOAPMessage msg = smc.getMessage(); 37 SOAPPart sp = msg.getSOAPPart(); 38 SOAPEnvelope se = sp.getEnvelope(); 39 SOAPHeader sh = se.getHeader(); 40 Name name = 41 se.createName( 42 "HeaderTest", 43 "AXIS", 44 "http://xml.apache.org/axis"); 45 SOAPHeaderElement she = sh.addHeaderElement(name); 46 she.setActor(_actorURI); 47 she.addAttribute(se.createName("counter", "", ""), "1"); 48 she.addAttribute(se.createName("faultCounter", "", ""), "1"); 49 } catch (Exception e) { 50 e.printStackTrace(); 51 } 52 53 return true; 54 } 55 56 59 public boolean handleResponse(MessageContext context) { 60 System.out.println("Hey - in Handle response"); 61 try { 62 String counter = null; 63 String faultCounter = null; 64 65 SOAPMessageContext smc = (SOAPMessageContext ) context; 66 SOAPMessage msg = smc.getMessage(); 67 SOAPPart sp = msg.getSOAPPart(); 68 SOAPEnvelope se = sp.getEnvelope(); 69 SOAPHeader sh = se.getHeader(); 70 SOAPBody sb = se.getBody(); 71 Name name = 72 se.createName( 73 "HeaderTest", 74 "AXIS", 75 "http://xml.apache.org/axis"); 76 Iterator iter = sh.extractHeaderElements(_actorURI); 77 while (iter.hasNext()) { 78 SOAPHeaderElement she = (SOAPHeaderElement ) iter.next(); 79 counter = 80 she.getAttributeValue(se.createName("counter", "", "")); 81 System.out.println( 82 "The counter in the element sent back is " + counter); 83 84 faultCounter = 85 she.getAttributeValue(se.createName("faultCounter", "", "")); 86 System.out.println( 87 "The faultCounter in the element sent back is " + faultCounter); 88 89 } 90 91 if ((counter != null) && (counter.equals("3")) && (!sb.hasFault())) { 92 JAXRPCHandlerTestCase.completeRoundtrip(); 93 } 94 95 if ((faultCounter != null) && (faultCounter.equals("3")) && (sb.hasFault())) { 96 JAXRPCHandlerTestCase.setFaultRoundtrip(Integer.parseInt(faultCounter)); 97 } 98 99 100 } catch (Exception e) { 101 e.printStackTrace(); 102 } 103 104 return false; 105 } 106 107 110 public boolean handleFault(MessageContext context) { 111 return false; 112 } 113 114 117 public void init(HandlerInfo config) { 118 } 119 120 123 public void destroy() { 124 } 125 126 129 public QName [] getHeaders() { 130 return null; 131 } 132 133 } 134 135 | Popular Tags |