Skip to content
Open

WK10 #19

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions YahooServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.origamisoftware.teach.advanced.services;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar;
import javax.servlet.http.*;

/**
* BasicServlet request data from the web service that is used by the WebStockService
*/
public class YahooServlet extends HttpServlet{
private String symbol;
private Calendar d1, d2;

public YahooServlet(String symbol, Calendar from, Calendar until){
this.symbol = symbol;
this.d1 = from;
this.d2 = until;
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("http://finance.yahoo.com/d/quotes.csv?s="+ symbol + "&f=" + d1 + d2);
out.println("</body>");
out.println("</html>");
}
}
140 changes: 123 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,124 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.isaacVazquez.advancedjava</groupId>
<artifactId>isaacVazquez-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>isaacVazquez-app</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.origamisoftware.teach.effective</groupId>
<artifactId>week-6-stock-ticker-solution</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>week-6-stock-ticker-solution</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerArgument>-Xlint</compilerArgument>
<encoding>${project.build.sourceEncoding}</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<type>jar</type>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>

<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4</version>
</dependency>

<dependency>
<groupId>org.apache.ibatis</groupId>
<artifactId>ibatis-sqlmap</artifactId>
<version>2.3.4.726</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.2.6.Final</version>
</dependency>

<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>

<dependency>
<groupId>com.yahoofinance-api</groupId>
<artifactId>YahooFinanceAPI</artifactId>
<version>x.y.z</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.2.6.Final</version>
</dependency>
</dependencies>

</project>
46 changes: 46 additions & 0 deletions stockQuote.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<jsp:useBean id="StockQuery" class="com.origamisoftware.teach.advanced.model.StockQuery" scope="request"/>
<jsp:useBean id="Interval" class="com.origamisoftware.teach.advanced.util.Interval" scope="request"/>
<jsp:setProperty name="StockQuery" property="*"/>
<jsp:setProperty name="Interval" property="*"/>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Stock Quote Request</title>
</head>
<body>
<h2>
Please enter StockQuery information: <br>
</h2>
<P></P>
<h3>
Retrieve Data form the Database:
</h3>
<form name="stockQuoteDB" action="stockQuoteResults.jsp" method="post">
Stock Symbol : <input type="text" name="symbol"
value='<%= StockQuery.getSymbol() == null ? "" : StockQuery.getSymbol() %>'><br>
Stock Date From : <input type="text" name="from"
value='<%= StockQuery.getFrom()== null ? "" : StockQuery.getFrom() %>'><br>
Stock Date Until : <input type="text" name="until"
value='<%= StockQuery.getUntil()== null ? "" : StockQuery.getUntil() %>'><br>
Stock Date Interval : <input type="text" name="interval"
value='<%= Interval.getMinutes() != 0 ? "" : Interval.getMinutes() %>'><br>
<input type="SUBMIT" value="OK">
<input type="HIDDEN" name="submit" value="true">
</form>
<h3>
Retrieve Data form the Yahoo Finance Web App:
</h3>
<form name="stockQuoteYahoo" action="stockQuoteResults.jsp" method="post">
Stock Symbol : <input type="text" name="s"><br>
Stock Date From : <input type="text" name="d1">'><br>
Stock Date Until : <input type="text" name="d2">'><br>
<input type="SUBMIT" value="OK">
<input type="HIDDEN" name="submit" value="true">
</form>

</body>
</html>
28 changes: 28 additions & 0 deletions stockQuoteResults.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="javax.servlet.http.*" %>
<jsp:useBean id="StockQuery" class="com.origamisoftware.teach.advanced.model.StockQuery" scope="request"/>
<jsp:useBean id="Interval" class="com.origamisoftware.teach.advanced.util.Interval" scope="request"/>
<jsp:useBean id="YahooServlet" class="com.origamisoftware.teach.advanced.services.YahooServlet" scope="request"/>
<jsp:setProperty name="StockQuery" property="*"/>
<jsp:setProperty name="Interval" property="*"/>
<jsp:setProperty name="YahooServlet" property="*"/>

<html>
<head>
<title>Stock Quote Query Results</title>
</head>
<body>
<h1>Your Stock Quote</h1>

Symbol: <%= StockQuery.getSymbol() %>
Date From: <%= StockQuery.getFrom() %>
Date Until: <%= StockQuery.getUntil() %>
Interval in Minutes: <%= Interval.getMinutes() %>

<%=
YahooServlet.doGet(HttpServletRequest request, HttpServletResponse response)
%>
Thank you!
</body>
</html>