Showing posts with label spring-integration. Show all posts
Showing posts with label spring-integration. Show all posts

Tuesday, October 14, 2014

Spring Resolve Error : Element 'beans' cannot have character [children], because the type's content type is element-only.

I was working with Spring framework and get this error in the applicationcontext.xml (spring-integration-context.xml with Spring-Integration):

 Element 'beans' cannot have character [children], because the type's content type is element-only.

So something is wrong with my configuration. In fact, after reading carefully again the xml, I have found that I have added a wrong comment. So if you get this error, just check again your xml tags.

I get also this error :

cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'int-mqtt:outbound-channel-adapter'.
- schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/integration/mqtt/spring-integration-mqtt.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the 
document is not .

In fact the problem was that the given xsd address don't exists. By checking, I have found the right one:

http://www.springframework.org/schema/integration/mqtt/spring-integration-mqtt-4.0.xsd

Normally if you use maven you will not get this error.


Tuesday, May 6, 2014

Resolved : Logging in Jboss EAP 6 (JBoss AS7), Spring using Log4j

I was for a good time wondering why my Log4j is logging only the messages coming from my classes but not frameworks like  Spring, JDBC Template, CSveed. Every think was well configured, no error messages but I see framework messages only in the server.log.





So finally, I found the right steps to do.

Step 1:


Exclude Logging from JBoss. This previous article explains how to do.
So here is my jboss-deployment-structure.xml :


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<jboss-deployment-structure>
 <deployment>
 <!-- Add this line in the server lauch parameter : -Dorg.jboss.as.logging.per-deployment=false -->
  <exclusions>
   <module name="org.apache.log4j"/>
   <module name="org.apache.commons.logging"/>
              <module name="org.slf4j" />
             <module name="org.slf4j.impl" />
  </exclusions>   
 </deployment>
</jboss-deployment-structure>

Step 2:


Put you log4j.xml or log4j.properties in your classpath. In a Maven project, it should be under "\src\main\resources". Othrwhise, you can fix the classpath in the web.xml



1
2
3
4
5
6
7
8
<listener>
 <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

<context-param>
 <param-name>log4jConfigLocation</param-name>
 <param-value>classpath:/main/resources/META-INF/log4j.xml</param-value>
</context-param>


Step 3:

So Now, we need to add the required jar, AND Exclude some Jars. In the pom.xml, we need to exclude commons-logging from Spring-context jar and we need to add slf4j-api, slf4j-log4j12, jcl-over-slf4j, log4j.



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-context</artifactId>
 <version>${spring.version}</version>
 <exclusions>
  <exclusion>
   <artifactId>commons-logging</artifactId>
   <groupId>commons-logging</groupId>
  </exclusion>
 </exclusions>
</dependency>
<dependency>
 <groupId>org.slf4j</groupId>
 <artifactId>slf4j-api</artifactId>
 <version>${slf4j-log4j12.version}</version>
 <scope>runtime</scope>
</dependency>
<dependency>
 <groupId>org.slf4j</groupId>
 <artifactId>slf4j-log4j12</artifactId>
 <version>${slf4j-log4j12.version}</version>
 <scope>runtime</scope>
</dependency>
<dependency>
 <groupId>org.slf4j</groupId>
 <artifactId>jcl-over-slf4j</artifactId>
 <version>${slf4j-log4j12.version}</version>
 <scope>runtime</scope>
</dependency>
<dependency>
 <groupId>log4j</groupId>
 <artifactId>log4j</artifactId>
 <version>${log4j.version}</version>
</dependency>

So this step was the latest and Important step that I have discovered and which blocked my logging before.

Wednesday, April 30, 2014

Spring-Integration Resolve Error: one of inputChannelName or inputChannel is required

I have encountered one time this kind of error while deploying my  Web application based on Spring-Integration. The error were:

Caused by: java.lang.IllegalStateException: one of inputChannelName or inputChannel is required
at org.springframework.util.Assert.state(Assert.java:385) [spring-core-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.integration.config.ConsumerEndpointFactoryBean.initializeEndpoint(ConsumerEndpointFactoryBean.java:225) [spring-integration-core-4.0.0.M4.jar:]


In fact, I was managing errorChannel and my Service Activator responsible of handling the error messages was declared like this :


1
2
3
4
5
6
7
8
<int:channel id="errorChannel"/>

<int:service-activator id="errorHandler"
 input-channel="errorChannel" 
 method="handleError" 
 output-channel="nullChannel" 
 ref="errorHandler"/>
  

Although my input channel is declared, I get the error.
The problem was that I put the same name for the id and ref in the service-activator. So the error is caused by that and not because the input channel is not declared. So I have rectified my code :



1
2
3
4
5
6
7
8
<int:channel id="errorChannel"/>

<int:service-activator id="errorService"
   input-channel="errorChannel" 
   method="handleError" 
   output-channel="nullChannel" 
   ref="errorHandler"/>
  

Monday, April 21, 2014

Resolve Error: org/springframework/cglib/transform/impl/MemorySafeUndeclaredThrowableStrategy

I was working on a web application using Spring application.

When deploying my application on JBoss eap 6.2 Server, I got this Error :

Caused by: java.lang.NoClassDefFoundError: org/springframework/cglib/transform/impl/MemorySafeUndeclaredThrowableStrategy
at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:187) [spring-aop-3.2.8.RELEASE.jar:3.2.8.RELEASE]
...
Caused by: java.lang.ClassNotFoundException: org.springframework.cglib.transform.impl.MemorySafeUndeclaredThrowableStrategy from [Module "deployment.dbm.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197) [jboss-modules.jar:1.3.0.Final-redhat-2]

It was strange as I was using Spring Integration 3.0.2.RLEASE.

<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version> 3.0.2.RELEASE</version>
</dependency>

As I have then used the 4.0.0.M4 version of Spring-Integration. So I have decided to use it and once updated the web application was deploying with success.

<repositories>
<repository>
<id>spring-milestones</id>
<url>http://repo.springsource.org/libs-milestone/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>4.0.0.M4</version>
</dependency>

Monday, April 14, 2014

Spring Integration: Mqtt integration and Transformation of the mqtt Message from CSV to Java Bean using int:transformer


Working with Spring Integration, the use of Mqtt become very easy. In fact we need only to declare an int-mqtt:message-driven-channel-adapter in the applicationContext or spring-integration-context.xml

The code is :



The integration graph looks then like this :

So in order to convert the message coming from the broker (in CSV format), we need to call the method convert in the created CsvConverter class. In order to configure this using int:transformer, we need to declare a spel-function where we specify the class and called method, then we use the Id inside the spEL expression inside the transformer by putting # before the id of the converter.
so here is the code.

<int:spel-function id="csvConverter" class="org.converter.CsvConverter" method="convert(java.lang.String)" />

<int:transformer id="csvTransformer"
input-channel="mqttMessages"
output-channel="record" expression="#csvConverter(payload)" />

So now the transformer will call the CSVConverter which will convert the mqtt message payload from CSV to Java Bean (here Record).  The conversion is done using CSVeed framework which construct the given bean from the csv message.




Spring integration Channel Queue Get the current queue size (queue monitoring)

Using Spring-integration (version 4.0.0.M4), I was using a channel Queue where I Put Mqtt Messages. Multi-threads will take messages from that queue in order to process them.
I needed to know the size of the Queue and to Log it. Warning may be logger if the Queue is reaching some threshold.

So my code look like this:
In the spring-integration.xml  (or applicationcontext.xml), I have declared my channel having a Queue.


No in my Code, I use :

@Qualifier(value="mqttMessages")
@Autowired(required=false)
QueueChannel  queue;

So I get the channel by its Id. So now I can get the Channel Queue Size using :
queue.getQueueSize()

Thursday, April 3, 2014

Spring-integration-mqtt development and resolve MessageDispatchingException Dispatcher has no subscribers

I was using Spring-Integration-Mqtt in order to get messages from the mqtt Broker.


 

But while testing my application, I got this exception:

 org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:107) [spring-integration-core-4.0.0.M4.jar:]
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97) [spring-integration-core-4.0.0.M4.jar:]
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77) [spring-integration-core-4.0.0.M4.jar:]
... 10 more

Although the sent messages were received, I got the error. After some investigation, I have found that the problem don't come from spring-mqtt but from my side.
In fact by error, I have declared the service-activator and another bean  with the same Id.

So, If you have this error, make sure that your integration.xml (or applicationContext.xml) is correct.

Now, in order to take benefit from mqtt using Spring, you need to use spring-integration-mqtt and just configure few lines.

The Pom looks like this (if you have problem to locate the remote repository, see this post) :





And the intergration.xml:



Articles les plus consultés