在 SLSB 和 JAX-WS 中指定 JAXB 包 [英] Specify JAXB Packages in SLSB and JAX-WS
问题描述
我正在使用 SLSB 和 JAX-WS 创建一个简单的 SOAP Web 服务注释.我想传递的对象是从 OGC 模式生成的 JAXB,感谢 java.net 上的 OGC 项目.我遇到问题的一种特定方法(其中导致部署失败)是一个字段(eventTime)的情况请求对象 (GetResult) 与请求对象.这种类型的 ObjectFactory 是不同的,有是编组/解组时的问题.
I am creating a simple SOAP web service using a SLSB and JAX-WS annotations. The objects I would like to pass are JAXB generated from OGC schemas, thanks for the OGC project at java.net. One particular method I am having trouble with (which causes the deployment to fail) is a situation where a field (eventTime) of the request object (GetResult) is in a different package than the request object. The ObjectFactory for this type is different and there is a problem when marshalling/unmarshalling.
我得到的错误的一个子集:
A subset of the errors I'm getting:
<代码>没有带有 @XmlElementDecl 元素的 ObjectFactory{http://www.opengis.net/ogc}temporalOps.此问题与以下位置有关:在受保护的 javax.xml.bind.JAXBElementnet.opengis.sos.v_1_0_0.GetResult$EventTime.temporalOps在 net.opengis.sos.v_1_0_0.GetResult$EventTime在受保护的 java.util.Listnet.opengis.sos.v_1_0_0.GetResult.eventTime在 net.opengis.sos.v_1_0_0.GetResult在公共 net.opengis.sos.v_1_0_0.GetResultnet.opengis.sos.v_1_0_0.ObjectFactory.createGetResult()在 net.opengis.sos.v_1_0_0.ObjectFactory
在标准 SE 应用程序中,当我初始化 JAXBContext 时下面,一切正常.
In a standard SE application, when I initialize the JAXBContext like below, everything works well.
JAXBContext context = JAXBContext.newInstance("net.opengis.sos.v_1_0_0:net.opengis.sensorml.v_1_0_1:net.opengis.sos.v_1_0_0.filter.v_1_1_0");
如何在 JAX-WS 上下文中设置 JAXB 包?
How do I set the JAXB packages in the JAX-WS context?
我的应用服务器/环境是 GF 3.1.
My app server/environment is GF 3.1.
感谢您的帮助!
史蒂夫
推荐答案
我使用 @UsesJAXBContext 让它工作 - 起初有点麻烦,因为 NB 6.9 和 7.0b 想要链接 com.sun.internal.* 版本的UsesJAXBContext 和相关的,这当然不是 JAX-WS RI 正在寻找的.一旦我修复了这些并将依赖项添加到 jaxws-rt,版本 2.2.3,一切都运行良好.
I got it working with @UsesJAXBContext - had a little trouble at first because NB 6.9 and 7.0b wanted to link the com.sun.internal.* versions of the UsesJAXBContext and related, which of course isn't what JAX-WS RI is looking for. Once I fixed these, and added the dependency to jaxws-rt, version 2.2.3, everything worked great.
@WebService(serviceName = "SOS")//, targetNamespace = "http://www.opengis.net/sos/1.0")
@UsesJAXBContext(value = SosServices.SosJaxbContext.class)
//@XmlSeeAlso({net.opengis.sos.v_1_0_0.filter.v_1_1_0.ObjectFactory.class, net.opengis.sensorml.v_1_0_1.ObjectFactory.class})
public class SosServices {
@WebMethod(operationName = "GetResult")
public GetResultResponse getResult(GetResult request) {
throw new UnsupportedOperationException();
}
public static class SosJaxbContext implements JAXBContextFactory {
@Override
public JAXBRIContext createJAXBContext(SEIModel sei,
List<Class> classesToBind, List<TypeReference> typeReferences)
throws JAXBException {
List<Class> classList = new ArrayList<Class>();
classList.addAll(classesToBind);
classList.add(TemporalOpsType.class);
List<TypeReference> refList = new ArrayList<TypeReference>();
refList.addAll(typeReferences);
refList.add(new TypeReference(new QName("http://www.opengis.net/ogc", "temporalOps"), TemporalOpsType.class));
return JAXBRIContext.newInstance(classList.toArray(new Class[classList.size()]),
refList, null, sei.getTargetNamespace(), false, null);
}
}
}
感谢 ogc(java.net 项目)邮件列表上的 Aleksei Valikov 指向@UsesJAXBContext 的指针!
Thanks to Aleksei Valikov on the ogc (java.net project) mailing list to the pointer to @UsesJAXBContext!
这篇关于在 SLSB 和 JAX-WS 中指定 JAXB 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!