2011-04-29 98 views
0

我正在用wsgen工具的幫助來嘗試wsdl生成。我已經認可了jaxb-api.jar和jaxws-api.jar文件。從wsgen工具生成wsdl時出錯

我有一個圖書館TestTo具有AS

public class TestingTo implements Serializable{ 
    public String name; 
} 

這TestTO庫包含在Web服務項目TestingTo類。

我的WebService是如下─

@WebService() 
public class IcfInfra { 

    @WebMethod(operationName = "printTest") 
    public TestingTo printTest(@WebParam(name = "string") String string) 
    { 
     TestingTo to = new TestingTo(); 
     to.name = string; 
     System.out.println(string); 
     return to; 
    } 
} 

當我運行Ant腳本WSGEN我收到以下錯誤 -

main: 
    [exec] Note:  ap round: 1 
    [exec] Problem encountered during annotation processing; 
    [exec] see stacktrace below for more information. 
    [exec] java.lang.NullPointerException 
    [exec]  at com.sun.tools.ws.processor.modeler.annotation.WebServiceVisit 
or.isLegalType(WebServiceVisitor.java:794) 
    [exec]  at com.sun.tools.ws.processor.modeler.annotation.WebServiceVisit 
or.isLegalMethod(WebServiceVisitor.java:642) 
    [exec]  at com.sun.tools.ws.processor.modeler.annotation.WebServiceVisit 
or.methodsAreLegal(WebServiceVisitor.java:611) 
    [exec]  at com.sun.tools.ws.processor.modeler.annotation.WebServiceVisit 
or.isLegalImplementation(WebServiceVisitor.java:529) 
    [exec]  at com.sun.tools.ws.processor.modeler.annotation.WebServiceVisit 
or.shouldProcessWebService(WebServiceVisitor.java:332) 
    [exec]  at com.sun.tools.ws.processor.modeler.annotation.WebServiceVisit 
or.visitClassDeclaration(WebServiceVisitor.java:123) 
    [exec]  at com.sun.tools.apt.mirror.declaration.ClassDeclarationImpl.acc 
ept(ClassDeclarationImpl.java:95) 
    [exec]  at com.sun.tools.ws.processor.modeler.annotation.WebServiceAP.bu 
ildModel(WebServiceAP.java:329) 
    [exec]  at com.sun.tools.ws.processor.modeler.annotation.WebServiceAP.pr 
ocess(WebServiceAP.java:270) 
    [exec]  at com.sun.mirror.apt.AnnotationProcessors$CompositeAnnotationPr 
ocessor.process(AnnotationProcessors.java:60) 
    [exec]  at com.sun.tools.apt.comp.Apt.main(Apt.java:454) 
    [exec]  at com.sun.tools.apt.main.JavaCompiler.compile(JavaCompiler.java 
:258) 
    [exec]  at com.sun.tools.apt.main.Main.compile(Main.java:1102) 
    [exec]  at com.sun.tools.apt.main.Main.compile(Main.java:964) 
    [exec]  at com.sun.tools.apt.Main.processing(Main.java:95) 
    [exec]  at com.sun.tools.apt.Main.process(Main.java:85) 
    [exec]  at com.sun.tools.apt.Main.process(Main.java:67) 
    [exec]  at com.sun.tools.ws.wscompile.WsgenTool.buildModel(WsgenTool.jav 
a:219) 
    [exec]  at com.sun.tools.ws.wscompile.WsgenTool.run(WsgenTool.java:123) 
    [exec]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    [exec]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcces 
sorImpl.java:39) 
    [exec]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMet 
hodAccessorImpl.java:25) 
    [exec]  at java.lang.reflect.Method.invoke(Method.java:597) 
    [exec]  at com.sun.tools.ws.Invoker.invoke(Invoker.java:131) 
    [exec]  at com.sun.tools.ws.WsGen.main(WsGen.java:52) 
    [exec] error: compilation failed, errors should have been reported 
    [exec] Result: 1 

現在我修改我的web服務作爲

@WebService() 
@XmlSeeAlso({ 
    TestingTo.class 
}) 
public class IcfInfra { 
    ... 
} 

當我執行螞蟻腳本我得到錯誤 -

main: 
    [exec] Exception in thread "main" java.lang.ArrayStoreException: sun.reflec 
t.annotation.TypeNotPresentExceptionProxy 
    [exec]  at sun.reflect.annotation.AnnotationParser.parseClassArray(Annot 
ationParser.java:653) 
    [exec]  at sun.reflect.annotation.AnnotationParser.parseArray(Annotation 
Parser.java:460) 
    [exec]  at sun.reflect.annotation.AnnotationParser.parseMemberValue(Anno 
tationParser.java:286) 
    [exec]  at sun.reflect.annotation.AnnotationParser.parseAnnotation(Annot 
ationParser.java:222) 
    [exec]  at sun.reflect.annotation.AnnotationParser.parseAnnotations2(Ann 
otationParser.java:69) 
    [exec]  at sun.reflect.annotation.AnnotationParser.parseAnnotations(Anno 
tationParser.java:52) 
    [exec]  at java.lang.Class.initAnnotationsIfNecessary(Class.java:3070) 
    [exec]  at java.lang.Class.getAnnotation(Class.java:3029) 
    [exec]  at com.sun.tools.ws.wscompile.WsgenOptions.validateEndpointClass 
(WsgenOptions.java:244) 
    [exec]  at com.sun.tools.ws.wscompile.WsgenOptions.validate(WsgenOptions 
.java:226) 
    [exec]  at com.sun.tools.ws.wscompile.WsgenTool.run(WsgenTool.java:122) 
    [exec]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    [exec]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcces 
sorImpl.java:39) 
    [exec]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMet 
hodAccessorImpl.java:25) 
    [exec]  at java.lang.reflect.Method.invoke(Method.java:597) 
    [exec]  at com.sun.tools.ws.Invoker.invoke(Invoker.java:131) 
    [exec]  at com.sun.tools.ws.WsGen.main(WsGen.java:52) 

欣賞如果有人能讓我知道需要做什麼才能成功生成wsdl。

感謝, Adish

回答

0

我usualy利用CXF作爲SOAP實現和Maven項目配置,請參閱鏈接末(有一個示例項目下載)。但我的猜測是,你必須設置訪問類型,請TestingTo類這樣的(見javadoc):

@XmlAccessorType(XmlAccessType.FIELD) 
public class TestingTo implements Serializable{ 
    public String name; 
} 

CXF: Defining Contract first webservices with wsdl generation from java

+0

感謝莫里茨的快速回復。我嘗試使用XmlAccessorType註釋但是我得到相同的錯誤。我會在你的文章中查看CXF鏈接。 – Adish 2011-04-29 16:55:21