yqq_3747
yqq_3747
2021-01-20 17:18

地址动态调用WebService出现问题

  • java
  • eclipse

地址动态调用WebService出现问题 :Error reading XMLStreamReader: Unexpected EOF in prolog

服务端接口

package com.example.demo.ibiz;

import java.util.List;

import javax.jws.WebMethod;
import javax.jws.WebService;

import com.example.demo.entitys.UserEntity;

@WebService(name = "userWebService", targetNamespace = "http://ibiz.demo.example.com")
public interface IUserWebServiceBIZ {
	
	@WebMethod
	public List<UserEntity> getUserEntitys();
	
}

服务端接口实现类

package com.example.demo.biz;

import java.util.List;

import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.example.demo.entitys.UserEntity;
import com.example.demo.ibiz.IUserWebServiceBIZ;
import com.example.demo.mapper.UserMapper;

@Component
@WebService(serviceName = "userWebService", targetNamespace = "http://ibiz.demo.example.com", 
endpointInterface = "com.example.demo.ibiz.IUserWebServiceBIZ")
public class UserWebServiceBIZ implements IUserWebServiceBIZ {

	@Autowired
	private UserMapper userMapper;

	@Override
	public List<UserEntity> getUserEntitys() {
		return userMapper.selectList(null);
	}
	
}

CXF配置类

package com.example.demo.config;

import javax.xml.ws.Endpoint;

import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.example.demo.ibiz.IUserWebServiceBIZ;


@Configuration
public class WebServiceConfig {
	
	@Autowired
	private IUserWebServiceBIZ userWebServiceBIZ;
	
    @Bean(name = "cxfServlet")
    public ServletRegistrationBean<CXFServlet> cxfServlet() {
        return new ServletRegistrationBean<>(new CXFServlet(), "/services/*");
    }
    
    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus(){
        return  new SpringBus();
    }
    
    @Bean(name = "sweptPayEndpoint")
    public Endpoint sweptPayEndpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), userWebServiceBIZ);
        endpoint.publish("/userWebService");
        return endpoint;
    }
}

客户端调用

package com.example.demo;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CxfWebserviceApplication {

	public static void main(String[] args) {
		SpringApplication.run(CxfWebserviceApplication.class, args);
		invokeService_2();
	}
	
	public static void invokeService_2(){
	    // 创建动态客户端
	    JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
	    Client client = dcf.createClient("http://localhost:8000/EasyExcel/services/userWebService?wsdl");
	    // 需要密码的情况需要加上用户名和密码
//	    client.getOutInterceptors().add(new ClientLoginInterceptor("", ""));
	    Object[] objects = new Object[0];
	    try {
	        // invoke("方法名",参数1,参数2,参数3....);
	        //这里注意如果是复杂参数的话,要保证复杂参数可以序列化
	        objects = client.invoke("getUserEntitys");
	        System.out.println("返回数据:" + objects[0]);
	    } catch (java.lang.Exception e) {
	        e.printStackTrace();
	    }
	}
}

客户端调用错误信息

org.apache.cxf.binding.soap.SoapFault: Error reading XMLStreamReader: Unexpected EOF in prolog
 at [row,col {unknown-source}]: [1,0]
	at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:292) ~[cxf-rt-bindings-soap-3.2.6.jar:3.2.6]
	at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:70) ~[cxf-rt-bindings-soap-3.2.6.jar:3.2.6]
	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) [cxf-core-3.2.6.jar:3.2.6]
	at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:833) [cxf-core-3.2.6.jar:3.2.6]
	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1695) [cxf-rt-transports-http-3.2.6.jar:3.2.6]
	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1572) [cxf-rt-transports-http-3.2.6.jar:3.2.6]
	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1373) [cxf-rt-transports-http-3.2.6.jar:3.2.6]
	at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56) [cxf-core-3.2.6.jar:3.2.6]
	at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:673) [cxf-rt-transports-http-3.2.6.jar:3.2.6]
	at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:63) [cxf-core-3.2.6.jar:3.2.6]
	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) [cxf-core-3.2.6.jar:3.2.6]
	at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:537) [cxf-core-3.2.6.jar:3.2.6]
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:446) [cxf-core-3.2.6.jar:3.2.6]
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:361) [cxf-core-3.2.6.jar:3.2.6]
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319) [cxf-core-3.2.6.jar:3.2.6]
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:339) [cxf-core-3.2.6.jar:3.2.6]
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:325) [cxf-core-3.2.6.jar:3.2.6]
	at com.example.demo.CxfWebserviceApplication.invokeService_2(CxfWebserviceApplication.java:32) [main/:na]
	at com.example.demo.CxfWebserviceApplication.main(CxfWebserviceApplication.java:15) [main/:na]
Caused by: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
 at [row,col {unknown-source}]: [1,0]
	at com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOF(StreamScanner.java:684) ~[woodstox-core-5.1.0.jar:5.1.0]
	at com.ctc.wstx.sr.BasicStreamReader.handleEOF(BasicStreamReader.java:2213) ~[woodstox-core-5.1.0.jar:5.1.0]
	at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2119) ~[woodstox-core-5.1.0.jar:5.1.0]
	at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1175) ~[woodstox-core-5.1.0.jar:5.1.0]
	at com.ctc.wstx.sr.BasicStreamReader.nextTag(BasicStreamReader.java:1198) ~[woodstox-core-5.1.0.jar:5.1.0]
	at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:173) ~[cxf-rt-bindings-soap-3.2.6.jar:3.2.6]
	... 18 common frames omitted

org.apache.cxf.binding.soap.SoapFault: Error reading XMLStreamReader: Unexpected EOF in prolog
 at [row,col {unknown-source}]: [1,0]
	at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:292)
	at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:70)
	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
	at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:833)
	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1695)
	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1572)
	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1373)
	at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
	at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:673)
	at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:63)
	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
	at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:537)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:446)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:361)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:339)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:325)
	at com.example.demo.CxfWebserviceApplication.invokeService_2(CxfWebserviceApplication.java:32)
	at com.example.demo.CxfWebserviceApplication.main(CxfWebserviceApplication.java:15)
Caused by: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
 at [row,col {unknown-source}]: [1,0]
	at com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOF(StreamScanner.java:684)
	at com.ctc.wstx.sr.BasicStreamReader.handleEOF(BasicStreamReader.java:2213)
	at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2119)
	at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1175)
	at com.ctc.wstx.sr.BasicStreamReader.nextTag(BasicStreamReader.java:1198)
	at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:173)
	... 18 more

百度了好久依旧无法解决

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

0条回答

为你推荐

换一换