Proper Tomcat Resource configuration for MySql

Lately, I was faced with a mysql error when configured as a Resource in the tomcat server.xml configuration file.

The error looked the following:

STACKTRACE:

com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 

** BEGIN NESTED EXCEPTION ** 

java.net.SocketException
MESSAGE: Broken pipe

STACKTRACE:

java.net.SocketException: Broken pipe
	at java.net.SocketOutputStream.socketWrite0(Native Method)
	at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)

The problem was that I was not using the validationQuery parameter to be sure that the connection is still alive. So the parameter I neede absolutely were :

    validationQuery="select current_date()" removeAbandoned="true" removeAbandonedTimeout="300" logAbandoned="false" initialSize="3"

Here is part of the server.xml file


     <Engine name="Catalina8680" defaultHost="localhost8680">
          <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                 resourceName="UserDatabase"/>
          <Host name="localhost8680"  appBase="webapps8680"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
                <Context reloadable="true" displayName="myapp" docBase="/opt/apache-tomcat-6.0.20/webapps8680/myapp" path="/myapp" workDir="work/Catalina8680/localhost8680/myapp">
                
                <Resource name="jdbc/myapp_ds_0409085721" auth="Container" type="javax.sql.DataSource"
                   maxActive="10" maxIdle="3" maxWait="10000"
                   username="myapp_db" password="myapp_prod" driverClassName="org.gjt.mm.mysql.Driver"
                   url="jdbc:mysql://localhost:3306/myapp" 
                   validationQuery="select current_date()" removeAbandoned="true" removeAbandonedTimeout="300" logAbandoned="false"
                   initialSize="3"/>

...


Build App with Aurelia in Visual Studio 2015

This is a quick How-To open the Aurelia Skeleton project in Visual Studio 2015. (The bad thing for now CTP6, is that it does not support ES6 syntax).

(UPDATE : Soon after writing this, I cam across this post which you should prefer when wanting to start with Aurelia : post from Scott Allen on Aurelia an Asp.net 5)

First follow these instruction to get up and running with an Aurelia Development environment : Aurelia get started cheat sheet – installation steps

1.Then create a new Project in Visual Studio : An Asp.net Web application

aurelia-1

choose the Empty Template

aurelia-2

2.This project should be created where you extracted the aurelia skeleton project (for me : C:_temp\GitHub\aurelia-playground)

aurelia-3

3.Copy (Cut and Paste) the content of the aurelia skeleton project (C:_temp\GitHub\aurelia-playground\aurelia-skeleton-v-0.12) to the new Asp.net project (C:_temp\GitHub\aurelia-playground\Aurelia.Skeleton)

4.edit the project.json file and change the web root to be the root folder :

    "webroot": ".",

5.Now you can just hit F5 and see chrome starting with the aurelia-skeleton nav project running.

6.or better from the Task Runner Explorer you can start the Task tdd and watch and start coding.

aurelia-4

Aurelia get started cheat sheet – installation steps

This post briefly lists the step you must do to start coding an Aurelia powered app. for the long story go to Aurelia Get started page.

  1. install node or update to the latest version . this step is important.

  2. install gulp globaly :
    npm install -g gulp
    
  3. install jspm globaly:
    npm install -g jspm
    
  4. configure jspm with github credentials : (follow instructions)
    jspm registry config github
    
  5. download the skeleton app : https://github.com/aurelia/skeleton-navigation/releases and extract it to a folder of your choice

  6. navigate to the root of the app :

    cd C:\_temp\GitHub\aurelia-playground\skeleton-navigation-0.12.0
    
  7. launch npm and jspm install
    npm install
    jspm install -y
    
  8. launch the command to start a webserver that listens on : http://localhost:9000/
    gulp watch
    

History :

12/04/2015 : tested with v0.12

jasmine test with configurable angular services

This post is just a jasmine braindump :

When testing angularjs services that needs to be configured, this is the way to configure it

 beforeEach(module('angular-toolkit-auth', 
                         function (authProvider, openIdProvider) {
     authProvider.setAuthenticationType('Bearer');
 }));

if you need more than one module to be instantiated for your test:

beforeEach(function(){
    module('angular-toolkit-storage');
    module('angular-toolkit-auth');
});

// or you can call them one after the other like so

beforeEach(module('angular-toolkit-auth'));
beforeEach(module('angular-toolkit-auth-config'));

openId id_token validation in javascript (an angular service)

This post is related to the following stackoverflow question :
How can I validate an openId id_token in javascript.

The Short story

we need to use JSWS.

  1. download the libraries from here. I’ve downloaded version 3.0.2.
  2. in your index.html,reference the jws-3.0.js, the json-sans-eval.js file that you downloaded above
    (json-sans-eval is located in [jsjws-3.0.2\ext] directory. (more info on it can be found here
    json-sans-eval site)
  3. if you run the code, you will get the following exception : b64utohex is not defined
  4. you need to reference another library. in fact I found the related project jsrsasign having the required libraries.
    you can download a release here : https://github.com/kjur/jsrsasign/tags/
    I downloaded the version 4.7.0 and took out the jsrsasign-4.7.0-all-min.js file and added in referencing scripts.

Now you have all the necessary files to get it done using the following code :

  function validateToken(id_token, cert) {
        var jws = new KJUR.jws.JWS();
        var result = 0;
        result = jws.verifyJWSByPemX509Cert(id_token, cert);
        if (result) {
            result = JSON.parse(jws.parsedJWS.payloadS);
        } else {
            result = 'unable to verify token';
        }
        return result;
    }

Token validation coming from an openid endpoint will also be part fo my angular-toolkit project : check it here

Read more to get the Long story …

Continue reading openId id_token validation in javascript (an angular service)

Async Test with jasmine and angularjs

This post describes how to test angular services that makes use of promise (simple or with $http, $timeout…) with the jasmine testing framework. All the code is located here : angular-playground. I use karma to display the test result. So just karma start at the root.
for more info on async support check this:

Continue reading Async Test with jasmine and angularjs

Install sinon with jasmine and Karma

lately I wanted to use sinon within karma. So I simply did the following :

install sinon with bower : bower install sinon

then added the sinon.js to the karma files in the karma.conf.js like so :

files: [
'../bower_components/angular/angular.js',
'../bower_components/angular-mocks/angular-mocks.js',
'../src//.js',
'./unit/
/.js'
],

and use it in my jasmine test specs file…. but it didn’t work.

And here is the solution:

in a command prompt, navigate to the root of your project and type :

npm install karma-sinon --save-dev

then in your karma.conf.js file add the following:

frameworks: ['jasmine', 'sinon']

You can now use sinon in your jasmine files


var mySUT = {
    callCallback: function (cb) {
        cb();
    }
}

 describe('spies', function () {
        it('should spy on a callback', function(){
            var spy = sinon.spy();  
            
            mySUT.callCallback(spy);
            
            expect(spy.called).toBe(true);
            
            
        });
    })