我已经创建了一个用于调用Web服务的动态客户端。该客户端调用名为businessWorkItem的Web服务。该服务创建了一个工作项。我在下面给出了代码:
package com.tcs.telecom.tib;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.endpoint.Client;
import java.lang.reflect.Method;
public class WorkItem
{
public WorkItem()
{
}
public static void main(String str[]) throws Exception
{
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(wsdlname);
Object createWorkItemRequest = Thread.currentThread().getContextClassLoader().loadClass(classname).newInstance();
Method m1 = createWorkItemRequest.getClass().getMethod("externalItemRefId", String.class);
m1.invoke(createWorkItemRequest,"9361117");
Object[] response = client.invoke("createWorkItem", createWorkItemRequest);
System.out.println("Response is " + response[0]);
}
}
当我运行此代码时,我得到未声明的throwable exception.Error log:
[main] INFO org.apache.cxf.bus.spring.BusApplicationContext - Refreshing org.apache.cxf.bus.spring.BusApplicationContext@bf1a4a: display name [org.apache.cxf.bus.spring.BusApplicationContext@bf1a4a]; startup date [Wed Mar 04 18:13:34 IST 2015]; root of context hierarchy
[main] INFO org.apache.cxf.bus.spring.ControlledValidationXmlBeanDefinitionReader - Loading XML bean definitions from class path resource [META-INF/cxf/cxf.xml]
[main] INFO org.apache.cxf.bus.spring.ControlledValidationXmlBeanDefinitionReader - Loading XML bean definitions from class path resource [META-INF/cxf/cxf-extension-jaxws.xml]
[main] INFO org.apache.cxf.bus.spring.ControlledValidationXmlBeanDefinitionReader - Loading XML bean definitions from class path resource [META-INF/cxf/cxf-extension-soap.xml]
[main] INFO org.apache.cxf.bus.spring.ControlledValidationXmlBeanDefinitionReader - Loading XML bean definitions from class path resource [META-INF/cxf/cxf-extension-xml.xml]
[main] INFO org.apache.cxf.bus.spring.ControlledValidationXmlBeanDefinitionReader - Loading XML bean definitions from class path resource [META-INF/cxf/cxf-extension-addr.xml]
[main] INFO org.apache.cxf.bus.spring.ControlledValidationXmlBeanDefinitionReader - Loading XML bean definitions from class path resource [META-INF/cxf/cxf-extension-http.xml]
[main] INFO org.apache.cxf.bus.spring.BusApplicationContext - Bean factory for application context [org.apache.cxf.bus.spring.BusApplicationContext@bf1a4a]: org.springframework.beans.factory.support.DefaultListableBeanFactory@15c7b94
[main] INFO org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@15c7b94: defining beans [cxf,org.apache.cxf.bus.spring.BusApplicationListener,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.apache.cxf.resource.ResourceManager,org.apache.cxf.configuration.Configurer,org.apache.cxf.binding.BindingFactoryManager,org.apache.cxf.transport.DestinationFactoryManager,org.apache.cxf.transport.ConduitInitiatorManager,org.apache.cxf.wsdl.WSDLManager,org.apache.cxf.phase.PhaseManager,org.apache.cxf.workqueue.WorkQueueManager,org.apache.cxf.buslifecycle.BusLifeCycleManager,org.apache.cxf.endpoint.ServerRegistry,org.apache.cxf.endpoint.ServerLifeCycleManager,org.apache.cxf.endpoint.ClientLifeCycleManager,org.apache.cxf.transports.http.QueryHandlerRegistry,org.apache.cxf.endpoint.EndpointResolverRegistry,org.apache.cxf.headers.HeaderManager,org.apache.cxf.catalog.OASISCatalogManager,org.apache.cxf.endpoint.ServiceContractResolverRegistry,org.apache.cxf.jaxws.context.WebServiceContextResourceResolver,org.apache.cxf.jaxws.context.WebServiceContextImpl,org.apache.cxf.binding.soap.SoapBindingFactory,org.apache.cxf.binding.soap.SoapTransportFactory,org.apache.cxf.binding.soap.customEditorConfigurer,org.apache.cxf.binding.xml.XMLBindingFactory,org.apache.cxf.ws.addressing.policy.AddressingAssertionBuilder,org.apache.cxf.ws.addressing.policy.AddressingPolicyInterceptorProvider,org.apache.cxf.ws.addressing.policy.UsingAddressingAssertionBuilder,org.apache.cxf.transport.http.policy.HTTPClientAssertionBuilder,org.apache.cxf.transport.http.policy.HTTPServerAssertionBuilder,org.apache.cxf.transport.http.policy.NoOpPolicyInterceptorProvider,org.apache.cxf.transport.http.ClientOnlyHTTPTransportFactory]; root of factory hierarchy
[main] INFO org.apache.cxf.endpoint.dynamic.DynamicClientFactory - Loading the JAXB 2.1 simple binding for client.
Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy32.bind(Unknown Source)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:271)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:196)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:189)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:144)
at com.tcs.telecom.tib.workItem.main(workItem.java:11)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.cxf.common.util.ReflectionInvokationHandler.invoke(ReflectionInvokationHandler.java:52)
... 6 more
Caused by: java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy34.error(Unknown Source)
at com.sun.tools.internal.xjc.api.impl.s2j.SchemaCompilerImpl.error(SchemaCompilerImpl.java:301)
at com.sun.tools.internal.xjc.util.ErrorReceiverFilter.error(ErrorReceiverFilter.java:67)
at com.sun.xml.internal.xsom.impl.parser.ParserContext$2.error(ParserContext.java:191)
at com.sun.xml.internal.xsom.impl.parser.ParserContext$1.reportError(ParserContext.java:169)
at com.sun.xml.internal.xsom.impl.parser.NGCCRuntimeEx.reportError(NGCCRuntimeEx.java:160)
at com.sun.xml.internal.xsom.impl.parser.NGCCRuntimeEx.reportError(NGCCRuntimeEx.java:163)
at com.sun.xml.internal.xsom.impl.parser.NGCCRuntimeEx.checkDoubleDefError(NGCCRuntimeEx.java:135)
at com.sun.xml.internal.xsom.impl.parser.state.Schema.action5(Schema.java:113)
at com.sun.xml.internal.xsom.impl.parser.state.Schema.onChildCompleted(Schema.java:1201)
at com.sun.xml.internal.xsom.impl.parser.state.NGCCHandler.revertToParentFromEnterElement(NGCCHandler.java:135)
at com.sun.xml.internal.xsom.impl.parser.state.complexType.enterElement(complexType.java:407)
at com.sun.xml.internal.xsom.impl.parser.state.NGCCRuntime.startElement(NGCCRuntime.java:244)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.internal.xjc.util.SubtreeCutter.startElement(SubtreeCutter.java:93)
at com.sun.tools.internal.xjc.reader.ExtensionBindingChecker.startElement(ExtensionBindingChecker.java:135)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.internal.xjc.reader.xmlschema.parser.IncorrectNamespaceURIChecker.startElement(IncorrectNamespaceURIChecker.java:113)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.internal.xjc.reader.xmlschema.parser.CustomizationContextChecker.startElement(CustomizationContextChecker.java:178)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner$LocationResolver.startElement(DOMForestScanner.java:132)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:229)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:266)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:235)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:112)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:77)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:85)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestParser.parse(DOMForestParser.java:89)
at com.sun.tools.internal.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:253)
at com.sun.xml.internal.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:332)
at com.sun.xml.internal.xsom.impl.parser.NGCCRuntimeEx.importSchema(NGCCRuntimeEx.java:243)
at com.sun.xml.internal.xsom.impl.parser.state.importDecl.action0(importDecl.java:71)
at com.sun.xml.internal.xsom.impl.parser.state.importDecl.leaveElement(importDecl.java:169)
at com.sun.xml.internal.xsom.impl.parser.state.NGCCRuntime.endElement(NGCCRuntime.java:300)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at com.sun.tools.internal.xjc.util.SubtreeCutter.endElement(SubtreeCutter.java:97)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at com.sun.tools.internal.xjc.reader.xmlschema.parser.CustomizationContextChecker.endElement(CustomizationContextChecker.java:184)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner$LocationResolver.endElement(DOMForestScanner.java:125)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:240)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:266)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:235)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:112)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:77)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:85)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestParser.parse(DOMForestParser.java:89)
at com.sun.tools.internal.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:253)
at com.sun.xml.internal.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:332)
at com.sun.xml.internal.xsom.impl.parser.NGCCRuntimeEx.importSchema(NGCCRuntimeEx.java:243)
at com.sun.xml.internal.xsom.impl.parser.state.importDecl.action0(importDecl.java:71)
at com.sun.xml.internal.xsom.impl.parser.state.importDecl.leaveElement(importDecl.java:169)
at com.sun.xml.internal.xsom.impl.parser.state.NGCCRuntime.endElement(NGCCRuntime.java:300)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at com.sun.tools.internal.xjc.util.SubtreeCutter.endElement(SubtreeCutter.java:97)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at com.sun.tools.internal.xjc.reader.xmlschema.parser.CustomizationContextChecker.endElement(CustomizationContextChecker.java:184)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner$LocationResolver.endElement(DOMForestScanner.java:125)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:240)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:266)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:235)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:112)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:77)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:85)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestParser.parse(DOMForestParser.java:89)
at com.sun.tools.internal.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:253)
at com.sun.xml.internal.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:332)
at com.sun.xml.internal.xsom.impl.parser.NGCCRuntimeEx.importSchema(NGCCRuntimeEx.java:243)
at com.sun.xml.internal.xsom.impl.parser.state.importDecl.action0(importDecl.java:71)
at com.sun.xml.internal.xsom.impl.parser.state.importDecl.leaveElement(importDecl.java:169)
at com.sun.xml.internal.xsom.impl.parser.state.NGCCRuntime.endElement(NGCCRuntime.java:300)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at com.sun.tools.internal.xjc.util.SubtreeCutter.endElement(SubtreeCutter.java:97)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at com.sun.tools.internal.xjc.reader.xmlschema.parser.CustomizationContextChecker.endElement(CustomizationContextChecker.java:184)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner$LocationResolver.endElement(DOMForestScanner.java:125)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:240)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:266)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:235)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:112)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:77)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:85)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestParser.parse(DOMForestParser.java:89)
at com.sun.tools.internal.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:253)
at com.sun.xml.internal.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:332)
at com.sun.xml.internal.xsom.impl.parser.NGCCRuntimeEx.importSchema(NGCCRuntimeEx.java:243)
at com.sun.xml.internal.xsom.impl.parser.state.importDecl.action0(importDecl.java:71)
at com.sun.xml.internal.xsom.impl.parser.state.importDecl.leaveElement(importDecl.java:169)
at com.sun.xml.internal.xsom.impl.parser.state.NGCCRuntime.endElement(NGCCRuntime.java:300)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at com.sun.tools.internal.xjc.util.SubtreeCutter.endElement(SubtreeCutter.java:97)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at com.sun.tools.internal.xjc.reader.xmlschema.parser.CustomizationContextChecker.endElement(CustomizationContextChecker.java:184)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner$LocationResolver.endElement(DOMForestScanner.java:125)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:240)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:266)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:235)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:112)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:77)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:85)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForestParser.parse(DOMForestParser.java:89)
at com.sun.tools.internal.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:253)
at com.sun.xml.internal.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:332)
at com.sun.xml.internal.xsom.impl.parser.ParserContext.parse(ParserContext.java:113)
at com.sun.xml.internal.xsom.parser.XSOMParser.parse(XSOMParser.java:153)
at com.sun.xml.internal.xsom.parser.XSOMParser.parse(XSOMParser.java:142)
at com.sun.tools.internal.xjc.ModelLoader.createXSOM(ModelLoader.java:504)
at com.sun.tools.internal.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:253)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.cxf.common.util.ReflectionInvokationHandler.invoke(ReflectionInvokationHandler.java:52)
... 127 more
Caused by: java.lang.RuntimeException: Error compiling schema from WSDL at {wsdl}: 'abc' is already defined
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory$InnerErrorListener.error(DynamicClientFactory.java:601)
... 132 more
Caused by: org.xml.sax.SAXParseException; systemId: wlistxsd=./abc.xsd; lineNumber: 47; columnNumber: 32; 'abc' is already defined
at com.sun.xml.internal.xsom.impl.parser.ParserContext$1.reportError(ParserContext.java:165)
... 122 more
有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
stacktrace表示wsdl中的重复属性。您必须使用jaxb绑定修改wsdl。并提供修改后的wsdl文件以生成客户端。
Caused by: org.xml.sax.SAXParseException; systemId: wlistxsd=./abc.xsd; lineNumber: 47; columnNumber: 32; 'abc' is already defined
at com.sun.xml.internal.xsom.impl.parser.ParserContext$1.reportError(ParserContext.java:165)
要使用嵌入式绑定自定义wsdl,您可以执行以下操作。 1.将jaxb名称空间添加到模式定义 2.使用新名称注释重复属性(在示例中,我使用' newname'注释重复属性)
<s:schema elementFormDefault="qualified" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0">
<xs:complexType>
<xs:sequence>
<xs:abc minOccurs="0" />
**<xs:abc minOccurs="1" >**
<xs:annotation>
<xs:appinfo>
<jaxb:property name="newname"/>
</xs:appinfo>
</xs:annotation>
**</xs:abc>**
</xs:sequence>
</xs:complexType>