diff --git a/.gitignore b/.gitignore
index 3fb2be90..0b7eee47 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@
.idea
/*.iml
/classes/
+/.java-version
diff --git a/pom.xml b/pom.xml
index ebf3e8f7..6b5b7350 100644
--- a/pom.xml
+++ b/pom.xml
@@ -41,8 +41,7 @@
UTF-8
- 1.8
- 1.8
+ 11
@@ -113,7 +112,7 @@
org.apache.maven.plugins
maven-javadoc-plugin
- 2.9.1
+ 3.3.0
attach-javadocs
@@ -123,7 +122,38 @@
-
+
+ org.apache.maven.plugins
+ maven-clean-plugin
+ 3.3.2
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.11.0
+
+ ${maven.compiler.release}
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 3.2.2
+
+ false
+ false
+
+
+
+
org.apache.maven.wagon
@@ -274,4 +304,4 @@
-
\ No newline at end of file
+
diff --git a/src/main/java/yahoofinance/histquotes2/CrumbManager.java b/src/main/java/yahoofinance/histquotes2/CrumbManager.java
index 1ca30a11..a3989748 100644
--- a/src/main/java/yahoofinance/histquotes2/CrumbManager.java
+++ b/src/main/java/yahoofinance/histquotes2/CrumbManager.java
@@ -46,14 +46,17 @@ private static void setCookie() throws IOException {
redirectableRequest.setConnectTimeout(YahooFinance.CONNECTION_TIMEOUT);
redirectableRequest.setReadTimeout(YahooFinance.CONNECTION_TIMEOUT);
+ Map requestProperties = new HashMap();
+ requestProperties.put("Cookie", cookie);
+ requestProperties.put("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5.2 Safari/605.1.15");
- URLConnection connection = redirectableRequest.openConnection();
+ URLConnection connection = redirectableRequest.openConnection(requestProperties);
for(String headerKey : connection.getHeaderFields().keySet()) {
if("Set-Cookie".equalsIgnoreCase(headerKey)) {
for(String cookieField : connection.getHeaderFields().get(headerKey)) {
for(String cookieValue : cookieField.split(";")) {
- if(cookieValue.matches("B=.*")) {
+ if(cookieValue.matches("A1S=.*")) {
cookie = cookieValue;
log.debug("Set cookie from http request: {}", cookie);
return;
@@ -162,6 +165,7 @@ private static void setCrumb() throws IOException {
Map requestProperties = new HashMap();
requestProperties.put("Cookie", cookie);
+ requestProperties.put("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5.2 Safari/605.1.15");
URLConnection crumbConnection = redirectableCrumbRequest.openConnection(requestProperties);
InputStreamReader is = new InputStreamReader(crumbConnection.getInputStream());
diff --git a/src/main/java/yahoofinance/quotes/query1v7/QuotesRequest.java b/src/main/java/yahoofinance/quotes/query1v7/QuotesRequest.java
index 5daf346c..b429229c 100644
--- a/src/main/java/yahoofinance/quotes/query1v7/QuotesRequest.java
+++ b/src/main/java/yahoofinance/quotes/query1v7/QuotesRequest.java
@@ -16,6 +16,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import yahoofinance.histquotes2.CrumbManager;
/**
*
@@ -61,7 +62,9 @@ public List getResult() throws IOException {
params.put("symbols", this.symbols);
String url = YahooFinance.QUOTES_QUERY1V7_BASE_URL + "?" + Utils.getURLParameters(params);
-
+ if (!CrumbManager.getCrumb().isEmpty()) {
+ url = url + "&crumb=" + CrumbManager.getCrumb();
+ }
// Get JSON from Yahoo
log.info("Sending request: " + url);
diff --git a/src/test/java/yahoofinance/CrumbManagerTest.java b/src/test/java/yahoofinance/CrumbManagerTest.java
new file mode 100644
index 00000000..6f5deae7
--- /dev/null
+++ b/src/test/java/yahoofinance/CrumbManagerTest.java
@@ -0,0 +1,19 @@
+package yahoofinance;
+
+import static org.junit.Assert.assertNotNull;
+import org.junit.Test;
+import java.io.IOException;
+import yahoofinance.histquotes2.CrumbManager;
+
+/**
+ *
+ * @author gilberto.andrade
+ */
+public class CrumbManagerTest {
+
+ @Test
+ public void getCrumbTest() throws IOException {
+ assertNotNull(CrumbManager.getCrumb());
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/yahoofinance/QuoteRequestTest.java b/src/test/java/yahoofinance/QuoteRequestTest.java
new file mode 100644
index 00000000..56177831
--- /dev/null
+++ b/src/test/java/yahoofinance/QuoteRequestTest.java
@@ -0,0 +1,19 @@
+package yahoofinance;
+
+import java.io.IOException;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author gilberto.andrade
+ */
+public class QuoteRequestTest {
+
+ @Test
+ public void getQuoteTest() throws IOException {
+ Stock stock = YahooFinance.get("INTC");
+ assertEquals(stock.getStats().getSymbol(), "INTC");
+
+ }
+}
\ No newline at end of file