1 22 package org.jboss.test.webservice.jbws83; 23 24 import javax.xml.namespace.QName ; 25 import javax.xml.rpc.handler.GenericHandler ; 26 import javax.xml.rpc.handler.MessageContext ; 27 import javax.xml.rpc.handler.soap.SOAPMessageContext ; 28 import javax.xml.soap.SOAPException ; 29 import javax.xml.soap.SOAPMessage ; 30 31 import org.jboss.logging.Logger; 32 33 import java.io.ByteArrayOutputStream ; 34 import java.io.IOException ; 35 36 public class ClientHandler extends GenericHandler 37 { 38 private static final Logger log = Logger.getLogger(ClientHandler.class); 40 41 protected QName [] headers; 42 43 public QName [] getHeaders() 44 { 45 return headers; 46 } 47 48 public boolean handleRequest(MessageContext msgContext) 49 { 50 try 51 { 52 processMessage(msgContext); 53 return true; 54 } 55 catch (RuntimeException rte) 56 { 57 throw rte; 58 } 59 catch (Exception e) 60 { 61 throw new IllegalArgumentException (e.toString()); 62 } 63 } 64 65 public boolean handleResponse(MessageContext msgContext) 66 { 67 try 68 { 69 processMessage(msgContext); 70 return true; 71 } 72 catch (RuntimeException rte) 73 { 74 throw rte; 75 } 76 catch (Exception e) 77 { 78 throw new IllegalArgumentException (e.toString()); 79 } 80 } 81 82 84 private void processMessage(MessageContext msgContext) throws SOAPException , IOException 85 { 86 SOAPMessageContext soapContext = (SOAPMessageContext )msgContext; 87 SOAPMessage soapMessage = soapContext.getMessage(); 88 89 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 90 soapMessage.writeTo(baos); 91 String msgStr = new String (baos.toByteArray()); 92 93 log.debug(msgStr); 94 95 String expElement = "<my-msg>Kermit</my-msg>"; 96 if (msgStr.indexOf(expElement) < 0) 97 throw new SOAPException ("Cannot find " + expElement + " in SOAPMessage"); 98 } 99 } 100 | Popular Tags |