有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java JAXB为属性返回null

我正在用SpringWS开发一个soap web服务。我有这个功能:

@PayloadRoot(namespace = NAMESPACE, localPart = "data")
@ResponsePayload
public Theaters getTheaters(
        @RequestPayload final JAXBElement<TheaterSearch> dataElement)
        throws SQLException {
    TheaterSearch data = dataElement.getValue();
    System.out.println(ReflectionToStringBuilder.toString(dataElement));
    if (data.getMovieId() == null && data.getLocation() == null) {
        throw new IllegalArgumentException();
    } else {
        if (data.getMovieId() == null) {
            return db.getTheaters(data.getLocation());
        } else {
            if (data.getLocation() == null) {
                return db.getTheatersForMovie(data.getMovieId());
            } else {
                Theaters theaters = db.getTheatersForMovie(
                        data.getMovieId(), data.getLocation());
                return theaters;
            }
        }
    }
}

Eclipse中的下一个测试通过,当我从Eclipse调用mvn test(菜单运行方式)时。奇怪的问题是,当我从命令行调用mvn test时,它没有通过。JAXB返回具有null属性的TheaterSearch对象。所以我得到一个IllegalArgumentException。如何调试此问题

@Test
public void TheaterEndpoint() throws Exception {
    Source requestPayload = new StreamSource(new ClassPathResource("data.xml").getInputStream() );
    Source responsePayload = new StreamSource(new ClassPathResource("response.xml").getInputStream());

    mockClient.sendRequest(withPayload(requestPayload)).
            andExpect(payload(responsePayload));
}

数据。xml

<data xmlns="http://iaws/ws/contractfirst/example" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://iaws/ws/contractfirst/example Request.xsd">
    <movieId>tt0387564</movieId>
    <location>NY</location>
</data>

剧院搜索

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "data")
public class TheaterSearch {

@XmlElement(name = "movieId", nillable = false)
private String movieId;

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

public TheaterSearch(final String movieId,
        final String location) {
    if (movieId == null && location == null) {
        throw new IllegalArgumentException();
    }
    this.movieId = movieId;
    this.location = location;
}

public final String getMovieId() {
    return movieId;
}
public final String getLocation() {
    return location;
}

}


共 (0) 个答案