1 7 package org.jboss.webservice.server; 8 9 11 import org.jboss.axis.providers.java.RPCInvocation; 12 import org.jboss.axis.providers.java.RPCProvider; 13 import org.jboss.ejb.plugins.AbstractInterceptor; 14 import org.jboss.invocation.Invocation; 15 import org.jboss.invocation.InvocationKey; 16 import org.jboss.webservice.Constants; 17 18 import javax.xml.rpc.handler.HandlerChain ; 19 import javax.xml.rpc.handler.soap.SOAPMessageContext ; 20 21 31 public class ServiceEndpointInterceptor 32 extends AbstractInterceptor 33 { 34 36 44 public Object invoke(final Invocation mi) throws Exception 45 { 46 47 SOAPMessageContext msgContext = (SOAPMessageContext )mi.getPayloadValue(InvocationKey.SOAP_MESSAGE_CONTEXT); 49 if (msgContext == null) 50 { 51 return getNext().invoke(mi); 52 } 53 54 57 HandlerChain handlerChain = (HandlerChain )msgContext.getProperty(Constants.HANDLER_CHAIN); 58 if (handlerChain == null) 59 throw new IllegalStateException ("Cannot obtain handler chain from msg context"); 60 61 RPCInvocation invocation = (RPCInvocation)msgContext.getProperty(RPCProvider.RPC_INVOCATION); 63 if (invocation == null) 64 throw new IllegalStateException ("Cannot obtain RPCInvocation from message context"); 65 66 try 67 { 68 if (handlerChain.handleRequest(msgContext) == false) 70 { 71 log.warn("FIXME: handlerChain.handleRequest() returned false"); 72 return null; 73 } 74 75 RPCInvocation invAfterRequestHandler = (RPCInvocation)msgContext.getProperty(RPCProvider.RPC_INVOCATION); 77 78 if (invocation.equals(invAfterRequestHandler) == false) 80 { 81 Object [] args = invAfterRequestHandler.getArgValues(); 82 if (args.length != mi.getArguments().length) 83 throw new IllegalArgumentException ("Invalid argument list in RPCInvocation"); 84 85 for (int i = 0; i < args.length; i++) 86 { 87 Class miClass = mi.getArguments()[i].getClass(); 88 Class rpcClass = args[i].getClass(); 89 if (miClass.isAssignableFrom(rpcClass) == false) 90 throw new IllegalArgumentException ("RPCInvocation argument cannot be assigned: " + miClass.getName() + " != " + rpcClass.getName()); 91 92 mi.getArguments()[i] = args[i]; 93 } 94 } 95 } 96 catch (Exception e) 97 { 98 log.error("Error processing request handler chain", e); 99 throw e; 100 } 101 102 Object resObj = null; 103 try 104 { 105 resObj = getNext().invoke(mi); 107 } 108 catch (Exception e) 109 { 110 msgContext.setProperty(Constants.LAST_FAULT, e); 111 log.error("Error from service endpoint, processing fault handler chain", e); 112 113 if (handlerChain.handleFault(msgContext) == false) 115 { 116 log.warn("FIXME: handlerChain.handleFault() returned false"); 117 return null; 118 } 119 120 throw e; 122 } 123 124 try 125 { 126 invocation.prepareResponseEnvelope(resObj); 128 129 if (handlerChain.handleResponse(msgContext) == false) 131 { 132 log.warn("FIXME: handlerChain.handleResponse() returned false"); 133 return null; 134 } 135 136 } 141 catch (Exception e) 142 { 143 log.error("Error processing response handler chain", e); 144 throw e; 145 } 146 147 return resObj; 148 } 149 } 150 | Popular Tags |