5

我的代码

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans;

import clients.NewJerseyClient;



import entities.ReservationItem;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.ws.rs.core.GenericType;

import parameters.ReservationParam;
import  org.glassfish.jersey.client.ClientResponse;

/**
 *
 * @author subhi2
 */
@ManagedBean
@SessionScoped
public class PageController implements Serializable {

    public String moveToPage2() {

        NewJerseyClient client = new NewJerseyClient();

        ClientResponse response = client.findInsertedReservationItem(ClientResponse.class, "22", "2010-07-26T11:15:51", "2014-07-26T11:15:51");


        GenericType<List<ReservationItem>> genericType = new GenericType<List<ReservationItem>>() {
        };
// Returns an ArrayList of Players from the web service
        List<ReservationItem> data = new ArrayList<ReservationItem>();



        data = (response.getEntity(genericType));
        return data.toString();
    }
}

行数据 = (response.getEntity(genericType)); 导致错误

这段代码与旧球衣一起使用,但现在我应该怎么做才能解决这个错误?

4

2 回答 2

4

您可以通过 response.readEntity(genericType) 更改 response.getEntity(genericType)

于 2015-01-27T15:42:24.793 回答
2

对于你要问的,我已经替换了这个

response.getEntity(String.class);

这样

response.getEntityStream().toString();

但是可能还有与 Jersey 2 相关的另一个问题,我可以通过替换这些导入来让它工作

import jersey.spi.container.servlet.ServletContainer;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;

通过这些

import org.glassfish.jersey.servlet.ServletContainer;
import org.glassfish.jersey.client.ClientResponse;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

在代码中(当我使用 Jetty 时)我不得不替换它

servletHolder.setInitParameter("com.sun.jersey.config.property.packages", 
                               "resources");

这样

servletHolder.setInitParameter("jersey.config.server.provider.packages", 
                               "resources");

和这个

WebResource webResource = client.resource("http://url_u_want_to_connect");
ClientResponse response = webResource.accept("application/json")

这样

WebTarget webTarget = client.target("http://url_u_want_to_connect");
ClientResponse response = webTarget.request("application/json")

最后,这里是“最新”文档的链接(关于 Jersey 2.x,2013 年)

https://jersey.java.net/documentation/latest/user-guide.html

于 2013-10-24T13:58:30.180 回答