How to set timeout on burlap protocol caucho’s implementation

October 29, 2011 Leave a comment

Burlap can be easily used with spring, but with caucho’s implementation. actually it doesn’t seem possible to set the connection timeout.
The only method i’ve found is to set the default timeout for jvm’s http client with these jvm’s properties

Categories: My Work

How to generate serialVersionUID with intellij idea (no external plugin needed)

September 16, 2011 Leave a comment

Select the Serializzation issues inspections:

Then use the idea tools to generate the field (click on the lamp)

Categories: My Work

How to log transaction informations in jboss 4.2.3.GA

September 2, 2011 2 comments

You have to change two files:

1: jbossjta-properties.xml (for logging more info at arjuna level)

from:

...
<property name="com.arjuna.common.util.logging.DebugLevel"
            type="System" value="0x00000000">
...

to:

...
<property name="com.arjuna.common.util.logging.DebugLevel"
            type="System" value="0xffffffff">
...

2: jboss-log4j.xml (to configure log4j) adding the following lines

...
   <category name="com.arjuna">
      <priority value="DEBUG"/>
   </category>

  <category name="org.jboss.tm">
      <priority value="DEBUG"/>
   </category>

  <category name="org.jboss.resource">
      <priority value="TRACE"/>
   </category>
...

to filter log and show which resources was enlisted in a specific transaction, we can use a command like this:
grep -a “7f000101:c2ab:4e65eaa4:1eb” server.log | grep -a Enlisting

Categories: My Work

How to extends a jar packaged maven plugin

I’ve used this plugin to extend dependency plugin’s copy-dependency goal.

This is my mojo

/**
 * @extendsPlugin dependency
 * @extendsGoal copy-dependencies
 * @goal deploy-env-lib
 * @requiresDependencyResolution test
 * @aggregator
 */
public class DeployEnvironmentLibMojo extends CopyDependenciesMojo{

    /**
     * La home di JBoss.
     *
     * @parameter expression="${jboss.home}"
     * @required
     */
    protected String jbossHome;

    /**
     * Il nome del server JBoss.
     *
     * @parameter expression="${jboss.serverName}"
     * @required
     */
    protected String jbossServerName;

    /**
     * POM
     *
     * @parameter expression="${project}"
     * @readonly
     * @required
     */
    protected MavenProject project;

    public void execute() throws MojoExecutionException {
        getLog().info("------------------------------------------------------------------------");
        getLog().info("DEPLOY-ENV-LIB");
        getLog().info("------------------------------------------------------------------------");
        super.outputDirectory=this.outputDirectory;
        super.overWriteReleases=this.overWriteReleases;
        super.overWriteSnapshots=this.overWriteSnapshots;
        super.overWriteIfNewer=this.overWriteIfNewer;
        super.includeScope=this.includeScope;
        super.excludeGroupIds=this.excludeGroupIds;
        super.excludeArtifactIds=this.excludeArtifactIds;
        super.project=this.project;
        super.repositoryFactory=this.repositoryFactory;
        super.installer=this.installer;
        super.factory=this.factory;
        super.resolver=this.resolver;
        super.remoteRepos=this.remoteRepos;
        super.copyPom=this.copyPom;
        super.execute();

    }
}

My mojo extends dependency plugin’s CopyDependenciesMojo, inheriting its properties.
These declarations:

* @extendsPlugin dependency
* @extendsGoal copy-dependencies

are maven-inherit-plugin specific. With the help of these instructions maven-inherit-plugin merges the plugin.xml files exposing inherited properties.

Without this code

super.outputDirectory=this.outputDirectory;
super.overWriteReleases=this.overWriteReleases;
super.overWriteSnapshots=this.overWriteSnapshots;
super.overWriteIfNewer=this.overWriteIfNewer;
super.includeScope=this.includeScope;
super.excludeGroupIds=this.excludeGroupIds;
super.excludeArtifactIds=this.excludeArtifactIds;
super.project=this.project;
super.repositoryFactory=this.repositoryFactory;
super.installer=this.installer;
super.factory=this.factory;
super.resolver=this.resolver;
super.remoteRepos=this.remoteRepos;
super.copyPom=this.copyPom;

the program won’t work correctly. It seems like the parameters injection doesn’t work correctly with superclasses…

These are the new entries in my plugin pom:

   <build>
        <plugins>
            <plugin>
                <groupId>org.ops4j</groupId>
                <artifactId>maven-inherit-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>inherit</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <type>maven-plugin</type>
            <version>2.2</version>
        </dependency>
    </dependencies>

Categories: My Work

How to recursively search a pattern with GREP in many files with the same name

November 5, 2010 Leave a comment

rgrep -iH –include=filename ‘pattern’ .

N.B. the trailing point is important!

Categories: My Work Tags:

How exclude test execution with maven release plugin

October 13, 2010 Leave a comment

mvn release:prepare -Darguments=”-Dmaven.test.skip=true”

Categories: My Work Tags:

How to send a tx transactional jms message from a local jboss to a remote jboss (version 4.2.3.GA)

September 1, 2010 Leave a comment

To send a jms message from a jboss to a remote jboss destination you have to configure a new JMSResourceAdapter.

This code does not work!

    Properties properties = new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
    properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
    properties.put(Context.PROVIDER_URL, "jnp://192.168.1.131.129:1299");
    InitialContext jndiContext = new InitialContext(properties);

    //[2] Look up connection factory and queue.
    ConnectionFactory connectionFactory = (ConnectionFactory)jndiContext.lookup("UIL2XAConnectionFactory");
    Queue queue = (Queue)jndiContext.lookup("Queue/DataTransferQueue");

This code correctly sends the message but the tx transactional behaviour is not implemented

You have to:
1. deploy a new JMSResourceAdapter duplicating the file hajndi-jms-ds.xml e.g. remote-jms-ds.xml:

<?xml version="1.0" encoding="UTF-8"?>

<connection-factories>
 
  <!-- ==================================================================== -->
  <!-- JMS Stuff                                                            -->
  <!-- ==================================================================== -->

  <!-- The JMS provider loader -->
  <mbean code="org.jboss.jms.jndi.JMSProviderLoader"
	 name="jboss.mq:service=JMSProviderLoader,name=RemoteJMSProvider">
    <attribute name="ProviderName">RemoteJMSProvider</attribute>
    <attribute name="ProviderAdapterClass">
      org.jboss.jms.jndi.JNDIProviderAdapter
    </attribute>
    <!-- The combined connection factory -->
    <attribute name="FactoryRef">XAConnectionFactory</attribute>
    <!-- The queue connection factory -->
    <attribute name="QueueFactoryRef">XAConnectionFactory</attribute>
    <!-- The topic factory -->
    <attribute name="TopicFactoryRef">XAConnectionFactory</attribute>
    <!-- Access JMS via HAJNDI -->
    <attribute name="Properties">
       java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
       java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
       java.naming.provider.url=10.4.0.7:1100
    </attribute>
  </mbean>


  <!-- JMS XA Resource adapter, use this to get transacted JMS in beans -->
  <tx-connection-factory>
    <jndi-name>RemoteJmsXA</jndi-name>
    <xa-transaction/>
    <rar-name>jms-ra.rar</rar-name>
    <connection-definition>org.jboss.resource.adapter.jms.JmsConnectionFactory</connection-definition>
    <config-property name="SessionDefaultType" type="java.lang.String">javax.jms.Topic</config-property>
    <config-property name="JmsProviderAdapterJNDI" type="java.lang.String">java:/RemoteJMSProvider</config-property>
    <max-pool-size>20</max-pool-size>
    <!--security-domain-and-application>JmsXARealm</security-domain-and-application-->
  </tx-connection-factory>
</connection-factories>

2. now you can get the new connection factory in the local jndi (really getting the adapter pointing the remote connection factory) and then get the remote destination via a remote jndi context.

    Properties properties = new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
    properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
    properties.put(Context.PROVIDER_URL, "jnp://10.4.0.7:1100");
    InitialContext localJndiContext = new InitialContext();
    InitialContext remoteJndiContext = new InitialContext(properties);

    //[2] Look up connection factory and queue.
    ConnectionFactory connectionFactory = (ConnectionFactory)localJndiContext.lookup("java:/RemoteJmsXA");
    Queue queue = (Queue)remoteJndiContext.lookup("Queue/DataTransferQueue");
    //now you can send a jms message and the real sending will be done at tx commit time.
     Connection  connection = connectionFactory.createConnection();
     Session session = connection.createSession();
     MessageProducer  sender = session.createProducer(queue);

references:
HowDoIConfigureTheJMSResourceAdapterToUseARemoteConnectionFactory
JBossMQHAOverview

Categories: My Work Tags: , ,

How to send a jms message to an activemq queue with camel and spring

these are the necessary dependencies for using camel to send a message to an activemq queue…

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
                <version>${spring.version}</version>
            </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jaxb</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jms</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-camel</artifactId>
            <version>${activemq.version}</version>
        </dependency>       

In this spring context i’m defining a camel context with the endpoint pointing to the queue…

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 	
	xmlns:context="http://www.springframework.org/schema/context"
     xmlns:camel="http://camel.apache.org/schema/spring"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
	 http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
 

<!-- my activemq component -->
    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="brokerURL" value="tcp://myserver:61616"/>
        <property name="transacted" value="true"/>        
        <property name="usePooledConnection" value="true"/>
    </bean>

<!-- this is the camel context -->
    <camel:camelContext id="myCamelContext" trace="true">
        <camel:endpoint id="myQueue" uri="activemq:queue:myqueue/myService?jmsMessageType=Text"/>
        <camel:dataFormats>
            <camel:jaxb id="JaxbContext" contextPath="it.germanogiudici.types.mymessagetype.v1_0" prettyPrint="true"/>
        </camel:dataFormats>
    </camel:camelContext>
</beans>

Finally here I’m using the ProducerTemplate to send the message…

//here I'm using an helper class to retrieve the camel context bean from spring context
                CamelContext camelContext = (CamelContext) SpringApplicationContextHelper.getInstance().getBean("myCamelContext");
                Endpoint myQueue = (Endpoint) SpringApplicationContextHelper.getInstance().getBean("myQueue");
                logProcess.debug("endpoint a cui spedire l'evento: " + myQueue.getEndpointUri());
                ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
                producerTemplate.sendBody(myQueue, depositEvent);

Categories: My Work Tags: , , ,

How to sign and verify a message using spring

February 19, 2010 Leave a comment

You can use spring-crypto-utils a wrapper around java’s native cryptography API. I’m very proud of my little collaboration to this project, hosted by Mirko Caserta.

With real little configuration…

    <crypt:keystore id="keystore" location="classpath:keystore.jks" password="password"/>
    <crypt:privateKey id="privateKey" keystore-ref="keystore" alias="test" password="password"/>
    <crypt:signer id="signer" privateKey-ref="privateKey" algorithm="SHA1withRSA"/>

…you can sign a message using a code like this:

public class MyBusinessSigner {

    @Autowired
    private Signer signer;

    public void myBusinessMethod() {
        // I am not a very useful business method but
        // I can do digital signatures!
        byte[] signature = signer.sign(messageToBeTrusted);
    }
}

Categories: My Work Tags: , ,

How to delete recursively nested directories in Linux by name

February 5, 2010 Leave a comment
find . -type d -name NOME-DIRECTORY -exec rm -rf {} \;

thanks to Mirko…

Categories: My Work Tags:
Follow

Get every new post delivered to your Inbox.