I have craeted a Web Application that can be deployed on Heroku by maven eclipse.
Group Id: org.glassfish.jersey.archetypes
Artifact Id: jersey-heroku-webapp
version: 2.17
then I followed this guide(1.5) to push it to Heroku.
https://jersey.java.net/documentation/latest/getting-started.html#heroku-webapp
I can not access my apple
class from the http link- like this:
https://salty-refuge-2027.herokuapp.com/apple
and I am getting the error 500
I have tested it before without the JDBC procedure and I got the output Hello, from apple class
therefore I guess it depends on the my implementation for the Heroku Postgres
https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-java
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("apple")
public class Apple {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getIt() {
try {
getConnection();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "Hello, from apple class";
}
private static Connection getConnection() throws URISyntaxException, SQLException {
//I have modified my orginal ingredients.
URI dbUri = new URI(System.getenv("postgres://mglfe545z6ixsgk:yf8gyK1hBh3jknzqepLnajWRLv@
ec2-60-16-433-222.compute-1.amazonaws.com:5432/d5kal1r7jtavr9"));
String username = dbUri.getUserInfo().split(":")[0];
String password = dbUri.getUserInfo().split(":")[1];
String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':'
+ dbUri.getPort() + dbUri.getPath();
Connection con = DriverManager.getConnection(dbUrl, username, password);
System.out.println("It works");
return con;
}
}
I appreciate any help.