我的代码
/*
* 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();
}
}
这条线
data =(response.getEntity(genericType));
导致错误
此代码正在使用旧球衣,但现在我应该怎么做才能解决此错误?
答案 0 :(得分:3)
您可以通过response.readEntity(genericType)更改response.getEntity(genericType)
答案 1 :(得分:2)
根据你的要求,我已经取代了这个
response.getEntity(String.class);
由此
response.getEntityStream().toString();
但是可能存在与泽西岛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