我有一套通常部署在Glassfish服務器中的REST風格的Web服務。 問題是我工作的地方只能和Apache一起工作,所以我不得不切換,現在是問題出現的地方。 我設法部署了幾個RESTful資源,它們工作得很好(他們所做的只是從數據庫中檢索信息並返回POJO的ArrayList中的信息)。代碼示例:TomEE與Jersey REST風格的Web服務
@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) {
}
}
問題是當我使用澤西創建客戶端的資源,爲了從一個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,但沒有任何作品。 預先感謝您
事情是我沒有使用Maven,因此我沒有Maven文物。讓我瘋狂的是,這種設置在Glassfish中完全正常工作,而且不在TomEE中。我不知道如何將這些庫添加到Jersey的classpath中。無論如何感謝 – Asiertxo