tisdag 19 november 2013

One golden line

Starting to explore the Spring v3 world just recently. Both at work and privately.

Quite fast I stumbled upon a problem that I couldn't figure out too fast. Ye, spring is kind of big.
I wanted to serve some static content. Instead of letting my apache do that, I added this line in the spring configuration:

<mvc:resources mapping="/**" location="/" />

Then it serves all my index.html and javascripts etc..

fredag 5 juli 2013

Deployed Yakutia

Yakutia is now deployed to prod!

In the previous post I thought I had issues with ports, domain, server or whatever.
However it was quite a embarrassing misunderstanding from my part, it was only related to session in the browser (I'm guessing cache or cookie stuff). So I would suggest to use portbase for creating a new domain in glassfish. Really convenient.

Well as post title says I have now deployed my webapp to "production". Since my production is not up 24/7 I wont reveal my webapp just now. The jenkins pipeline is now capable to do the following things:
  • build (compile, unit test, sonar analysis)
  • deploy (update db with liquibase, add the new ear artifact)
  • test (execute integration tests via selenium)
  • deploy (deploy the new artifact to "production")
Now I have some cleaning up to do in the pipeline and I will come back with some new cool features hopefully :) (planning for zero-downtime deploy). The last thing for this "sprint" is to fix code violations and increase the code coverage. 

And btw, it feels great to have vacation! ;)

onsdag 26 juni 2013

Yakutia game progress

I will try to blog more about my hobby-project Yakutia.

Mainly it is a project for me to learn the Java EE suite and have something to fiddle around with on my spare time. Since I have been working in a few projects with continuous delivery/integration I also setting up my own pipeline for this project. 

Now I have been struggling with having two glassfish instances on the same server box (unfortunately I don't have the resources for having two servers..). 

What I have been struggling with now is to setup two glassfish instances (one for test and one for "prod). However I seem to have a problem with getting the both instances standalone and not to be interfering with each other. 

I created both domains with the asadmin command with:
$: ./asadmin create-domain --portrange <myportrange>

That seemed to do the trick with clashing ports.

However when I login to the second instance and are logged in to the first one, I get thrown out from the first one. The same issue is for my deployed web-app. So I will try to find a solution for this. It might be that I am using the same domain name? I have really no clue.
If not, I don't know the best practice for this but maybe running two different domains in the same instance?

tisdag 5 februari 2013

JFokus 2013, day one thoughts

Hey!

For the first time I attended JFokus, and I think it is awesome. The feeling is like: I want to code, and I wanna do it now! Such a good inspiration source.
I will try to write some of the nice things that I learned or want to remember: 

1. Need to start to listen to podcasts. Not just for java but from others too. But hey, in this case I mean java posse. Find it here.

2. A quite fun dude from oracle that have been working on a project called noosehorn. Support for javascript in jvm kind of. Didn't sound that easy to integrate a dynamic language support in the jvm and vice versa. However he got the js framework to be 100% ecma-compliant and the performance kicked all others asses. Will be included in java8.

3. Spdy and websockets. Sounds to be kind of future. Save bandwith with spdy, i.e. dont need to resend same html headers all the time. Intruduction to bidirectional communication on the web, which is kind of hot.

4. Kick-ass development! Use chat at work :), fail your tests fast, have a bug hunter week for each developer. Use pairing between tester/developers. Hmm and also one thing that I didn't fully understood: branch a lot. But short branches, really short max 2 days. Actually makes sense.. but I need to sleep on it now :)

More to come tomorrow.

lördag 12 januari 2013

ejb + jpa + test = true?

Just finished off my test boilerplate for my javaEE project. I used the openEJB embedded container to deploy my ejb. I also fixed to possibility to test entities via hibernate in the same testcase. I think that's pretty cool since you actually can do more integration close testing even before deploying to a real application server. Trying to adapt to Antionio Goncalves nomock movement.

So I just wanted to show off my simple boilerplate as well:
@LocalClient
public class EjbTestCase {

    public static EJBContainer container;
    public static Context context;
    private static Properties prop;

    @Resource
    protected UserTransaction userTransaction;

    @PersistenceContext
    protected EntityManager entityManager;

    @BeforeClass
    public static void setup() {
        prop = new Properties();
        prop.put("jdbc/testDB", "new://Resource?type=DataSource");
        prop.put("jdbc/testDB.JdbcDriver", "org.hsqldb.jdbcDriver");
        prop.put("jdbc/testDB.JdbcUrl", "jdbc:hsqldb:mem:example");
        prop.put(Context.INITIAL_CONTEXT_FACTORY,
                "org.apache.openejb.client.LocalInitialContextFactory");

        container = EJBContainer.createEJBContainer(prop);
        context = container.getContext();
    }

    @Before
    public void setupEm() throws NamingException, SystemException,
            NotSupportedException {
        context.bind("inject",this);
        userTransaction.begin();
    }

    @After
    public void tearDownEm() throws HeuristicRollbackException, 
            RollbackException, HeuristicMixedException, SystemException {
        userTransaction.rollback();
    }

    @AfterClass
    public static void tearDown() {
        container.close();
    }
}

Pretty neat huh? At least I like it and thats whats matters right now :). As you can see you are able to get the context from the container + a entityManager in the same test.

The code is on github: examplesJavaEE

torsdag 3 januari 2013

External processes via groovy script

Had one problem one trying to kick off an external process from a groovy script. Actually two problems:

1. Not getting desired output from process (java process with INFO logging)
Solution:
process.consumeProcessOutput(System.out, System.err)

Add that method to your process that you want to kick off and it will print the stuff you want.

2. Could not build up my argument list correctly
Well I had laborated with a linux command like """ping -c 2 localhost""" and it worked like a charm to just add """my command""".execute(). However when I started to get the arguments passed from another script they got separated.
My solution was like this:
Build up the strings again and then use ProcessBuilder. Like this:

def process = new ProcessBuilder(command).redirectErrorStream(true).start();

Where the command is a ArrayList with combined parameters. Like:

def command = []
command[0] = "ping"
command[1] = "-c"
command[2] = "2"
command[3] = "localhost"

Could probably be used nice but for this time it worked nice.