2011-04-11 48 views
5

我正在使用SLSB和JAX-WS 註釋創建一個簡單的SOAP Web服務。我想傳遞的對象是由OGC模式生成的JAXB,感謝在java.net上的OGC項目。我遇到的一種特殊方法(其中 導致部署失敗)是請求對象(GetResult)的字段(eventTime) 與請求對象 不在同一個包中。這種類型的ObjectFactory是不同的,在編組/解組時,存在 問題。在SLSB和JAX-WS中指定JAXB包

我得到了錯誤的子集:

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。

感謝您的幫助!

史蒂夫

+0

[此博客](http://weblogs.java.net/blog/kohlert/archive/2006/10/jaxws_and_type.html)指出在服務類上使用@XmlSeeAlso看起來很有前途,但看起來像它直到JAX-WS 2.2才被採用。地鐵(通過JAX-RS RI項目)似乎支持2.2規範......但我還沒有工作。在GF 3.0.1上試用它...也許它沒有符合JAX-WS的版本。今晚稍後再試。想法,任何人? – 2011-04-13 13:29:44

+0

@XmlSeeAlso似乎是一個很好的方法,但沒有解決問題。我被指向@UsesJAXBContext,但似乎metro有一個[bug](http://java.net/jira/browse/JAX_WS-270),它不調用JAXBContextFactory的createJAXBContext()已創建,已開放數年。調查繼續.... – 2011-04-15 12:37:07

回答

3

我得到了它與@UsesJAXBContext工作 - 有一個小麻煩首先是因爲NB 6.9和7.0B希望將com.sun.internal鏈接*的UsesJAXBContext和相關的版本這當然不是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); 
     } 
    } 
} 

感謝阿列克謝Valikov在OGC(java.net項目)郵件列表指針@UsesJAXBContext!