Camel integration with existing web application - apache-camel

I have a web application providing rest full service and another standalone (jar) application doing soap request response (using camel)
Can someone give me pointers to me for how to integrate the two applications
Specifically around how to kick camel routes when war file is deployed in tomcat, and how to re-run the routes when a specific HTTP request arrives.
I am using camel DSL (xml) and spring.
UPDATE 1:
I have followed this
Checked that web.xml has following lines:
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.mycompany.server.Binder</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Created a /WEB-INF/applicationContext.xml file and put all my routes and beans in it (btw I have beans.xml file as well in src/main/resources which is getting read by spring).
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
">
<!-- Camel applicationContext -->
<!-- this import needed to bring in CXF classes -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
<property name="location" value="classpath:${env}/my.properties" />
</bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:${env}/my.properties</value>
</list>
</property>
</bean>
<camel:camelContext id="camelContext">
<camel:contextScan/>
<camel:template id="serviceConsumerTemplate" defaultEndpoint="direct:start" />
<camel:threadPoolProfile defaultProfile="true" id="defaultThreadPool" poolSize="10" maxPoolSize="15" />
<camel:route id="serviceGetAccount">
<camel:from uri="timer://kickoff?repeatCount=1"/>
<camel:to uri="bean:serviceGetAccountProcessor" />
<camel:to uri="bean:serviceRequestHeaderCreator" />
<camel:to uri="cxf:bean:serviceGetAccountEndpoint?dataFormat=POJO" />
<camel:to uri="bean:serviceGetAccountResponseProcessor" />
</camel:route>
</camel:camelContext>
<bean id="serviceRequestHeaderCreator" class="com.mycompany.service.soap.SOARequestHeaderCreator">
<property name="serviceName" value="service" />
<property name="spnValue" value="${nj.spn}" />
<property name="securityTokenEnabled" value="true" />
<property name="sendingApplication" value="NJ SERVICE" />
<property name="serviceVersion" value="3.0.2" />
<property name="sendingHost" ref="localHostName"/>
</bean>
<cxf:cxfEndpoint id="serviceGetAccountEndpoint"
address="${request.endpoint}/serviceAccountRequestResponsePT"
endpointName="s:serviceAccountRequestResponsePort"
serviceName="s:serviceAccountRequestResponseHTTP"
xmlns:s="http://soa.mycompany.com/services/service/wsdl/v3"
serviceClass="com.mycompany.services.service.wsdl.v3.serviceAccountRequestResponsePT"
loggingFeatureEnabled="true">
</cxf:cxfEndpoint>
<bean id="serviceGetAccountProcessor" class="com.mycompany.service.serviceGetAccountProcessor"/>
<bean id="serviceGetAccountResponseProcessor" class="com.mycompany.service.serviceGetAccountResponseProcessor"/>
</beans>
Up the logging level of log4j.logger.org.apache.camel=DEBUG
However do not see any camel log lines of routes starting.
Update 2:
I was not doing mvn clean generate-sources.
Once I started doing mvn clean and rebuilding the war file, camel kicked in.

Seems your spring context does not really fire. Make sure it is!
There should be some Spring info log events telling you about this.
Try adding this:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

Related

Dispatcher servlet entry in web.xml is not allowing the login view (AngularJS) to load (404)

Doing SPA in AngularJS, when I remove the dispatcher servlet configuration
in web.xml the login view page appears, but if I place the dispatcher
servlet entry in web.xml login page won't load (appear) and shows HTTP 404.
I am not able to resolve this issue, should I add any extra configuration?
Technologies used are Spring REST not MVC, Spring Security and AngularJS.
Could please somebody give the solution?
Below are the files.
web.xml:
<web-app>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/test-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
test-servlet(dispatcher servlet).xml
<beans>
<context:annotation-config/>
<mvc:annotation-driven />
<context:component-scan base-package="com.org.simpro"/>
<jpa:repositories base-package="com.org.simpro"></jpa:repositories>
<bean id="hibernateJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
</bean>
<bean id="HelloWorldRestController" class="com.org.simpro.controller.HelloWorldRestController">
<property name="userService" ref="userServiceImpl"></property>
</bean>
<bean id= "userServiceImpl" class="com.org.simpro.service.UserServiceImpl">
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:#localhost:1521:xe"/>
<property name="username" value="HR"/>
<property name="password" value="hr"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"></property>
<property name="packagesToScan" value="com.org.simpro.model" />
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<!--
<prop key="javax.persistence.schema-generation.database.action">none</prop>
<prop key="hibernate.ejb.use_class_enhancer">true</prop>
//jpa hibernate properties
hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.format_sql=true
hibernate.hbm2ddl.auto=create-drop
hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
hibernate.show_sql=false
-->
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<import resource="security-context.xml"/>
</beans>

what does different tags in the below camel-CXF does

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
<!-- Defined the real JAXRS back end service -->
<jaxrs:server id="restService"
address="http://localhost:${CXFTestSupport.port2}/CxfRsRouterTest/rest"
staticSubresourceResolution="true">
<jaxrs:serviceBeans>
<ref bean="customerService"/>
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.json.JSONProvider"/>
<bean id="customerService" class="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService" />
<!-- Defined the server endpoint to create the cxf-rs consumer -->
<cxf:rsServer id="rsServer" address="http://localhost:${CXFTestSupport.port1}/CxfRsRouterTest/route"
serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"
loggingFeatureEnabled="true" loggingSizeLimit="20" skipFaultLogging="true">
<cxf:providers>
<ref bean="jsonProvider"/>
</cxf:providers>
</cxf:rsServer>
<!-- Defined the client endpoint to create the cxf-rs consumer -->
<cxf:rsClient id="rsClient" address="http://localhost:${CXFTestSupport.port2}/CxfRsRouterTest/rest"
serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"
loggingFeatureEnabled="true" skipFaultLogging="true">
<cxf:providers>
<ref bean="jsonProvider"/>
</cxf:providers>
</cxf:rsClient>
<!-- The camel route context -->
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<!-- Just need to ignoreDeleteMethodMessageBody -->
<from uri="cxfrs://bean://rsServer"/>
<to uri="log:body?level=INFO"/>
<to uri="cxfrs://bean://rsClient?ignoreDeleteMethodMessageBody=true"/>
</route>
</camelContext>
</beans>
In the Camel Docs they say that cxf:rsServer is a REST Consumer where as cxf:rsClient is a REST producer but the code seems to do vice-versa.
Also i want to understand the difference between Jaxrs tag and cxf:rsserver and cxf:rsclient tags.
jaxrs:server : create a basic endpoint service.
cxf:rsServer : Is a camel component to create REST endpoint. It will turn a request into a normal Java object.
cxf:rsClient : Do the opposite of rsServer, it turn a java object to a REST request.
<camelContext>
<route>
<from uri="cxfrs://bean://rsServer" />
<to uri="log:body?level=INFO" />
<to uri="cxfrs://bean://..=true" />
</route>
</camelContext>
If we take a look to the code example, we see that this is a proxy. We received a REST request, we log it and then forward it.
<cxf:rsServer id="rsServer" address="http://localhost:${CXFTestSupport.port1}/CxfRsRouterTest/route"
serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"
loggingFeatureEnabled="true" loggingSizeLimit="20" skipFaultLogging="true">
<cxf:providers>
<ref bean="jsonProvider"/>
</cxf:providers>
</cxf:rsServer>
<cxf:rsClient id="rsClient" address="http://localhost:${CXFTestSupport.port2}/CxfRsRouterTest/rest"
serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"
loggingFeatureEnabled="true" skipFaultLogging="true">
<cxf:providers>
<ref bean="jsonProvider"/>
</cxf:providers>
</cxf:rsClient>
Theses tags is for configure your cxf component outside from the camel-route.
Hope this help.

No mapping found for HTTP request with URI in DispatcherServlet with name [duplicate]

This question already has answers here:
Why does Spring MVC respond with a 404 and report "No mapping found for HTTP request with URI [...] in DispatcherServlet"?
(13 answers)
Closed 6 years ago.
I don't have any idea how i can link my css a js file
Please healp. I only get this request:
No mapping found for HTTP request with URI [/LiblaryProject/WebContent/js/script.js] in DispatcherServlet with name 'library'
library-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.myliblary.*" />
<bean id="UserDAO" class="com.myliblary.dao.UserDAOImpl">
<constructor-arg>
<ref bean="sessionFactory" />
</constructor-arg>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/liblarydb" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
<tx:annotation-driven />
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<mvc:annotation-driven/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/Pages/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
<servlet>
<servlet-name>library</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>library</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
and in my Home.jsp I have someting like:
<script src="<c:url value="WebContent/js/script.js" />"></script>
<link href="/css/custom.css" rel="stylesheet" type="text/css" />
By using the url-pattern / you have overriden the container`s default servlet. This is the servlet which serves static content from the root of the web application. To keep your mapping you need to configure the Spring default servlet handler. How this works is that requests for static resources now comes through Spring instead of default servlet. Spring will now lookup the container defualt servlet based on container type. To achieve this add the line below to your application config file
<mvc:defualt-servlet-handler/>
In your controller accepts requests such as "/" because in your web.xml this way. Try changing this:
Example:
Web.XML:
<servlet-mapping>
<servlet-name>library</servlet-name>
<url-pattern>.*htm</url-pattern>
</servlet-mapping>

Using JASYPT outside camel context

I am trying to decrypt properties using JASYPT in camel blueprint outside camel context like follows.
Is it not possible to use JASYPT + Property Component outside camel context?
I am using servciemix 5.0.0
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<cm:property-placeholder id="prop" persistent-id="mypersistent">
<!-- list some properties for this test -->
<cm:default-properties>
<cm:property name="cool.result" value="ENC(jU1ypXF709gpmOsJ2nKGgTbtd3oAs0n3rUNxEmMp2G8=)"/>
<cm:property name="jms.password" value="ENC(QhKlLI3eMKUhsUSPEWIRFw==)"/>
</cm:default-properties>
</cm:property-placeholder>
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
<property name="location" value="blueprint:prop"/>
<property name="propertiesParser" ref="jasypt"></property>
</bean>
<!-- define the jasypt properties parser with the given password to be used -->
<bean id="jasypt" class="org.apache.camel.component.jasypt.JasyptPropertiesParser">
<property name="password" value="secret"/>
</bean>
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://127.0.0.1:61616" />
<property name="userName" value="smx"/>
<property name="password" value="${jms.password}"/>
</bean>
</property>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<!-- define the camel properties placeholder, and let it leverage jasypt -->
<!--<propertyPlaceholder id="properties"
location="blueprint:prop"
propertiesParserRef="jasypt"/>-->
<route>
<from uri="file://inputfolder"/>
<log message="jms password {{jms.password}}"/>
<setBody><constant>Foo message</constant></setBody>
<to uri="jms:queue:default.inputchannel?jmsMessageType=Text&transferExchange=true"/>
<to uri="{{cool.result}}"/>
</route>
</camelContext>
It is giving me following error
ava.lang.SecurityException: User name [smx] or password is invalid.
at org.apache.activemq.security.JaasAuthenticationBroker.addConnection(JaasAuthenticationBroker.java:80)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.broker.MutableBrokerFilter.addConnection(MutableBrokerFilter.java:97)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.broker.TransportConnection.processAddConnection(TransportConnection.java:733)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.broker.jmx.ManagedTransportConnection.processAddConnection(ManagedTransportConnection.java:79)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.command.ConnectionInfo.visit(ConnectionInfo.java:139)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.broker.TransportConnection.service(TransportConnection.java:292)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.broker.TransportConnection$1.onCommand(TransportConnection.java:149)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.transport.MutexTransport.onCommand(MutexTransport.java:50)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.transport.WireFormatNegotiator.onCommand(WireFormatNegotiator.java:113)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.transport.AbstractInactivityMonitor.onCommand(AbstractInactivityMonitor.java:270)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.transport.TransportSupport.doConsume(TransportSupport.java:83)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTransport.java:214)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:196)[84:org.apache.activemq.activemq-osgi:5.9.0]
at java.lang.Thread.run(Thread.java:745)[:1.7.0_60]
You cannot use org.apache.camel.component.jasypt.JasyptPropertiesParser outside Apache Camel, or the <camelContext>.
For <bean> then its the blueprint propertyplaceholder that is responsible for setting up the properties. So you need some way to hook in jasypt into osgi blueprint property placeholder, eg this stuff
<cm:property-placeholder id="prop" persistent-id="mypersistent">
Like Ibsen said, blueprint property placeholder needs to be looked into. Here is a working blueprint solving the above mentioned issue
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
xmlns:enc="http://karaf.apache.org/xmlns/jasypt/v1.0.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<ext:property-placeholder id="prop">
<!-- list some properties for this test -->
<ext:default-properties>
<ext:property name="cool.result" value="ENC(jU1ypXF709gpmOsJ2nKGgTbtd3oAs0n3rUNxEmMp2G8=)"/>
<ext:property name="jms.password" value="ENC(QhKlLI3eMKUhsUSPEWIRFw==)"/>
</ext:default-properties>
</ext:property-placeholder>
<enc:property-placeholder>
<enc:encryptor class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
<property name="config">
<bean class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
<property name="algorithm" value="PBEWithMD5AndDES" />
<property name="passwordEnvName" value="CAMEL_ENCRYPTION_PASSWORD" />
</bean>
</property>
</enc:encryptor>
</enc:property-placeholder>
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
<property name="location" value="blueprint:prop"/>
<property name="propertiesParser" ref="jasypt"></property>
</bean>
<!-- define the jasypt properties parser with the given password to be used -->
<bean id="jasypt" class="org.apache.camel.component.jasypt.JasyptPropertiesParser">
<property name="password" value="secret"/>
</bean>
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://127.0.0.1:61616" />
<property name="userName" value="smx"/>
<property name="password" value="${jms.password}"/>
</bean>
</property>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<!-- define the camel properties placeholder, and let it leverage jasypt -->
<!--<propertyPlaceholder id="properties"
location="blueprint:prop"
propertiesParserRef="jasypt"/>-->
<route>
<from uri="file://inputfolder"/>
<log message="jms password {{jms.password}}"/>
<setBody><constant>Foo message</constant></setBody>
<to uri="jms:queue:default.inputchannel?jmsMessageType=Text&transferExchange=true"/>
<to uri="{{cool.result}}"/>
</route>
</camelContext>
</blueprint>

Bean is initialized with #Controller but #RequestMapping doesn't get called

Below is my setup for the new Spring 3 annotation based controller:
// dispatcher-servlet.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"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-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/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<!--
The index controller.
-->
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="index" />
<!-- Enables plain controllers -->
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="order" value="1" />
<property name="ignoreAcceptHeader" value="true" />
<property name="mediaTypes">
<map>
<entry key="xml" value="application/xml" />
<entry key="json" value="application/json" />
</map>
</property>
</bean>
<!-- Entity Property binding for webBindingInitializer -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="org.opevel.web.BindingInitializer" />
</property>
</bean>
<context:component-scan base-package="org.opevel.web"/>
</beans>
// web.xml
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
<url-pattern>/auth</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
// Spring controller
package org.opevel.web;
#Controller
public class LoginGoogleController {
private static final Logger log = Logger.getLogger(LoginGoogleController.class.getName());
public LoginGoogleController() {
log.info("constructing LoginGoogleController");
}
#RequestMapping(value="/auth", method=RequestMethod.GET)
public String doGet(HttpServletRequest request, HttpServletResponse response) throws Exception {
return "redirect:index";
}
}
When I navigate to /auth, I get a 404. When I try to register the bean in the applicationContext like this:
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/auth">GoogleLoginService</prop>
</props>
</property>
<bean id="GoogleLoginService" class="org.opevel.web.LoginGoogleController" />
I get a BeanException stating that the bean is already registered at /logingoogle through ControllerClassNamehandlerMapping. I am using Spring 3.0.2 on Google App Engine.
Will appreciate some help.
I was able to fix this my removing both the ControllerClassNameHandlerMapping and SimpleUrlHandlerMapping beans from the application context file.
Regards y'all
That error is telling you that you don't need <bean id="GoogleLoginService" class="org.opevel.web.LoginGoogleController" /> in your applicationContext. Also you don't need <bean id="urlMapping">
#Controller creates a bean for you and #RequestMapping creates the URL mapping.

Resources