1

I have the following:

  • System A - Authorization (REST API)
  • System B - Needs to check for auth
  • System C - Needs to check for auth
  • System D - Needs to check for auth

And I have many environment:

  • Development
  • Homolog
  • Production

Each one will have different URLs for System A. So I want to create a project that will integrate those systems. Since All Systems use Jersey and Spring, I can create one filter (jersey) that will abort the request in case the user is not authorized.

So the idea is to create Integration System that will be a JAR with Jerseys filters and uses the parents configuration (Active profile from Spring) to get the correct URL. I might even use this JAR to make System B communicate with System D also, if I can make this work.

The trick is, making this JAR get the correct .properties file based on the Enviroment (set on the parent-project). To be honest, I dont know where to begin.

Reading the DOCs for Spring Environment I found:

Do not use profiles if a simpler approach can get the job done. If the only thing changing between profiles is the value of properties, Spring's existing PropertyPlaceholderConfigurer / may be all you need.

I could have 3 different properties files (development, homolog or production) or I could have one properties file with different keys:

system.a.url.develpment=http://localhost:8080/systemA/authorize
system.a.url.homolog=http://localhost:8081/systemA/authorize
system.a.url.production=http://api.systemA.com/authorize

What is the best approach? What would you do?

Marco Noronha
  • 115
  • 1
  • 9
  • 31

1 Answers1

1

In such "simple" case I would only use property file for configuration of urls and have different config files for different environments (dev, prod,..) with one (same named property), e.g.

system.a.url=http://localhost:8081/systemA/authorize

You can manage your property files manually (e.g. outside your jar/war) or you can use maven profiles to make jar/war file specific for your environment. But I don't see the need for spring profiles.

EDIT: Alternatively you can use environment variables to "configure" settings specific to an environment (what a coincidence in the names :)). Note that you can have different environments also inside one machine. For more details check e.g. this.

export AUTH_URL="http://localhost:8081/systemA/authorize"
sodik
  • 4,675
  • 2
  • 29
  • 47
  • 3
    The latter, using maven profiles to create different artifacts, is a no go imho. You want a single trusted artifact that you move to different environments as that is what you test, there is no guarantee that all artifacts are exactly the same. The only viable solution is to use an external properties file and have that in a well known location. – M. Deinum Oct 29 '14 at 12:09
  • I need only ONE JAR for this. Because that JAR will be a dependency for all systems. This JAR needs to know on what environment the parent-project is working on, so I can get the correct URL. – Marco Noronha Oct 29 '14 at 12:12
  • if you want only one jar, then you can depend on external configuration. Or alternatively, you need to use any input from outside (system env. variables or -Dparams) to define your environment or directly the URL needed (depending if you have more configuration related to one environment) – sodik Oct 29 '14 at 12:16
  • The thing is: that environment needs to come from the PROJECT it self. That's because one server will host more than one environment for that system. Eg.: cloud server will host "beta" and "production". In this matter, I need the SystemA-Beta to tell that jar that its on "beta" and the SystemA-Production to tell that jar that its on "production". – Marco Noronha Oct 29 '14 at 12:20
  • imho it is not flexible solution to define all "possible" environments inside jar...you can't reuse that jar if there is any change in the future (new server/new environment). I would go for external configuration (either via defined external files or via environment variables) – sodik Oct 29 '14 at 12:24
  • @sodik if it comes from extenal file or system variables, how can the same server host two "environments" (like beta and production)? – Marco Noronha Oct 29 '14 at 12:30
  • each system process can have its own environment variables. in linux if you set environment variable it will have effect only for programs started afterwards from that session. – sodik Oct 29 '14 at 12:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/63874/discussion-between-marco-noronha-and-sodik). – Marco Noronha Oct 29 '14 at 14:57