Thursday, August 8, 2013

Problem

When you try to execute the maven comand mvn clean install shows the following message error: 
...
Exception in thread "main" Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"

Reason

There is not enough memory to execute all the steps necessary to the build (integration tests, start the jetty server etc.).

Solution

Creation of a environment variable MAVEN_OPTS with the value -Xmx1024m -XX:MaxPermSize=512m

Related Links

Maven throws “java.lang.OutOfMemoryError”

Setting Java heap space under Maven 2 on Windows

Problema

Ao tentar executar o comando mvn clean install apresentava o seguinte mensagem de erro (de forma reduzida):
...
Exception in thread "main" Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"

Motivo

Não existia memória suficiente para execução de todos os passos da construção (execução dos teste de integração, do servidor jetty etc.).

Solução

Criação da variável de ambiente MAVEN_OPTS com o valor -Xmx1024m -XX:MaxPermSize=512m

Links Relacionados

Maven throws “java.lang.OutOfMemoryError”

Setting Java heap space under Maven 2 on Windows


Thursday, September 27, 2012

No RequestContext for operation GWT

Problem

When trying to execute a Spring Roo Application that uses GWT it shows the following message error in console: No RequestContext for operation.


Attention 

This error also occurs  when using RequestFactory and the methods from the client side are not compatibles with the server side. Before trying what is explained here, make sure that the methods were created properly. More information about how to create the methods see this GWT documentation: https://developers.google.com/web-toolkit/doc/latest/DevGuideRequestFactory

Reason

Changes made in a subclass of RequestContext. Apparently it is related to compilation/build problems.

Solution

Recompile/rebuild the project. A simple rebuild did not work to me. Follow the steps that I think I did to resolve the problem. I am not sure because I do not simulated the error again. In the command line:


 mvn clean
 mvn compile
 mvn gwt:run

If not work, try in eclipse:

plugin do google->GWT Compile Projet

If not work try to recompile/rebuild in other ways.

No RequestContext for operation GWT





Problema

Ao tentar executar uma aplicação Spring Roo que utiliza o GWT apresenta a seguinte mensagem de erro no console: No RequestContext for operation.



Observação:

Este erro também acontece ao se utilizar RequestFactory e os métodos no lado cliente e no lado servidor não estejam compatíveis. Antes de tentar o explicado aqui certifique-se que os métodos foram criados corretamente. Maiores informações de como os métodos devem ser criados, ver a seguinte documentação do GWT: https://developers.google.com/web-toolkit/doc/latest/DevGuideRequestFactory?hl=pt-BR


Motivo

Modificações feita em classe filha de RequestContext. Aparentemente o projeto ficou inconsistente após modificações em classe filha de RequestContext. Está relacionado a problemas de build/compilação do projeto

Solução

Reconstruir o projeto. Uma simples rebuild não funcionou. Segue os passos que provavelmente efetuei para solucionar o problema. Não simulei o erro novamente. Na linha de comando execute:


 mvn clean
 mvn compile
 mvn gwt:run

Não tenho certeza se o passo seguinte também é necessário. No eclipse:

plugin do google->GWT Compile Projet

Se não funcionar tente recompilar/reconstruir de com outras sequências/formas.




Thursday, September 15, 2011

Spring Roo - Error: One or more exceptions caught, see full set in UmbrellaException#getCauses

Problem

When trying to save a entity in spring roo (using in the web tier gwt) it showed the following error message:

Error: One or more exceptions caught, see full set in UmbrellaException#getCauses

Reason

The declaration of an empty constructor was causing the problem. The roo cause was not identified.

Solution

Remove the constructor. In my case the code was changed from:

public class A {
transient B b;

A(){
this.b = getStub();
}
...
}

to:

public class A {
transient B b= getStub();
...
}



Spring Roo - Error: One or more exceptions caught, see full set in UmbrellaException#getCauses

Problema

Ao tentar salvar uma entidade no spring roo (usando na camada de visão o gwt) apresentou o seguinte problema.

Error: One or more exceptions caught, see full set in UmbrellaException#getCauses

Motivo

A declaração de um construtor vazio estava ocasionando o problema. Mas a causa raiz não foi identificada.

Solução

Remover o construtor vazio. No meu caso foi modificado o código de:

public class A {
transient B b;

A(){
this.b = getStub();
}
...
}

para:

public class A {
transient B b= getStub();
...
}

Wednesday, September 14, 2011

Mock/Stub EntityManager in Spring Roo

Problem

Trying to create unit test to the method persist from a class created in Spring Roo using a stub do the EntityManger that is passed in the constructor as follows:


public class ClassATest {
    @Test
    public void whenPersistShoulCallClassB() throws Exception {
        
        Mockery contexto = new Mockery();
        final ClassB classB = contexto.mock(ClassB.class);
        
        final ClassA classA = 
            new ClassA(getEntityManagerStub(), classB);

        contexto.checking(new Expectations() {{
            one(classB).doSomething(classA);

        }
    });
        classA.persist();
        
        contexto.assertIsSatisfied();
    }

    private EntityManager getEntityManagerStub() {
        return new EntityManager() {
            ...
        }
    }
}
Source from ClassA

public class ClassA {
...

    public ClassA(EntityManager entityManager, ClassB classB) {
        this.entityManager = entityManager;
        this.classB = classB;
    }



    @Transactional
    public void persist() {
        if (this.entityManager == null) this.entityManager = entityManager();
     
        this.entityManager.persist(this);
     
        classB.doSomething(this);
     
    }

...
 }


This test works inside Eclipse, but doesn´t when called by maven, as a result of  mvn jetty:run-exploded.

Reason

Probably Spring Roo is injecting the EntityManager just before the call to the constructor.

Solution

Use of setter injection, as follows:

public class ClassATest {
    @Test
    public void whenPersistShoulCallClassB() throws Exception {
        
        Mockery contexto = new Mockery();
        final ClassB classB = contexto.mock(ClassB.class);
        
        final ClassA classA =
            new ClassA(classB);
        classeA.setEntityManager(getEntityManagerStub());
        
        contexto.checking(new Expectations() {{
            one(classB).doSomething(classeA);

        }
    });
        classeA.persist();
        
        contexto.assertIsSatisfied();
    }

    private EntityManager getEntityManagerStub() {

        return new EntityManager() {
            ...
        }

    }
}


Código da ClasseA


public class ClasseA {
...

    public ClasseA(ClasseB classeB) {
        this.classeB = classeB;
    }


    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }




    @Transactional
    public void persist() {
        if (this.entityManager == null) this.entityManager = entityManager();
      
        this.entityManager.persist(this);
      
        classeB.doSomething(this);
      
    }

...
 }


There must be a more elegant solution that enables the utilization of construction injection. When I have time to research, I will post it.