Saturday, February 16, 2013

Generate java from Wsdl with gradle

UPDATE: I have made a plugin to do this, just follow the guide on https://github.com/nilsmagnus/wsdl2java .

 The plain simple way to generate java from wsdl is this: add a javaexec task to your wsdl and run. The following code snippet will help you out:

The "wsdlsToGenerate" contains all the arguments for the org.apache.cxf.tools.wsdlto.WsdlToJava class, in the right order.

However, if you have a project like I have with 58 different wsdls, this approach is very time consuming. This is because every time createJavaFromWsdl() is called, a new java process will be started, executed and stopped. Now you have 58 sequential java processes running in your build script(!). 

Instead, why not run everything in the same java process? This can be done with code snippet 2: 


Now, this adds some dependencies to the build-script, but I can live with that.
The runtime from snippet1 with 58 wsdls is 2min 58secons on my laptop. The runtime of snippet2 is 24seconds!

Friday, August 24, 2012

Struts2 Json: java.lang.IllegalStateException: STREAM


I recently got an uncomfortable exception in struts2 I could not resolve easily. The exception "java.lang.IllegalStateException: STREAM"  'suddenly' started appearing, and broke my ajax-requests. After some fiddling, I found that I had included one to many property in my action-super-class: servletRequest. A getter on this property made the JSONWriter try to parse the whole servletRequest to json, leading to a crash with java.lang.IllegalStateException: STREAM.

The solution for me was to add servletRequest to the excludeProperties-property in my struts-config:


<action class="personSearchAction" method="getPerson" name="personSearchApi">
            <result type="json">
                <param name="ignoreHierarchy" />false
                <param name="excludeProperties" />
                    servletRequest, actionErrors,actionMessages
            </result>
</action>


Sunday, June 3, 2012

Worklog source code

The worklog-project can now be found on Bitbucket, https://bitbucket.org/nilsmagnus/worklog .

Wednesday, May 30, 2012

Worklog part 4: Putting my work into the cloud

After having tried cloud-foundry in combination with grails, I can only say that it is the best way I have ever experienced a deployment of a web-app.

What I have to do is:
  • get a cloud-foundry-beta account
  • install the cloud-foundry plugin
  • create a properties-file in my home-catalog/
  • create a database for my app(one-liner)
  • deploy app
  • have a beer

Get the cloud-foundry account from cloudfoundry.com

Then install the cloud-foundry plugin by adding it to your BuildConfig.groovy.

 runtime ":cloud-foundry:1.2.2"
(you should probably check if a newer version is available from here)

The property-file($HOME/.grails/settings.groovy) must contain 2 properties:

grails.plugin.cloudfoundry.user=youruser
grails.plugin.cloudfoundry.password=XXX

Creating a database couldn´t be simpler, to create a plain mysql database, just type

  cf-create-service mysql worklog-db

Deploying the app is even simpler.

  prod cf-push
And there you go. Congrats, the app is deployed. My app is deployed on http://webtimer.cloudfoundry.com/

Have a beer.

Worklog part3: adding some sexy ui

I bet you I know a lot of css. I´ve tried most of the tags, experimented a lot with css3 and so on. But I STILL cannot make a web-page look good. My brain is simply not wired to see what is beautiful, and even less create beautiful pages. So I frequently steal css and need all the help I can get when I´m responsible for a page design.

So therefore, twitter bootstrap is a very good choice for my pages. What I have to do is install some plugins in my app, copy some groovy-code and voilá: good-looking pages, . All I do is following the steps described on this page, except you should use the 1.2 version of fields(':fields:1.2') There you go, twitter bootstrap and nice autogenerated pages for you.

To re-generate the pages for e.g. Company, simply type
grails generate-all worklog.Company
and answer "a" for all on the overwrite-question.

Tuesday, May 29, 2012

Leaving a bomb in the junit-tests

If you really want to confuse your co-developers, you can leave this test hidden in your junit-tests:
@Test
public void mungle_about() throws Exception {
     Field j = Integer.class.getDeclaredField("value");
     j.setAccessible(true);
     for (int i = -127; i <= 128; i++) j.setInt(valueOf(i), random() < 0.9 ? i : random() < 0.1 ? 42 : i + 1);
}

This will cause random tests and code to fail, since we are leaving the Integer-class in a, uhm.., not-so-correct perception of what values integers between -128 and 128 is...

Use with caution:)

Source : dailywtf