【问题标题】:Internal Server error on jersey while posting application/xml发布应用程序/xml 时球衣上的内部服务器错误
【发布时间】:2017-01-22 06:27:02
【问题描述】:

我已经为这个错误苦苦挣扎了好几个小时;我正在尝试在其正文中使用 xml 发出 http post 请求;我设法这样做了:

@POST
@Path("/callback")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_XML)
public Response updateStatus(InputBean inputBean) {     
    //my code
}

我的 xml 注释是这样的:

@XmlRootElement(name = "project")
public class Project {

    @XmlElement(name ="result")
    private String result;    

    public Project() {
    }

    public String getResult() {
        return result;
    }

    public void setResult (String result) {
        this.result = result;
    }  
}

输入 bean 实际上比这更复杂;我已经在调试模式下运行了我的代码,并验证了在使用邮递员并发出请求后 inputbean 得到了增强;但是有一个问题,我的 bean 中有一些字段,它们的命名如下:项目名称;带有“-”字符的所有这些字段在发出请求时都不会得到增强,所以我想添加一个注释:

@XmlElement(name ="project-name")
    private String projectName;

当我添加该注释并运行代码时,我得到一个内部服务器错误 500,并且无法调试那些值应该是“可读”的代码,我只需要增强这些字段,但我仍然不知道如何,所有没有“-”字符的其他字段在此过程中得到增强。

正文请求的xml:

 <bag>
<action>bag­execution­result</action>
    <detail>
        <project name="IBankerPorting">
            <component>ASA</component>
            <tag>trunk//264989</tag>
            <request-id>203782</request-id>
            <tag-id>254753</tag-id>
            <date>2010-02-03 12:16</date>
            <security-needed>no</security-needed>
            <type>MAINTENANCE</type>
            <result-ci>-0.000</result-ci>
            <result-pmd-highest>-1</result-pmd-highest>
            <result-pmd-high>-1</result-pmd-high>
            <result-pmd-medium>-1</result-pmd-medium>
            <result-cc-open-issue>0</result-cc-open-issue>
            <result>approved</result>
        </project>
    </detail>
</bag> 

例如。在我的 bean 中,每个不包含“-”的字段都得到了增强(由于 jersey,xml 已经采用了一个值),除了那些带有“-”的字段,比如 request-id

【问题讨论】:

  • 请澄清在使用邮递员后得到增强。
  • 解释String project-name;在Java中是如何工作的?
  • @XmlElement(name ="project-name") private String projectName 和项目上的一样,只是这里拼错了;当我使用邮递员使用我的 xml 正文发出像 localhost:port/etc 这样的发布请求时,inputBean 从我的 xml 中获取一些值(感谢 jersey unmarshallowing 属性),但来自项目名称等字段的值是 null ;生病更新问题更清楚

标签: java xml jersey postman


【解决方案1】:

我最终找到了解决方案,我在包含 xml 字段的 pojo 类中添加了这个语句:@XmlAccessorType(XmlAccessType.FIELD)

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "project")
public class Project {

    @XmlElement(name ="result")
    private String result;    

    public Project() {
    }

    public String getResult() {
        return result;
    }

    public void setResult (String result) {
        this.result = result;
    }  
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-24
    • 2021-11-08
    • 1970-01-01
    • 1970-01-01
    • 2015-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多