Spring XD - mail sink configuration for outlook - outlook

I'm trying to configure Spring XD's mail sink to send messages to an outlook account. This is my stream definition:
stream create outlookMailSink --definition "http | mail --to='\"email#address.com\"' --host=outlook.office365.com --subject=payload+' world'" --deploy
I'm testing using this shell command:
http post --data Hello
I am getting the following error message:
Failed message 1: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:84)
I have investigated this in the Spring XD documentation and internet searches but I haven't found a solution that works. Can anyone help me with this please?

I found a solution which involves creating a new mail sink module which is a slight modification of spring XD's supplied mail sink module. The stream must also include to, from, host, port, username and password options.
Copy the ..\spring-xd-<version>\xd\modules\sink\mail folder and rename to secure-mail.
In ..\spring-xd-<version>\xd\modules\sink\secure-mail rename both mail.properties and mail.xml to secure-mail.properties and secure-mail.xml respectively.
Replace the contents of secure-mail.xml with the following:
<?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:file="http://www.springframework.org/schema/integration/file"
xmlns:int-mail="http://www.springframework.org/schema/integration/mail"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
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://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<channel id="input" />
<int-mail:header-enricher input-channel="input" output-channel="send">
<int-mail:to expression="${to:null}" />
<int-mail:from expression="${from:null}" />
<int-mail:subject expression="${subject:null}" />
<int-mail:cc expression="${cc:null}" />
<int-mail:bcc expression="${bcc:null}" />
<int-mail:reply-to expression="${replyTo:null}" />
<int-mail:content-type expression="${contentType:null}" />
</int-mail:header-enricher>
<channel id="send" />
<int-mail:outbound-channel-adapter
channel="send" host="${host}" port="${port}" username="${username:}"
password="${password:}" java-mail-properties="javaMailProperties"/>
<util:properties id="javaMailProperties">
<beans:prop key="mail.smtp.starttls.enable">true</beans:prop>
</util:properties>
</beans:beans>
Create the stream as follows:
stream create outlookMailSink --definition "http | secure-mail --to='\"email#address.com\"' --from='\"email#address.com\"' --host=outlook.office365.com --port=587 --username=email#address.com --password=password --subject=payload+' world'" --deploy
Test using shell command: http post --data Hello
The contents of secure-mail.xml is almost identical to mail.xml, the key is to set the property mail.smtp.starttls.enable to be true in order to enable TLS encryption for communication over port 587. OF course you could just modify Spring XD's mail sink module directly and use this - it's up to you.
I'd be interested to hear if anyone has a better solution to this? For example, is it possible to set the mail.smtp.starttls.enable property on start-up of Spring XD thereby allowing you to use the original mail sink module? I tried this by modifying the xd-singlenode startup script - the property was set but it didn't affect the mail sink module.
References:
https://stackoverflow.com/a/24765052/2124106
https://stackoverflow.com/a/23823863/2124106
http://docs.spring.io/spring-integration/reference/html/mail.html

Related

deploying rest api war and starting with App Manager produces error FAIL - Application at context path

First time working with web apps and created a simple springboot rest api and it worked fine locally. Deployed the war to a tomcat server by copying the war file into the /webapps/ directory and restarted tomcat.
I checked if this was successful by opening the tomcat web application manager page and can see the app listed:
http://1xx.xxx.xxx.xxx:8080/manager/
When I click start to get it running the following error appears:
FAIL - Application at context path [/first_restapi] could not be started
I searched around and most answers suggest ensuring all pom file dependencies are included and to check the logs. I checked the logs on the tomcat server and the following error stuck out:
Exception sending context initialized event to listener instance of class
[org.springframework.web.context.ContextLoaderListener]
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem:
Unable to locate Spring NamespaceHandler for XML schema namespace
[http://www.springframework.org/schema/security]
Offending resource: ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]
I did not include a servlet-context.xml file as the tutorial did not show that. But I added it anyway and still got the same error. Can anyone help with this issue?
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
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://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->
<!-- Enables the Spring MVC #Controller programming model -->
<annotation-driven />
<security:http auto-config="true" create-session="stateless">
<security:intercept-url pattern="/**" access="ROLE_USER"
requires-channel="http"/>
<security:http-basic />
</security:http>
</beans:beans>
You have a dependency problem. For each XML namespace that you (effectively) use in your configuration file, you need the appropriate NamespaceHandler. So in your case, to use the:
beans or util namespace you need spring-beans.jar,
context or task namespace you need spring-context.jar,
mvc namespace you need spring-webmvc.jar,
security namespace you need spring-security-config.jar.
You certainly don't have the last one dependency.

Configuring TCP communications with Spring Integration Issues

I seem to be having some trouble configuring my Spring MVC backend to receive and send TCP messages. Looking at the configuration a user suggests in this question - how to plug a TCP-IP client server in a spring MVC application - I tried to place this configuration into my root-context.xml. However, for all of the tags it displays a message such as:
Unable to locate Spring NamespaceHandler for element 'int-ip:tcp-outbound-gateway' of schema namespace 'http://www.springframework.org/schema/integration/ip'
int-ip:tcp-outbound-gateway and int:gateway both display cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'int:gateway' (replace int:gateway with int-ip:tcp-outbound-gateway).
Here is my root-context.xml file:
<?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:int="http://www.springframework.org/schema/integration"
xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd
http://www.springframework.org/schema/integration/ http://www.springframework.org/schema/integration/spring-integration.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
<int:gateway id="gw"
service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway"
default-request-channel="input"/>
<int-ip:tcp-connection-factory id="client"
type="client"
host="localhost"
port="1234"
single-use="true"
so-timeout="10000"/>
<int:channel id="input" />
<int-ip:tcp-outbound-gateway id="outGateway"
request-channel="input"
reply-channel="clientBytes2StringChannel"
connection-factory="client"
request-timeout="10000"
remote-timeout="10000"/>
<int:transformer id="clientBytes2String"
input-channel="clientBytes2StringChannel"
expression="new String(payload)"/>
</beans>
What am I doing incorrectly? Also, some general tips as to how I could use Spring to send and receive TCP communications would be appreciated :)
It appears you don't have the spring-integration-ip and spring-integration-core jars on your classpath. You need to bundle them into your war or otherwise make them available on the classpath according to your app server's requirements.

LDAP Authentication with Spring Security throwing LDAP error 49, 52e for any userDn

I have basic sample 3.2.4 ldap-xml script downloaded from spring security. The only part modified is the application security context.xml to point to my ldap server instead of dummy server.
<bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<constructor-arg value="ldap://server:389"/>
<property name="userDn" value="cn=myUsername"/>
<property name="password" value="myPassword"/>
</bean>
Now thing is, no matter what I provide in userDn value, whether it is, "afdjljaf" or "1234244" or even " ". I get error as
"LDAP: error code 49 - 80090308 : LdapErr: DSID-0C0903A9, comment:
AcceptSecurityContext error, data 52e".
Using AdFind.exe "http://www.joeware.net/freetools/tools/adfind/usage.htm", using same userDn (Lets assume my userDn is XYZ, and password is passxyz), I am able to login in ldap server using command
"Adfind.exe -h server:port -u XYZ -up passxyz"
I am able to connect to ldap server successfully and browse directory.
Can someone please tell me equivalent value for userDn and password properties that I should put in security context xml?
userDN should be like that "cn=myUsername,ou=myDepartment,dc=mydomain,dc=com". your user name should contain partition name and another thing you can use spring security tags.
<?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:s="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<s:ldap-server id="contextSource" url="${ldap.url}" manager-dn="${ldap.userDn}"
manager-password="${ldap.password}"/>
</beans>
UPDATE:
your server url should contain partition name too. "ldap://10.0.0.1:389/DC=mycompany,DC=com,DC=tr"
Generally Speaking, a DN or Distinguished Name contains a full path of the object with active directory.
CN=myUsername is not a valid DN. Firstly, where you put myUsername, should actually go the object's name (NOT their samAccountName or UserPrincipalName, i.e. a username, or their displayName for that matter) and should contain the domain name and containers like this example:
CN=Joe Bloggs,OU=Users,OU=Company,DN=domainname,DN=local
This can be accessed by viewing the distinguishedName property of an active directory object.

Datasource mysql failover - howto configure?

I'm using a spring project with org.apache.commons.dbcp.BasicDataSource datasource.
If i want my Database to support a failover where do i configure it?
I cant find any references with google
You were a bit generic in the question. I describe some possible solutions.
If you can use c3p0 here is an example with mysql server.
In the tomcat server.xml define this:
<Resource
name="jdbc/trm"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver"
password="password"
user="username"
auth="Container"
description="DB Connection pool for TRM application"
minPoolSize="2"
maxPoolSize="4"
acquireIncrement="1"
factory="org.apache.naming.factory.BeanFactory"
jdbcUrl=jdbc:mysql://localhost:3306,backupdb.something.com:3306/dbname
preferredTestQuery="SELECT 'Connection' = 'true'"
testConnectionOnCheckout="true"
/>
In case of sql server replace
jdbcUrl=jdbc:mysql://localhost:3306,backupdb.something.com:3306/dbname
with
jdbcUrl="jdbc:sqlserver://mainserver:1433;failoverPartner=backupserver;databaseName=nameofyourdatabase;applicationName=appname"
In case of oracle another solution is recomended. I just give you the link to the offical spring documentation:
http://static.springsource.org/spring-data/jdbc/docs/current/reference/html/orcl.failover.html
and I just copy here the spring bean to be used for completness.
<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:orcl="http://www.springframework.org/schema/data/orcl"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/orcl
http://www.springframework.org/schema/data/orcl/spring-data-orcl-1.0.xsd">
<orcl:pooling-datasource id="racDataSource"
url="jdbc:oracle:thin:#(description=(address_list=
(address=(host=rac1)(protocol=tcp)(port=1521))
(address=(host=rac2)(protocol=tcp)(port=1521)))
(connect_data=(service_name=racdb1)))"
properties-location="classpath:orcl.properties"
fast-connection-failover-enabled="true" 1
ONS-configuration="rac1:6200,rac2:6200"/> 2
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="racDataSource"/>
</bean>
</beans>
Other approaches are possible. E.g. using the AbstractRoutingDataSource offered from springframework.

spring social xml config

i have already read the spring social document but the part of configuration is Java based, but my project's configuration is xml based. so please tell me how config spring social in spring xml config file. thank you and sorry for my poor english
Posting your code and issues will help us to provide you the best solution. Refer to the link below may be that is what you are looking for
http://harmonicdevelopment.tumblr.com/post/13613051804/adding-spring-social-to-a-spring-mvc-and-spring
Take a look at the example xml config
https://github.com/SpringSource/spring-social-samples/tree/master/spring-social-showcase-xml/src/main/webapp/WEB-INF/spring
You have to create a social config xml file and you have to import to your root-context.xml file. Also, you may think about configure your app with spring security. It's depends of your project architecture.
Sample spring social xml config file :
<?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:social="http://www.springframework.org/schema/social"
xmlns:facebook="http://www.springframework.org/schema/social/facebook" xmlns:bean="http://java.sun.com/jsf/core"
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-3.2.xsd
http://www.springframework.org/schema/social http://www.springframework.org/schema/social/spring-social.xsd
http://www.springframework.org/schema/social/facebook http://www.springframework.org/schema/social/spring-social-facebook.xsd">
<!-- Ensures that configuration properties are read from a property file -->
<context:property-placeholder location="file:${sampleapp.appdir}/conf/appparam.txt"/>
<!--
Configures FB and Twitter support.
-->
<facebook:config app-id="${facebook.clientId}" app-secret="${facebook.clientSecret}" />
<!--
Configures the connection repository. This application uses JDBC
connection repository which saves connection details to database.
This repository uses the data source bean for obtaining database
connection.
-->
<social:jdbc-connection-repository data-source-ref="sampleappDS" connection-signup-ref="accountConnectionSignup"/>
<!--
This bean is custom account connection signup bean for your registeration logic.
-->
<bean id="accountConnectionSignup" class="com.sampleapp.social.AccountConnectionSignup"></bean>
<!--
This bean manages the connection flow between the account provider and
the example application.
-->
<bean id="connectController" class="org.springframework.social.connect.web.ConnectController" autowire="constructor">
<constructor-arg index="0" ref="connectionFactoryLocator"/>
<constructor-arg index="1" ref="connectionRepository"/>
</bean>
Sample root-context.xml :
<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:aop="http://www.springframework.org/schema/aop" xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<!-- Scan for Spring beans declared via annotations. -->
<context:component-scan base-package="com.sampleapp"/>
<context:annotation-config/>
<context:property-placeholder location="file:${sampleapp.appdir}/conf/appparam.txt"/>
<cache:annotation-driven/>
<!-- Root Context: defines shared resources visible to all other web components -->
<import resource="security-config.xml"/>
<import resource="classpath*:spring/bean-context.xml"/>
<import resource="classpath*:spring/persistence-config.xml"/>
<import resource="social-config.xml"/>
<aop:aspectj-autoproxy proxy-target-class="true"/>

Resources