Monday, September 29, 2014

Configure Pip and Npm Behind a Proxy

In Linux;

It's a must to set your HTTP_PROXY and HTTPS_PROXY env
export HTTP_PROXY=http://proxy.mycompany.com:3333
export HTTPS_PROXY=http://proxy.mycompany.com:3333
It's also a must for Windows environment to set those variables

for pip
pip install package
Is enough, although
pip --proxy http://proxy.mycompany.com:3333 install package
also can do the trick

For npm

Nope, the variables can't work. Npm use a configuration file and it can be added via command line npm config set
npm config set proxy http://proxy.mycompany.com:3333
npm config set https-proxy http://proxy.mycompany.com:3333

and do the job
npm install package

They say that NodeJS faster than Python?

Thursday, September 18, 2014

Action Report: poc-swagger-springmvc

Upgrading swagger-springmvc from version 0.65 to 0.8.8 is not a smooth upgrade in eGospel project. So, I decided to create separated Proof of Concept (POC) to make sure if we removed some complexity in the project, the investigation will be lot easier. My (stupid) first mistake is, I forgot to add
<bean class="com.mangofactory.swagger.configuration.SpringSwaggerConfig" />
in my springmvc-context.xml. After 1-2 hour, I figured out what happen, but till now still lamented for 2 hours wasted because of my stupidity. Moral of the story is, don't do any coding, when you are tired and sleepy, just rest!

Then I add (and replaced) the latest swagger-ui from "https://github.com/wordnik/swagger-ui" dist folder, and add their index.html as my "welcome-file" in web.xml
The controller I built is very simple HelloController, with one function returning Hello object and another function returning String. I also add HelloControllerTestIT for integration test, and setup all maven-plugin as in my eGospel project. And testing phase is success.

But problem now happen when I deploy my poc in application server (in my case, Tomcat) and browse it in browser. Yes, the swagger-ui can list down the controllers (which the swagger is working), but when I "Tryit out!" I got http 404; not found error. It's strange since the integration test can find the service.

I do more readings (by browsing), and guess it caused by relative path in the URL. I read several sources:
https://github.com/wordnik/swagger-ui/issues/114
https://github.com/wordnik/swagger-ui/issues/355
https://github.com/wordnik/swagger-ui/issues/337
http://stackoverflow.com/questions/14262660/rest-api-swagger-java-jersey-wrong-listing-path-and-additional-apis

Although not directly helping me, in my problem, I know what I need to do. Change my basepath into absolute path!
Since I don't want to make my hand dirty by writing my own CustomizeSwaggerConfiguration, what I need to do is to extend SpringSwaggerConfig into my new class. here comes SpringSwaggerConfig. 
package com.dariawan.poc.config;

import com.mangofactory.swagger.configuration.SpringSwaggerConfig;
import com.mangofactory.swagger.models.configuration.SwaggerModelsConfiguration;
import com.mangofactory.swagger.paths.AbsoluteSwaggerPathProvider;
import com.mangofactory.swagger.paths.SwaggerPathProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 *
 * @author Desson Ariawan <teodesson@yahoo.com>
 */
@Configuration
//@ComponentScan(basePackages = {"com.mangofactory.swagger.controllers"})
@Import(SwaggerModelsConfiguration.class)
public class MySpringSwaggerConfig extends SpringSwaggerConfig {

    @Bean
    @Override
    public SwaggerPathProvider defaultSwaggerPathProvider() {
        return new AbsoluteSwaggerPathProvider();
    }
}

Yes, what I do is only overriding  defaultSwaggerPathProvider() function. Replace bean in springmvc-context.xml, now using MySpringSwaggerConfig.
<bean class="com.dariawan.poc.config.MySpringSwaggerConfig" />

And voila! Integration Test now passed, and swagger-ui also showing what I'm expecting.



You can check complete project in https://github.com/teodesson/poc-swagger-springmvc
Now I need to sleep.

Update: add pictures, and later on: added spring-security into the project, no functional impact, swagger and spring-mvc works as expected

Monday, September 15, 2014

POC: Swagger - Spring MVC (And Swagger UI)

My eGospel project using SpringMVC in the backend, and produces JSON RESTful web services via it's controllers as JSON objects. To quickly see the list of the services, and do simple check, I use swagger-ui (which means I also need to use swagger, in this case swagger-springmvc). Previously, I'm using swagger-springmvc ver 0.6.5. But when I'm upgrading to ver 0.8.8, it start to have issues.

So, I decided to create another project, as showcase or working example of the framework. I will write my finding on another post. Please check the project on github, and please give me some direction.

Introduction to Spring Web MVC framework

The Spring Web model-view-controller (MVC) framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, locale, time zone and theme resolution as well as support for uploading files. The default handler is based on the @Controller and@RequestMapping annotations, offering a wide range of flexible handling methods. With the introduction of Spring 3.0, the @Controller mechanism also allows you to create RESTful Web sites and applications, through the @PathVariable annotation and other features.

What's Swagger?

The goal of Swagger™ is to define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined via Swagger, a consumer can understand and interact with the remote service with a minimal amount of implementation logic. Similar to what interfaces have done for lower-level programming, Swager removes the guesswork in calling the service.
Check out Swagger-Spec for additional information about the Swagger project, including additional libraries with support for other languages and more.

Swagger UI

Swagger UI is part of Swagger project. The Swagger project allows you to produce, visualize and consume your OWN RESTful services. No proxy or 3rd party services required. Do it your own way.
Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation and sandbox from a Swagger-compliant API. Because Swagger UI has no dependencies, you can host it in any server environment, or on your local machine.

Sunday, September 7, 2014

eGospel in GitHub

I copied my eGospel project from a private repository in Bitbucket to GitHub. If you interested, you can check the project in this repo.

So, what is eGospel?
in short; eGospel is a simple church dynamic website project, running on Java.

For Techies, Geeks 'n Coders,
this is the summary of technologies adopted in this project:
  • Java (for sure, now I'm using JDK 1.7)
  • Spring Framework, including Spring Security and Spring Data JPA
  • Hibernate
  • AngularJS
  • Twitter Bootstrap
  • And a quite number of Javascript libraries (jQuery, Underscore JS, etc)
I decided to skip Coffeescript this time. I think I need more hands-on on AngularJS to get the essence of this framework, before (if needed) later on encapsulate it with another framework.