⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rpcprovider.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2001-2004 The Apache Software Foundation. *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *  *      http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.axis.providers.java;import org.apache.axis.AxisFault;import org.apache.axis.Constants;import org.apache.axis.MessageContext;import org.apache.axis.components.logger.LogFactory;import org.apache.axis.description.OperationDesc;import org.apache.axis.description.ParameterDesc;import org.apache.axis.description.ServiceDesc;import org.apache.axis.constants.Style;import org.apache.axis.handlers.soap.SOAPService;import org.apache.axis.message.RPCElement;import org.apache.axis.message.RPCHeaderParam;import org.apache.axis.message.RPCParam;import org.apache.axis.message.SOAPBodyElement;import org.apache.axis.message.SOAPEnvelope;import org.apache.axis.soap.SOAPConstants;import org.apache.axis.utils.JavaUtils;import org.apache.axis.utils.Messages;import org.apache.commons.logging.Log;import org.xml.sax.SAXException;import javax.xml.namespace.QName;import javax.xml.rpc.holders.Holder;import javax.wsdl.OperationType;import java.lang.reflect.Method;import java.util.ArrayList;import java.util.Iterator;import java.util.Vector;/** * Implement message processing by walking over RPCElements of the * envelope body, invoking the appropriate methods on the service object. * * @author Doug Davis (dug@us.ibm.com) */public class RPCProvider extends JavaProvider {    protected static Log log =            LogFactory.getLog(RPCProvider.class.getName());    /**     * Process the current message.     * Result in resEnv.     *     * @param msgContext self-explanatory     * @param reqEnv the request envelope     * @param resEnv the response envelope     * @param obj the service object itself     */    public void processMessage(MessageContext msgContext,                               SOAPEnvelope reqEnv,                               SOAPEnvelope resEnv,                               Object obj)            throws Exception {        if (log.isDebugEnabled()) {            log.debug("Enter: RPCProvider.processMessage()");        }        SOAPService service = msgContext.getService();        ServiceDesc serviceDesc = service.getServiceDescription();        RPCElement body = getBody(reqEnv, msgContext);        Vector args = null;        try {            args = body.getParams();        } catch (SAXException e) {            if(e.getException() != null)                throw e.getException();            throw e;        }        int numArgs = args.size();        OperationDesc operation = getOperationDesc(msgContext, body);        // Create the array we'll use to hold the actual parameter        // values.  We know how big to make it from the metadata.        Object[] argValues = new Object[operation.getNumParams()];        // A place to keep track of the out params (INOUTs and OUTs)        ArrayList outs = new ArrayList();        // Put the values contained in the RPCParams into an array        // suitable for passing to java.lang.reflect.Method.invoke()        // Make sure we respect parameter ordering if we know about it        // from metadata, and handle whatever conversions are necessary        // (values -> Holders, etc)        for (int i = 0; i < numArgs; i++) {            RPCParam rpcParam = (RPCParam) args.get(i);            Object value = rpcParam.getObjectValue();            // first check the type on the paramter            ParameterDesc paramDesc = rpcParam.getParamDesc();            // if we found some type info try to make sure the value type is            // correct.  For instance, if we deserialized a xsd:dateTime in            // to a Calendar and the service takes a Date, we need to convert            if (paramDesc != null && paramDesc.getJavaType() != null) {                // Get the type in the signature (java type or its holder)                Class sigType = paramDesc.getJavaType();                // Convert the value into the expected type in the signature                value = JavaUtils.convert(value, sigType);                rpcParam.setObjectValue(value);                if (paramDesc.getMode() == ParameterDesc.INOUT) {                    outs.add(rpcParam);                }            }            // Put the value (possibly converted) in the argument array            // make sure to use the parameter order if we have it            if (paramDesc == null || paramDesc.getOrder() == -1) {                argValues[i] = value;            } else {                argValues[paramDesc.getOrder()] = value;            }            if (log.isDebugEnabled()) {                log.debug("  " + Messages.getMessage("value00",                        "" + argValues[i]));            }        }        // See if any subclasses want a crack at faulting on a bad operation        // FIXME : Does this make sense here???        String allowedMethods = (String) service.getOption("allowedMethods");        checkMethodName(msgContext, allowedMethods, operation.getName());        // Now create any out holders we need to pass in        int count = numArgs;        for (int i = 0; i < argValues.length; i++) {            // We are interested only in OUT/INOUT            ParameterDesc param = operation.getParameter(i);            if(param.getMode() == ParameterDesc.IN)                continue;            Class holderClass = param.getJavaType();            if (holderClass != null &&                    Holder.class.isAssignableFrom(holderClass)) {                int index = count;                // Use the parameter order if specified or just stick them to the end.                if (param.getOrder() != -1) {                    index = param.getOrder();                } else {                    count++;                }                // If it's already filled, don't muck with it                if (argValues[index] != null) {                    continue;                }                argValues[index] = holderClass.newInstance();                // Store an RPCParam in the outs collection so we                // have an easy and consistent way to write these                // back to the client below                RPCParam p = new RPCParam(param.getQName(),                        argValues[index]);                p.setParamDesc(param);                outs.add(p);            } else {                throw new AxisFault(Messages.getMessage("badOutParameter00",                        "" + param.getQName(),                        operation.getName()));            }        }        // OK!  Now we can invoke the method        Object objRes = null;        try {            objRes = invokeMethod(msgContext,                                  operation.getMethod(),                                  obj, argValues);        } catch (IllegalArgumentException e) {            String methodSig = operation.getMethod().toString();            String argClasses = "";            for (int i = 0; i < argValues.length; i++) {                if (argValues[i] == null) {                    argClasses += "null";                } else {                    argClasses += argValues[i].getClass().getName();                }                if (i + 1 < argValues.length) {                    argClasses += ",";                }            }            log.info(Messages.getMessage("dispatchIAE00",                    new String[]{methodSig, argClasses}),                    e);            throw new AxisFault(Messages.getMessage("dispatchIAE00",                    new String[]{methodSig, argClasses}),                    e);        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -