1 16 17 package samples.echo; 18 19 import org.apache.axis.AxisFault; 20 import org.apache.axis.Message; 21 import org.apache.axis.MessageContext; 22 import org.apache.axis.components.logger.LogFactory; 23 import org.apache.axis.handlers.BasicHandler; 24 import org.apache.axis.message.SOAPEnvelope; 25 import org.apache.axis.message.SOAPHeaderElement; 26 import org.apache.axis.utils.Messages; 27 import org.apache.commons.logging.Log; 28 29 import javax.xml.namespace.QName ; 30 31 32 40 public class echoHeaderStructHandler extends BasicHandler 41 { 42 static Log log = 43 LogFactory.getLog(echoHeaderStringHandler.class.getName()); 44 45 public static final String ECHOHEADER_STRUCT_ID = "echoHeaderStructHandler.id"; 46 public static final String HEADER_NS = "http://soapinterop.org/echoheader/"; 47 public static final String HEADER_REQNAME = "echoMeStructRequest"; 48 public static final String HEADER_RESNAME = "echoMeStructResponse"; 49 public static final String ACTOR_NEXT = "http://schemas.xmlsoap.org/soap/actor/next"; 50 public static final String STRUCT_NS = "http://soapinterop.org/xsd" ; 51 public static final String STRUCT_NAME = "SOAPStruct"; 52 public static final QName SOAPStructType = new QName (STRUCT_NS, STRUCT_NAME); 53 54 public boolean canHandleBlock(QName qname) { 55 if (HEADER_NS.equals(qname.getNamespaceURI()) && 56 HEADER_REQNAME.equals(qname.getLocalPart())) { 57 return true; 58 } 59 60 return false; 61 } 62 63 66 public void invoke(MessageContext context) throws AxisFault 67 { 68 if (context.getPastPivot()) { 69 SOAPStruct hdrVal= (SOAPStruct)context.getProperty(ECHOHEADER_STRUCT_ID); 72 if (hdrVal == null) 73 return; 74 75 Message msg = context.getResponseMessage(); 76 if (msg == null) 77 return; 78 SOAPEnvelope env = msg.getSOAPEnvelope(); 79 SOAPHeaderElement header = new SOAPHeaderElement(HEADER_NS, 80 HEADER_RESNAME, 81 hdrVal); 82 env.addHeader(header); 83 } else { 84 Message msg = context.getRequestMessage(); 86 if (msg == null) 87 throw new AxisFault(Messages.getMessage("noRequest00")); 88 89 SOAPEnvelope env = msg.getSOAPEnvelope(); 90 SOAPHeaderElement header = env.getHeaderByName(HEADER_NS, 91 HEADER_REQNAME); 92 93 if (header != null) { 94 SOAPStruct hdrVal ; 97 try { 100 hdrVal = (SOAPStruct)header.getValueAsType(SOAPStructType); 101 } catch (Exception e) { 102 throw AxisFault.makeFault(e); 103 } 104 context.setProperty(ECHOHEADER_STRUCT_ID, hdrVal) ; 105 header.setProcessed(true); 106 } 107 } 108 } 109 } 110 | Popular Tags |