mocktransport.java

来自「it is a tools for developing J2ME applic」· Java 代码 · 共 61 行

JAVA
61
字号
package org.ksoap2.transport.mock;

import java.io.*;
import java.lang.reflect.*;

import org.ksoap2.*;
import org.ksoap2.serialization.*;
import org.ksoap2.transport.*;
import org.xmlpull.v1.*;

// makes the parse more visible
public class MockTransport extends Transport {

    public void parseResponse(SoapEnvelope envelope, InputStream is) throws XmlPullParserException, IOException {
        super.parseResponse(envelope, is);
    }
    
    /** 
     * Need to override this to make it visible.
     * @see org.ksoap2.transport.Transport#createRequestData(org.ksoap2.SoapEnvelope)
     */
    public byte[] createRequestData(SoapEnvelope envelope) throws IOException {
        return super.createRequestData(envelope);
    }

    public void call(String targetNamespace, SoapEnvelope envelope) throws IOException, XmlPullParserException {
        throw new RuntimeException("not really doing anything");
    }

    /** Invoke - from SoapServlet. */
    public static SoapObject invoke(Object service, SoapObject soapReq) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        String name = soapReq.getName();
        Class types[] = new Class[soapReq.getPropertyCount()];
        Object[] args = new Object[soapReq.getPropertyCount()];
        PropertyInfo arg = new PropertyInfo();
        for (int i = 0; i < types.length; i++) {
            soapReq.getPropertyInfo(i, arg);
            types[i] = (Class) arg.type;
            args[i] = soapReq.getProperty(i);
        }
        // expensive invocation here.. optimize with method cache,
        // want to support method overloading so need to figure in
        // the arg types..
        Object result = null;
        try {
            Method method = service.getClass().getMethod(name, types);
            result = method.invoke(service, args);
        } catch (NoSuchMethodException nsme) {
            // since the properties do not match the required method calls when attributes are present
            // we will also search for a call that takes a single "SoapObject" as the input.
            Method method = service.getClass().getMethod(name, new Class[] { SoapObject.class });
            result = method.invoke(service, new Object[] { soapReq });
        }
        SoapObject response = new SoapObject(soapReq.getNamespace(), name + "Response");
        if (result != null)
            response.addProperty("return", result);
        return response;
    }


}

⌨️ 快捷键说明

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