We are facing some issue with our spring boot application. we are using Embedded tomcat. when we hit couple of urls with the keywords having special characters, its not reaching our application. The application is hosted in google cloud. We are unable to reproduce this on local, but when he hit the same url in other environments , we can see the blank page. We checked by adding lot of logs in filters and our controllers, the request is not coming to our application it self. Can somebody help me with this issue.
Example: www.test.com/s/5%2F8%20spark%20plug
as #chrylis mentioned, there isn't anything that you can do in your application to allow this type of URL to work, as the problem is before your application, and your application never gets the request.
I recommend that instead of spending a lot of time investigating why the Google Cloud platform is choking on the URLs, you take a hard look at your application and ask yourself if you really need these 'nonstandard' urls.
If, for instance, "5%2F8%20spark%20plug" is something provided by an end-user (or a url-encoded version of something provided by an end-user), then perhaps it would be better to use an id (a Long or a UUID) instead - something that is "normalized" and known to not create a URL-parsing issue.
Related
So I have a Spring Boot app, with an Angular Front-end. My plan is to embed Tomcat in the Spring Boot app for routing, reverse proxies, etc. What I want to happen is the user types in the URL, the Spring Boot tomcat server figures out if there is a domain linked to that request and so on, however if the user types in the specified IP and Port it brings up the Admin Panel which is the Angular CLI application which already has injections, and Authentication and session control. I don't want people being routed to the Admin Panel unless that condition is filled. I would like the http request to go to the tomcat server and if the condition is met then it pulls up the Angular App. However, I am not quite sure how one would go about this, is it possible to call the Angular app from the Spring application?
Update:
After hearing some feedback I made a diagram to help explain what I am looking for:
Routing Diagram, so in this a client or user would type in "https://example.com/" in their browser, it would first go to angular being the frontend, angular realizes it does not have the example.com resource so it requests just example.com/ from the backend, which knows where the resource is and then injects the html file back into the front end. The only time in which a user would be greeted with the login page I have constructed is if they have typed in the primary IP address of the server, which I would probably end up injecting by some variable from the backend as the front end wouldn't know what the IP is... thats a different issue I would have to solve. Is there a better way to do this? Should I be using React.js instead of angular? so far my application structure is very similar to this github repository: https://github.com/liliumbosniacum/spring-security-angular I have modified it and fixed some of the code and am looking into better ways but this was my starting point. I really hope this clarifies, I am looking for if there is a better way to do this or if this is not how it should be done how should it be done? like just an explanation with a diagram on what a better way would be? and Is Angular the Right front end for me?
What I understand from your problem is that you want your Spring boot app to route requests to views created by your Angular program and need some authentication features.
For me, I'd rather divide the project into frontend and backend and use JWT tokens, but for your situations you can have a look on this official Spring documentation. It's a detailed post that integrates Spring boot and Angular, and it also deals with Spring security.
We're using Websphere to host a series of applications for us:
We have an API that's hosted at the root, written in Java
We have an Angular application hosted at /admin
We have another Angular application hosted at /marketing
My concern is about deep-linking. If a user is at /marketing/products/1, and they refresh their browser or share the link, I need the server to send that route to the correct Angular application so it can be generated correctly.
In a simpler setup, where the Angular application is living at the root, I would use the Java application's web.xml file to redirect traffic to "/". But in my current scenario, I need traffic for the marketing site to go to "/marketing", not just to "/". Just like a deep-link from the admin site would need to go to "/admin".
Furthermore, the base URLs for these Angular applications are subject to change, and we also plan to add additional Angular sites to this same server. So I'm really looking for a solution that can work dynamically and have the server redirect to the first "slug" in the URL rather than matching specific directories.
Any ideas? (And please excuse and correct any misconceptions I've demonstrated above -- I currently know very little about WebSphere)
I can see a couple possible ways forward.
You could still use the error-page directive in web.xml, but specify the URL of a servlet in your application that could do the inspection manually and issue a redirect as appropriate. How the list of context roots is provided to your app will differ based on how it's packaged, but it could be done using files, environment variables, or JNDI entries in server.xml.
If the URLs could be changed, the Angular apps could be changed to use HashLocationStrategy in their routers which would sidestep the error page. It doesn't seem likely that that's the case but I'll put it here to get it out of the way.
You could consider splitting each Angular app into its own .war file and configuring the context root in the webApplication element in server.xml. Then redirecting to / in web.xml would work since that / is relative to the context-root.
We ended up combining those separate Angular applications into 1 so that WebSphere could direct everything to "/" and Angular routing could handle everything from there.
I have designed a independent Angular 4 application in Node.js and also design a rest api service using dropwizard. I have tried to connect website as static asset for dropwizard service but I could not integrate it properly. I had gone through several links on google, everywhere repeating same thing which I have tried many a times.
One thing I thought of deploying both of these independently but a question rises how?? How can I deploy two thing on server under same domain?
Another thing which can be possible is Integrate Dropwizard with angular app, which I have tried and read many docs. but still If someone can give some sort of link related to creating these in maven is most welcome.
I need some insight regarding this.
Thanks.
How can I deploy two thing on server under same domain?
Deploy them behind a reverse proxy like nginx and use different context paths.
You could serve the result of package Angular app as a Dropwizard asset
Then you can call the rest API from Angular.
Remember that Dropwizard is just some code to glue together Jersey (for rest), Jetty (webserver) and Jackson (JSON), with the main purpose of simplifying configuration.
I know that by sending a http post request to http://host:port/shutdown, we can shutdown a Springboot application. Is it possible to restart the whole springboot application by sending a http request in a production environment? So we don't need to login in the server to do that. Thank you.
I don't think such a thing exists, I'll be glad to be proven otherwise:
Spring boot doesn't do any assumptions about the environment it runs in. So when spring boot process gets shut down, re-starting it again is "out of competence" of spring boot infrastructure which is just a bunch of java classes running inside a JVM process.
You can find Here a list of endpoints exposed by the spring boot. There is a "shutdown" method that you've mentioned there, but there is no "restart" functionality exposed.
Now there are other techniques that probably can help:
If the application gets shut down because of some illegal state of some spring bean, maybe it makes sense to expose some endpoint that will "clean up" the state and make application operational again. If the application has to be restarted due to changes in configuration files or something, then you might want to consider using spring cloud's Refresh Scope for Beans. It's kind of hard to provide more information here, because you haven't mentioned the reason for shutting down the application, but I guess you've got the direction.
Having said that, there are probably some different ways to achieve what you want depending on the environment your application runs in:
If you're running in AWS for example, you can take advantage of their autoscaling policies, shut down the application remotely and AWS will run another instance for you. I'm not an expert in AWS, but I saw this working in ECS for example.
If you're running "java -jar" just on some server and want to make sure that when your process ends (by using 'shutdown') it should be started again, its possible to use some kind of wrapper that would wrap the process in service and track the service availability. There are even ready solutions for this, like Tanuki wrapper (I'm not affiliated with this product but used once its free version and it served us great)
If you're using Docker infrastructure you can change the policy and restart the container automatically when it gets shut down, I haven't used this by myself, but according to This excellent blog post is perfectly doable.
You should look at Spring boot jenkins You will also find a small article explaining how to configure the project on jenkins.
I am using Wildfly 10.1.0.Final on the Ubuntu 16.04.02 LTS Server, I put the SSL from letsencrypt.org running with the H2 (HTTP 2) protocol and Spring Security 4.2.2.RELEASE in Production.
The server is working fine with a very good performance and is not slow but I'm getting many bug reports in the wildfly log of java.net.URISyntaxException (Error 500), from user agents like "Mozilla / 5.0 Jorgee".
I would like to know how I can block these type of bad user agents (malware, bots, etc) and(or) prevent this from happening.
Thanks in advance for all the help.
I had the same problem multiple times recently and the requests origin were random (Brazil, Germany, Argentine, US, Ireland...). I'm not sure if there is a way to blacklist these request within WildFly configuration however, you may want to consider to create a custom Java EE Filter.
The solution to my problem was to get a WAF in front of the CDN but if you don't have one you may want to add Nginx in front of your Web App and blacklist the user agent "Jorgee" as well as paths such as:
/2phpmyadmin/
/admin/phpMyAdmin/
...
You can find more info in this blog post by Kurtis Rader.