In Spring DSL, How can Camel's HTTP4 component be configured to use NTLM authentication?
I am able to configure Camel's HTTP component to use NTLM authentication, successfully, using this Spring DSL configuration:
<!-- Works: HTTP (3) Configuration -->
<bean id="httpConfig" class="org.apache.camel.component.http.HttpConfiguration">
<property name="authMethod" value="NTLM"/>
<property name="authHost" value="my-active-directory-host"/>
<property name="authDomain" value="my-ad-domain"/>
<property name="authUsername" value="my-username"/>
<property name="authPassword" value="my-password"/>
</bean>
<!-- Works: HTTP (3) Component-->
<bean id="httpmw" class="org.apache.camel.component.http.HttpComponent">
<property name="camelContext" ref="camel"/>
<property name="httpConfiguration" ref="httpConfig"/>
</bean>
But, my best attempt to configure the HTTP4 component fails because I do not know how to set the httpClientConfiguration of the HttpComponent. Or perhaps, there is another way to wire the HTTP4 component?
<!-- Works: HTTP4 Configuration -->
<bean id="httpClientConfig" class="org.apache.camel.component.http.NTLMAuthenticationHttpClientConfigurer">
<constructor-arg name="proxy" value="false"/>
<constructor-arg name="user" value="my-username"/>
<constructor-arg name="pwd" value="my-password"/>
<constructor-arg name="domain" value="my-ad-domain"/>
<constructor-arg name="host" value="my-active-directory-host"/>
</bean>
<!-- Does not work: HTTP4 Component, exception
Caused by: org.springframework.beans.NotWritablePropertyException:
Invalid property 'httpClientConfiguration' of bean class [org.apache.camel.component.http4.HttpComponent]:
Bean property 'httpClientConfiguration' is not writable or has an invalid setter method.
Does the parameter type of the setter match the return type of the getter?
-->
<bean id="http4mw" class="org.apache.camel.component.http4.HttpComponent">
<property name="camelContext" ref="camel"/>
<property name="httpClientConfiguration" ref="httpClientConfig"/>
</bean>
Related
We are using Spring Cache Manager with spring-data-redis 1.5.2. These days we want to upgrade spring-data-redis to latest release i.e:1.6.2.RELEASE.
For some weird reason everything works good with 1.5.2 but when upgrading to 1.6.2 we get
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'cacheManager' defined in ServletContext
resource [/WEB-INF/spring-cache.xml]: Unsatisfied dependency
expressed through constructor argument with index 0 of type
[org.springframework.data.redis.core.RedisOperations]: Ambiguous
constructor argument types - did you specify the correct bean
references as constructor arguments?
This message seems like a mistake as redisTemplate is RedisTemplate which implements RedisOperations.
Any idea how to solve it?
P.S
note that when removing the cache configuration the 1.6.2 version seems to work good. So the issue is with the cache.
Configuration
web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-redis.xml
/WEB-INF/spring-cache.xml
</param-value>
</context-param>
spring-redis.xml
<context:annotation-config />
<bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration" />
<bean
class="org.springframework.security.web.session.HttpSessionEventPublisher" />
<!-- end of seesion managment configuration -->
<bean id="redisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="port" value="${app.redis.port}" />
<property name="hostName" value="${app.redis.hostname}" />
<property name="password" value="${app.redis.password}" />
<property name="usePool" value="true" />
</bean>
<!-- for publishing string over redis channels -->
<bean id="stringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="redisConnectionFactory" />
</bean>
<!-- for storing object into redis key,value -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="redisConnectionFactory" />
</bean>
spring-cache.xml
<!-- This file must load after spring-redis.xml -->
<cache:annotation-driven />
<!-- declare Redis Cache Manager -->
<bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager"
c:template-ref="redisTemplate" />
</beans>
It seems the reason for this bug is that RedisCacheManager has two constructors. Both of them has RedisOperations as parameter. Forsome reason Spring couldnot understand its related to the first constructor and not to the second one. a work around is mention constructor-arg index
<bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager">
<constructor-arg index="0" ref="redisTemplate"></constructor-arg>
</bean>
While upgrading from Spring Data Redis 1.5.2.RELEASE to 1.6.2.RELEASE, we need to use the below config for RedisCacheManager. Previous releases were using redis-template-ref instead of redis-operations-ref.
<beans:bean id='cacheManager'
class='org.springframework.data.redis.cache.RedisCacheManager'
c:redis-operations-ref='redisTemplate'>
</beans:bean>
This is an old question, but for those who reach this page.
<bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager" factory-method="create" c:connection-factory-ref="jedisConnectionFactory" p:transaction-aware="true" />
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" p:connection-factory-ref="jedisConnectionFactory" />
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:host-name="${cache.redis.host}" p:port="${cache.redis.port}" p:use-pool="true">
<constructor-arg ref="jedisPoolConfig"></constructor-arg>
</bean>
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig" p:maxTotal="${cache.redis.pool.maxTotal}" p:maxIdle="${cache.redis.pool.maxIdle}" p:maxWaitMillis="${cache.redis.pool.maxWaitMillis}" p:testOnBorrow="true" />
I am using Camel-HTTP4 2.10.4 component for calling remote REST services from my application. This communication requires SSL configuration. I successfully tested my configuration with hard coded values for resource and password.
Now I need to configure the same using camel's Property-Placeholder. I am using nested properties in spring configuration. ex:
${${env:${default.fallback.env}}.path.to.keystore}
I followed Using PropertyPlaceholder and defined
<bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
<property name="locations">
<list>
<ref bean="confgPath1" />
<ref bean="configPath2" />
</list>
</property>
</bean>
and sslContextParameters as follows
<camel:sslContextParameters id="sslContextParameters">
<camel:trustManagers>
<camel:keyStore resource="{{{{default.fallback.env}}.keystore.file}}"
password="{{{{default.fallback.env}}.keystore.password}}" />
</camel:trustManagers>
<camel:keyManagers keyPassword="{{{{default.fallback.env}}.keystore.password}}">
<camel:keyStore resource="{{{{default.fallback.env}}.keystore.file}}"
password="{{{{default.fallback.env}}.keystore.password}}" />
</camel:keyManagers>
<camel:clientParameters>
<camel:cipherSuitesFilter>
<camel:include>.*</camel:include>
</camel:cipherSuitesFilter>
</camel:clientParameters>
</camel:sslContextParameters>
My application loads spring context successfully at start up. But after hitting the endpoint I am getting Error:
Failed to resolve endpoint <<My remote service URL>> due to: Error parsing property value: {{{{default.fallback.env}}.keystore.password}}.
I am able to use Camel's property placeholder for simple properties. For ex
{{default.fallback.env}}
But, when I try to use nested properties it is giving me above specified Error. Help me find out the proper way to solve this.
Current camel property component doesn't support the nested properties, so I just fill a JIRA for it.
As Camel property doesn't support the nested properties in the first place, you can define just define the property file like this, and set the environment from the system property and use {{someproperty}} to reference the properties.
someproperty={{{{environment}}.someproperty}}
# LOCAL SERVER
junit.someproperty=junit
# LOCAL SERVER
local.someproperty=local
# TEST
test.someproperty=test
# PROD
prod.someproperty=prod
I just used the Spring way to create Camel SSL configuration:
<bean id="sslContextParameters" class="org.apache.camel.util.jsse.SSLContextParameters">
<property name="keyManagers">
<bean class="org.apache.camel.util.jsse.KeyManagersParameters">
<property name="keyPassword" value="${dsi.key.password}" />
<property name="keyStore">
<bean class="org.apache.camel.util.jsse.KeyStoreParameters">
<property name="resource" value="${dsi.keystore.file}" />
<property name="type" value="JKS" />
<property name="password" value="${dsi.keystore.password}" />
<property name="camelContext" ref="camelContext" />
</bean>
</property>
<property name="camelContext" ref="camelContext" />
</bean>
</property>
<property name="camelContext" ref="camelContext" />
</bean>
I believe with Spring's property resolver you can achieve more and you do not need to use the custom bridge resolver.
I am using Spring WebServiceTemplate in my client side code to send request to an existing 3rd party web service.
<bean id="vehicleQuotationWebServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<constructor-arg ref="messageFactory"/>
<property name="marshaller" ref="vehicleQuotationMarshaller" />
<property name="unmarshaller" ref="vehicleQuotationMarshaller" />
<property name="faultMessageResolver" ref="vehicleServiceClientFaultMessageResolver" />
<property name="defaultUri" value="http://localhost:8080/quote/endpoints"/>
</bean>
Everything was working fine until they added security check from the server side. Right now, in order to pass the server side security authenication, I need to pass some values from a cookie to the server. This I can do easily in SoapUI by modifying the http header (adding the cookie's value there), but my question is how can I do it in Java code with the Spring's WebServiceTemplate?
You can extend the WebServiceTemplate or in a more easy way use a custom sender who extends Spring's
org.springframework.ws.transport.http.CommonsHttpMessageSender
and set in your bean definition
<bean id="vehicleQuotationWebServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<constructor-arg ref="messageFactory"/>
<property name="marshaller" ref="vehicleQuotationMarshaller" />
<property name="unmarshaller" ref="vehicleQuotationMarshaller" />
<property name="faultMessageResolver" ref="vehicleServiceClientFaultMessageResolver" />
<property name="defaultUri" value="http://localhost:8080/quote/endpoints"/>
<property name="messageSender">
<bean class="org.springframework.ws.transport.http.MyHttpComponentsMessageSender"/>
</property>
</bean>
take a look at Spring forums
JSESSIONID and setting cookie for WebServiceTemplate
I'm trying to understand how to send https post request with post data using spring web or and other spring tools.
so far I've been using httpclient but i'm trying to convert to spring :)
the https post request should ignore self signed certificate.
please provide an example on how it can be done.
thank you
I use Spring Integration to send http POST and GET
http://static.springsource.org/spring-integration/reference/html/http.html
The request-factory bean need to be configured to allow self-signed certificates.
I use the following wiring to declare apacheHttpsRequestFactory to be used by http Spring Integration endpoints.
The httpClient bean can be injected to other Spring Beans and used to send http requests:
#Autowired
private HttpClient httpClient;
Here is the fragment of spring-intefration-context.xml:
<!-- HTTPS connection to trust self signed certificates -->
<bean id="sslSocketFactory" class="org.apache.http.conn.ssl.SSLSocketFactory">
<constructor-arg name="trustStrategy">
<bean class="org.apache.http.conn.ssl.TrustSelfSignedStrategy" />
</constructor-arg>
<constructor-arg name="hostnameVerifier">
<bean class="org.apache.http.conn.ssl.AllowAllHostnameVerifier" />
</constructor-arg>
</bean>
<bean id="httpsSchemaRegistry" class="org.apache.http.conn.scheme.SchemeRegistry">
<property name="items">
<map>
<entry key="https">
<bean class="org.apache.http.conn.scheme.Scheme">
<constructor-arg value="https" />
<constructor-arg value="443" />
<constructor-arg ref="sslSocketFactory" />
</bean>
</entry>
</map>
</property>
</bean>
<bean id="httpClient" class="org.apache.http.impl.client.DefaultHttpClient">
<constructor-arg>
<bean class="org.apache.http.impl.conn.PoolingClientConnectionManager">
<constructor-arg ref="httpsSchemaRegistry" />
</bean>
</constructor-arg>
</bean>
<bean id="apacheHttpsRequestFactory"
class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory">
<constructor-arg ref="httpClient" />
I am trying to evaluate HornetQ and the possibility of embedding it in a spring application. To start with a simple setup I am just trying to initialize it as follows. I didn't find much documentation about how to do this, apart from the fact that 'you can'.
I am using Spring 3 and HornetQ 2.1.1GA
My Spring configuration looks like this, however if theres a simpler cleaner configuration it would be better. I want the minimalistic approach first and then build on it.:
<?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.xsd">
<bean name="mbeanServer" class="java.lang.management.ManagementFactory" factory-method="getPlatformMBeanServer" />
<bean name="fileConfiguration" class="org.hornetq.core.config.impl.FileConfiguration" init-method="start" destroy-method="stop" />
<bean name="hornetQSecurityManagerImpl" class="org.hornetq.spi.core.security.HornetQSecurityManagerImpl" />
<!-- The core server -->
<bean name="hornetQServerImpl" class="org.hornetq.core.server.impl.HornetQServerImpl">
<constructor-arg ref="fileConfiguration" />
<constructor-arg ref="mbeanServer" />
<constructor-arg ref="hornetQSecurityManagerImpl" />
</bean>
<!-- The JMS server -->
<bean name="jmsServerManagerImpl" class="org.hornetq.jms.server.impl.JMSServerManagerImpl" init-method="start" destroy-method="stop" >
<constructor-arg ref="hornetQServerImpl" />
</bean>
<bean name="connectionFactory" class="org.hornetq.jms.client.HornetQConnectionFactory" >
<constructor-arg>
<bean class="org.hornetq.api.core.TransportConfiguration">
<constructor-arg value="org.hornetq.integration.transports.netty.NettyConnectorFactory" />
<constructor-arg>
<map key-type="java.lang.String" value-type="java.lang.Object">
<entry key="port" value="5445"></entry>
</map>
</constructor-arg>
</bean>
</constructor-arg>
</bean>
<bean name="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory"></property>
</bean>
</beans>
With this config I am getting the error:
SEVERE: Unable to deploy node [queue: null] DLQ
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
...
29-Dec-2010 18:16:34 org.hornetq.core.logging.impl.JULLogDelegate error
SEVERE: Unable to deploy node [queue: null] ExpiryQueue
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
...
9-Dec-2010 18:16:34 org.hornetq.core.logging.impl.JULLogDelegate error
SEVERE: Unable to deploy node [queue: null] ExampleQueue
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
Its must be something obvious related to JNDI, but I would appreciate the proper minimalistic configuration to start with and then expand on it afterwards. The HornetQ configuration files are the default ones that come with the distribution (default queues, default users etc.)
You need to define the JMS queues you want to add to the server, and specify an empty list of JNDI bindings for each queue. To do this, add a JMSConfigurationImpl to your JMSServerManagerImpl bean definition. For example, if you need to define a queue called "testqueue":
<bean id="hornetQJmsConfig" class="org.hornetq.jms.server.config.impl.JMSConfigurationImpl">
<constructor-arg index="0">
<list/>
</constructor-arg>
<!-- Queue configurations -->
<constructor-arg index="1">
<list>
<bean class="org.hornetq.jms.server.config.impl.JMSQueueConfigurationImpl">
<!-- Name -->
<constructor-arg index="0" value="testqueue"/>
<!-- Selector -->
<constructor-arg index="1"><null/></constructor-arg>
<!-- Durable queue -->
<constructor-arg index="2" value="true"/>
<!-- JNDI bindings, empty list for none -->
<constructor-arg index="3"><list/></constructor-arg>
</bean>
</list>
</constructor-arg>
<!-- Topic configurations -->
<constructor-arg index="2">
<list/>
</constructor-arg>
</bean>
Since the second and third constructor args take a list of queue and topic configurations, you can add as many queues and topics as you like. For more than one or two, it's probably best to create a Spring template object.