在SLSB和JAX-WS中指定JAXB包

Ste*_*ert 5 java jax-ws jaxb jersey

我正在使用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");
Run Code Online (Sandbox Code Playgroud)

如何在JAX-WS上下文中设置JAXB包?

我的应用服务器/环境是GF 3.1.

谢谢您的帮助!

史蒂夫

Ste*_*ert 3

我让它与 @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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

感谢 ogc(java.net 项目)邮件列表上的 Aleksei Valikov 指向@UsesJAXBContext 的指针!