This commit is contained in:
Éibhear Ó hAnluain 2017-08-12 21:07:21 +01:00
parent 7fe1c4c8c6
commit 632e4dfeff
4 changed files with 165 additions and 1 deletions

View file

@ -46,7 +46,7 @@
: git checkout lesson-1
** Lesson 1 -- compile the code.
*** Starting point
A clean git working area
@ -159,3 +159,48 @@
app.
5. Test the application. If all is well, move on to lesson 5:
: git checkout lesson-5
** Lesson 5 -- Add new functionality
*** Starting point
A clean working brought up to date to include the two new files:
=${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse/AstroFun.java=
and =${DEV_HOME}/source/lib/AstroLib-1.1.5ws.jar=, and an update
to
=${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse/MyHelloWorldServlet.java=.
*** Goal
A working, updated application deployed to tomcat
*** Steps
0. [@0] Pre-steps
- Make sure your environment is set up as per the previous lessons:
+ =DEV_HOME= is set to where the git repository is cloned to
+ =CLASSPATH= contains =tomcat8-servlet-api.jar=
- Clean out the working area if there are unnecessary/unwanted files:
: rm -vf ${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse/*.class
: rm -vf ${DEV_HOME}/source/lib/javaBootcampNoEclipse.?ar
: rm -vfr ${DEV_HOME}/webapp
- Review the changes that have been applied to the working area
1. Compile the java files (including the new java file) as per
Lesson 1.
Does it compile? If not, why. Two hints:
- there was a new jar file introduced to the repository
- there's a bug in the package specification in the new java
file. Looking closely at the branches of this git repository,
you might even find a fix for it.
2. Build the jar file as per Lesson 2 (except, this time, the
=lib= directory exists already).
3. Build the war file as per Lesson 3.
4. Deploy the updated application as per lesson 4. You will need
to undeploy the previous version first.
Does it deploy? Why not? (Hint: there was a new jar file
introduced to the repository)
5. Fix the new bug, undeploy the bad application and deploy the
corrected one.

View file

@ -0,0 +1,94 @@
import com.mhuss.AstroLib.*;
import com.mhuss.Util.*;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import java.util.Date;
public class AstroFun {
private double lat, lon;
private ObsInfo whereAmI;
private AstroDate myAD;
private PlanetData sunData, moonData;
public AstroFun() {
// Grand Island, Nebraska, U.S.A.
this.lat = 40.9162;
this.lon = -98.2962;
this.whereAmI = new ObsInfo (new Latitude(lat), new Longitude(lon));
// 2017-08-21 13:00 CDT
this.myAD = new AstroDate ( 21, 8, 2017, 21, 14, 0 );
this.sunData = new PlanetData (Planets.SUN, myAD.jd(), whereAmI);
this.moonData = new PlanetData (Planets.LUNA, myAD.jd(), whereAmI);
}
public double getSunD() {
double tmp;
try {
tmp = this.sunData.getDeclination();
}
catch ( NoInitException nieOops ) {
tmp = 0;
}
return tmp;
}
public double getSunRA() {
double tmp;
try {
tmp = this.sunData.getRightAscension();
}
catch ( NoInitException nieOops ) {
tmp = 0;
}
return tmp;
}
public double getMoonD() {
double tmp;
try {
tmp = this.moonData.getDeclination();
}
catch ( NoInitException nieOops ) {
tmp = 0;
}
return tmp;
}
public double getMoonRA() {
double tmp;
try {
tmp = this.moonData.getRightAscension();
}
catch ( NoInitException nieOops ) {
tmp = 0;
}
return tmp;
}
public static void main(String[] args) {
// System.out.println("Hello World!");
AstroFun hmm = new AstroFun();
System.out.print ("Sun: ");
System.out.println
( "Declination: " + Math.toDegrees(hmm.getSunD()) +
", Right Ascension: " + Math.toDegrees(hmm.getSunRA())
);
System.out.print ("Moon: ");
System.out.println
( "Declination: " + Math.toDegrees(hmm.getMoonD()) +
", Right Ascension: " + Math.toDegrees(hmm.getMoonRA())
);
}
}

View file

@ -9,6 +9,18 @@ public class MyHelloWorldServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
double sunD = 0, sunRA = 0, moonD = 0, moonRA = 0;
String oopsMsg = new String ("No exception");
AstroFun myAstroInfo = new AstroFun();
sunD = Math.toDegrees(myAstroInfo.getSunD());
sunRA = Math.toDegrees(myAstroInfo.getSunRA());
moonD = Math.toDegrees(myAstroInfo.getMoonD());
moonRA = Math.toDegrees(myAstroInfo.getMoonRA());
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
@ -18,6 +30,19 @@ public class MyHelloWorldServlet extends HttpServlet {
out.println("<body>");
out.println("<h1 align=\"center\">Éibhear's Hello World (Servlet) example</h1>");
out.println("<p>Ho there!</p>");
if ( oopsMsg.equals("No exception") ) {
out.println("<p>Position in the sky of the Sun and the Moon as seen from Grand " +
"Island in Nebraska on Monday the 21<sup>st</sup> of August at 21:14 " +
"UTC.</p>");
out.println("<table>");
out.println("<tr><th>Body</th><th>Declination (degrees N of equator)</th><th>Right Ascension (degrees E of the Vernal Equinox)</th></tr>");
out.println("<tr><th>Sun</th><td>" + sunD + "</td><td>" + sunRA + "</td></tr>");
out.println("<tr><th>Moon</th><td>" + moonD + "</td><td>" + moonRA + "</td></tr>");
out.println("</table>");
}
else {
out.println("<p>We regret to say that we can't bring you the information you're looking for at the moment. Please come back later (because, y'know, your visit is important to us, 'n' all!).</p>");
}
out.println("</body>");
out.println("</html>");
}

Binary file not shown.