[英]Specify JAXB Packages in SLSB and JAX-WS
我正在使用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是什么尋找。 一旦我修復了這些,並將依賴項添加到jaxws-rt,版本2.2.3,一切都很好。
@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項目)郵件列表中指向@UsesJAXBContext的指針!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.