Spring Integration gateway proxy bean for <int:gateway> not being created - java

I have a context as follows
<?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:int="http://www.springframework.org/schema/integration"
xmlns:int-amqp="http://www.springframework.org/schema/integration/amqp"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/amqp
http://www.springframework.org/schema/integration/amqp/spring-integration-amqp.xsd
http://www.springframework.org/schema/rabbit
http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<int:gateway id="fooGateway" service-interface="com.foo.FooGateway" />
</beans>
My gateway interface is as follows:
public interface FooGateway
{
public void foo(String foo);
}
This context is imported into another context but the fooGateway bean is never created by GatewayProxyFactoryBean.
I've set a breakpoint in GatewayProxyFactoryBean and I can see that it is not creating a proxy for this interface.

Turn on DEBUG logging for org.springframework; the bean creation process emits lots of information including when it reads particular configuration files.

Related

Invoke annotated aspect on all methods with a specific annotation

I have an application based on MVC and I want to log inputs/outputs from all my controllers.
Also, each of my controller methods is annotated with some specific annotation (eg: #MyControllerMethod).
I wrote an Annotated Aspect which works fine when I use the annotation (eg: LogRequestReply) from the aspect on my controller methods.
#Around("#annotation(com.xyz.LogRequestReply)")
public Object logRequestResponse(ProceedingJoinPoint pjp) throws Throwable {
#MyControllerMethod
#LogRequestReply /* It invokes my logRequestResponse method */
public ResponseEntity controllerMethodA(...) {}
However, I have a lot of controller methods and each with annotation MyControllerMethod.
Is there a way I can make my aspect annotation make work on all controller methods by default, such that each of the methods automatically calls my aspect logger and I can log the inputs/outputs?
Note:
I also looked into writing an interceptor extending from HandlerInterceptorAdapter. But it has its own complexity of being able to log request/response where the stream can only be read once.
Please suggest.
One option is to let the #Around definition less restrictive, add a restriction by package or something like that.
Internally you can check if this is a Controller by this check bellow and then print the request/response:
#Pointcut("within(com.mypackage.controller..*)")
private void inControllerPackage() {
}
#Around("inControllerPackage()")
public Object logRequestResponse(ProceedingJoinPoint pjp) throws Throwable {
if (pjp.getSignature().getDeclaringType().isAnnotationPresent(RestController.class)) {
...
}
Perhaps you should include the AOP in your controller-config
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-4.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">
<mvc:default-servlet-handler />
<context:component-scan base-package="com.xyz.controller" />
<aop:aspectj-autoproxy proxy-target-class="true" />
<bean id="whatever" class="com.xyz.controller.MyRestController"/>
</bean>
and in your Aspect you can also include the within combined with annotation:
#Around(value = "#within(com.xyz.server.annotation.MyAnnotationForController) || #annotation(com.xyz.server.annotation.MyAnnotationForController)")
public Object ownersTimeZone(ProceedingJoinPoint joinPoint) throws Throwable {
//whatever you need before
Object obj = joinPoint.proceed();
//whatever you need after
return obj;
}

Spring instance is not starting if one of the route-builder instance is failed

We are initializing the 2 different camel routes via spring context xml,
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
<routeBuilder ref="DescriptiveInfoRoute"/>
<routeBuilder ref="DescriptiveInfoRouteV2"/>
</camelContext>
</beans>
Both the routes are separate each will having it's input properties files to read the input values. (which makes 2 input files should be compulsory in order for both the routes to get initialized and starts the application). Now we got a new requirement one input file may or may not present. So is there any way in the spring to successfully start the application even if one the route was successfully initialized.
Thanks in advance,
Raghavan

Hadoop Spring multiple inputs and mappers in a job

How to specify multiple input files and their respective format in a Job tag?
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/hadoop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/hadoop http://www.springframework.org/schema/hadoop/spring-hadoop.xsd">
<context:property-placeholder location="hadoop.properties"/>
<configuration>
fs.default.name=${hd.fs}
yarn.resourcemanager.address=${hd.rm}
mapreduce.framework.name=${mr.fw}
</configuration>
<job id="wordcountJob"
input-path="${wordcount.input.path}"
output-path="${wordcount.output.path}"
mapper="org.apache.hadoop.examples.WordCount.TokenizerMapper"
reducer="org.apache.hadoop.examples.WordCount.IntSumReducer"/>
</beans:beans>
Like we can a specify in simple java program.
MultipleInputs.addInputPath(job, firstPath, FirstInputFormat.class, FirstMap.class);
MultipleInputs.addInputPath(job, sencondPath, SecondInputFormat.class, SecondMap.class);
I goggled a lot even i checked its xsd file. I did not find any attribute so how can we specify multiple inputs in a job?

What's wrong with my Spring Batch context?

Here is the context for Spring Batch:
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:b="http://www.springframework.org/schema/batch"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
<b:job id="bar" job-repository="my-job-repository">
<b:step id="foo">
<b:tasklet transaction-manager="my-transaction-manager">
<b:chunk reader="itemReader" writer="itemWriter"/>
<b:tasklet>
</b:step>
</b:job>
</beans:beans>
This is what Spring Batch says:
org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found
starting with element 'b:tasklet'. One of
'{"http://www.springframework.org/schema/batch":transaction-attributes,
"http://www.springframework.org/schema/batch":no-rollback-exception-classes,
"http://www.springframework.org/schema/batch":listeners,
"http://www.springframework.org/schema/beans":bean,
"http://www.springframework.org/schema/beans":ref}' is expected.
What's wrong with my XML?
ps. I'm using org.springframework.batch:spring-batch-core:2.1.7.RELEASE
You forgot to close the tasklet tag. probably copied from here and replicated the mistake

send message from java program to activemq using mule

Iam trying to send a string message from a java program to queue in ActiveMQ using MULE.Iam new to mule this is my mule-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-3.0.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/3.1/mule-jms.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd">
<jms:activemq-connector name="jmsConnector"
specification="1.1"
brokerURL="tcp://localhost:61616" />
<model name="jmsModel">
<service name="jmsService">
<inbound>
</inbound>
<outbound>
<pass-through-router>
<jms:outbound-endpoint queue="myQueue" />
</pass-through-router>
</outbound>
</service>
</model>
</mule>
and following is my java class
public class MuleCaller {
public static void main(String args[])
{
MuleCaller springCaller = new MuleCaller();
springCaller.runListner();
// spAsync.onMessage(null);
}
public void runListner(){
ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] {
"mule-config.xml"
});
}
What are the mistakes here, and iam not clear what to be written in
Thanks and regards
This is based on an older Mule version (3.1.2) and is using flow syntax
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/3.1/mule-jms.xsd">
<jms:activemq-connector name="jmsConnector"
brokerURL="tcp://localhost:61616"
specification="1.1"
maxRedelivery="30"
disableTemporaryReplyToDestinations="true"
createMultipleTransactedReceivers="true"
acknowledgementMode="CLIENT_ACKNOWLEDGE"
numberOfConcurrentTransactedReceivers="1"
persistentDelivery="true">
</jms:activemq-connector>
<flow name="inbound JMS service">
<jms:inbound-endpoint connector-ref="jmsConnector" queue="/jmsQueue" exchange-pattern="one-way">
<jms:transaction action="BEGIN_OR_JOIN"/>
</jms:inbound-endpoint>
<echo-component/>
</flow>
Using the ActiveMQ console you can create a queue called jmsQueue and manually send messages to it. A Mule process using the config above should print out whatever text is in the message you place on the queue.
Firstly, there is a connector-ref attribute of the jms:outbound-endpoint tag that you should likely use to specific to where outbound messages are to go.
like this:
<jms:outbound-endpoint connector-ref="jmsConnection" queue="myQueue" />
Secondly, without an inbound route, i've no clue what data is to be operated on by your service. try to go through some more of the example.

Categories