我有一组RESTful Web服务,通常部署在Glassfish服务器中。 问题是,我工作的地方只能与Apache一起工作,所以我不得不切换,现在问题来了。 我已经设法部署了几个RESTful资源,它们工作得很好(他们所做的只是从数据库中检索信息并在POJO的ArrayList中返回该信息)。代码示例:
@Path("/FH01T02")
public class FH01T02Resource {
@Context
private UriInfo context;
/**
* Creates a new instance of FH01T02Resource
*/
public FH01T02Resource() {
}
/**
* Retrieves representation of an instance of WS_Resources.FH01T02Resource
*
* @return an instance of java.lang.String
*/
@GET
@Produces(javax.ws.rs.core.MediaType.APPLICATION_JSON)
public Response FH01T02() throws SQLException {
try {
ArrayList<Coche_FH01T02> lista = new ArrayList<>();
com.ibm.db2.jcc.DB2SimpleDataSource ds = new com.ibm.db2.jcc.DB2SimpleDataSource();
// set connection properties
ds.setServerName("l42fis25");
ds.setPortNumber(12040);
ds.setDatabaseName("FH044201");
ds.setDriverType(4);
// get connection
java.sql.Connection con = ds.getConnection("ufhadm", "UFHADM");
System.out.println("Successful connection to 'fh044201' using JDBC Type 4 driver");
ResultSet rs = null;
Statement stmt = con.createStatement(rs.TYPE_SCROLL_INSENSITIVE, rs.CONCUR_READ_ONLY);
String query = "SELECT * FROM FH01T02";
rs = stmt.executeQuery(query);
while (rs.next()) {
Coche_FH01T02 coche = new Coche_FH01T02();
coche.setWerk(rs.getString("WERK"));
coche.setSpj(rs.getString("SPJ"));
coche.setKanr(rs.getString("PZ"));
coche.setWerk0(rs.getString("WERK0"));
coche.setSpj0(rs.getString("SPJ0"));
coche.setKnr0(rs.getString("KNR0"));
coche.setWerk1(rs.getString("WERK1"));
coche.setStatus1(rs.getString("STATUS1"));
coche.setFgstwelt(rs.getString("FGSTWELT"));
coche.setFgstspez(rs.getString("FGSTSPEZ"));
coche.setFgsttm(rs.getString("FGSTTM"));
coche.setFgstpz(rs.getString("FGSTPZ"));
coche.setFgstmj(rs.getString("FGSTMJ"));
coche.setFgstwk(rs.getString("FGSTWK"));
coche.setFgstlfd(rs.getString("FGSTLFD"));
coche.setMotornummer(rs.getString("MOTORNUMMER"));
coche.setKmodell(rs.getString("KMODELL"));
coche.setPlatz(rs.getString("PLATZ"));
coche.setRpk_nr(rs.getString("RPK_NR"));
coche.setTpvk(rs.getString("TPVK"));
coche.setWerk_rl(rs.getString("WERK_RL"));
coche.setRohbaulinie(rs.getString("ROHBAULINIE"));
coche.setWerk_ml(rs.getString("WERK_ML"));
coche.setMontagelinie(rs.getString("MONTAGELINIE"));
coche.setWerk_ll(rs.getString("WERK_LL"));
coche.setLacklinie(rs.getString("LACKLINIE"));
coche.setKarossenzustand(rs.getString("KAROSSENZUSTAND"));
coche.setExt_waggonnr(rs.getString("EXT_WAGGONNR"));
coche.setExt_waggon_lfd(rs.getString("EXT_WAGGON_LFD"));
coche.setExt_waggon_pos(rs.getString("EXT_WAGGON_POS"));
coche.setExt_ist_seq(rs.getString("EXT_IST_SEQ"));
lista.add(coche);
}
rs.close();
stmt.close();
con.close();
return Response.status(200).entity(lista).build();
} catch (Exception e) {
return Response.status(200).entity(e.getMessage()).build();
}
}
/**
* PUT method for updating or creating an instance of FH01T02Resource
*
* @param content representation for the resource
*/
@PUT
@Consumes(MediaType.APPLICATION_XML)
public void putXml(String content) {
}
}
问题来自于我使用Jersey为这些资源创建客户端,以便从JSP调用(所有这些都是为了服务一系列网页)而且我收到此错误:
org.apache.jasper.JasperException:java.lang.RuntimeException: 抛出java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:479) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
我手动设置了库,甚至下载了该死的JerseyClientBuilder,但没有任何效果。 提前谢谢
答案 0 :(得分:0)
首先,您必须在Jersy的类路径中添加几个库以支持JSP和注释配置:
Maven文物:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>apache-jsp</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-plus</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-annotations</artifactId>
</dependency>
如果您使用嵌入式Jersy,则必须配置其JSP支持。
答案 1 :(得分:0)
如果您使用tomee 1,则无法使用jaxrs客户端API,但如果使用tomee 7则内置但基于CXF。具体地从您的webapp中删除所有运动衫和jaxrs api罐子,您将使其顺利运行。你的代码似乎足够便携,不在乎不使用运动衫。