Thursday, April 15, 2021

CORS header 'Access-Control-Allow-Origin' missing and Java Servlet

 As it is answered here, HttpServlet.doOptions() method has to be overridden the following way:

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
@WebServlet(
    name = "MyServlet",
    urlPatterns = {"/myservlet"}
)
public class MyServlet extends HttpServlet {
	
    @Override
    protected void doOptions
        
(
            
HttpServletRequest req,
            HttpServletResponse resp
        )         throws IOException {         resp.setHeader("Access-Control-Allow-Origin", "*");      resp.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");      resp.setHeader("Access-Control-Allow-Headers", "*");     }     @Override     protected void doPost
        (
            HttpServletRequest req,
            HttpServletResponse resp
        )         throws IOException {         resp.setHeader("Access-Control-Allow-Origin", "*");         resp.setContentType("text/plain");         resp.setCharacterEncoding("UTF-8");         resp.getOutputStream().println("OK");     }     @Override     protected void doGet
        (
            HttpServletRequest req,
            HttpServletResponse resp
        )         throws IOException {         doPost(req, resp);     } }

Sunday, April 11, 2021

Covid19 Travel Information - updated daily

Another web project finished. This time daily updated corona virus related travel information at:

Covid19 Travel Information

HTML, javascript without any frameworks, only Papa Parse for CSV parsing and python for data processing. Data is fetched from The Humanitarian Data Exchange. There is no database at all and site is hosted on GitHub Pages!

Covid19 Bar Chart Race

I got bored watching 'ordinary' corona virus charts, I couldn't find updated bar chart race, so I made it myself. A small weekend project at:

Covid19 Bar Chart Race

Data comes from The Humanitarian Data Exchange, it is processed with python and Flourish is used for visualization. Unfortunately, automatic data upload is available in their business plans only, so there is one manual step left to. Hosted on GitHub Pages!


Saturday, April 3, 2021

NOAA API web servers rejecting Android app requests (error code 403)

Probably it is a NOAA's (National Oceanic and Atmospheric Administration) response to problems outlined in this article: Weather Service Internet systems are crumbling as key platforms are taxed and failing.

HTTP(S) requests to weather.gov servers made from Android apps (that are using default User-Agent header) are failing with error code - 403 Forbidden. Not sure exactly since when, and not sure what User-Agent headers are blocked, in my case it was a testing device with:

"Dalvik/2.1.0 (Linux; U; Android 5.0.2; Android SDK built for x86_64 Build/LSY66K)"

 The solution is pretty simple, you have to make request with User-Agent header set as described in this Stack Overflow answer