81,094
社区成员
发帖
与我相关
我的任务
分享
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);
}
}
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
重启服务就好了。 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 类,
我还是不知道该怎办办呀。。。求助。。。 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子包,后报找不到……………… 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,不知道会怎么样?