用CXF连接XML接口,wsdl2java生成本地文件后,连接出错。
查了下好像说是什么jar包冲突,但是不知道怎么解决。
package com.test;
import javax.xml.ws.Holder;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.tmforum.mtop.fmw.xsd.hdr.v1.CommunicationPatternType;
import org.tmforum.mtop.fmw.xsd.hdr.v1.CommunicationStyleType;
import org.tmforum.mtop.fmw.xsd.hdr.v1.Header;
import org.tmforum.mtop.nra.xsd.alm.v1.AlarmListType;
import org.tmforum.mtop.rtm.wsdl.ar.v1_0.AlarmRetrieval;
import org.tmforum.mtop.rtm.wsdl.ar.v1_0.GetActiveAlarmsCountException;
import org.tmforum.mtop.rtm.wsdl.ar.v1_0.GetActiveAlarmsException;
import org.tmforum.mtop.rtm.xsd.ar.v1.GetActiveAlarmsCountRequest;
import org.tmforum.mtop.rtm.xsd.ar.v1.GetActiveAlarmsCountResponse;
import org.tmforum.mtop.rtm.xsd.ar.v1.GetActiveAlarmsRequest;
public class test2 {
public static void main(String[] args) {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(AlarmRetrieval.class);
factory.setAddress("http://172.17.11.89:9997/AlarmRetrieval");
AlarmRetrieval alarmRetrieval = (AlarmRetrieval) factory.create();
Header header = new Header();
header.setActivityName("getActiveAlarmsCount");
header.setCommunicationPattern(CommunicationPatternType.SIMPLE_RESPONSE);
header.setCommunicationStyle(CommunicationStyleType.RPC);
header.setSecurity("Adminstrator:1q2w3e4r5t");
GetActiveAlarmsRequest request = new GetActiveAlarmsRequest();
try {
AlarmListType alt =alarmRetrieval.getActiveAlarms(new Holder<Header>(header), request);
System.out.println("The Count of All Active Alarm is :" + alt.getAlarm().get(0).getAdditionalText());
} catch (GetActiveAlarmsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
异常信息:
2014-11-3 16:09:08 org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
信息: Creating Service {http://www.tmforum.org/mtop/rtm/wsdl/ar/v1-0}AlarmRetrievalService from class org.tmforum.mtop.rtm.wsdl.ar.v1_0.AlarmRetrieval
Exception in thread "main" java.lang.NoSuchMethodError: javax.xml.stream.XMLEventFactory.newFactory()Ljavax/xml/stream/XMLEventFactory;
at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor$HeadersProcessor.<clinit>(ReadHeadersInterceptor.java:281)
at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:185)
at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:65)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:798)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1638)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1527)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1330)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:638)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:514)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:423)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:326)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:279)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:138)
at $Proxy68.getActiveAlarms(Unknown Source)
at com.test.test2.main(test2.java:31)
------解决思路----------------------
AlarmRetrieval alarmRetrieval = (AlarmRetrieval) factory.create();
错误发生在这一行,是不是你的factory不能创建AlarmRetrieval对象
NoSuchMethodError找不到方法,应该是factory里没有对应的方法吧,
或者xml配置错误等