wxm586878 2019-03-18 11:44
浏览 450
已结题

用spring+axis调用自己写的一个测试webservice接口报错,代码如下

接口代码
```public interface TestWebService {

public String getWgceaUrl(String jsonString)throws Exception;

}

实现代码

public class TestWebServiceImpl implements TestWebService{

    @Override
    public String getWgceaUrl(String jsonString) throws Exception {
        System.out.print("测试");
        return "1111111";
    }
}

```整合类
/**
 * 用于axis1与Spring进行整合
 */
public class IntegrationService extends ServletEndpointSupport {


    private ApplicationContext applicationContext;


    private TestWebService testWebService;

    @Override
    protected void onInit() throws ServiceException {
        // 初始化Spirng 配置
        applicationContext = super.getApplicationContext();

        testWebService = (TestWebService) applicationContext.getBean("testWebService");


    }

    /**
     *
     * @Description: 接口
     * @param
     * @return
     * @throws Exception
     */


    public String getWgceaUrl(String jsonString) throws Exception {
        return String.valueOf(testWebService.getWgceaUrl(jsonString));

    }
```package cn.dreamit.p1001.webservice;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

import javax.xml.namespace.QName;
import java.net.URL;

测试类如下
public class test {

    private String nameSpaceUri = "http://192.168.0.18:8080/DreamWeb/services/testWebService";
    //private String nameSpaceUri = "http://www.ntrl.gov.cn/services/WebService";
    private String wsdlUrl = nameSpaceUri + "?wsdl";

    private Service service=null;
    private Call call=null;

    public final void init() throws Exception {
        // 创建调用对象
        service = new Service();
        call = (Call) service.createCall();

        // 调用 远程方法
        call.setOperationName(new QName(nameSpaceUri, "getWgceaUrl"));
        // 设置URL
        call.setTargetEndpointAddress(new URL(wsdlUrl));
    }



    public final void testGet() throws Exception {



        // 执行远程调用,同时获得返回值
        String r = (String) call.invoke(new Object[] {"11"});

        System.out.println("jsonStrings=" + r);


    }


    public static void main(String[] args) {

        test test = new test();
        try {
            test.init();
            test.testGet();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
wsdl配置如下

<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
















<handler name="Authenticate"

          type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" />
<handler  name="LocalResponder"

          type="java:org.apache.axis.transport.local.LocalResponder" />
<handler  name="URLMapper"  type="java:org.apache.axis.handlers.http.URLMapper"

/>
<service  name="AdminService"  provider="java:MSG">
    <parameter  name="allowedMethods"  value="AdminService" />
    <parameter  name="enableRemoteAdmin"  value="false" />
    <parameter  name="className"  value="org.apache.axis.utils.Admin" />
    <namespace>http://xml.apache.org/axis/wsdd/</namespace>
</service>
<service  name="Version"  provider="java:RPC">
    <parameter  name="allowedMethods"  value="getVersion" />
    <parameter  name="className"  value="org.apache.axis.Version" />
</service>
<transport  name="http">
    <requestFlow>
        <handler  type="URLMapper" />
        <handler  type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />
    </requestFlow>
</transport>
<transport  name="local">
    <responseFlow>
        <handler  type="LocalResponder" />
    </responseFlow>
</transport>

<!-- 自定义服务 -->
<service  name="testWebService"  provider="java:RPC">
    <parameter  name="className"  value="cn.dreamit.p1001.webservice.service.TestWebService" />
</service>



springcontext.xml配置如下

<?xml version="1.0" encoding="UTF-8"?>
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

<context:annotation-config />
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <property name="maxUploadSize" value="209715200"></property>
    <property name="defaultEncoding" value="UTF-8"></property>
</bean>

<bean
        id="testWebService"
        class="cn.dreamit.p1001.webservice.service.impl.TestWebServiceImpl" />



报错异常如下

faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.lang.InstantiationException: cn.dreamit.p1001.webservice.service.TestWebService
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}hostname:VDN91YQHSK5EG2L

java.lang.InstantiationException: cn.dreamit.p1001.webservice.service.TestWebService
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:796)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at cn.dreamit.p1001.webservice.test.testGet(test.java:37)
at cn.dreamit.p1001.webservice.test.main(test.java:50)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?