JAXBException:不是类上的有效属性
我们有一个需要使用外部Web服务的应用程序。 为此,我们使用cxf-codegen-plugin插件提供的wsdl2java目标,通过Maven从WSDL生成一组Java工件。
在应用程序中,我们希望设置端点以用于运行时的Web服务调用(以满足测试环境中不同的Web服务端点URL),因此我们已经编写了一些如下代码来为我们执行此操作:
private <T> T createServiceObject(final Class<T> p_seiClass) throws MalformedURLException {
final Service serviceFactory = Service.create(new URL(wsdlLocation), new QName(targetNamespace, serviceName));
final T service = serviceFactory.getPort(p_seiClass);
((BindingProvider) service).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "endpoint");
return service;
}
当代码运行时,它会在serviceFactory.getPort行上失败并执行以下命令:
javax.xml.ws.WebServiceException: class ZZZ.YYYwebservice.v5.types.ProcessUIRequestResponse do not have a property of the name ProcessUIRequestResult
at com.sun.xml.internal.ws.client.sei.ResponseBuilder$DocLit.<init>(ResponseBuilder.java:512)
at com.sun.xml.internal.ws.client.sei.SEIMethodHandler.buildResponseBuilder(SEIMethodHandler.java:172)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.<init>(SyncMethodHandler.java:86)
at com.sun.xml.internal.ws.client.sei.SEIStub.<init>(SEIStub.java:83)
at com.sun.xml.internal.ws.client.WSServiceDelegate.createEndpointIFBaseProxy(WSServiceDelegate.java:641)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:344)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:326)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:364)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:368)
at javax.xml.ws.Service.getPort(Service.java:172)
at com.XXX.XXX.XXX.YYY.integration.facade.jaxws.ProcessUIRequestFacadeJaxws.createServiceObject(ProcessUIRequestFacadeJaxws.java:53)
at com.XXX.XXX.XXX.YYY.integration.facade.jaxws.ProcessUIRequestFacadeJaxws.processUIRequest(ProcessUIRequestFacadeJaxws.java:39)
at com.XXX.XXX.XXX.YYY.integration.facade.jaxws.ProcessUIRequestFacadeJaxwsTest.test(ProcessUIRequestFacadeJaxwsTest.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: javax.xml.bind.JAXBException: ProcessUIRequestResult is not a valid property on class ZZZ.YYYwebservice.v5.types.ProcessUIRequestResponse
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getElementPropertyAccessor(JAXBContextImpl.java:954)
at com.sun.xml.internal.ws.client.sei.ResponseBuilder$DocLit.<init>(ResponseBuilder.java:501)
... 37 more
在底部,我可以看到javax.xml.bind.JAXBException:ProcessUIRequestResult不是类ZZZ.YYYwebservice.v5.types.ProcessUIRequestResponse上的有效属性,这表明生成的ProcessUIRequestResponse.java文件存在问题。
我看过那个文件,看不到任何明显的东西(ProcessUIRequestResult在类中定义并且有一个getter和setter)。 课程如下:
package YYY.ZZZwebservice.v5.types;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import YYY.ZZZbase.BaseVO;
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="ProcessUIRequestResult" type="{http://YYY/ZZZbase/}BaseVO" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"processUIRequestResult"
})
@XmlRootElement(name = "ProcessUIRequestResponse")
public class ProcessUIRequestResponse {
@XmlElement(name = "ProcessUIRequestResult")
protected BaseVO processUIRequestResult;
/**
* Gets the value of the processUIRequestResult property.
*
* @return
* possible object is
* {@link BaseVO }
*
*/
public BaseVO getProcessUIRequestResult() {
return processUIRequestResult;
}
/**
* Sets the value of the processUIRequestResult property.
*
* @param value
* allowed object is
* {@link BaseVO }
*
*/
public void setProcessUIRequestResult(BaseVO value) {
this.processUIRequestResult = value;
}
public ProcessUIRequestResponse withProcessUIRequestResult(BaseVO value) {
setProcessUIRequestResult(value);
return this;
}
}
有谁知道这个问题会是什么? 我无法发现任何明显的信息,也无法找到任何有关问题的信息。
感谢您的帮助提前。
编辑 - 基于洛伦佐的回答于20/09年更新
不幸的是,Web服务是第三方服务,我无权修改XSD。 在从中生成Java时,我使用了WSDL的服务器URL。
但是,作为测试,我修改了生成的ProcessUIRequestResponse.java,将属性更改为以大写字母开头以匹配WSDL并引发相同的错误。
有没有人有任何想法?
26/09号进一步编辑提供更新**
我一直在对此进行更多的调查,发现它实际上是服务端点接口生成方式的问题。 这是生成的内容:
/**
* This class was generated by Apache CXF 2.5.2 2013-09-26T13:05:17.389+01:00 Generated source version: 2.5.2
*
*/
@WebService(targetNamespace = "http://zzz/yyywebservice/v5/types/", name = "Types")
@XmlSeeAlso({ zzz.yyyentityview.ObjectFactory.class, zzz.yyyview.search.postcode.ObjectFactory.class,
zzz.yyyentityview.validation.ObjectFactory.class, zzz.serializable_dictionary.ObjectFactory.class,
zzz.yyyview.search.app.ObjectFactory.class, zzz.yyybase.ObjectFactory.class, zzz.yyybase.enums.ObjectFactory.class,
zzz.yyyview.uw.ObjectFactory.class, zzz.yyyview.app.ObjectFactory.class, zzz.yyyview.search.bank.ObjectFactory.class,
zzz.yyyview.search.list.ObjectFactory.class, zzz.yyyentityview.app.ObjectFactory.class,
zzz.yyyentityview.client.ObjectFactory.class, ObjectFactory.class })
public interface Types {
@WebResult(name = "ProcessUIRequestResult", targetNamespace = "")
@ResponseWrapper(localName = "ProcessUIRequestResponse", targetNamespace = "http://zzz/yyywebservice/v5/types/", className = "zzz.yyywebservice.v5.types.ProcessUIRequestResponse")
@RequestWrapper(localName = "ProcessUIRequest", targetNamespace = "http://zzz/yyywebservice/v5/types/", className = "zzz.yyywebservice.v5.types.ProcessUIRequest")
@WebMethod(operationName = "ProcessUIRequest", action = "http://zzz/yyywebservice/v5/ProcessUIRequest")
public zzz.yyybase.BaseVO processUIRequest(
@WebParam(name = "ProcessUIRequest", targetNamespace = "http://zzz/yyywebservice/v5/types/") zzz.yyybase.BaseVO processUIRequest);
@WebResult(name = "GetActivityStatusEntityResult", targetNamespace = "")
@ResponseWrapper(localName = "GetActivityStatusEntityResponse", targetNamespace = "http://zzz/yyywebservice/v5/types/", className = "zzz.yyywebservice.v5.types.GetActivityStatusEntityResponse")
@RequestWrapper(localName = "GetActivityStatusEntity", targetNamespace = "http://zzz/yyywebservice/v5/types/", className = "zzz.yyywebservice.v5.types.GetActivityStatusEntity")
@WebMethod(operationName = "GetActivityStatusEntity", action = "http://zzz/yyywebservice/v5/GetActivityStatusEntity")
public zzz.yyybase.ActivityStatusVOBase getActivityStatusEntity(
@WebParam(name = "ProcessUIRequest", targetNamespace = "http://zzz/yyywebservice/v5/types/") zzz.yyybase.BaseVO processUIRequest);
}
问题出在@WebResult注释和空白targetNamespace上。 当我手动编辑类并添加我期望的targetNamespace(基于查看XSD)时,我可以成功调用Web服务。
我在XSD中查找了任何缺少的名称空间定义或任何其他明显的错误,但我无法找到任何东西。 有没有人有任何关于targetNamespace或@WebResult从哪里生成的指针?
这可能是wsdl2java如何命名包的问题。 如果targetNamespace(wsdl)是骆驼大小写符号,那么你的包也需要骆驼大小写。 例如:
对于targetNamespace =“http://your.domain/WebAdminServices/WebSiteMgmt”
包domain.your.webAdminServices.webSiteMgmt; - >工作:)
包domain.your.webadminservices.websitemgmt; - >不工作:(
希望能帮助到你,
路易斯
我有类似的问题,我发现这个链接上的东西,你应该尝试以下几点:
Javabean属性名称通常是小写字母。 您的WSDL中有一个大写的标记名称,即ProcessUIRequestResult ,但在您的类中有一个小写属性processUIRequestResult ,由方法名称setProcessUIRequestResult和getProcessUIRequestResult表示。
WSDL到Java代码的生成似乎是正确的,但并不意味着其他库代码将遵守WSDL和/或Java注释。
你可以使用小写元素名称吗?
链接地址: http://www.djcxy.com/p/16003.html