1 7 package org.jboss.webservice.handler; 8 9 11 import org.jboss.logging.Logger; 12 13 import javax.xml.namespace.QName ; 14 import javax.xml.rpc.JAXRPCException ; 15 import javax.xml.rpc.handler.Handler ; 16 import javax.xml.rpc.handler.HandlerInfo ; 17 import javax.xml.rpc.handler.MessageContext ; 18 import javax.xml.rpc.soap.SOAPFaultException ; 19 20 25 public class HandlerWrapper implements Handler 26 { 27 private static Logger log = Logger.getLogger(HandlerWrapper.class); 28 29 public final static int DOES_NOT_EXIST = 0; 30 public final static int METHOD_READY = 1; 31 32 private static String [] stateNames = new String []{"DOES_NOT_EXIST", "METHOD_READY"}; 34 35 private Handler delegate; 37 private int state; 39 40 43 public HandlerWrapper(Handler handler) 44 { 45 delegate = handler; 46 state = DOES_NOT_EXIST; } 48 49 52 public int getState() 53 { 54 return state; 55 } 56 57 60 public String getStateAsString() 61 { 62 return stateNames[state]; 63 } 64 65 68 public QName [] getHeaders() 69 { 70 return delegate.getHeaders(); 71 } 72 73 76 public void init(HandlerInfo config) throws JAXRPCException 77 { 78 log.debug("init: " + delegate); 79 delegate.init(config); 80 state = METHOD_READY; 81 } 82 83 86 public void destroy() throws JAXRPCException 87 { 88 log.debug("destroy: " + delegate); 89 state = DOES_NOT_EXIST; 90 delegate.destroy(); 91 } 92 93 96 public boolean handleRequest(MessageContext msgContext) throws JAXRPCException , SOAPFaultException 97 { 98 if (state == DOES_NOT_EXIST) 99 { 100 log.warn("Handler is in state DOES_NOT_EXIST, skipping Handler.handleRequest for: " + delegate); 101 return true; 102 } 103 104 try 105 { 106 return delegate.handleRequest(msgContext); 107 } 108 catch (RuntimeException e) 109 { 110 return handleRuntimeException(e); 111 } 112 } 113 114 117 public boolean handleResponse(MessageContext msgContext) 118 { 119 if (state == DOES_NOT_EXIST) 120 { 121 log.warn("Handler is in state DOES_NOT_EXIST, skipping Handler.handleResponse for: " + delegate); 122 return true; 123 } 124 125 try 126 { 127 return delegate.handleResponse(msgContext); 128 } 129 catch (RuntimeException e) 130 { 131 return handleRuntimeException(e); 132 } 133 } 134 135 138 public boolean handleFault(MessageContext msgContext) 139 { 140 if (state == DOES_NOT_EXIST) 141 { 142 log.warn("Handler is in state DOES_NOT_EXIST, skipping Handler.handleFault for: " + delegate); 143 return true; 144 } 145 146 try 147 { 148 return delegate.handleFault(msgContext); 149 } 150 catch (RuntimeException e) 151 { 152 return handleRuntimeException(e); 153 } 154 } 155 156 160 private boolean handleRuntimeException(RuntimeException e) 161 { 162 if ((e instanceof SOAPFaultException ) == false) 163 { 164 log.warn("RuntimeException in handler method, transition to DOES_NOT_EXIST"); 165 destroy(); 166 } 167 168 throw e; 169 } 170 171 174 public int hashCode() 175 { 176 return delegate.hashCode(); 177 } 178 179 182 public String toString() 183 { 184 return "[state=" + getStateAsString() + ",handler=" + delegate + "]"; 185 } 186 } 187 | Popular Tags |