1 16 17 package org.apache.axis.providers; 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.components.script.Script; 25 import org.apache.axis.components.script.ScriptFactory; 26 import org.apache.axis.description.OperationDesc; 27 import org.apache.axis.description.ParameterDesc; 28 import org.apache.axis.handlers.soap.SOAPService; 29 import org.apache.axis.message.RPCElement; 30 import org.apache.axis.message.RPCHeaderParam; 31 import org.apache.axis.message.RPCParam; 32 import org.apache.axis.message.SOAPBodyElement; 33 import org.apache.axis.message.SOAPEnvelope; 34 import org.apache.axis.soap.SOAPConstants; 35 import org.apache.axis.utils.JavaUtils; 36 import org.apache.axis.utils.Messages; 37 import org.apache.commons.logging.Log; 38 39 import javax.xml.namespace.QName ; 40 import java.util.Vector ; 41 42 public class BSFProvider extends BasicProvider { 43 protected static Log log = 44 LogFactory.getLog(BSFProvider.class.getName()); 45 46 47 public static final String OPTION_LANGUAGE = "language"; 48 public static final String OPTION_SRC = "src"; 49 public static final String OPTION_SCRIPT = "script"; 50 51 public void invoke(MessageContext msgContext) throws AxisFault { 52 try { 53 SOAPService service = msgContext.getService(); 54 String language = (String ) service.getOption(OPTION_LANGUAGE); 55 String scriptStr = (String ) service.getOption(OPTION_SRC); 56 57 if (log.isDebugEnabled()) { 58 log.debug("Enter: BSFProvider.processMessage()"); 59 } 60 61 OperationDesc operation = msgContext.getOperation(); 62 63 Vector bodies = msgContext.getRequestMessage().getSOAPEnvelope().getBodyElements(); 64 if (log.isDebugEnabled()) { 65 log.debug(Messages.getMessage("bodyElems00", "" + bodies.size())); 66 log.debug(Messages.getMessage("bodyIs00", "" + bodies.get(0))); 67 } 68 69 RPCElement body = null; 70 71 for (int bNum = 0; body == null && bNum < bodies.size(); bNum++) { 73 if (!(bodies.get(bNum) instanceof RPCElement)) { 79 SOAPBodyElement bodyEl = (SOAPBodyElement) bodies.get(bNum); 80 if (bodyEl.isRoot() && operation != null && bodyEl.getID() == null) { 84 ParameterDesc param = operation.getParameter(bNum); 85 if (param != null) { 87 Object val = bodyEl.getValueAsType(param.getTypeQName()); 88 body = new RPCElement("", 89 operation.getName(), 90 new Object []{val}); 91 } 92 } 93 } else { 94 body = (RPCElement) bodies.get(bNum); 95 } 96 } 97 98 String methodName = body.getMethodName(); 99 Vector args = body.getParams(); 100 int numArgs = args.size(); 101 102 Object [] argValues = new Object [numArgs]; 103 104 for (int i = 0; i < numArgs; i++) { 110 RPCParam rpcParam = (RPCParam) args.get(i); 111 Object value = rpcParam.getObjectValue(); 112 113 ParameterDesc paramDesc = rpcParam.getParamDesc(); 115 116 if (paramDesc != null && paramDesc.getJavaType() != null) { 120 121 Class sigType = paramDesc.getJavaType(); 123 124 value = JavaUtils.convert(value, 126 sigType); 127 128 rpcParam.setObjectValue(value); 129 } 130 argValues[i] = value; 131 } 132 133 Script script = ScriptFactory.getScript(); 134 Object result = script.run(language, service.getName(), scriptStr, methodName, argValues); 135 136 RPCElement resBody = new RPCElement(methodName + "Response"); 137 resBody.setPrefix(body.getPrefix()); 138 resBody.setNamespaceURI(body.getNamespaceURI()); 139 resBody.setEncodingStyle(msgContext.getEncodingStyle()); 140 141 Message resMsg = msgContext.getResponseMessage(); 142 SOAPEnvelope resEnv; 143 144 if (resMsg == null) { 146 resEnv = new SOAPEnvelope(msgContext.getSOAPConstants()); 147 148 resMsg = new Message(resEnv); 149 msgContext.setResponseMessage(resMsg); 150 } else { 151 resEnv = resMsg.getSOAPEnvelope(); 152 } 153 154 QName returnQName = operation.getReturnQName(); 155 if (returnQName == null) { 156 returnQName = new QName ("", methodName + "Return"); 157 } 158 159 if (msgContext.getSOAPConstants() == 161 SOAPConstants.SOAP12_CONSTANTS) { 162 returnQName = Constants.QNAME_RPC_RESULT; 163 } 164 165 RPCParam param = new RPCParam(returnQName, result); 166 param.setParamDesc(operation.getReturnParamDesc()); 167 if (!operation.isReturnHeader()) { 168 resBody.addParam(param); 169 } else { 170 resEnv.addHeader(new RPCHeaderParam(param)); 171 } 172 173 resEnv.addBodyElement(resBody); 174 175 } catch (Exception e) { 176 entLog.debug(Messages.getMessage("toAxisFault00"), e); 177 throw AxisFault.makeFault(e); 178 } 179 } 180 181 public void initServiceDesc(SOAPService service, MessageContext msgContext) 182 throws AxisFault { 183 } 184 } 185 186 | Popular Tags |