I am using spring boot application with appliaction.properties.
In the project there is XML file written by another company to configure Stomp, and there is hardcoded IP of the server, but I want to change those IP to take value from application.properties.
is there any way to do it?
application.properties
property.env=SLA
property.endpoint=http://172.1.1.139/router
tcmanager.xml
<tcmanager>
<channelbuilders>
<channelbuilder>
<class>com.company.tc.stomp.TcStompChannelBuilder</class>
<config>
<properties>
<property>brokerURL=[property.endpoint]</property> //this is the place
<property>login=login</property>
<property>passcode=pass</property>
</properties>
<in> [...] </in>
<out> [...]</out>
</config>
</channelbuilder>
</channelbuilders>
<processingbuilders>
<processingbuilder>
<class>com.company.tc.template.camel.MainProcessingBuilder</class>
<config>
<properties>
<property>p1=1</property>
</properties>
</config>
</processingbuilder>
</processingbuilders>
</tcmanager>
Related
We have profiles described as :
<profiles>
<!-- Local/Windows development -->
<profile>
<id>local</id>
<activation/>
<properties>
<INSTALL_MACHINE_LIST>localhost</INSTALL_MACHINE_LIST>
<COPY_MODE>local</COPY_MODE>
</properties>
</profile>
<!-- Development -->
<profile>
<id>dev</id>
<activation/>
<properties>
<INSTALL_MACHINE_LIST>dev01</INSTALL_MACHINE_LIST>
</properties>
</profile>
<!-- QA -->
<profile>
<id>qa</id>
<activation/>
<properties>
<INSTALL_MACHINE_LIST>dqa01</INSTALL_MACHINE_LIST>
</properties>
</profile>
<!-- Production -->
<profile>
<id>prod</id>
<activation/>
<properties>
<INSTALL_MACHINE_LIST>prod01</INSTALL_MACHINE_LIST>
</properties>
</profile>
</profiles>
For our test environment, we have 2 properties file (under src/main/test/resources) application-local.properties and application.properties file. The plan is to use application-local.properties in "local" profile mode ( on our development windows system) and application.properties for rest of the profile modes. In spring context (spring-context.xml), currently, we are manually switching between 2 properties file depending on what profile we are using. Looking for a way to select automatically application-local.properties for "local" profile and application.properties for any other type of profile. Is there a way to use if-then-else condition in xml based spring-context file? I tried :
<bean id="flag" class="java.lang.Boolean">
<constructor-arg value="#{ profile == 'local' ? true: false }" />
</bean>
<util:properties id="machineMetaDbProps" location="#{ flag ? 'application-local.properties' : 'application.properties' }"/>
Getting error :
Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Property or field 'profile' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public?'
try naming your property files like this:
application.properties
application-prod.properties
application-test.properties
and use "-Dspring.profiles.active=test" when starting your app
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html#howto-change-configuration-depending-on-the-environment
Xml Config:
In XML based config, you can make properties files related to a profile accessible to Spring via:
<beans profile="local">
<context:property-placeholder
location="classpath:docker-db.properties" ignore-unresolvable="true"/>
</beans>
<beans profile="test">
<context:property-placeholder
location="classpath:test-db.properties" ignore-unresolvable="true"/>
</beans>
Java Config:
Regarding to the active profile, you can also manually feed properties file to the spring vi java config as:
#Configuration
#Profile("local")
public class LocalPropertyReader {
#Bean
public static PropertyPlaceholderConfigurer properties() {
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
Resource[] resources = new ClassPathResource[] {
new ClassPathResource("docker-db.properties"), new ClassPathResource("application-local.properties")
};
ppc.setLocations(resources);
ppc.setIgnoreUnresolvablePlaceholders(true);
return ppc;
}
}
#Configuration
#Profile("test")
public class ProdPropertyReader {
#Bean
public static PropertyPlaceholderConfigurer properties() {
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
Resource[] resources = new ClassPathResource[] {
new ClassPathResource("test-db.properties"), new ClassPathResource("application-test.properties")
};
ppc.setLocations(resources);
ppc.setIgnoreUnresolvablePlaceholders(true);
return ppc;
}
}
Enabling Profile:
This can be done in following ways:
Using Spring context environment : ctx.getEnvironment().setActiveProfiles("local");
Using system property : System.setProperty("spring.profiles.active", "local");
Passing a system parameter at run time: -Dspring.profiles.active="local"
Enabling profile in web.xml
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>local</param-value>
</context-param>
More Info:
Load environment configurations and properties with Spring
Example
I have developed the dashboard in my application using flex 3.0. For this I have used JSP wrapper around the flex application. My application runs on JBoss application server. for communication between flex app and my application i am using LCDS. HTTPService component is being used to receive data from the server. Channel definitions are given in service-config.xml for amf and http channels and for both secure secure and not secure mode. In my proxy-config.xml i have defined Channels and destinations.
services-config.xml
...
...
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
<endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<polling-enabled>false</polling-enabled>
</properties>
</channel-definition>
<channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">
<endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>
<properties>
<add-no-cache-headers>false</add-no-cache-headers>
</properties>
</channel-definition>
<channel-definition id="my-http" class="mx.messaging.channels.HTTPChannel">
<endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/http" class="flex.messaging.endpoints.HTTPEndpoint"/>
</channel-definition>
<channel-definition id="my-secure-http" class="mx.messaging.channels.SecureHTTPChannel">
<endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/httpsecure" class="flex.messaging.endpoints.SecureHTTPEndpoint"/>
<properties>
<add-no-cache-headers>false</add-no-cache-headers>
</properties>
</channel-definition>
...
...
proxy-config.xml
...
...
<default-channels>
<channel ref="my-http"/>
<channel ref="my-amf"/>
<channel ref="my-secure-http"/>
<channel ref="my-secure-amf"/>
</default-channels>
...
...
<destination id="dashboardService">
<properties>
<url>/kr/servlet/DashboardServlet</url>
</properties>
</destination>
<destination id="dashboardJSPService">
<properties>
<url>/kr/krportal/dashboardJSPService.jsf</url>
</properties>
</destination>
...
...
In my development environment both secure and non secure mode were working fine. Now when I have deployed it behind the load balancer(which accepts secure requests only and if the request is not secure it redirects it to secure url) there is no response from the message broker servlet. One thing more I have observed is when the environment is non load balanced there are request like 'http://{server.name}:{server.port}/{context.root}/messagebroker/http'. and these requests are post request. But in load balanced environment with ssl the request is again like 'http://{server.name}:{server.port}/{context.root}/messagebroker/http' which is a post request and it is redirected to 'https://{server.name}:{server.port}/{context.root}/messagebroker/http' which is a get request. The content returned by this get request is null.
Looking for some comments
Thanks
This config file is used by both flex and lcds. Flex uses it to send messages to a specific endpoint and lcds uses this file to actually create the endpoints. You'll notice the at the end of the urls you see /amf, /amfsecure, /http, and /httpsecure. If your load balancer is redirecting a call like http://domain.com/app/messagebroker/amf to https://domain.com/app/messagebroker/amf it will fail because the ssl endpoint ends with /amfsecure.
Is there a way, to instruct Maven Surefire, to save the test starting time of each JUnit Test Case in the report xml file?
I expect that the report should look a bit like this:
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="com.chris.testcases.Timestamp" time="1,962.965" tests="1" errors="0" skipped="0" failures="0">
<properties>
<property ...>
</properties>
<testcase
name="Timestampfilter"
classname="com.chris.testcases.Timestamp"
time="1,339.383" <-- this is the already existing execution time
--> timestamp="2015-03-11 16:44:05" /> <-- this is the NEW attribute I need
...
</testsuite>
Background: I need this paramter for future processing in this xml, and just writing the timestamp in the "normal" logfile/output is no solution.
I am using: Maven 3.2.5 with Surefire-Plugin 2.18.1.
Update: I found an similar question here: https://jira.codehaus.org/browse/SUREFIRE-681
I have some points to resolve it in spring integration, I'm kind of newbie in spring integration.
The scenario is to process three dbf files and extract the data and send it to HTTP rest service as JSON if there is no response from that service during 3 mins should wait 10 mins and attempt again. The rest service will reply with json.
now I have three to four things I can't solve it:
I need to read the reply from rest service and depend on that reply decide either to retry or to finish the process. (beside if I send message to rest and no response should also retry)
I need to get multiple files from dynamic folder names for example ({wherever}/20140101/HERE WILL FIND THE THREE DBF FILES). there is any possibility to make folder name as pattern or as date with certain format? and the file adapter can process many files or files by file.
there is any possibility to process dbf files through spring integration and transform it to json
below my spring integration configuration:
<?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
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http.xsd"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-file="http://www.springframework.org/schema/integration/file"
xmlns:int-http="http://www.springframework.org/schema/integration/http"
xmlns:task="http://www.springframework.org/schema/task">
<int:service-activator input-channel="filesInChannelDBF"
output-channel="requestChannel" >
<bean class="com.mm.integration.serviceactivator.FileProcessor" />
</int:service-activator>
<int:channel id="requestChannel" />
<int-http:outbound-gateway request-channel="requestChannel"
url="http://localhost:8090/receiveGateway" http-method="POST" />
<int-file:inbound-channel-adapter id="filesInChannelDBF"
directory="file:input" filename-pattern="FILENAME*">
<int:poller id="poller" fixed-rate="100" task-executor="executor" />
</int-file:inbound-channel-adapter>
<task:executor id="executor" pool-size="10" />
</beans>
and here my pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven- 4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mm.integration</groupId>
<artifactId>XXXX</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
and here my spring entry point.
#RestController
#EnableAutoConfiguration
#EnableIntegration
#ImportResource("classpath:spring/config/concurrentFileProcessing-config.xml")
public class MainApp {
#RequestMapping(value="/receiveGateway" , method=RequestMethod.POST)
public String testGateway(String jSon){
System.out.println("Starting process the message [reciveing]");
return "{HelloMessage: \"Hello\"}";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(MainApp.class, args);
}
}
1- I need to read the reply from rest service and depend on that reply decide either to retry or to finish the process.
Any processor (e.g. <int-http:outbound-gateway>) endpoint can be configured with <request-handler-advice-chain>. And there is out-of-the-box advices for you: RequestHandlerRetryAdvice and ExpressionEvaluatingRequestHandlerAdvice. You can specify the retry advice as first one and expression as the second. With the last you can make some decision to throw or not an exception to initiate that wrapping retry. Because this one can retry only on exception. It would be better than get deal with RetryContext to have an ability to specify the custom RetryPolicy independently of exceptions.
In addition consider to use request-factory with timeout options to get deal with no response case.
2- I need to get multiple files from dynamic folder names for example ({wherever}/20140101/HERE WILL FIND THE THREE DBF FILES).
Consider to use RecursiveLeafOnlyDirectoryScanner to scan those timestamp directories from the specified root dir. From other side you even can provide any DirectoryScanner implementation to achieve the requiremnts.
3- there is any possibility to process dbf files through spring integration and transform it to json
No, Spring Integration doesn't support that feature. You can consider to use some existing tool to read DBF (https://github.com/iryndin/jdbf) and then build JSON manually.
From other side feel free to contribute it back to the framework as an extension with appropriate adapters.
Yesterday I spent half of day trying to force Flex Remoting to use HTTPS with no success.
Today I tried to connect to other domain.
I changed url of endpoint, but it looks like flex just ignores my changes.
I am sure that an old url doesn't exist in any file in src directory,
I even renamed services-config.xml to services-config2.xml, cleaned and rebuilded project many times, even made a release build, but it still connects to the same domain.
I have tested flex application in localhost and in the same domain, that has AMF services, but it works in the same way.
My services-config.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<services-config>
<services>
<service id="amfphp-flashremoting-service" class="flex.messaging.services.RemotingService" messageTypes="flex.messaging.messages.RemotingMessage">
<destination id="amfphp">
<channels>
<channel ref="my-amfphp-secure"/>
<channel ref="my-amfphp"/>
</channels>
<properties>
<source>*</source>
</properties>
</destination>
</service>
</services>
<channels>
<channel-definition id="my-amfphp-secure" class="mx.messaging.channels.SecureAMFChannel">
<endpoint uri="https://xxx.dev.company.com:443/AMF" class="flex.messaging.endpoints.SecureAMFEndpoint"/>
<properties>
<polling-enabled>false</polling-enabled>
<serialization>
<instantiate-types>false</instantiate-types>
<log-property-errors>true</log-property-errors>
</serialization>
<add-no-cache-headers>false</add-no-cache-headers>
</properties>
</channel-definition>
<channel-definition id="my-amfphp" class="mx.messaging.channels.AMFChannel" >
<endpoint uri="http://xxx.dev.company.com/AMF" class="flex.messaging.endpoints.AMFEndpoint" />
<properties>
<polling-enabled>false</polling-enabled>
<serialization>
<instantiate-types>false</instantiate-types>
<log-property-errors>true</log-property-errors>
</serialization>
<add-no-cache-headers>false</add-no-cache-headers>
</properties>
</channel-definition>
</channels>
</services-config>
RemoteObject definition in mxml:
<mx:RemoteObject id="Agentrpc" destination="amfphp" source="Agentrpc" showBusyCursor="true">
<mx:method name="getAgentID" result="getAgentID_resultHandler(event)" fault="faultHandler(event)"/>
</mx:RemoteObject>
I'm using Flex 3.
Edit: I took a look at generated/ dir and I see that FlexInit files (like MainModule_FlexInit-generated.as) contains code:
ServerConfig.xml =
<services>
<service id="amfphp-flashremoting-service">
<destination id="amfphp">
<channels>
<channel ref="my-amfphp-secure"/>
<channel ref="my-amfphp"/>
</channels>
</destination>
</service>
<channels>
<channel id="my-amfphp-secure" type="mx.messaging.channels.SecureAMFChannel">
<endpoint uri="https://gintautas.dev.company.com:443/AMF"/>
<properties>
<polling-enabled>false</polling-enabled>
</properties>
</channel>
<channel id="my-amfphp" type="mx.messaging.channels.AMFChannel">
<endpoint uri="http://gintautas.dev.company.com/AMF"/>
<properties>
<polling-enabled>false</polling-enabled>
</properties>
</channel>
</channels>
</services>;
That's correct, but application doesn't make requests to gintautas.dev.company.com
Edit 2: I installed Flash Builder 4 and tried to compile using 3.5 and 4.0(in compatibility mode) compilers, but both has the same problem :(
Can you try to clear your browser cache ? The content of the services.xml is injected into the SWF at compile time.
you can check what is being compiled into flex from the *-config.XML files with the following:
trace( ServerConfig.XML );
Also, if using WTP with tomcat, check if server is using the actual installation of tomcat, or a temp eclipse folder to run. that can sometimes cause mix ups.
You must "clean project" in Flex Builder when you change services-config.xml