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.bridge.COMBridge; 24 import org.apache.axis.deployment.wsdd.providers.WSDDComProvider; 25 import org.apache.axis.description.OperationDesc; 26 import org.apache.axis.description.ParameterDesc; 27 import org.apache.axis.handlers.soap.SOAPService; 28 import org.apache.axis.message.RPCElement; 29 import org.apache.axis.message.RPCHeaderParam; 30 import org.apache.axis.message.RPCParam; 31 import org.apache.axis.message.SOAPBodyElement; 32 import org.apache.axis.message.SOAPEnvelope; 33 import org.apache.axis.soap.SOAPConstants; 34 import org.apache.axis.utils.JavaUtils; 35 import org.apache.axis.utils.Messages; 36 37 import javax.xml.namespace.QName ; 38 import java.util.Hashtable ; 39 import java.util.Vector ; 40 41 public class ComProvider extends BasicProvider { 42 43 44 public void invoke(MessageContext msgContext) throws AxisFault { 45 try { 46 SOAPService service = msgContext.getService(); 47 String progID = (String ) service.getOption(WSDDComProvider.OPTION_PROGID); 48 String threadingModel = (String ) service.getOption(WSDDComProvider.OPTION_THREADING_MODEL); 49 50 if (log.isDebugEnabled()) { 51 log.debug("Enter: COMProvider.processMessage()"); 52 } 53 54 OperationDesc operation = msgContext.getOperation(); 55 56 Vector bodies = msgContext.getRequestMessage().getSOAPEnvelope().getBodyElements(); 57 if (log.isDebugEnabled()) { 58 log.debug(Messages.getMessage("bodyElems00", "" + bodies.size())); 59 log.debug(Messages.getMessage("bodyIs00", "" + bodies.get(0))); 60 } 61 62 RPCElement body = null; 63 64 for (int bNum = 0; body == null && bNum < bodies.size(); bNum++) { 66 if (!(bodies.get(bNum) instanceof RPCElement)) { 72 SOAPBodyElement bodyEl = (SOAPBodyElement) bodies.get(bNum); 73 if (bodyEl.isRoot() && operation != null && bodyEl.getID() == null) { 77 ParameterDesc param = operation.getParameter(bNum); 78 if (param != null) { 80 Object val = bodyEl.getValueAsType(param.getTypeQName()); 81 body = new RPCElement("", 82 operation.getName(), 83 new Object []{val}); 84 } 85 } 86 } else { 87 body = (RPCElement) bodies.get(bNum); 88 } 89 } 90 91 String methodName = body.getMethodName(); 92 Vector args = body.getParams(); 93 int numArgs = args.size(); 94 95 Vector argValues = new Vector (); 96 97 for (int i = 0; i < numArgs; i++) { 103 RPCParam rpcParam = (RPCParam) args.get(i); 104 Object value = rpcParam.getObjectValue(); 105 106 ParameterDesc paramDesc = rpcParam.getParamDesc(); 108 109 if (paramDesc != null && paramDesc.getJavaType() != null) { 113 114 Class sigType = paramDesc.getJavaType(); 116 117 value = JavaUtils.convert(value, 119 sigType); 120 121 rpcParam.setObjectValue(value); 122 } 123 argValues.add(value); 124 } 125 126 COMBridge bridge = new COMBridge(); 127 Hashtable props = new Hashtable (); 128 props.put("progid", progID); 129 if (threadingModel != null) 130 props.put("threadmodel", threadingModel); 131 132 Object result = bridge.execute(methodName, argValues, props); 133 134 RPCElement resBody = new RPCElement(methodName + "Response"); 135 resBody.setPrefix(body.getPrefix()); 136 resBody.setNamespaceURI(body.getNamespaceURI()); 137 resBody.setEncodingStyle(msgContext.getEncodingStyle()); 138 139 Message resMsg = msgContext.getResponseMessage(); 140 SOAPEnvelope resEnv; 141 142 if (resMsg == null) { 144 resEnv = new SOAPEnvelope(msgContext.getSOAPConstants()); 145 146 resMsg = new Message(resEnv); 147 msgContext.setResponseMessage(resMsg); 148 } else { 149 resEnv = resMsg.getSOAPEnvelope(); 150 } 151 152 QName returnQName = operation.getReturnQName(); 153 if (returnQName == null) { 154 returnQName = new QName ("", methodName + "Return"); 155 } 156 157 if (msgContext.getSOAPConstants() == 159 SOAPConstants.SOAP12_CONSTANTS) { 160 returnQName = Constants.QNAME_RPC_RESULT; 161 } 162 163 RPCParam param = new RPCParam(returnQName, result); 164 param.setParamDesc(operation.getReturnParamDesc()); 165 if (!operation.isReturnHeader()) { 166 resBody.addParam(param); 167 } else { 168 resEnv.addHeader(new RPCHeaderParam(param)); 169 } 170 171 resEnv.addBodyElement(resBody); 172 173 } catch (Exception e) { 174 entLog.debug(Messages.getMessage("toAxisFault00"), e); 175 throw AxisFault.makeFault(e); 176 } catch (Throwable t) { 177 entLog.debug(Messages.getMessage("toAxisFault00")); 178 throw new AxisFault(Messages.getMessage("toAxisFault00"), t); 179 } 180 } 181 182 public void initServiceDesc(SOAPService service, MessageContext msgContext) 183 throws AxisFault { 184 } 185 } 186 | Popular Tags |