upgrading Apache Camel 2 to 3, where did Main.setApplicationContextUri() method go? - java

I have an old codebase that uses camel 2.something. We have to upgrade to camel 3.14 for Nexus-flagged security issues. I'm going through the Upgrade Camel 2 to 3 docs. I see that Main moved packages, which I did, but now I'm getting an error that Main.setApplicationContextUri("camel-context.xml") is no longer a method on Main. I can't find it, nor a replacement in the upgrade docs.
What am I missing?
Also, if there's a way to do a simple camel config via beans and annotations instead of xml, I'd love a pointer to that. I'm also running into an issue parsing the camel-context.xml, so if I can get rid of that whole mess, I'd love to.
We are using Java 8 so I think the latest that works with that is Camel 3.14.6 so that's what I'm trying.
Here's our camel-context.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util" xmlns:cxf="http://cxf.apache.org/core"
xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:http="http://cxf.apache.org/transports/http/configuration"
xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:camel="http://camel.apache.org/schema/spring"
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://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
<!-- ================================== -->
<!-- Define camel context -->
<!-- ================================== -->
<camel:camelContext id="camel" trace="false">
<camel:propertyPlaceholder id="queriesConfig" location="lib/queries.properties" />
<!-- Location for route scan -->
<camel:package>com.blah.listener</camel:package>
</camel:camelContext>
<!-- configure the Camel SQL component to use the JDBC data source -->
<bean id="sqlComponent" class="org.apache.camel.component.sql.SqlComponent">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="bean1" class="com.foo.OurThing" />
<bean id="bean2" class="com.bar.OtherThing" />
Edit: Just found this. Are we supposed to convert camel-context.xml to application.properties? We also have an app-context.xml for basic Spring configuration, and there's a reference to the camel-context.xml there. I wonder if we replace camel-context.xml with application.properties, what to do with this reference? Just remove it, or change it?

Related

primary attribute not allowed inside bean tag

I have tried to set the default validation message file to messages.properties file. It worked. However, for some reason the primary attribute inside validator bean is marked red in the applicationContext.xml file.
The error message, "Attribute primary is not allowed here".
I have tried to find the reason of this in many resources and cross-checked many possibilities, but everything seems fine with my configuration.
I use Intellij Idea, Spring version - 3.2.17 RELEASE, Hibernate version - 3.6.10.Final.
Can anyone explain the reason ?
applicationContext.xml -
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://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/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd"
default-autowire="byName">
<context:component-scan base-package="com.test.leavemanagement"/>
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages"/>
</bean>
<mvc:annotation-driven validator="validator"/>
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" primary="true">
<property name="validationMessageSource" ref="messageSource"/>
</bean>
</beans>

Having trouble setting up my pom.xml correctly to pass a variable to an XML file

So I'm fumbling my way through this, it's a project that I'm taking the reigns of because nobody else can (original dev left, nobody else with any experience to do it) but I'm trying my hardest here. My apologies if what I have already makes no sense, I'm not a developer really.
So I have my pom.xml file, and in the resources section I have it pulling values from some resource directories, depending on the profile used:
<resources>
<resource>
<directory>src/main/resources/${profile.name}</directory>
<includes>
<include>../../webapp/WEB-INF/applicationContext.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
One line in src/main/resources/test/application.properties is the following:
app.api.databaseUrl=jdbc:mysql://databasehostname:3306/testDatabase
You'll notice up above that I tried getting it to place this value in my applicationContext.xml file, so that a different database can be used for test and prod profiles - but that piece isn't working. It seems to be pulling all the values from application.properties, but I can't figure out how to put those in applicationContext.xml. Here's what I have in that file:
<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:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="${app.api.databaseUrl}"/>
<property name="username" value="username" />
<property name="password" value="password" />
</bean>
<bean id="cartDAO" class="com.crown.apps.cart.dao.impl.CartDAOImpl">
<property name="dataSource" ref="dataSource" />
</bean>
When building the war file, "${app.api.databaseUrl}" does not change to the correct value, it stays the same.
I'm sure I'm doing something completely and utterly wrong, I'm sure my pom.xml setup is wrong but I don't know where to begin fixing it. Any advice?
Looks like you are using Spring 3.x, so please check this article. Basically, you have to specify the location of properties file in your beans configuration XML: <context:property-placeholder location="classpath:foo.properties" />

spring 4.0.2 schema error

I am trying to upgrade my spring 3.4 application to spring 4.0.2
I imported all the spring-4.0.2 jar files but am getting errors in the dispatcher-servlet.xml
if I use this code, I get Referenced file contains errors (http://www.springframework.org/schema/beans/spring-beans-4.0.xsd)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
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-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<!-- automatic scan base folder to detect controllers -->
<context:component-scan base-package="com.shaw.csdss"/>
<mvc:annotation-driven />
<!-- This file will contain the view name mappings to the jsp -->
<bean id = "jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix"><value>/</value></property>
<property name="suffix"><value>.jsp</value></property>
<property name="order" value="1" />
</bean>
</beans>
I tried to remove the -4.0 from the xsd references but I get same error on spring-mvc-xsd now.
I even tried to discard everything and just copy the xml from the spring reference documentation as follow
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven />
<bean id = "jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix"><value>/</value></property>
<property name="suffix"><value>.jsp</value></property>
<property name="order" value="1" />
</bean>
</beans>
but with this simple file I get error on
cvc-complex-type.2.4.c: the matching wildcard is strict, but no declaration can be found of element 'mvcannotation-driven
Any example I take from spring4.0 reference document, gives me same error.
is this a problem with spring4.0.2 or am I missing something?
Thank you for your help

Spring XWSS Message Signing

I am currently working on a client interface which connects to a third party web service.
This 3rd party web service requires that all messages sent to them are signed with the client's private key.
I am attempting to implement this using Spring's XWSS support as documented here:
http://docs.spring.io/spring-ws/site/reference/html/security.html
The issue I'm facing is that the messages I send out are not being signed despite what as far as I can tell is a correct configuration.
My applicationContext.xml is as follows:
<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:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
^
|
|
B
E
A
N
S
|
|
V
<bean id="wsSecurityInterceptor"
class="org.springframework.ws.soap.security.xwss.XwsSecurityInterceptor">
<property name="policyConfiguration" value="classpath:securityPolicy.xml"/>
<property name="callbackHandlers">
<list>
<ref bean="keyStoreHandler"/>
</list>
</property>
</bean>
<bean id="keyStoreHandler"
class="org.springframework.ws.soap.security.xwss.callback.KeyStoreCallbackHandler">
<property name="keyStore" ref="keyStore"/>
<property name="privateKeyPassword" value="ckpass"/>
</bean>
<bean id="keyStore"
class="org.springframework.ws.soap.security.support.KeyStoreFactoryBean">
<property name="location" value="file:///C:/path/to/security/clientKeystore.jks"/>
<property name="password" value="cspass"/>
</bean>
</beans>
My securityPolicy.xml consists of the following:
<xwss:SecurityConfiguration dumpMessages="true" xmlns:xwss="http://java.sun.com/xml/ns/xwss/config">
<xwss:Sign>
</xwss:Sign>
</xwss:SecurityConfiguration>
However there are no messages being dumped to standard output when I send messages out and the messages I send out do not contain the signature elements I would expect.
I suspect I am missing something quite trivial here however I cannot tell what that is for the life of me!
In your configuration you only configure the interceptor. Currently it takes up only memory just hanging around and doing nothing. You should hook this interceptor up to your WebServiceTemplate (or class that extends WebServiceGatewaySupport.
Assuming you have one of those you should have something like this.
<bean id="yourClient" class="YourClientClass">
<property name="interceptors" ref="wsSecurityInterceptor"/>
// Your other properties here
</bean>
This wired your interceptor to the WebServiceTemplate used, without it the interceptor is basically not used.

MongoDB replication with Spring

I configured Spring with MongoDB on my local machine, without replication, and everything works fine.
I also have a replica set that works fine.
Now I tried to add the replica set, but the reads/writes still go to my local machine!
This is my configuration, host1-3 are virtual machines:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd">
<mongo:repositories base-package="my.repositories" />
<mongo:mongo replica-set="host1:27017,host2:27017,host3:27017" />
<mongo:db-factory dbname="my_db" />
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
</bean>
Anyone has ideas/suggestions? Thanks!
Edit:
Ok so I found the problem, just needed to add mongo-ref to the factory. So the correct configuration is:
<mongo:mongo id="mongo" replica-set="host1:27017,host2:27017,host3:27017" />
<mongo:db-factory dbname="my_db" mongo-ref="mongo" />
Ok so I found the problem, just needed to add mongo-ref to the factory. So the correct configuration is:
<mongo:mongo id="mongo" replica-set="host1:27017,host2:27017,host3:27017">
<mongo:db-factory dbname="my_db" mongo-ref="mongo" />
Writes will always go to the primary. Reads go to the primary by default unless you change the Read Preference in your use of the Java driver.

Categories