I am stuggelin to create a ftp connection with the spring ftpSessionFactory.
In my project I am using the xml configuration for a ftp connection with TLS (it works):
<bean id="ftpSessionFactory"
class="org.springframework.integration.ftp.session.DefaultFtpsSessionFactory">
<property name="host" value="#{configurationService.configuration.getProperty('file.transfer.server.host')}" />
<property name="port" value="#{configurationService.configuration.getProperty('file.transfer.server.port')}" />
<property name="username" value="#{configurationService.configuration.getProperty('file.transfer.server.user')}" />
<property name="password" value="#{configurationService.configuration.getProperty('file.transfer.server.password')}" />
<property name="clientMode" value="2"/>
<property name="fileType" value="2"/>
<property name="useClientMode" value="true"/>
<property name="keyManager" ref="keyManager"/>
<property name="protocol" value="TLS"/>
<property name="trustManager" ref="trustManager"/>
<property name="prot" value="P"/>
<property name="needClientAuth" value="true"/>
<property name="sessionCreation" value="true"/>
<property name="implicit" value="false"/>
</bean>
Now I need a second connection, but without TLS (dont ask :D). For that I just replaced the fields in Java:
ftpSessionFactory.setHost(host);
ftpSessionFactory.setPort(port);
ftpSessionFactory.setUsername(username);
ftpSessionFactory.setPassword(password);
ftpSessionFactory.setProtocol(StringUtils.isNoneEmpty(protocol) ? protocol : null); // <-- null for no TLS
But that gives me this error: javax.net.ssl.SSLException: 500 AUTH: unknown command.
Then I tried it the hard coded way (it works):
FTPClient f = new FTPClient();
f.connect(host);
f.login(username, password);
Now my question:
How can I modify the xml part (I guess with setter) so it works for both?
Use DefaultFtpSessionFactory instead of DefaultFtpsSessionFactory.
Related
I'm using a spring datasource and is unable to connect to Oracle AQ Queue.
Connection connection = null;
AQSession aqSess = null;
connection = ds.getConnection();
connection.setAutoCommit(false);
DataSourceUtils.getTargetConnection(connection);
Class.forName("oracle.AQ.AQOracleDriver");
aqSess = AQDriverManager.createAQSession(connection);
aqSession = aqSess;
But still get this: oracle.jms.AQjmsException: JMS-112: Connection is invalid any tips would be appreciated.
<bean id="myId" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:#myIpAddress:dev"/>
<property name="username" value="user"/>
<property name="password" value="pass"/>
<property name="removeAbandoned" value="true"/>
<property name="initialSize" value="2"/>
<property name="maxIdle" value="8"/>
<property name="maxActive" value="30"/>
<property name="maxWait" value="60000"/>
</bean>
AQException: oracle.AQ.AQException: JMS-112: Connection is invalid
at oracle.AQ.AQDriverManager.createAQSession(AQDriverManager.java:193)
I fixed my problem using the following code:
OracleConnection oracleConnection = connection.unwrap(OracleConnection.class);
Recording it here as an answer in case others find this question when having a similar problem.
Oracle AQ doesn't match with BasicDataSource
useOracleDataSource instead
but if you want to use BasicDataSource:
In many application server environments the JDBC connection is wrapped
in an implementation specific class that delegates to the underlying
native JDBC connection. Oracle's AQ connection factory needs the
native Oracle connection and will throw an "oracle.jms.AQjmsException:
JMS-112: Connection is invalid" exception if the connection is wrapped
by a foreign class. To solve this problem you can specify a
NativeJdbcExtractor that can be used to unwrap the connection. Spring
provides a number of implementations to match the application server
environment. Here is an example for specifying a NativeJdbcExtractor.
<orcl:aq-jms-connection-factory id="connectionFactory"
use-local-data-source-transaction="true"
native-jdbc-extractor="dbcpNativeJdbcExtractor" 1
data-source="dataSource" />
<bean id="dbcpNativeJdbcExtractor"
class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"/>
<bean id="dbcpDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
https://docs.spring.io/spring-data/jdbc/old-docs/2.0.0.BUILD-SNAPSHOT/reference/html/orcl.streamsaq.html
Good Mornig.
I have an application in tomcat 8, java 1.7, Spring 3.2.2 and primefaces 5.0. When the application starts, it shows the next debug message in console:
Looking up JNDI object with name [java:comp/env/etl.csv.token]
localhost-startStop-1: org.springframework.jndi.JndiLocatorDelegate
Converted JNDI name [java:comp/env/etl.csv.token] not found
But the key isn't in the JNDI context. It is in a properties file. The application works fine and takes the property from the properties file, but i can't understand why spring is trying to find the property in the JNDI context
The properties file is like this:
database.driverClassName=org.postgresql.Driver
database.initialSize=3
database.maxActive=15
database.maxIdle=10
database.minIdle=3
database.maxWait=10000
etl.csv.token=,
And its properties are used like this:
<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource">
<property name="driverClassName" value="${database.driverClassName}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.username}" />
<property name="password" value="${database.password}" />
<property name="initialSize" value="${database.initialSize}" />
<property name="maxActive" value="${database.maxActive}" />
<property name="maxIdle" value="${database.maxIdle}" />
<property name="maxWait" value="${database.maxWait}" />
<property name="minIdle" value="${database.minIdle}" />
<property name="testOnBorrow" value="true" />
<property name="validationQuery" value="SELECT CURRENT_TIMESTAMP" />
<property name="removeAbandoned" value="true" />
</bean>
For all properties, the behaviour is the same. I would like that message does not appear
Sorry for the english, is not my native language
Any help will be apreciated.
I am trying to setup an Amazon EC2 with tomcat and mysql. Both are up and running, both are in same instance. My confusions is, what jdbc url I have to use to connect my database on the same instance
<bean id="masterDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>WHAT TO ADD HERE</value>
</property>
.....
Add them like this:
<property name="url" value="jdbc:mysql://localhost/_dbName" />
<property name="username" value="your username" />
<property name="password" value="your password" />
Try the following:
jdbc:mysql://localhost/database_name?user=your_username&password=your_greatsqlpw
or
jdbc:mysql://127.0.0.1/database_name?user=your_username&password=your_greatsqlpw
As long as your server is secure you should not be concerned about security too much since the connections are only internal in the server.
I am using jasypt-1.9.0 for encryption.
Jdbc.properties
jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:#localhost:1521:ORCL
jdbc.username=testuser
jdbc.password=ENC(lKmVnTVL3zSJXrZpwFmhd6crSHLzYihH)
hibernate.dialect=org.hibernate.dialect.OracleDialect
jpa.databasePlatform=toplink.hibernate.EssentialsHSQLPlatformWithNative
jpa.database=ORCL
C:\jasypt-1.9.0\bin>encrypt input=testuser password=testuser
----ENVIRONMENT-----------------
Runtime: Sun Microsystems Inc. Java HotSpot(TM) Client VM 1.5.0_17-b04
----ARGUMENTS-------------------
input: testuser
password: testuser
----OUTPUT----------------------
lKmVnTVL3zSJXrZpwFmhd6crSHLzYihH
I got the reference from one of your site. I am using multiple context file. I have
configured
<bean
class="org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfi
gurer">
<constructor-arg>
<bean 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="APP_ENCRYPTION_PASSWORD" />
</bean>
</property>
</bean>
</constructor-arg>
<property name="locations">
<list>
<value>classpath:/META-INF/props/db/jdbc.properties</
value>
</list>
</property>
</bean>
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"
value="${jdbc.driverClassName}" ></property>
<property name="url"
value="${jdbc.url}" ></property>
<property name="username"
value="${jdbc.username}" ></property>
<property name="password"
value="${jdbc.password}"></property>
<property name="initialSize" value="10"> </property>
<property name="maxActive"
value="30"> </property>
<property name="maxIdle"
value="10"> </property>
<property name="maxWait"
value="5000"> </
property>
<property name="removeAbandoned"
value="true"> </
property>
<property name="logAbandoned"
value="true"> </
property>
</bean>
When I login my application I am getting error::
org.jasypt.exceptions.EncryptionInitializationException: Password not
set for Password Based Encryptor
It appears your "APP_ENCRYPTION_PASSWORD" property is not properly set as an environment variable. See this link to check if it has been properly set as an environment variable. To check if there is a problem with the rest of your configuration, change <property name="passwordEnvName" value="APP_ENCRYPTION_PASSWORD" /> to <property name="password" value="YOUR_PLAIN_TEXT_PASSWORD_HERE" /> and replace YOUR_PLAIN_TEXT_PASSWORD_HERE with your plain text password to test if the rest of your configuration is working.
To set APP_ENCRYPTION_PASSWORD as an environment variable in Windows XP see this link.
Alternatively, you can pass the password in as a vm argument when you run your program. If it is a standalone program, you will pass it like java ClassWithMain -DAPP_ENCRYPTION_PASSWORD=your_password. If it is a web application, you will have to pass the same arguments when starting your server. See this question on SO on how to do that for tomcat. Then in your spring configuration, replace <property name="passwordEnvName" value="APP_ENCRYPTION_PASSWORD" /> with <property name="passwordSysPropertyName" value="APP_ENCRYPTION_PASSWORD" />.
Once you set the Environment variable. Please restart your eclipse.
You may not face this isssue. If issue still persist than try to find your environment variables by below code..
Map<String, String> env = System.getenv();
for (String envName : env.keySet()) {
System.out.format("%s=%s%n", envName,
en`enter code here`v.get(envName));
}
I have a database that is connected through an unreliable network connection to an application server, so occasionally the connections break down. Each time this happens, all database connections in the AP pool will need to reconnect - which they don't unfortunately.
I went through different setups of c3p0, dbcp and bonecp as pools and used JTDS as well as the SQL Server V3 driver, (I even ditched pooling atogether to try out whether the regular DataSource would be able to create a new unpooled connection - which it didn't) but all configuration variants don't seem able to recover after network failure.
To clarify, none of the DataSources were able to get a new Connection. Is there some inherent Problem with the MS Sql Server regarding reconnects? Am I missing something fundamental here?
I realize this might not be of big help, but just as an example this is the dbcp configuration
<bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.databaseurl}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="idleConnectionTestPeriodInMinutes" value="1" />
<property name="idleMaxAgeInMinutes" value="1" />
<property name="maxConnectionsPerPartition" value="3" />
<property name="minConnectionsPerPartition" value="1" />
<property name="partitionCount" value="1" />
<property name="acquireIncrement" value="5" />
<property name="acquireRetryAttempts" value="50" />
<property name="acquireRetryDelayInMs" value="1000" />
<property name="queryExecuteTimeLimitInMs" value="5000" />
<property name="connectionTestStatement" value="SELECT count(*) FROM dbo.sysobjects" />
<property name="closeConnectionWatch" value="true" />
<property name="lazyInit" value="false" />
<property name="statementsCacheSize" value="100" />
<property name="releaseHelperThreads" value="3" />
</bean>