#Machine Learning #Neural Networks

Perceptron Learning Algorithm

This note illustrates the use of perceptron learning algorithm to identify the discriminant function with weight to partition the linearly separable data step-by-step. The material mainly outlined in Kröse et al. [1] work, and the example is from the Janecek’s [2] slides. In machine learning, the perceptron is an supervised learning algorithm used as a binary classifier, which is used to identify whether a input data belongs to a specific group (class) or not. ...

Author 5 min
#AWS #Maven

Using Amazon S3 as a Private Maven Repository

This article is a quick tutorial to setup a private maven repository using Amazon S3 instead of Nexus or Artifactory. First we need to create a S3 bucket used to store two types of maven artifacts: stores two types of artifacts: releases and snapshots. repository.example.com/[snapshots, releases] Since we want a private repository, we can securely control access to this bucket for our users by leveraging AWS Identity and Access Management (IAM). ...

Author 2 min
#Apache Shiro #GlassFish

Apache Shiro NullPointerException after Logout on GlassFish 4.1

I’m currently working on a web application on Java EE7 stack and I’ve integrated Apache Shiro with CAS for security. Everything goes well, except the GlassFish 4.1 (build 13) server logs keep getting filled with following errors when calling logout() method: Info: Session event listener threw exception java.lang.NullPointerException at org.jboss.weld.servlet.WeldTerminalListener.getSessionContext(WeldTerminalListener.java:65) at org.jboss.weld.servlet.WeldTerminalListener.sessionDestroyed(WeldTerminalListener.java:57) at org.apache.catalina.session.StandardSession.expire(StandardSession.java:910) at org.apache.catalina.session.StandardSession.expire(StandardSession.java:854) at org.apache.catalina.session.StandardSession.expire(StandardSession.java:842) at org.apache.catalina.session.StandardSession.invalidate(StandardSession.java:1603) at org.apache.catalina.session.StandardSessionFacade.invalidate(StandardSessionFacade.java:204) at org.apache.shiro.web.session.HttpServletSession.stop(HttpServletSession.java:113) at org.apache.shiro.session.ProxiedSession.stop(ProxiedSession.java:107) at org.apache.shiro.subject.support.DelegatingSubject$StoppingAwareProxiedSession.stop(DelegatingSubject.java:419) at org. ...

Author 3 min
#Apache Shiro #SSO #CAS #LDAP

Integrating Apache Shiro with CAS Authentication via LDAP

In this post I want to share how to setup SSO with CAS and LDAP authentication, and then demonstrate how to integrate Apache Shiro with CAS in the web application. An Example of An Individual LDAP Entry The following entry which represented in LDIF would be used to login the CAS. In this case, the username will be the full email address (case-insensitive) and the password is the value of userPassword attribute. ...

Author 5 min
#Jersey #ContextResolver #SimpleModule

How to Customise the Jackson JSON ObjectMapper in Java EE Enterprise Application

Assume we have a naive User POJO class with a BSON Type ObjectId field, i.e., id. public class User { private ObjectId id; private String username; private String password; private Date createdAt; public getters/setters; ... We can expect the following outputs from our REST services which is not a String with 24 hex characters. { "_id": { "new": false, "machine": 805608948, "timeSecond": 1403022678, "inc": -871980150, "time": 1403022678000 }, "username": "John Smith", "password": "am9obiBzbWl0aCBwYXNzd29yZA", "createdAt": 1403022678341 } As we know, it can be solved by using the Jackson annotation for configuring Serializer class to serialize the associated value. ...

Author 3 min
#Java #MongoDB #Morphia #Map-Reduce

Map-Reduce with MongoDB and Morphia

Just a note to record the usage of Map-Reduce with MongoDB and Morphia. Firstly, add the Morphia dependency. <dependency> <groupId>org.mongodb</groupId> <artifactId>mongo-java-driver</artifactId> <version>2.11.2</version> </dependency> <dependency> <groupId>org.mongodb.morphia</groupId> <artifactId>morphia</artifactId> <version>0.105</version> </dependency> The syntax of MapReduceCommand in Morphia as shown in MapReduceCommand.java: public MapReduceCommand( DBCollection inputCollection, String map, String reduce, String outputCollection, OutputType type, DBObject query) { // Compiled Code } Here we want to group the sales amount (i.e., subtotal) of each county and exclude the null-subtotal from collection. ...

Author 2 min
#Java #MongoDB

Using the MongoDB Aggregation Framework via MongoDB Asynchronous Java Driver

Introduction I often use Morphia in projects for mapping Java objects to/from MongoDB and it’s Query API instead of building the complex DBObject query. However, the current version (v. 0.105) without aggregate command support. Fortunately, the MongoDB Asynchronous Java Driver provides the aggregate builder to construct complex pipelines of operators in fluent way. As usual, the following paragraphs will express some basic usages of mongodb-async-driver in aggregation pipeline framework through an example. ...

Author 3 min
#Java EE #Swagger #JAX-RS #Jersey

Integrating Swagger into JAX-RS with Java EE 6 specification

Introduction Swagger is an awesome framework we often used to describe, consume and visualize our RESTful web services. Typically, we use Tomcat with Jersey as a servlet, then specify the Swagger package and Swagger Configuration class into web.xml, finally annotate the resources, methods and models to complete the configurations. Our team recently built a Java EE 7 application for a RESTful web service. The goal of this article is to share our experiences of configuring Swagger in Glassfish 4 without a web. ...

Author 4 min
#CentOS #Tomcat

CentOS: Installing Apache Portable Runtime (APR) for Tomcat

Introduction In Tomcat, the default HTTP Connector is BIO (Blocking I/O) connector with stability, low concurrency characteristics. To boost the Tomcat performance, the alternative ways either adapt NIO (Non-Blocking I/O) or APR (Apache Portable Runtime) connector. Especially, the APR performance is generally better than others when using SSL protocol. For more details on performance among these connectors can reference the Mike Noordermeer’s comparison. Prerequisites for installing APR APR library APR-util library OpenSSL library To begin our installation, we’ll first need to install the OpenSSL to the server because we install CentOS 6. ...

Author 2 min