Empty uri in rest response

核能气质少年 提交于 2019-12-02 04:17:48

问题


I am developing a plugin for nexus oss .My app creates a rest call response(to a request from server) . But when the server receives it , it throws error as follows

 javax.xml.bind.UnmarshalException:
 unexpected element (uri:"", local:"com.collabnet.teamforge.ia.types.GetConfigurationParametersResponse"). 
Expected elements are 
\lt{http://www.collab.net/teamforge/integratedapp}CreateProjectConfigurationRequest\gt,
\lt{http://www.collab.net/teamforge/integratedapp}GetConfigurationParametersRequest\gt,
\lt{http://www.collab.net/teamforge/integratedapp}GetConfigurationParametersResponse\gt,
\lt{http://www.collab.net/teamforge/integratedapp}GetPageComponentParametersRequest> 

I guess the reason behind this exception is that the response doesn't match with the expected because the uri ( this is just my guess , if it's wrong please correct me),that is the namespace in response is not set .

snip of the Code in my plugin is as follows


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "configurationParameter"
})
@XmlRootElement(name = "GetConfigurationParametersResponse", namespace = "http://www.collab.net/teamforge/integratedapp")
public class GetConfigurationParametersResponse
    extends BaseResponse
{

Why is name space not picked up while creating response ?

Even correct me if the real reason for the exception is not the empty uri. If so what is the real reason behind this exception ? Please help .


回答1:


Based on the error message the XML document being passed to JAXB is. It appears as though this XML is being created by something other than JAXB (I suspect XStream).

<com.collabnet.teamforge.ia.types.GetConfigurationParametersResponse>
    ...
</com.collabnet.teamforge.ia.types.GetConfigurationParametersResponse>

Your JAXB mappings are expecting an XML document like the following:

<GetConfigurationParametersResponse xmlns="http://www.collab.net/teamforge/integratedapp">
    ...
</GetConfigurationParametersResponse>

If you need to interact with the following XML:

<com.collabnet.teamforge.ia.types.GetConfigurationParametersResponse>
    ...
</com.collabnet.teamforge.ia.types.GetConfigurationParametersResponse>

Then you can change your mapping to be:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "configurationParameter"
})
@XmlRootElement(name = "com.collabnet.teamforge.ia.types.GetConfigurationParametersResponse")
public class GetConfigurationParametersResponse
    extends BaseResponse
{


来源:https://stackoverflow.com/questions/17961790/empty-uri-in-rest-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!