TRƯỜNG HỢPgọi WebService Restful với phiên bản client Jersey 2,2
Tôi cố gắng để lấy dữ liệu người dùng để Servlet lọc sử dụng dịch vụ REST.
pom.xml
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
MÃ
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
Client client = ClientBuilder.newClient(new ClientConfig());
String entity = client.target("http://localhost:8080/insame/webresources/com.insame.entity.users")
.path("count")
.request(MediaType.TEXT_PLAIN)
.get(String.class);
System.out.println("entity-------->" +entity);
REST:
@GET
@Path("count")
@Produces("text/plain")
public String countREST() {
return String.valueOf(super.count());
}
VẤN ĐỀ
javax.ws.rs.ProcessingException: java.net.SocketException: Unexpected end of file from server
at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:202)
at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:215)
at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:650)
WARNING: StandardWrapperValve[com.insame.service.ApplicationConfig]: Servlet.service() for servlet com.insame.service.ApplicationConfig threw exception
javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
at org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:904)
at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:749)
at org.glassfish.jersey.client.JerseyInvocation.access$500(JerseyInvocation.java:88)
at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:650)
HỎI
0) là gì sai trái trong mã của tôi?
1) Cách khôn ngoan nhất để lấy dữ liệu từ bộ lọc servlet bằng cách sử dụng REST + JPA là gì?
2) Nếu có cách khác để thực hiện việc này, tốt hơn tôi muốn nói, hãy cho tôi biết?
3) Là Jersey Khách hàng là cách duy nhất
4) Làm thế nào tôi có thể có được EntityManager và gọi các dịch vụ còn lại trực tiếp từ bộ lọc mà không Jersey khách hàng?
Jersey tài liệu và các ví dụ: http://jersey.java.net/documentation/latest/user-guide.html#d0e2481
Cảm ơn, Sami