Specify JAXB Packages in SLSB and JAX-WS

前端 未结 1 475
醉话见心
醉话见心 2020-12-16 07:23

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 projec

相关标签:
1条回答
  • 2020-12-16 07:49

    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);
            }
        }
    }
    

    Thanks to Aleksei Valikov on the ogc (java.net project) mailing list to the pointer to @UsesJAXBContext!

    0 讨论(0)
提交回复
热议问题