You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2020/05/11 04:50:54 UTC
[wicket] branch wicket-7.x updated: WICKET-6784 StockQuote example
does not work because the web service is no more available
This is an automated email from the ASF dual-hosted git repository.
mgrigorov pushed a commit to branch wicket-7.x
in repository https://gitbox.apache.org/repos/asf/wicket.git
The following commit(s) were added to refs/heads/wicket-7.x by this push:
new 8853059 WICKET-6784 StockQuote example does not work because the web service is no more available
8853059 is described below
commit 8853059da6cfdb195601f30e88003a0937c8dd13
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Mon May 11 07:43:02 2020 +0300
WICKET-6784 StockQuote example does not work because the web service is no more available
Remove the stock quote example
(cherry picked from commit 9987de6f0b9db97f68ddd95ab9371c6c97d4de45)
---
.../wicket/examples/stockquote/StockQuote.java | 223 ---------------------
.../examples/stockquote/StockQuoteApplication.java | 45 -----
.../examples/stockquote/StockQuoteLabel.java | 82 --------
.../examples/stockquote/StockQuoteLabel2.java | 53 -----
.../wicket/examples/stockquote/StockQuotePage.html | 30 ---
.../wicket/examples/stockquote/StockQuotePage.java | 100 ---------
.../apache/wicket/examples/homepage/HomePage.html | 1 -
wicket-examples/src/main/webapp/WEB-INF/web.xml | 16 --
8 files changed, 550 deletions(-)
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/stockquote/StockQuote.java b/wicket-examples/src/main/java/org/apache/wicket/examples/stockquote/StockQuote.java
deleted file mode 100644
index c9ed9bc..0000000
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/stockquote/StockQuote.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.examples.stockquote;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.ProtocolException;
-import java.net.URL;
-import java.net.URLConnection;
-
-/**
- * Provides access to a SOAP service for getting stock quotes based on a symbol. Found on
- * http://www.devx.com/Java/Article/27559/0/page/2
- */
-public class StockQuote
-{
- /**
- * We used to use the www.xmethods.com demo webservice for stockquotes. We now use webservicex,
- * as xmethods was really overloaded and unreliable.
- */
- private static final String serviceUrl = "http://www.webservicex.net/stockquote.asmx";
-
- /** the symbol to get the quote for. */
- private String symbol;
-
- /**
- * Default constructor.
- */
- public StockQuote()
- {
- }
-
- /**
- * Constructor setting the symbol to get the quote for.
- *
- * @param symbol
- * the symbol to look up
- */
- public StockQuote(String symbol)
- {
- this.symbol = symbol;
- }
-
- /**
- * Gets the symbol.
- *
- * @return the symbol
- */
- public String getSymbol()
- {
- return symbol;
- }
-
- /**
- * Sets the symbol for getting the quote.
- *
- * @param symbol
- */
- public void setSymbol(String symbol)
- {
- this.symbol = symbol;
- }
-
- /**
- * Gets a stock quote for the given symbol
- *
- * @return the stock quote
- */
- public String getQuote()
- {
- final String response = getSOAPQuote(symbol);
-
- // make sure we get
- int start = response.indexOf("<Last>") + "<Last>".length();
- int end = response.indexOf("</Last>");
-
- // if the string returned isn't valid, just return empty.
- if (start < "<Last>".length())
- {
- return "(unknown)";
- }
- String result = response.substring(start, end);
- return result.equals("0.00") ? "(unknown)" : result;
- }
-
- /**
- * Calls the SOAP service to get the stock quote for the symbol.
- *
- * @param symbol
- * the name to search for
- * @return the SOAP response containing the stockquote
- */
- private String getSOAPQuote(String symbol)
- {
- String response = "";
-
- try
- {
- final URL url = new URL(serviceUrl);
- final String message = createMessage(symbol);
-
- // Create the connection where we're going to send the file.
- HttpURLConnection httpConn = setUpHttpConnection(url, message.length());
-
- // Everything's set up; send the XML that was read in to
- // the service.
- writeRequest(message, httpConn);
-
- // Read the response and write it to standard out.
- response = readResult(httpConn);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- return response;
- }
-
- /**
- * Writes the message to the connection.
- *
- * @param message
- * the message to write
- * @param httpConn
- * the connection
- * @throws IOException
- */
- private void writeRequest(String message, HttpURLConnection httpConn) throws IOException
- {
- OutputStream out = httpConn.getOutputStream();
- out.write(message.getBytes());
- out.close();
- }
-
- /**
- * Sets up the HTTP connection.
- *
- * @param url
- * the url to connect to
- * @param length
- * the length to the input message
- * @return the HttpurLConnection
- * @throws IOException
- * @throws ProtocolException
- */
- private HttpURLConnection setUpHttpConnection(URL url, int length) throws IOException,
- ProtocolException
- {
- URLConnection connection = url.openConnection();
- HttpURLConnection httpConn = (HttpURLConnection)connection;
- // Set the appropriate HTTP parameters.
- httpConn.setRequestProperty("Content-Length", String.valueOf(length));
- httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
- httpConn.setRequestProperty("SOAPAction", "\"http://www.webserviceX.NET/GetQuote\"");
- httpConn.setRequestMethod("POST");
- httpConn.setDoOutput(true);
- httpConn.setDoInput(true);
- return httpConn;
- }
-
- /**
- * Reads the response from the http connection.
- *
- * @param connection
- * the connection to read the response from
- * @return the response
- * @throws IOException
- */
- private String readResult(HttpURLConnection connection) throws IOException
- {
- InputStream inputStream = connection.getInputStream();
- InputStreamReader isr = new InputStreamReader(inputStream);
- BufferedReader in = new BufferedReader(isr);
-
- StringBuilder sb = new StringBuilder();
- String inputLine;
- while ((inputLine = in.readLine()) != null)
- {
- sb.append(inputLine);
- }
-
- in.close();
- return sb.toString();
- }
-
- /**
- * Creates the request message for retrieving a stock quote.
- *
- * @param symbol
- * the symbol to query for
- * @return the request message
- */
- private String createMessage(String symbol)
- {
- StringBuilder message = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
- message.append("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
- message.append(" <soap:Body>");
- message.append(" <GetQuote xmlns=\"http://www.webserviceX.NET/\">");
- message.append(" <symbol>").append(symbol).append("</symbol>");
- message.append(" </GetQuote>");
- message.append(" </soap:Body>");
- message.append("</soap:Envelope>");
- return message.toString();
- }
-}
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/stockquote/StockQuoteApplication.java b/wicket-examples/src/main/java/org/apache/wicket/examples/stockquote/StockQuoteApplication.java
deleted file mode 100644
index 44a7d8e..0000000
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/stockquote/StockQuoteApplication.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.examples.stockquote;
-
-import org.apache.wicket.Page;
-import org.apache.wicket.examples.WicketExampleApplication;
-
-/**
- * Application class for stock quote example.
- *
- * @author Martijn Dashorst
- */
-public class StockQuoteApplication extends WicketExampleApplication
-{
- /**
- * Constructor.
- */
- public StockQuoteApplication()
- {
- }
-
- /**
- * @see org.apache.wicket.Application#getHomePage()
- */
- @Override
- public Class<? extends Page> getHomePage()
- {
- return StockQuotePage.class;
- }
-
-}
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/stockquote/StockQuoteLabel.java b/wicket-examples/src/main/java/org/apache/wicket/examples/stockquote/StockQuoteLabel.java
deleted file mode 100644
index dd9d1e0..0000000
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/stockquote/StockQuoteLabel.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.examples.stockquote;
-
-import org.apache.wicket.markup.ComponentTag;
-import org.apache.wicket.markup.MarkupStream;
-import org.apache.wicket.markup.html.WebComponent;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.Model;
-
-/**
- * Gets a stock quote from a webservice. This component is a full blown, built from the ground up
- * component. See the other stock quote examples for alternatives of creating custom components.
- *
- * The model that is provided is used as the symbol for lookup. When used without an explicit model,
- * the component tries the CompoundPropertyModel method of retrieving the model first. When that
- * results in an empty string, the component will use its ID as symbol.
- *
- * You can use this component in your webapplication just as you might want to use a
- * <code>Label</code>.
- */
-public class StockQuoteLabel extends WebComponent
-{
- /**
- * Constructor
- *
- * @param id
- * See Component
- */
- public StockQuoteLabel(String id)
- {
- super(id);
- }
-
- /**
- * Convenience constructor. Same as StockQuoteLabel(String, new Model<String>(String))
- *
- * @param id
- * See Component
- * @param symbol
- * The symbol to look up
- *
- * @see org.apache.wicket.Component#Component(String, IModel)
- */
- public StockQuoteLabel(String id, String symbol)
- {
- super(id, new Model<>(symbol));
- }
-
- /**
- * @see org.apache.wicket.Component#Component(String, IModel)
- */
- public StockQuoteLabel(String id, IModel<String> model)
- {
- super(id, model);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag)
- {
- String symbol = getDefaultModelObjectAsString();
- StockQuote quote = new StockQuote(symbol);
- replaceComponentTagBody(markupStream, openTag, quote.getQuote());
- }
-}
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/stockquote/StockQuoteLabel2.java b/wicket-examples/src/main/java/org/apache/wicket/examples/stockquote/StockQuoteLabel2.java
deleted file mode 100644
index 8bae00d..0000000
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/stockquote/StockQuoteLabel2.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.examples.stockquote;
-
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.model.AbstractReadOnlyModel;
-
-/**
- * StockQuote example provided by Jonathan Locke. This component shows you how to reuse existing
- * components (the StockQuoteLabel ISA Label), and how to use models internally in your component.
- *
- * Note that this component doesn't work with CompoundPropertyModel's lazy initialization.
- */
-public class StockQuoteLabel2 extends Label
-{
- /**
- * Constructor taking the symbol directly.
- *
- * @param id
- * the component id
- * @param symbol
- * the symbol to look up
- */
- public StockQuoteLabel2(String id, final String symbol)
- {
- super(id, new AbstractReadOnlyModel<String>()
- {
- /**
- * Gets the stockquote for the given symbol.
- */
- @Override
- public String getObject()
- {
- final StockQuote quote = new StockQuote(symbol);
- return quote.getQuote();
- }
- });
- }
-}
\ No newline at end of file
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/stockquote/StockQuotePage.html b/wicket-examples/src/main/java/org/apache/wicket/examples/stockquote/StockQuotePage.html
deleted file mode 100644
index d9f8a5e..0000000
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/stockquote/StockQuotePage.html
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
-<head>
- <title>Wicket Examples - stockquote</title>
- <link rel="stylesheet" type="text/css" href="style.css"/>
-</head>
-<body>
- <!-- component for the examples application -->
- <span wicket:id="mainNavigation"/>
-
- <!-- first example -->
- <p>
- IBM stockquote (example 1): <span wicket:id="stockIBM">1.23</span>
- </p>
- <p>
- IBM stockquote (example 2): <span wicket:id="stock2IBM">1.23</span>
- </p>
-
- <!-- second example -->
- <p>
- <form wicket:id="form">
- Type symbol: <input wicket:id="symbol" type="text" />
- <input type="submit" />
- </form>
- <p>
- Stock quote of <span wicket:id="symbol">symbol</span> is <span wicket:id="quote">quote</span>.
- </p>
- </p>
-</body>
-</html>
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/stockquote/StockQuotePage.java b/wicket-examples/src/main/java/org/apache/wicket/examples/stockquote/StockQuotePage.java
deleted file mode 100644
index a82b86d..0000000
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/stockquote/StockQuotePage.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.examples.stockquote;
-
-import org.apache.wicket.examples.WicketExamplePage;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.form.Form;
-import org.apache.wicket.markup.html.form.TextField;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.PropertyModel;
-import org.apache.wicket.util.io.IClusterable;
-
-
-/**
- * Stock quote webservice custom component example.
- *
- * @author Martijn Dashorst
- */
-public class StockQuotePage extends WicketExamplePage
-{
- /**
- * Constructor
- */
- public StockQuotePage()
- {
- // code for the first example, directly using the
- // stock quote component.
- add(new StockQuoteLabel("stockIBM", "IBM"));
-
- // use the second example component
- add(new StockQuoteLabel2("stock2IBM", "IBM"));
-
- // code for second example: using a form for selecting the
- // symbol of the stock quote.
-
- // shared model to get and set the symbol property on the
- // quote instance
- final IModel<String> model = new PropertyModel<>(quote, "symbol");
-
- // form holding the input field.
- final Form<?> form = new Form("form");
- add(form);
- form.add(new TextField<>("symbol", model));
-
- // labels for displaying the chosen symbol
- add(new Label("symbol", model));
-
- // and its quote
- add(new StockQuoteLabel("quote", model));
- }
-
- /**
- * Quote instance used for communicating between the form input field and the display labels for
- * showing the stock quote.
- */
- private final Quote quote = new Quote();
-
- /**
- * POJO to hold the symbol for the quote query.
- */
- public static class Quote implements IClusterable
- {
- private String symbol;
-
- /**
- * Gets the symbol.
- *
- * @return the symbol
- */
- public String getSymbol()
- {
- return symbol;
- }
-
- /**
- * Sets the symbol.
- *
- * @param symbol
- * the symbol
- */
- public void setSymbol(String symbol)
- {
- this.symbol = symbol;
- }
- }
-}
\ No newline at end of file
diff --git a/wicket-examples/src/main/resources/org/apache/wicket/examples/homepage/HomePage.html b/wicket-examples/src/main/resources/org/apache/wicket/examples/homepage/HomePage.html
index d83ae2c..e40b9fc 100644
--- a/wicket-examples/src/main/resources/org/apache/wicket/examples/homepage/HomePage.html
+++ b/wicket-examples/src/main/resources/org/apache/wicket/examples/homepage/HomePage.html
@@ -52,7 +52,6 @@
<tr><td align="right"><a href="kitten-captcha">kitten-captcha</a></td><td> - Another approach to captchas</td></tr>
<tr><td align="right"><a href="dates">dates</a></td><td> - Date component example from the wicket-date project.</td></tr>
- <tr class="section"><td align="right"><a href="stock">stockquote</a></td><td> - Stock quote example.</td></tr>
<tr><td align="right"><a href="guestbook">guestbook</a></td><td> - A blog-like multi-user guestbook.</td></tr>
<tr><td align="right"><a href="hangman">hangman</a></td><td> - The game of hangman.</td></tr>
<tr><td align="right"><a href="library">library</a></td><td> - A simple application.</td></tr>
diff --git a/wicket-examples/src/main/webapp/WEB-INF/web.xml b/wicket-examples/src/main/webapp/WEB-INF/web.xml
index fb326f9..f8025ec 100644
--- a/wicket-examples/src/main/webapp/WEB-INF/web.xml
+++ b/wicket-examples/src/main/webapp/WEB-INF/web.xml
@@ -122,15 +122,6 @@
</filter>
<filter>
- <filter-name>StockQuoteApplication</filter-name>
- <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
- <init-param>
- <param-name>applicationClassName</param-name>
- <param-value>org.apache.wicket.examples.stockquote.StockQuoteApplication</param-value>
- </init-param>
- </filter>
-
- <filter>
<filter-name>HangmanApplication</filter-name>
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
<init-param>
@@ -499,13 +490,6 @@
<url-pattern>/niceurl/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
- </filter-mapping>
-
- <filter-mapping>
- <filter-name>StockQuoteApplication</filter-name>
- <url-pattern>/stock/*</url-pattern>
- <dispatcher>REQUEST</dispatcher>
- <dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<filter-mapping>