首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用ProxyFactory替换RestEasyWebTarget不起作用

用ProxyFactory替换RestEasyWebTarget不起作用
EN

Stack Overflow用户
提问于 2013-11-26 00:38:55
回答 1查看 1.2K关注 0票数 0

在从Resteasy 2.4升级到3.0.5之后,我的客户不再调用work了。我期望的实体(就像字符串一样简单)总是为null。在调试模式下,我可以在服务器端的Response对象中看到它的设置,但是在客户端,响应中的实体为null。下面是一个示例调用:

接口:

代码语言:javascript
复制
  /**
   * @return all expired licenses
   */
  @GET
  @ClientResponseType(entityType = LicenseList.class)
  @Path("/expired")
  @Produces(MediaType.APPLICATION_XML)
  public Response getExpiredLicenses();

执行情况:

代码语言:javascript
复制
  /**
   * @return all expired licenses
   */
  @Override
  public Response getExpiredLicenses() {
    try {
      LicenseList list = LicensesDBUtil.getExpiredLicenses();
      Response resp = Response.ok().entity(list).build();
      return resp;
    } catch (SQLException e) {
      LOG.error("Error getting expired licenses : " + e.getMessage());
      return   Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).type(MediaType.TEXT_PLAIN).build();
    }

测试电话:

代码语言:javascript
复制
  @Test
  public void testGetExpiredLicenses() throws Exception {
        ResteasyClientBuilder rsb = new ResteasyClientBuilder();
    ResteasyClient rsc = rsb.build();
    ResteasyWebTarget target = rsc.target(BASEURL);
    return target.proxy(RiskScapeLicenseService.class);
    Response response = client.getExpiredLicenses();
    assertTrue(HttpResponseCodes.SC_OK == response.getStatus());
    @SuppressWarnings("unchecked")
    JAXBElement<LicenseList> element = (JAXBElement<LicenseList>) response.getEntity();
    LicenseList list = element.getValue();
    assertEquals(4, list.getLicenses().size());
    for (License lic : list.getLicenses()) {
      assertTrue((new Date()).after(DateUtils.parseDate(lic.getValidTo(), new String[] { "yyyy-MM-dd" })));
    }
  }

我的web.xml文件:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <display-name>riskscapelic_rest</display-name>
  <listener>
    <listener-class>
            org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
    </listener-class>
  </listener>
  <servlet>
    <servlet-name>Resteasy</servlet-name>
    <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Resteasy</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
  <context-param>
    <param-name>resteasy.scan</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>resteasy.servlet.mapping.prefix</param-name>
    <param-value>/</param-value>
  </context-param>
</web-app>

LicenseList类:

代码语言:javascript
复制
@XmlRootElement(name = "LicenseList")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "licenseList", propOrder = {
    "licenses"
})
public class LicenseList {

    @XmlElement(name = "Licenses", required = true)
    protected List<License> licenses;

    /**
     * Gets the value of the licenses property.
     * 
     * <p>
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the JAXB object.
     * This is why there is not a <CODE>set</CODE> method for the licenses property.
     * 
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getLicenses().add(newItem);
     * </pre>
     * 
     * 
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link License }
     * 
     * 
     */
    public List<License> getLicenses() {
        if (licenses == null) {
            licenses = new ArrayList<License>();
        }
        return this.licenses;
    }

}

我使用JDK 1.7,Tomcat 7.0.47

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-26 23:02:29

因此,我通过使用jaxb:version="2.0“更新我的模式并重新生成jaxb类来解决我的问题。提示是有人提到了Resteasy客户端-> JAX-RS2.0错配迁移问题。还要注意的是,在这个jaxb版本中,genearator仍然省略了XmlRootElementis,因此需要将它添加到用作POST请求输入的所有类中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20206426

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档