当前位置: 代码迷 >> Java Web开发 >> xfire java.lang.IllegalStateException: Could not initialize Service解决思路
  详细解决方案

xfire java.lang.IllegalStateException: Could not initialize Service解决思路

热度:4860   发布时间:2016-04-10 22:46:01.0
xfire java.lang.IllegalStateException: Could not initialize Service
大家好!
我在网上下载了一个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");  
  相关解决方案