xfire java.lang.IllegalStateException: Could not initialize Service

调皮的芋头 2014-03-19 07:33:24
大家好!
我在网上下载了一个xfire 客户端消费的实例,运行时报错:
Exception in thread "main" java.lang.IllegalStateException: Could not initialize Service.
at org.codehaus.xfire.jaxws.ServiceDelegate.<init>(ServiceDelegate.java:77)
at org.codehaus.xfire.jaxws.Provider.createServiceDelegate(Provider.java:32)
at javax.xml.ws.Service.<init>(Service.java:56)
at test.jax.HelloWorldSimple.<init>(HelloWorldSimple.java:54)
at test.xfireclient.ClientMain.main(ClientMain.java:25)
Caused by: java.lang.NoSuchMethodException: test.jax.HelloWorldSimple.getPortClassMap()
at java.lang.Class.getMethod(Class.java:1605)
at org.codehaus.xfire.jaxws.ServiceDelegate.<init>(ServiceDelegate.java:60)
... 4 more

客户端代码为:
package test.xfireclient;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.xml.namespace.QName;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFactory;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.Handler;
import javax.xml.ws.handler.HandlerResolver;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.PortInfo;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;

import test.jax.HelloWorldSimple;
public class ClientMain {

@SuppressWarnings("unchecked")
public static void main(String[] args) {
HelloWorldSimple simple = new HelloWorldSimple();

simple.setHandlerResolver(new HandlerResolver() {
public List<Handler> getHandlerChain(PortInfo portInfo) {
List<Handler> list = new ArrayList<Handler>();
list.add(new MySOAPHandler());
return list;
}
});
test.jax.HelloWorldSimplePortType port = simple.getHelloWorldSimpleHttpPort();
System.out.println(port.sayHello("cat1"));
}
static class MySOAPHandler implements SOAPHandler<SOAPMessageContext> {

public Set<QName> getHeaders() {
return null;
}

public void close(MessageContext context) {
}

public boolean handleFault(SOAPMessageContext context) {
throw new UnsupportedOperationException("Not supported yet.");
}

public boolean handleMessage(SOAPMessageContext context) {
Boolean outboundProperty = (Boolean) context
.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty.booleanValue()) {
SOAPMessage message = context.getMessage();
try {
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
SOAPFactory factory = SOAPFactory.newInstance();
SOAPElement authenticationToken = factory
.createElement("AuthenticationToken");
SOAPElement userName = factory.createElement("userName");
userName.setValue("wander");
SOAPElement password = factory.createElement("password");
password.setValue("wander");
authenticationToken.addChildElement(userName);
authenticationToken.addChildElement(password);

SOAPHeader header = envelope.addHeader();
header.addChildElement(authenticationToken);

} catch (SOAPException e) {
e.printStackTrace();
}
}
return true;
}
}
}

报错的类:
package test.jax;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;

/**
* This class was generated by the JAX-WS RI. JAX-WS RI 2.1.3-hudson-390-
* Generated source version: 2.0
* <p>
* An example of how this class may be used:
*
* <pre>
* HelloWorldSimple service = new HelloWorldSimple();
* HelloWorldSimplePortType portType = service.getHelloWorldSimpleHttpPort();
* portType.add(...);
* </pre>
*
* </p>
*
*/
@WebServiceClient(name = "HelloWorldSimple", targetNamespace = "http://simple.xfire.webservice/HelloWorld", wsdlLocation = "http://localhost:8080/webservice_server3/services/HelloWorldSimple?wsdl")
public class HelloWorldSimple extends Service {

private final static URL HELLOWORLDSIMPLE_WSDL_LOCATION;
private final static Logger logger = Logger
.getLogger(test.jax.HelloWorldSimple.class.getName());

static {
URL url = null;
try {
URL baseUrl;
baseUrl = test.jax.HelloWorldSimple.class.getResource(".");
url = new URL(/*baseUrl,*/
"http://localhost:8080/webservice_server3/services/HelloWorldSimple?wsdl");
} catch (MalformedURLException e) {
logger
.warning("Failed to create URL for the wsdl Location: 'http://localhost:8080/msg/services/HelloWorldSimple?wsdl', retrying as a local file");
logger.warning(e.getMessage());
}
HELLOWORLDSIMPLE_WSDL_LOCATION = url;
}

public HelloWorldSimple(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}

public HelloWorldSimple() {
super(HELLOWORLDSIMPLE_WSDL_LOCATION,
new QName("http://simple.xfire.webservice/HelloWorld",
"HelloWorldSimple"));
}

/**
*
* @return returns HelloWorldSimplePortType
*/
@WebEndpoint(name = "HelloWorldSimpleHttpPort")
public HelloWorldSimplePortType getHelloWorldSimpleHttpPort() {
return super.getPort(new QName(
"http://simple.xfire.webservice/HelloWorld",
"HelloWorldSimpleHttpPort"), HelloWorldSimplePortType.class);
}

}
...全文
4005 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_17731799 2015-07-30
  • 打赏
  • 举报
回复
引用 14 楼 squarea_de 的回复:
[quote=引用 13 楼 u014682894 的回复:] [quote=引用 12 楼 u014682894 的回复:] [quote=引用 4 楼 huxiweng 的回复:] java.lang.NoSuchMethodException: test.jax.HelloWorldSimple.getPortClassMap() 你的class里就没有这个方法:getPortClassMap()
版主,你好,求教这个问题啊,我干掉xfire-all-1.2.6.jar后,它报找不到Provider,这个怎么解决啊,
 public ServiceDelegate(URL wsdlLocation, QName serviceName, Class clientClass)
  {
    this.wsdlLocation = wsdlLocation;
    this.serviceName = serviceName;
    try
    {
      Method method = clientClass.getMethod("getPortClassMap", new Class[0]);

      Map port2Class = (Map)method.invoke(null, new Object[0]);
      for (Iterator itr = port2Class.entrySet().iterator(); itr.hasNext(); )
      {
        Map.Entry entry = (Map.Entry)itr.next();

        QName port = (QName)entry.getKey();
        Class clazz = (Class)entry.getValue();

        Service service = getService(clazz);
        this.port2Service.put(port, service);
        this.intf2service.put(clazz, service);
      }
    }
    catch (Exception e)
    {
      throw new IllegalStateException("Could not initialize Service.", e);
    }
  }
如果把ServiceDelegate.class中,关于 clientClass.getMethod("getPortClassMap", null); 这里改为null,不知道会怎么样?[/quote]不是干掉xfire-all-1.2.6.jar,是干掉它下面的jaxws子包,后报找不到………………[/quote] 朋友,你搞定了么? 我猜你是用的jdk1.7或者以上版本吧? 我也出现了楼主的问题,并且也去掉jaxws子包,在jdk1.6下成功运行了。。。 可是由于我们服务器是jdk1.7,结果就出现了新的问题, java.util.ServiceConfigurationError: javax.xml.ws.spi.Provider: Provider org.codehaus.xfire.jaxws.Provider not found 其中 GeneralmdmdatareleaseClientEp 是webservice client 类, 我还是不知道该怎办办呀。。。求助。。。 [/quote] 我也遇到了这个问题,1.7的jdk,我是看到了楼上的解答, 把xfire-all-1.2.6.jar里META-INF/services 目录下的javax.xml.ws.spi.Provider 内容改成com.sun.xml.internal.ws.spi.ProviderImpl 重启服务就好了。
小小的蚂蚁 2015-05-08
  • 打赏
  • 举报
回复
很多人说删除 org.codehaus.xfire.jaxws.Provider 类之后, 运行时会报类找不到错误. 现在提供另一种解决办法。 如果你的是web工程,那么在你的web工程的 META-INF 目录下面建一个 services 目录, 在 services 目录下添加文件: javax.xml.ws.spi.Provider 文件内容为 com.sun.xml.internal.ws.spi.ProviderImpl 保存,重启应用 应该就可以了。 我自己测试正常. 注意,文件内容不能有空格,换行,和其他字符. 其实文件内容就是指定了 javax.xml.ws.spi.Provider 的子类, 文件名必须是: javax.xml.ws.spi.Provider
squarea_de 2015-03-02
  • 打赏
  • 举报
回复
引用 13 楼 u014682894 的回复:
[quote=引用 12 楼 u014682894 的回复:] [quote=引用 4 楼 huxiweng 的回复:] java.lang.NoSuchMethodException: test.jax.HelloWorldSimple.getPortClassMap() 你的class里就没有这个方法:getPortClassMap()
版主,你好,求教这个问题啊,我干掉xfire-all-1.2.6.jar后,它报找不到Provider,这个怎么解决啊,
 public ServiceDelegate(URL wsdlLocation, QName serviceName, Class clientClass)
  {
    this.wsdlLocation = wsdlLocation;
    this.serviceName = serviceName;
    try
    {
      Method method = clientClass.getMethod("getPortClassMap", new Class[0]);

      Map port2Class = (Map)method.invoke(null, new Object[0]);
      for (Iterator itr = port2Class.entrySet().iterator(); itr.hasNext(); )
      {
        Map.Entry entry = (Map.Entry)itr.next();

        QName port = (QName)entry.getKey();
        Class clazz = (Class)entry.getValue();

        Service service = getService(clazz);
        this.port2Service.put(port, service);
        this.intf2service.put(clazz, service);
      }
    }
    catch (Exception e)
    {
      throw new IllegalStateException("Could not initialize Service.", e);
    }
  }
如果把ServiceDelegate.class中,关于 clientClass.getMethod("getPortClassMap", null); 这里改为null,不知道会怎么样?[/quote]不是干掉xfire-all-1.2.6.jar,是干掉它下面的jaxws子包,后报找不到………………[/quote] 朋友,你搞定了么? 我猜你是用的jdk1.7或者以上版本吧? 我也出现了楼主的问题,并且也去掉jaxws子包,在jdk1.6下成功运行了。。。 可是由于我们服务器是jdk1.7,结果就出现了新的问题, java.util.ServiceConfigurationError: javax.xml.ws.spi.Provider: Provider org.codehaus.xfire.jaxws.Provider not found 其中 GeneralmdmdatareleaseClientEp 是webservice client 类, 我还是不知道该怎办办呀。。。求助。。。
LJ_KB 2014-11-25
  • 打赏
  • 举报
回复
引用 12 楼 u014682894 的回复:
[quote=引用 4 楼 huxiweng 的回复:] java.lang.NoSuchMethodException: test.jax.HelloWorldSimple.getPortClassMap() 你的class里就没有这个方法:getPortClassMap()
版主,你好,求教这个问题啊,我干掉xfire-all-1.2.6.jar后,它报找不到Provider,这个怎么解决啊,
 public ServiceDelegate(URL wsdlLocation, QName serviceName, Class clientClass)
  {
    this.wsdlLocation = wsdlLocation;
    this.serviceName = serviceName;
    try
    {
      Method method = clientClass.getMethod("getPortClassMap", new Class[0]);

      Map port2Class = (Map)method.invoke(null, new Object[0]);
      for (Iterator itr = port2Class.entrySet().iterator(); itr.hasNext(); )
      {
        Map.Entry entry = (Map.Entry)itr.next();

        QName port = (QName)entry.getKey();
        Class clazz = (Class)entry.getValue();

        Service service = getService(clazz);
        this.port2Service.put(port, service);
        this.intf2service.put(clazz, service);
      }
    }
    catch (Exception e)
    {
      throw new IllegalStateException("Could not initialize Service.", e);
    }
  }
如果把ServiceDelegate.class中,关于 clientClass.getMethod("getPortClassMap", null); 这里改为null,不知道会怎么样?[/quote]不是干掉xfire-all-1.2.6.jar,是干掉它下面的jaxws子包,后报找不到………………
LJ_KB 2014-11-25
  • 打赏
  • 举报
回复
引用 4 楼 huxiweng 的回复:
java.lang.NoSuchMethodException: test.jax.HelloWorldSimple.getPortClassMap() 你的class里就没有这个方法:getPortClassMap()
版主,你好,求教这个问题啊,我干掉xfire-all-1.2.6.jar后,它报找不到Provider,这个怎么解决啊,
 public ServiceDelegate(URL wsdlLocation, QName serviceName, Class clientClass)
  {
    this.wsdlLocation = wsdlLocation;
    this.serviceName = serviceName;
    try
    {
      Method method = clientClass.getMethod("getPortClassMap", new Class[0]);

      Map port2Class = (Map)method.invoke(null, new Object[0]);
      for (Iterator itr = port2Class.entrySet().iterator(); itr.hasNext(); )
      {
        Map.Entry entry = (Map.Entry)itr.next();

        QName port = (QName)entry.getKey();
        Class clazz = (Class)entry.getValue();

        Service service = getService(clazz);
        this.port2Service.put(port, service);
        this.intf2service.put(clazz, service);
      }
    }
    catch (Exception e)
    {
      throw new IllegalStateException("Could not initialize Service.", e);
    }
  }
如果把ServiceDelegate.class中,关于 clientClass.getMethod("getPortClassMap", null); 这里改为null,不知道会怎么样?
LJ_KB 2014-11-25
  • 打赏
  • 举报
回复
引用 10 楼 zfmaizi 的回复:
[quote=引用 9 楼 hw1287789687 的回复:] 谢谢楼上的建议,我按照楼上说的删除Provider.class就好了。 具体操作: 删除xfire-all-1.2.6.jar 中org.codehaus.xfire.jaxws.Provider.class 就好了。 感谢大家的帮助
您好,我这边也出现和您一样的异常,按照您说的方法,删除xfire-all-1.2.6.jar 中org.codehaus.xfire.jaxws.Provider.class后,再次运行程序发现找不到类了,是其他地方还需要引用什么包吗?[/quote]哥们,我和你的情况差不多,你最后怎么解决的啊?我也是干掉 jaxws 子包之后报找不到类了,你要是知道的话,请告诉我,谢谢
zfmaizi 2014-10-30
  • 打赏
  • 举报
回复
引用 9 楼 hw1287789687 的回复:
谢谢楼上的建议,我按照楼上说的删除Provider.class就好了。 具体操作: 删除xfire-all-1.2.6.jar 中org.codehaus.xfire.jaxws.Provider.class 就好了。 感谢大家的帮助
您好,我这边也出现和您一样的异常,按照您说的方法,删除xfire-all-1.2.6.jar 中org.codehaus.xfire.jaxws.Provider.class后,再次运行程序发现找不到类了,是其他地方还需要引用什么包吗?
调皮的芋头 2014-03-21
  • 打赏
  • 举报
回复
谢谢楼上的建议,我按照楼上说的删除Provider.class就好了。
具体操作:
删除xfire-all-1.2.6.jar 中org.codehaus.xfire.jaxws.Provider.class 就好了。

感谢大家的帮助
Defonds 2014-03-20
  • 打赏
  • 举报
回复
引用 3 楼 defonds 的回复:
创建 Service 的代理的时候没有使用 jdk 自带的 javax.xml.ws.spi.Provider,而是使用了 xfire 包中的 javax.xml.ws.spi.Provider 把 xfire 包中的 jaxws 子包删除掉就可以了
javax.xml.ws.Service 它调用的,它的构造函数调用了 javax.xml.ws.spi.Provider 来创建 Service 类的代理。你按引用说的,删了试试
调皮的芋头 2014-03-20
  • 打赏
  • 举报
回复
引用 5 楼 rui888 的回复:
getPortClassMap 在那里。
没看到哪个地方调用getPortClassMap() 啊
调皮的芋头 2014-03-20
  • 打赏
  • 举报
回复
引用 2 楼 zhangxiaojie0321 的回复:
报错的类里面没有getPortClassMap()方法。。
确实没有
tony4geek 2014-03-20
  • 打赏
  • 举报
回复
getPortClassMap 在那里。
teemai 2014-03-20
  • 打赏
  • 举报
回复
java.lang.NoSuchMethodException: test.jax.HelloWorldSimple.getPortClassMap() 你的class里就没有这个方法:getPortClassMap()
Defonds 2014-03-20
  • 打赏
  • 举报
回复
创建 Service 的代理的时候没有使用 jdk 自带的 javax.xml.ws.spi.Provider,而是使用了 xfire 包中的 javax.xml.ws.spi.Provider 把 xfire 包中的 jaxws 子包删除掉就可以了
ay转身遇 2014-03-19
  • 打赏
  • 举报
回复
报错的类里面没有getPortClassMap()方法。。
birdCccc 2014-03-19
  • 打赏
  • 举报
回复
好长 。

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧