Spring integration FTP Server replied with: 426 Transfer failed - spring

I am currently working on spring integration with FTP support.
I made a transfer from local directory to a remote FTP server, But I am getting Server replied with: 426 Transfer failed error.
Caused by: org.springframework.messaging.MessagingException: Failed to write to '/4001/in/temp/V31406_200000_120001.writing' while uploading the file; nested exception is java.io.IOException: Failed to write to '/4001/in/temp/V31406_200000_120001.writing'. Server replied with: 426 Transfer failed
at org.springframework.integration.file.remote.RemoteFileTemplate.sendFileToRemoteDirectory(RemoteFileTemplate.java:592)
at org.springframework.integration.file.remote.RemoteFileTemplate.lambda$send$0(RemoteFileTemplate.java:319)
Below is my session factory code.
#Bean
#Order(Ordered.HIGHEST_PRECEDENCE)
public SessionFactory<FTPFile> ftpSessionFactory() {
DefaultFtpSessionFactory ftpSessionFactory = new DefaultFtpSessionFactory();
ftpSessionFactory.setHost(ftpHost);
ftpSessionFactory.setPort(ftpPort);
ftpSessionFactory.setUsername(ftpUser);
ftpSessionFactory.setPassword(ftpPasword);
LOGGER.info("ftpHost : {} ftpPort: {} ftpUser: {} ftpPasword: {} ", ftpHost, ftpPort, ftpUser, ftpPasword);
ftpSessionFactory.setClientMode(0);
return new CachingSessionFactory<FTPFile>(ftpSessionFactory, 10);
}

Related

JavaMail Spring boot properties does not recognize properties

I have a spring boot application with javamail, i configure spring.properties but it seems to not take properties to send email.
#mail properties
spring.mail.host = smtp.gmail.com
spring.mail.port = 587
spring.mail.username = eeee#gmail.com
spring.mail.password = eeee
spring.mail.protocol = smtp
spring.mail.defaultEncoding=UTF-8
spring.mail.smtp.starttls.enable=false
spring.mail.smtp.starttls.required=false
spring.mail.smtp.auth=true
spring.mail.smtp.connectiontimeout=5000
spring.mail.smtp.timeout=5000
spring.mail.smtp.writetimeout=5000
here the java code to send email
#Service
public class MailSenderServiceImpl implements IMailSenderService{
#Autowired
JavaMailSender mailSender;
#Override
public void sendEmailStatusNotification(Shipment shipment) throws IOException, MessagingException{
final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
message.setFrom(shipment.getSender().getSenderEmail());
message.setTo(new String[] {shipment.getRecipient().getRecipientEmail()});
message.setSubject("Shipment "+shipment.getTrackingNumber()+"status update");
message.setText("the shipment status is now :"+shipment.getStatus().getLabel());
this.mailSender.send(mimeMessage);
}
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
here we see this error
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeout -1;
nested exception is:
java.net.ConnectException: Connection refused: connect. Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeout -1;
nested exception is:
java.net.ConnectException: Connection refused: connect; message exceptions (1) are:
Failed message 1: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeout -1;
nested exception is:
java.net.ConnectException: Connection refused: connect
Any idea ?
By default spring.properties is not a properties source, try putting them in application.properties.

RabbitHandler to create consumer and retry on Fatal Exception in Spring for queue on listening to RabbitMQ

I am using Spring AMQP RabbitHandler and have written the following code:
#RabbitListener(queues = "#{testQueue.name}")
public class Tut4Receiver {
#RabbitHandler
public void receiveMessage(String message){
System.out.println("Message received "+message);
}
}
The Queue is defined like:-
#Bean
public Queue testQueue() {
return new AnonymousQueue();
}
I am using separate code to initialize the Connection Factory.
My question is if RabbitMQ is down for some time, it keeps on retrying to create a consumer but only if it receives a ConnectionRefused error. But suppose the user does not exist in RabbitMQ and there is a gap in which a new user will be created, then it receives a fatal error from RabbitMQ and it never retries due to which the result is auto delete queue would be created on RabbitMQ without any consumers.
Stack Trace:
SimpleMessageListenerContainer] [SimpleAsyncTaskExecutor-11] [|] [|||] Consumer received fatal exception on startup
org.springframework.amqp.rabbit.listener.exception.FatalListenerStartupException: Authentication failure
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:476)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1280)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.amqp.AmqpAuthenticationException: com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.
at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:65)
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:309)
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:547)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils$1.createConnection(ConnectionFactoryUtils.java:90)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.doGetTransactionalResourceHolder(ConnectionFactoryUtils.java:140)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.getTransactionalResourceHolder(ConnectionFactoryUtils.java:76)
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:472)
... 2 common frames omitted
Caused by: com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:339)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:813)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:767)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:887)
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:300)
SimpleMessageListenerContainer] [SimpleAsyncTaskExecutor-11] [|] [|||] Stopping container from aborted consumer
[|] [|||] Waiting for workers to finish.
[|] [|||] Successfully waited for workers to finish.
Any way to retry even on fatal exceptions like when the user does not exist?
Authentication failures are considered fatal by default and not retried.
You can override this behavior by setting a property on the listener container (possibleAuthenticationFailureFatal). The property is not available as a boot property so you have to override boot's container factory...
#Bean(name = "rabbitListenerContainerFactory")
public SimpleRabbitListenerContainerFactory simpleRabbitListenerContainerFactory(
SimpleRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
configurer.configure(factory, connectionFactory);
factory.setContainerConfigurer(smlc -> smlc.setPossibleAuthenticationFailureFatal(false));
return factory;
}

Starting RabbitMq as GenerigContainer in Gitlab Ci

I have a Spring Boot 2.1 Application which has integration tests. For integration tests purposes i want start a RabbitMq container with testcontainers framework. When I start those on my local machine everything seems to work i can access my rabbitMQ during the IT tests. However once i execute under gitlab-ci i constantly get connection refused exceptions
Here is my application-it-properties
spring.rabbitmq.host=localhost
spring.rabbitmq.virtualHost=/
spring.rabbitmq.port=5673
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
spring.rabbitmq.dynamic=true
spring.rabbitmq.template.retry.enabled=true
spring.rabbitmq.listener.simple.acknowledgeMode=AUTO
spring.rabbitmq.listener.simple.concurrency=5
This is my verify step in gitlab-ci
verify:feature:
stage: verify
script:
- git config --global user.email gitlab#test.de
- git config --global user.name gitlab
- git fetch --all
- git checkout origin/develop
- git merge $CI_BUILD_REF --no-commit --no-ff
- mvn $MAVEN_CLI_OPTS verify sonar:sonar $SONAR_PREVIEW_CLI_OPTS
only:
- /feature.*/
And this is how i start my testcontainer RabbitMQ
#Slf4j
#RunWith(SpringRunner.class)
#TestPropertySource(locations = {"classpath:application-it.properties"})
#SpringBootTest
public class TransformerServiceApplicationIt {
private static final int EXPOSED_RABBITMQ_PORT = 5672;
private static final int EXPORTED_RABBITMQ_PORT = 5673;
/**
* Start the rabbitmq.
*/
static {
final Consumer<CreateContainerCmd> rabbitCmd = e -> e.withPortBindings(new PortBinding(Ports.Binding.bindPort(EXPORTED_RABBITMQ_PORT), new ExposedPort(EXPOSED_RABBITMQ_PORT)));
final GenericContainer rabbitMq = new GenericContainer("rabbitmq:3-management").withExposedPorts(EXPOSED_RABBITMQ_PORT)
.withCreateContainerCmdModifier(rabbitCmd);
rabbitMq.start();
}....
}
And this is my exception
[org.springframework.amqp.rabbit.core.RabbitTemplate]: Factory method 'rabbitTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itRabbitMQConfig': Invocation of init method failed; nested exception is org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
My guess is that it has something to do with the hostname resolving for localhost on gitlab.
Try this:
static {
final GenericContainer rabbitMq = new GenericContainer("rabbitmq:3-management").withExposedPorts(EXPOSED_RABBITMQ_PORT);
rabbitMq.start();
// Pass the properties directly to the app. Do not use properties file.
System.setProperty("spring.rabbitmq.host", rabbitMq.getContainerIpAddress());
System.setProperty("spring.rabbitmq.port", rabbitMq.getMappedPort(5672).toString());
}

Spring jdbctemplate working on tomcat but gives error on WAS server

I am trying to connect to db2 using spring jdbc template. Everything is working fine when deployed on tomcat server. But the same application when I am trying to deploy on WAS server is not working and giving me the below exception.
com.ibm.db2.jcc.am.DisconnectNonTransientConnectionException: [jcc][t4][2030][11211][3.69.66] A communication error occurred during operations on the connection's underlying socket, socket input stream,
or socket output stream. Error location: Reply.fill() - socketInputStream.read (-1). Message: Received fatal alert: handshake_failure. ERRORCODE=-4499, SQLSTATE=08001
My datasource bean configuration is given below
#Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource=new DriverManagerDataSource();
dataSource.setDriverClassName("com.ibm.db2.jcc.DB2Driver");
dataSource.setUrl("url");
dataSource.setUsername("username");
dataSource.setPassword("password");
Properties connectionProperties=new Properties();
connectionProperties.setProperty("sslConnection", "true");
connectionProperties.setProperty("sslTrustStoreLocation", "pathToFile");
connectionProperties.setProperty("sslTrustStorePassword", "pass");
dataSource.setConnectionProperties(connectionProperties);
return dataSource;
}

Why do these properties fail to look up a ConnectionFactory from glassfish?

This code fails when used by a local java client to lookup a JMS ConnectionFactory from a Glassfish server running on localhost.
Can anyone tell me why? I'm so desperate even useful insults are welcome.
I put the Console output below (as formatted by my program).
InitialContext ctx = null;
ConnectionFactory factory = null;
// properties - set One
Hashtable<String,String> env = new Hashtable<String,String> ();
envTwo.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.enterprise.naming.impl.SerialInitContextFactory");
env.put(Context.URL_PKG_PREFIXES,
"com.sun.enterprise.naming");
env.put("org.omg.CORBA.ORBInitialPort",
"3700");
env.put("org.omg.CORBA.ORBInitialHost",
"localHost");
ctx = new InitialContext(env);
factory = (ConnectionFactory) ctx.lookup("jms/goConnectionFactory");
Console Output
Properties:
key: org.omg.CORBA.ORBInitialPort
value: 3700
key: java.naming.factory.initial
value: com.sun.enterprise.naming.impl.SerialInitContextFactory
key: org.omg.CORBA.ORBInitialHost
value: localHost
key: java.naming.factory.url.pkgs
value: com.sun.enterprise.naming
InitialContext returned: javax.naming.InitialContext#59494225
calling ctx.lookup()
The following was written to the .err stream. All else to .out stream by my program)
-------------------------------------------------------------
java.lang.NullPointerException
at com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:347)
at com.sun.enterprise.naming.impl.SerialContext.getProviderCacheKey(SerialContext.java:354)
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:384)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:329)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:477)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
at javax.naming.InitialContext.lookup(Unknown Source)
at org.america3.testclasses.OracleForumTestClass.main(OracleForumTestClass.java:59)
-------------------------------------------------------------
CAUGHT EXCEPTION: javax.naming.NamingException
MESSAGE : Lookup failed for 'jms/goConnectionFactory' in SerialContext[myEnv={org.omg.CORBA.ORBInitial
Port=3700, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, org.omg.CORBA.
ORBInitialHost=localHost, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImp
l, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
CAUSE : javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEn
v={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitCon
textFactory, org.omg.CORBA.ORBInitialHost=localHost, java.naming.factory.state=com.sun.corba.ee.impl.presentat
ion.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is java.
lang.NullPointerException]
STACK TRACE :
com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491)
com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
javax.naming.InitialContext.lookup(Unknown Source)
org.america3.testclasses.OracleForumTestClass.main(OracleForumTestClass.java:59)
I came to know that glassfish 4.1 is having this bug where local client cant connect to the MDB deployed on server. I tried the same with two ejb projects and it is working just fine.

Resources