1 23 24 package com.sun.enterprise.webservice; 25 26 import java.util.logging.Level ; 27 import java.lang.reflect.Method ; 28 import java.rmi.UnmarshalException ; 29 30 import com.sun.enterprise.webservice.monitoring.EndpointImpl; 31 32 import com.sun.xml.ws.spi.runtime.SystemHandlerDelegate; 33 import com.sun.xml.ws.spi.runtime.MessageContext; 34 import com.sun.enterprise.webservice.monitoring.JAXWSEndpointImpl; 35 36 import com.sun.enterprise.Switch; 37 import com.sun.ejb.Container; 38 import com.sun.ejb.Invocation; 39 import com.sun.enterprise.InvocationManager; 40 41 45 public class Ejb3SystemHandlerDelegate implements SystemHandlerDelegate { 46 47 private JAXWSEndpointImpl endpoint; 48 private WsUtil wsUtil = new WsUtil(); 49 50 51 public Ejb3SystemHandlerDelegate(JAXWSEndpointImpl endpoint) { 52 this.endpoint = endpoint; 53 } 54 55 56 103 public boolean processRequest(MessageContext messageContext)throws Exception { 104 String messageID = (String ) messageContext.get(EndpointImpl.MESSAGE_ID); 105 System.out.println("process request : Message ID " + messageID); 106 107 if (messageID!=null || (endpoint!=null && endpoint.hasListeners())) { 109 endpoint.processRequest(messageContext); 110 } 111 112 if (endpoint.getDescriptor().hasHandlerChain()) { 113 114 Switch theSwitch = Switch.getSwitch(); 116 InvocationManager invManager = theSwitch.getInvocationManager(); 117 Invocation inv = (Invocation) invManager.getCurrentInvocation(); 118 Container container = (Container) inv.container; 119 120 Method m = messageContext.getMethod(); 121 if (m!=null) { 122 try { 123 inv.method = m; 124 125 inv.setWebServiceMethod(inv.method); 126 127 if ( !container.authorize(inv) ) { 128 inv.exception = new Exception 129 ("Client not authorized for invocation of " 130 + inv.method); 131 } 132 } catch(Exception e) { 133 String errorMsg = "Error unmarshalling method for ejb " 134 + endpoint.getDescriptor().getEjbComponentImpl().getName(); 135 inv.exception = new UnmarshalException (errorMsg); 136 inv.exception.initCause(e); 137 } 138 } else { 139 inv.setWebServiceMethod(null); 140 } 141 142 if( inv.exception != null ) { 143 WsUtil.getDefaultLogger().log(Level.WARNING, "preRequestHandlerHook", inv.exception); 144 wsUtil.throwSOAPFaultException(inv.exception.getMessage(), 147 messageContext); 148 } 149 } 150 return true; 151 } 152 153 154 157 public void preInvokeEndpointHook(MessageContext messageContext) { 158 159 160 if (endpoint.getDescriptor().hasHandlerChain()) { 161 Switch theSwitch = Switch.getSwitch(); 163 InvocationManager invManager = theSwitch.getInvocationManager(); 164 Invocation inv = (Invocation) invManager.getCurrentInvocation(); 165 Container container = (Container) inv.container; 166 167 Method m = messageContext.getMethod(); 168 if (m!=null) { 169 try { 170 Method webServiceMethodInPreHandler = inv.getWebServiceMethod(); 171 172 if( webServiceMethodInPreHandler != null ) { 173 if( !webServiceMethodInPreHandler.equals(m) ) { 179 inv.exception = new UnmarshalException 180 ("Original method " + webServiceMethodInPreHandler + 181 " does not match post-handler method " + m); 182 } 183 } 184 } catch(Exception e) { 185 String errorMsg = "Exception while getting method for " + 186 ((inv != null ) ? 187 ((Container) inv.container).getEjbDescriptor().getName() : ""); 188 inv.exception = new UnmarshalException (errorMsg); 189 inv.exception.initCause(e); 190 } 191 192 if( inv.exception != null ) { 193 WsUtil.getDefaultLogger().log(Level.WARNING, "postEjbHandlerError", inv.exception); 194 195 wsUtil.throwSOAPFaultException(inv.exception.getMessage(), 196 messageContext); 197 } 198 } 199 } 200 } 201 202 218 public void processResponse(MessageContext messageContext) throws Exception { 219 String messageID = (String ) messageContext.get(EndpointImpl.MESSAGE_ID); 220 System.out.println("process response : Message ID " + messageID); 221 222 if (messageID!=null || (endpoint!=null && endpoint.hasListeners())) { 224 endpoint.processResponse(messageContext); 225 } 226 } 227 } 228 | Popular Tags |