当前位置: 代码迷 >> Java Web开发 >> CXF 服务发布成功,但无法通过公布地址加?wsdl获取wsdl
  详细解决方案

CXF 服务发布成功,但无法通过公布地址加?wsdl获取wsdl

热度:1215   发布时间:2016-04-13 22:44:39.0
CXF 服务发布成功,但无法通过发布地址加?wsdl获取wsdl
本帖最后由 matrix1984 于 2013-04-30 12:54:31 编辑
cxf + spring,通过cxf自带的EndpointImpl在main函数中启动服务。服务启动成功,用soap测试也没问题;但现在的问题是,我竟然不能用“%发布地址%?wsdl”来获取wsdl,服务把这个访问当成一个Request,因为没请求报文,自然就报错了(下面的错是从一个拦截器里出来的,里头有获取报文信息,贴出日志的目的是说明本来请求wsdl文件的动作被当成Request了)。

浏览器输入:http://localhost:8007/services/Resource4Opencode?wsdl

----------------------------
ID: 4
Address: http://localhost:8007/services/Resource4Opencode?wsdl
Http-Method: GET
Content-Type: 
Headers: {Accept=[text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8], Accept-Charset=[GBK,utf-8;q=0.7,*;q=0.3], accept-encoding=[gzip,deflate,sdch], Accept-Language=[zh-CN,zh;q=0.8], Cache-Control=[max-age=0], connection=[keep-alive], Content-Type=[null], Host=[localhost:8007], User-Agent=[Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1]}
--------------------------------------
2013-04-30 12:51:42 [ERROR] [qtp16555307-11 - /services/Resource4Opencode?wsdl] com.asiainfo.um.adapter2.forintr.webservice.server.business.interceptor.LoggingDBInInterceptor-(LoggingDBInInterceptor.java:120) : Parse payload error
org.dom4j.DocumentException: Error on line -1 of document  : Premature end of file. Nested exception: Premature end of file.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.dom4j.DocumentHelper.parseText(DocumentHelper.java:278)


之前都可以的,最近工程代码merge,lib目录重新整合了下,不过jar的版本基本都一样的。
其实不是一定要看wsdl,因为wsdl本地都有一份,只是觉得怪异。

下面是配置和代码:
webservice-server.xml
----------------------

<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:beans="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"

xmlns:sec="http://cxf.apache.org/configuration/security"
xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/transports/http-jetty/configuration http://cxf.apache.org/schemas/configuration/http-jetty.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean id="loggingFeature" class="org.apache.cxf.feature.LoggingFeature">
<property name="prettyLogging" value="true"/>
</bean> 
<bean id="logIn" class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
<bean id="logOut" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
<bean class="org.apache.cxf.binding.soap.saaj.SAAJInInterceptor"/>

<bean id="openCodeServiceImpl" class="com.asiainfo.um.adapter2.forintr.webservice.server.resource4opencode.service.Resource4OpencodePortTypeImpl"/>
<bean id="loggingDBInInterceptor" class="com.asiainfo.um.adapter2.forintr.webservice.server.business.interceptor.LoggingDBInInterceptor"/>
<bean id="loggingDBOutInterceptor" class="com.asiainfo.um.adapter2.forintr.webservice.server.business.interceptor.LoggingDBOutInterceptor"/>
<bean id="authInterceptor" class="com.asiainfo.um.adapter2.forintr.webservice.server.business.interceptor.AuthInterceptor"/>

<bean id="loyaltyMgtService" class="com.asiainfo.um.adapter2.forintr.webservice.server.loyalty.service.LoyaltyMgtPortTypeImpl"/>

<jaxws:endpoint id="openCode" 
implementor="#openCodeServiceImpl"
address="http://localhost:8007/services/Resource4Opencode"
publish="false">
<jaxws:features>
<ref bean="loggingFeature" />
</jaxws:features>
<jaxws:properties>
<entry key="schema-validation-enabled" value="true" />
</jaxws:properties>
<jaxws:inInterceptors>
<ref bean="loggingDBInInterceptor"/>
<ref bean="authInterceptor"/>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<ref bean="loggingDBOutInterceptor"/>
</jaxws:outInterceptors>
</jaxws:endpoint>

</beans>


MyServiceTest.java
-------------------

public class MyServiceTest {
private static Logger logger = Logger.getLogger(MyServiceTest.class);

public static void main(String[] args) {
String serverName = "openCode";
logger.info("The Webservice server name is " + serverName);
EndpointImpl endImpl = (EndpointImpl) WSSingletonServiceLocator.getInstance().getService(serverName);
endImpl.publish();
logger.info("start Webservice server " + serverName + " finish");
}

}


WSSingletonServiceLocator.java
----------------------------------

public class WSSingletonServiceLocator 
{
private static final WSSingletonServiceLocator instance = new WSSingletonServiceLocator();
private static final String WS_XML_NAMES = "classpath*:webservice-server.xml";
    private BeanFactory beanFactory;
    
private WSSingletonServiceLocator()
    {
       beanFactory = new ClassPathXmlApplicationContext(WS_XML_NAMES);
    }

    public static WSSingletonServiceLocator getInstance()
    {
        return instance;
    }

    public Object getService(String id)
    {
        return beanFactory.getBean(id);
    }
}

------解决思路----------------------

------解决思路----------------------
如果你确信发布成功了,那么访问http://localhost:8007/services它,可以看到你的服务列表
------解决思路----------------------
引用:
如果你确信发布成功了,那么访问http://localhost:8007/services它,可以看到你的服务列表

------解决思路----------------------
请教一下你的问题是怎么解决的?
一个word转pdf小程序带来的问题 
  相关解决方案