在SLSB和JAX-WS中指定JAXB软件包
问题内容:
我正在使用SLSB和JAX-WS批注创建一个简单的SOAP
Web服务。我要传递的对象是从OGC模式生成的JAXB,这要感谢java.net上的OGC项目。我遇到的一种特定方法(导致部署失败)是一种情况,其中请求对象(GetResult)的字段(eventTime)与请求对象位于不同的包中。此类型的ObjectFactory不同,在编组/解组时存在问题。
我收到的部分错误:
There's no ObjectFactory with an @XmlElementDecl for the element {http://www.opengis.net/ogc}temporalOps. this problem is related to the following location: 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时,一切正常。
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软件包?
我的应用服务器/环境是GF 3.1。
谢谢您的帮助!
史蒂夫
问题答案:
我将它与@UsesJAXBContext一起使用-最初遇到了一些麻烦,因为NB
6.9和7.0b希望链接UsesJAXBContext的com.sun.internal。*版本和相关版本,这当然不是JAX-WS
RI寻找。一旦我修复了这些问题,并将依赖性添加到2.2.3版的jaxws-rt中,一切工作就很好了。
@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的指针!