Visar inlägg med etikett url. Visa alla inlägg
Visar inlägg med etikett url. Visa alla inlägg

2017-12-10

Servlet Using Google Vision API Sample

Servlet Using Google Vision API

A simple servlet with POST getting an image URL and performs a SAFE SEARCH check using Google Vision API.
Note that it doesn't contain authorization. You can do it locally on your machine or run it live at App Engine using it's service account (it does that automatic so you just deploy it).

2016-10-13

Scala Request Uri Combinator Parser

URI Combinator Parser

In my last blog I created a URL parser but the HttpServletRequest is providing only path and query with the method getRequestUri() so I made a request URI parser too.

Code

This code needs the URL parser, see below.

See

Link to the URL parser:
https://gist.github.com/AIMMOTH/b9903387cdf6b9377e9a7f6ca8887281

2016-10-12

Scala URL Parser Combinator

URL Parser Combinator

(updated 2016-10-16)
It has bugged me that there is no parser of an URL so I made one.

Parser Combinator

Scala provides an excellent tool of parsing using a mix of code in DSL (domain specific language) and regular expressions. Together with unapply it's easy to match and take out the matching pieces.

URL

From Wikipedia there are the following parts of an URL (some are optional):
scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]

Code

Enjoy, I won't go into detail other than it breaks down the URL in the following order:
  1. Split URL by
    1. Mandatory scheme
    2. Optional domain
    3. Mandatory path
    4. Optional query and fragment
  2. Domain is split by
    1. Authorization
    2. Domain
    3. Port
Usually a greedy regexp matcher is used until a delimiter.