I've got the camel-box component working well via the corporate web proxy but it is very slow. I tried using the socks proxy instead, which works well for me for sftp transfers but it fails with almost no useful error message. Just an exception which I'll dig out and add to the question but didn't tell me anything. Can anyone spot anything wrong with my proxy configuration? This is equivalent to my applicationContext.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:context="http://www.springframework.org/schema/context" xmlns:amq="http://activemq.apache.org/schema/core" xmlns:camel="http://camel.apache.org/schema/spring" xmlns:p="http://www.springframework.org/schema/p" 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://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd ">
<camelContext xmlns="http://camel.apache.org/schema/spring" id="boxtest">
<route id="getids">
<description>Fetch the names and Box unique ids for the root folder</description>
<from uri="jetty:http://0.0.0.0:/info"/>
<to uri="box://folders/getFolderItems?folderId=0&pagingRequest=#pr"/>
<to uri="bean:dump"/>
</route>
</camelContext>
<bean class="org.apache.camel.component.box.BoxComponent" id="box">
<property name="configuration" ref="cfg"/>
</bean>
<bean class="org.apache.camel.component.box.BoxConfiguration" id="cfg">
<property name="httpParams">
<map>
<entry key="http.route.socks-proxy" value="true"/>
<entry key="http.route.default-proxy">
<bean class="org.apache.http.HttpHost" id="proxy">
<constructor-arg index="0" value="my-socks-proxy"/>
<constructor-arg index="1" value="1085"/>
</bean>
</entry>
</map>
</property>
<property name="userName" value="j#b.com"/>
<property name="clientId" value="a83445cd422dbfc62ba9"/>
<property name="clientSecret" value="1701df702c00126783fc1701df702c00126783fc"/>
<property name="authSecureStorage" ref="auth"/>
</bean>
<bean id="auth" class="mypackage.Auth">
<property name="filename" value="box_credentials.properties"/>
</bean>
<bean id="pr" class="com.box.boxjavalibv2.requests.requestobjects.BoxPagingRequestObject"/>
</beans>
here is the exception: http://pastebin.com/GpBeHJiD
So to formally answer my question, the error in the config is that the socks parameter needs to be boolean as follows:
<entry key="http.route.socks-proxy">
<value type="java.lang.Boolean">true</value>
</entry>
But the real problem is that camel-box in Camel 2.14.1 only has socks support for the login process not for the restful client.
I've submitted a patch for this.
https://issues.apache.org/jira/browse/CAMEL-8272
Related
I am trying to use the example project of Spring-Integration JMS for JMS integration, Which I have done succesfully. How ever I have a slightly different set of requirement. Where I need to listen from 1 JMS Broker using Publish Subscribe pattern and, I need to send the same listened JMS message to another Kafak Queue/or nay other queue. I am struggling with the configuration, as of now I have configured only for request and response queue. Here are the configuration. Please help.
Common.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:integration="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd">
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost"/>
</bean>
</property>
<property name="sessionCacheSize" value="10"/>
<property name="cacheProducers" value="false"/>
</bean>
<!-- <bean id="requestQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="queue.demo"/>
</bean> -->
<bean id="replyQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="queue.reply"/>
</bean>
<bean id="requestQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="queue.request"/>
</bean>
<integration:poller id="poller" default="true" fixed-delay="100"/>
</beans>
InboudChanelAdapter
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xmlns:stream="http://www.springframework.org/schema/integration/stream"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
http://www.springframework.org/schema/integration/stream
http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd">
<jms:message-driven-channel-adapter id="jmsIn"
destination="requestQueue"
channel="jmsInChannel" />
<channel id="jmsInChannel" />
<beans:beans profile="testCase">
<bridge input-channel="jmsInChannel" output-channel="queueChannel"/>
<channel id="queueChannel">
<queue />
</channel>
</beans:beans>
</beans:beans>
OutboundChannelAdapter.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xmlns:stream="http://www.springframework.org/schema/integration/stream"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
http://www.springframework.org/schema/integration/stream
http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd">
<stream:stdin-channel-adapter id="stdin" channel="stdinToJmsoutChannel"/>
<channel id="stdinToJmsoutChannel"/>
<channel id="jmsInChannel" />
<jms:outbound-channel-adapter id="jmsout" channel="jmsInChannel" destination="requestQueue"/>
</beans:beans>
**DemoConfig.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:integration="http://www.springframework.org/schema/integration"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd">
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost"/>
</bean>
</property>
<property name="sessionCacheSize" value="10"/>
<property name="cacheProducers" value="false"/>
</bean>
<bean id="connectionFactory2nd" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost"/>
</bean>
</property>
<property name="sessionCacheSize" value="10"/>
<property name="cacheProducers" value="false"/>
</bean>
<bean id="replyQueue" class="org.apache.activemq.command.ActiveMQQueue" >
<constructor-arg value="queue.reply"/>
</bean>
<bean id="requestQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="queue.request"/>
</bean>
<jms:message-driven-channel-adapter id="jmsIn"
destination="requestQueue"
channel="jmsInChannel"
connection-factory="connectionFactory"/>
<jms:publish-subscribe-channel id= "jmsInChannel"/>
<jms:topic id="Topic"></jms:topic>
</<jms:channel>
<jms:outbound-channel-adapter id="jmsout" channel="jmsInChannel" destination="replyQueue" connection-factory="connectionFactory2nd"/>
<integration:poller id="poller" default="true" fixed-delay="100"/>
</beans>
Looks like you don't have enough theoretical knowledge, so you should go to the Docs and Books about Spring Integration. You don't feel well what is MessageChannel yet.
<jms:message-driven-channel-adapter id="jmsIn"
destination="requestQueue"
channel="jmsInChannel" />
Means: listen on the requestQueue destination and send the Spring Integration Message to the jmsInChannel.
If you are going just to send that message to the another JMS destination you should do something like this:
<jms:outbound-channel-adapter id="jmsout" channel="jmsInChannel" destination="replyQueue"/>
And be sure that there is no more subscriber to that jmsInChannel, because it is a DirectChannel.
According to your current config you have additional subscriber as <bridge>. In this case the Round-Robin balancer works on that jmsInChannel and the first message will be sent to the first subscriber, and only the second - to the second, and so on.
If you want accept that message by both subscribers you should change jmsInChannel to the <publish-subscribe-channel>.
More info you can find from docs.
I'm trying to remotely call jmx bean exposed by spring using this guide
but when I launch my client code, it fails to load application context with such error
Caused by: java.io.IOException: Failed to retrieve RMIServer stub:
javax.naming.NameNotFoundException: jmxrmi at
javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:357)
at
javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:267)
at
org.springframework.jmx.support.MBeanServerConnectionFactoryBean.connect(MBeanServerConnectionFactoryBean.java:126)
at
org.springframework.jmx.support.MBeanServerConnectionFactoryBean.afterPropertiesSet(MBeanServerConnectionFactoryBean.java:114)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 38 more Caused by: javax.naming.NameNotFoundException: jmxrmi
Here is my server spring context
<?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:sws="http://www.springframework.org/schema/web-services"
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/web-services http://www.springframework.org/schema/web-services/web-services.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean" />
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="bean:name=testBean" value-ref="testBean" />
</map>
</property>
<property name="assembler">
<bean
class="org.springframework.jmx.export.assembler.InterfaceBasedMBeanInfoAssembler">
<property name="managedInterfaces">
<value>jmx.IJmxTestBean</value>
</property>
</bean>
</property>
<property name="server" ref="mbeanServer" />
</bean>
<bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
<property name="port" value="1199" />
</bean>
<bean id="testBean" class="jmx.JmxTestBean">
<property name="name" value="TEST" />
<property name="age" value="100" />
</bean>
<bean id="serverConnector"
class="org.springframework.jmx.support.ConnectorServerFactoryBean" depends-on="registry">
<property name="objectName" value="connector:name=rmi" />
<property name="serviceUrl"
value="service:jmx:rmi://localhost/jndi/rmi://localhost:1199/jmxrmi" />
</bean>
and this is my client spring context
<?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:sws="http://www.springframework.org/schema/web-services"
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/web-services http://www.springframework.org/schema/web-services/web-services.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="clientConnector"
class="org.springframework.jmx.support.MBeanServerConnectionFactoryBean">
<property name="serviceUrl"
value="service:jmx:rmi://localhost/jndi/rmi://localhost:1199/jmxrmi" />
</bean>
<bean id="proxy" class="org.springframework.jmx.access.MBeanProxyFactoryBean">
<property name="objectName" value="bean:name=testBean" />
<property name="proxyInterface" value="jmx.IJmxTestBean" />
<property name="server" ref="clientConnector" />
</bean>
Any ideas?
Ok, this is not the issue with spring jmx, but with the jboss eap that I'm deploying the apps. This code runs perfectly fine when I launch the spring contexts as standalone clients or on jetty. Since I run this on JBoss EAP 6.2 then jmx by rmi is not supported I need to find another way.
I am trying to use spring's unmarshaller to automatically unmarshal request body from xml to an object. But I failed getting the error util prfeix unbind. Could you tell me how can I use util:list and where can I find reference for util:list.
I did spot that the official documentation leave out a closing > in </property and I correct that in my configuration.
I find configuration far more frustrating that just write the code.
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<util:list id="beanList">
<ref bean="stringHttpMessageConverter"/>
<ref bean="marshallingHttpMessageConverter"/>
</util:list>
</property
</bean>
<bean id="stringHttpMessageConverter"
class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean id="marshallingHttpMessageConverter"
class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<property name="marshaller" ref="castorMarshaller" />
<property name="unmarshaller" ref="castorMarshaller" />
</bean>
<bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller"/>
You need to declare to util namespace; e.g.:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
This is the code to get the present working directory of a java application at runtime.
String currentWorkingDirectory = System.getProperty("user.dir")+System.getProperty("file.separator");
Is there any way by which this can be configured using the spring-context xml.
For ex:
<bean id="csvReportGenerator" class="some.path.CSVReportGenerator">
<constructor-arg name="outputFileName" value="${currentWorkingDirectory}/${reportOutputFileGeneric}"/>
</bean>
Yes, you can do it using Spring expressions. See section 6.4.1 of this article
<property name="userDir" value="#{ systemProperties['user.dir'] }"/>
<property name="fileSep" value="#{ systemProperties['file.separator'] }"/>
You can simply use classpath: or can use ./ if you are deploying in an unix environment(which usually is). Say, classpath:sample.properties or ./sample.properties
In spring-context.xml You can use
1) classpath:filename.properties or
2) ./filename.properties
3) file:./
For current dir of context-xml, ./ should work, but for working dir, file:./ works fine.
eg.
<?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:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
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">
<context:annotation-config />
<bean id="properties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="singleton" value="true" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath:/shaharma.properties</value>
<value>./shaharma-custom.properties</value>
</list>
</property>
</bean>
</beans>
I'm trying to use util-constant for ioc but I'm getting the following error message:
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'util:constant'.
All of the spring 3.1.1 dist jars are in my classpath and I was able to successfully run my program prior to making the changes that included the use of the util:constant tag.
Here's my ioc xml file:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:tool="http://www.springframework.org/schema/tool"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:config.properties</value>
</property>
</bean>
<bean id="main" class="pikefin.Main">
<property name="executorSample" ref="executorSample"/>
</bean>
<bean id="executorSample" class="pikefin.ExecutorSample">
<constructor-arg ref="threadPoolExecutor" />
</bean>
<bean id="threadPoolExecutor" class="java.util.concurrent.ThreadPoolExecutor">
<constructor-arg index="0" value="2"/>
<constructor-arg index="1" value="2"/>
<constructor-arg index="2" value="10"/>
<constructor-arg index="3"><util:constant static-field="java.util.concurrent.TimeUnit.SECONDS"/></constructor-arg>
<constructor-arg index="4" ref="arrayBlockingPool"/>
</bean>
<bean id="arrayBlockingPool" class="java.util.concurrent.ArrayBlockingQueue">
<constructor-arg value="5"/>
</bean>
</beans>
This is the correct declaration of util namespace (don't forget about specifying schemaLocation):
<?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:util="http://www.springframework.org/schema/util"
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">
</beans>
See more at C.2.2 The util schema.