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