在SLSB和JAX-WS中指定JAXB包 [英] Specify JAXB Packages in SLSB and JAX-WS
问题描述
我正在使用SLSB和JAX-WS
注释创建一个简单的SOAP Web服务。我想传递的对象是从OGC模式生成的JAXB,感谢java.net上的OGC项目。我遇到问题的一个特殊方法(
导致部署失败)是请求对象(GetResult)的字段(eventTime)
与$ b $不同的包中的情况b请求对象。这种类型的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:
对于元素
{http://www.opengis.net/ogc }temporalOps,没有带有@XmlElementDecl的ObjectFactory。
此问题与以下位置有关:
at protected javax.xml.bind.JAXBElement
net.opengis.sos.v_1_0_0.GetResult $ EventTime.temporalOps
at net。 opengis.sos.v_1_0_0.GetResult $ EventTime
at protected java.util.List
net.opengis.sos.v_1_0_0.GetResult.eventTime
at net.opengis.sos.v_1_0_0.GetResult
at public net.opengis.sos.v_1_0_0.GetResult
net.opengis.sos.v_1_0_0.ObjectFactory.createGetResult()
at 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.
感谢您的帮助!
Steve
推荐答案
我使用了@UsesJAXBContext - 起初有点麻烦,因为NB 6.9和7.0b想要链接UsesJAXBContext和相关的com.sun.internal。*版本,这当然不是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);
}
}
}
感谢Aleksei Valikov ogc(java.net project)邮件列表指向@UsesJAXBContext的指针!
Thanks to Aleksei Valikov on the ogc (java.net project) mailing list to the pointer to @UsesJAXBContext!
这篇关于在SLSB和JAX-WS中指定JAXB包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!