5

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:

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

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

How do I set the JAXB packages in the JAX-WS context?

My app server/environment is GF 3.1.

Thanks for the help!

Steve

Steve Siebert
  • 1,874
  • 12
  • 18
  • [This blog](http://weblogs.java.net/blog/kohlert/archive/2006/10/jaxws_and_type.html) indicating the use of @XmlSeeAlso on the service class looks real promising, but looks like it wasn't adopted until JAX-WS 2.2. Metro (via JAX-RS RI project) seems to support 2.2 spec...but I don't have it working quite yet. Trying it on GF 3.0.1...perhaps it doesn't have a compliant version of JAX-WS. Try later tonight. Thoughts, anyone? – Steve Siebert Apr 13 '11 at 13:29
  • @XmlSeeAlso seemed like a good approach but didn't solve the problem. I was pointed to @UsesJAXBContext, but it seems that metro has a [bug](http://java.net/jira/browse/JAX_WS-270) in it where it doesn't call the createJAXBContext() of the JAXBContextFactory I created, which has been open for several years. Investigation continues.... – Steve Siebert Apr 15 '11 at 12:37

1 Answers1

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

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

Steve Siebert
  • 1,874
  • 12
  • 18
  • 1
    Could you show import statements for these UsesJAXBContext, SEIModel, TypeReference? there seems to be multiple of these from different packages and I'm not sure which to. – cyberoblivion Nov 12 '18 at 23:33