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

Tuesday, May 22, 2012

Intellij + test coverage : duh...

As a long-time-eclipse-user, I was looking for a test-coverage tool for my erlatively newly acquired Intellij IDEA editor. At first I didn't find it, so I told myself I had to live without it, just read the testreports from my cobertura-plugin instead. confronting another intellij-user with my frustration, a nice guy called Magnus told me that IntelliJ ineed has support for test-coverage. Okay, so I'm just dumb and not finding the coverage option? Some time went on and I had accepted that intellij couldn't give me a coverage report.

Only to realzie a month later that all I had to do was to install the coverage plugin. And voila, the context-menu has the option "Run All Tests With Coverage".



Duh.

IDEA rocks btw.