Coder Social home page Coder Social logo

gmposter's Introduction

GmPoster

A Spark Framework app for posting local files to a remote server for locally installed HTML5 apps.

It runs on Java8 and uses Owner, Async-Http-Client and Netty.

Build

mvn clean package

Run with Java

java -jar GmPoster-1.0-SNAPSHOT-jar-with-dependencies.jar

Configuration

This is the Owner Config interface from which the settings are taken.

src/main/java/com/mcb/owner/Application.java

package com.mcb.owner;

import org.aeonbits.owner.Config;

@Config.Sources({
        "file:gm.properties",
        "file:~/.gm.properties",
        "file:/etc/gm.properties",
        "classpath:com/mcb/owner/Application.properties" })
public interface Application extends Config {

    @Key( "server.port" )
    int port();
    
    @Key( "server.cors.disable" )
    @DefaultValue( "False" )
    Boolean disableCors();
    
    @Key( "server.cors.allow.origin" )
    @DefaultValue( "*" )
    String corsAllowOrigin();
    
    @Key( "server.cors.request.method" )
    @DefaultValue( "*" )
    String corsRequestMethod();
    
    @Key( "server.cors.allow.headers" )
    @DefaultValue( "*" )
    String corsAllowHeaders();
    
    @Key( "app.route.name" )
    @DefaultValue( "route" )
    String routeName();
    
    @Key( "app.file.to.post" )
    String fileToPost();
    
    @Key( "app.remote.url" )
    String remoteUrl();
    
    @Key( "app.remote.auth.type" )
    String remoteAuthType();
    
    @Key( "app.remote.auth.username" )
    String remoteAuthUsername();
    
    @Key( "app.remote.auth.password" )
    String remoteAuthPassword();
    
    @Key( "app.remote.auth.header" )
    String remoteAuthHeaderName();
    
    @Key( "app.remote.auth.header.value" )
    String remoteAuthHeaderValue();
    
    @Key( "app.remote.status.expected" )
    @DefaultValue("201")
    int remoteStatusExpected();
}

src/main/resources/com/mcb/owner/Application.properties

#################################################################
#
# Settaggi relativi al server locale
#
#################################################################
server.port=8889
## per default CORS e' abilitato (false)
#server.cors.disable=false
#res.header("Access-Control-Allow-Origin", origin);
server.cors.allow.origin=*
#res.header("Access-Control-Request-Method", methods);
server.cors.request.method=*
#res.header("Access-Control-Allow-Headers", headers);
server.cors.allow.headers=*

#################################################################
#
# Settaggi relativi al API esposto dal server
#
#################################################################
# la parte del url dopo la porta ie http://localhost:8080/[route-name]/
app.route.name=gm
# questo dovrebbe essere il valore del file to post, se e' statico
app.file.to.post=pom.xml


#################################################################
#
# Settaggi relativi alla richiesta per caricare l'immagine
#
#################################################################

# url verso il quale si deve fare il POST
app.remote.url=http://localhost:8080/api/item/img
# stato http restituito dalla richiesta che indica che la chiamata e' andata a buon fine
app.remote.status.expected=201
# Ho implementato soltanto Basic/Digest authentication ma puo' essere facilmente esteso; altrimenti si usa direttamente app.remote.auth.header
app.remote.auth.type=Basic
app.remote.auth.username=matt
app.remote.auth.password=pwd1123

# per flessibilita' si puo' impostare direttamente l'header di usare per authenticazione
#app.remote.auth.header=Authorization
# il valore del app.remote.auth.header
#app.remote.auth.header.value=token dsafsafeakfjlasvjsavaslk

As you can see looking at the @Config.Sources annotation, the order in which the application looks for files to load is the following:

  1. file:gm.properties, ie. a file named gm.properties in the %CD% (pwd),
  2. file:~/.gm.properties, ie. a file named gm.properties in the user's home direcotry,
  3. file:/etc/gm.properties, ie. a file named gm.properties in the folder /etc/,
  4. classpath:com/mcb/owner/Application.properties, lastly, a file Application.properties on the classpath in the package com.mcb.owner.

NB. the Config will stop looking for properties files as soon as it finds one.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.