Configuring the URL context - java

I am working on configuring a website where the client wants us to configure URL's like example.com/newyork and example.com/england. We are using Java SpringBoot environment.
Please advise how should I approach this problem? Is this something that can be configured in spring boot/spring-mvc or is an apache configuration.

You have to use #RequestMapping("/myUrl") on your controller where myUrl should be replaced with the URL you want.
This should work.

Related

How can I toggle URL between environments?

I've been looking for a way to change the url my microservice is depending on from one environment to another, they told me that I should use spring cloud, and there is currently an application.yml that is used for deployment in openshift, but my knowledge of Spring Cloud is limited and I don't know how to inject the value of the application.yml URL into my java program.
String uri = "http://127.0.0.1:8080/route";
I am looking to change this variable depending on whether it is local, or in development
Why? For communication between microservices
private RestTemplate call = new RestTemplate();
Arrays.asList(call.getForObject(uri, Object[].class));
In local need: "http://127.0.0.1:8080/route";
In dev need : "http://www.myurl.com/route"
I hope I explained myself well
Thanks.
Ok, i think have the solution for my problem.
As I am using Openshift for deployments, and the local configuration for something else, I have used Spring Cloud with a configuration server, making it use one configuration locally, and in development another one overwriting the local configuration.
This solved my problem, thanks to other guys to answer with any solutions.
As "M. Deinum" and "Ken de Guzman" have already mentioned, use the "Spring Profiles" approach.
See here the docs, which explain the functionality:
External configuration: https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config
Usage of Profiles: https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-profiles or https://springframework.guru/spring-profiles/
In-depth read: https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#beans-environment

Apache Karaf Rest Service Issue

I am having a WAB application which is just having only one html file, and its working fine. the code is available on the below git link
https://github.com/vineethvnair0/Karaf/tree/master/first-wab
Now I want to define a rest service in the wab, with the same context root as my web app for example like below.
http://localhost:8181/first-wab/rest/hello
Please let me know how can i do it?
Simply add a CXF servlet to the web.xml. The exact solution depends on how you expose your Rest endpoints. Do you plan to use spring?

openejb + Tomcat : How to use ejbd protocol?

I have deployed an openEJB.war in a Tomcat container. I have deployed an EJB in the /webapps folder of Tomcat. When I call the ejb via HTTP it works fine :
props.put(Context.PROVIDER_URL, "http://localhost:8080/openejb/ejb");
I would like to use ejbd protocol instead of http but I don't know how to do this. If I replace http://localhost:8080/openejb/ejb by ejbd://localhost:4201/ or ejbd://localhost:8080/ it doesn't work. I think Tomcat doesn't provide any ejbd listener. If I deploy my EJB on openEJB standalone server, it works fine.
Do you know how can I fix this?
Thanks
For provider url we use
ejbd://localhost:4201/ejb
Also, you may need to review this page to setup all necessary properties and configuration: http://openejb.apache.org/3.0/embedded-and-remotable.html
Especially, set openejb.embedded.remotable to true

JAAS with servlet

I am trying to use JAAS for my servlet application. I could get a basic JAAS simple authentication (non-servlet) working.
But with the servlet where to i set this variable?
-Djava.security.auth.login.config=test_jaas.config
I also tried exporting JVM_OPTS to this as per this page http://www.kopz.org/public/documents/tomcat/jaasintomcat.html
But I still keep getting, "No LoginModules configured" while creating LoginContex.
Any help is appreciated.
It depends on the servlet container. If you're using Tomcat you have to configure a JAAS realm. See the Tomcat configuration documentation under Realms.
instead you can go to java_home/conf/security/java.security and add your config location by adding the following
login.config.url.1=file:[test_jaas.config path]

Spring MVC application context path

My Spring MVC application is runnning on a Tomcat behind an Apache 2 acting as a proxy. I access my app directly in tomcat via an url like http://localhost:8080/myapp. I access my app via proxy with an url like http://localhost/tomcat/myapp.
The second url makes my app behave incorrectly, because it supposes it lives in /myapp context path, but via the proxy it should live in /tomcat/myapp.
Is there a variable in Spring or Servlet API, that holds /tomcat/myapp if I am accessing it via the proxy, and /myapp if I am accessing it directly?
Thanx
I think you need to enable proxy support then. This link might help you or give a little hint in this regards.
http://tomcat.apache.org/tomcat-6.0-doc/proxy-howto.html
Just stumbled upon this post while searching for the config setting for tomcat.
There is a much easier way to configure tomcat to handle the exact situation you are experiencing. See:
http://tomcat.apache.org/tomcat-5.5-doc/proxy-howto.html
Simple configure a connector for the proxy in tomcat, and the servlet/struts context path issues will resolve.
-edit: Obviously I didn't read #2 comment...
I mean when I redirect to "/index.jsp"
it actually redirects to
"http://localhost/myapp/index.jsp"
instead of
"http://localhost/tomcat/myapp/index.jsp"
Redirect to index.jsp instead of /index.jsp
When you redirect to /index.jsp this acts as an absolute url and it gets redirected to myapp/index.jsp. index.jsp is a relative url and will redirect to tomcat/myapp/index.jsp

Categories

Resources