I'm having this problem with a new Spring Boot service, written in Kotlin, where I start to get 404 for any REST requests after some random time (When I deploy the service, instead, everything works fine, with the same REST APIs).
In addition, I've also other services, written in Java, that are running without any problem.
Just to specify:
all the components are well defined in the application;
I've moved logging filters and some authorization logic in libraries also used in the java services (services that are running perfectly);
I am not able to reproduce locally, it happens after some time only in staging and prod envs.
Then I've noticed a really strange thing:
when running a public request (so that I skip all the auth logic checks) the logger prints the response status as 200 -> but then the final answer that the client gets is 404.
Do you have any idea or tip?
Thanks
Problem fixed! It was a mistake in the middleware, there were two service without the correct routing setup -> traefik was not able to redirect the traffic in the right way
Related
I am a little out of my league on this one as I am still getting familiar with everything Springboot. Onto my problem...
I am unable to access actuator for an application that is running in a fat jar file on an application server. All works great when I run the application locally through Eclipse as I am perfectly able to access a couple of the endpoints (health, logfile) via a browser and Postman.
However, when I attempt to access those same endpoints (via curl, a browser or Postman) using the application server's url, I get a 404. I am able to access other custom written apis within the application with no issue, just not actuator apis.
I know I am missing something very obvious, but cannot figure out what that is.
Good - http://localhost:9091/actuator/health --> from a browser or Postman
Not good - http://my-app-testserver-01:9090/actuator/health or curl localhost:9090/actuator/healthand both yield the below error. NOTE that the curl is performed on the application server.
"timestamp":"2022-06-30T20:57:12.191+00:00","status":404,"error":"Not Found","path":"/actuator/health"
What else? Oh yeah, below is a snippet from my yml file pertaining to actuator and I believe that is ok.
Any insight on this is greatly appreciated. Thank you.
management:
server:
port: 9090
endpoints:
web:
exposure:
include: "health,info,logfile" ```
This is all set now. I was setting up the application on a new server and had to have the ports opened up for me. Once that was done I was able to access the Actuator apis with no issues.
Due to a certain lack of support between two technologies I wanted to implement, I find myself in the need to look for a "smarter" proxy server than the current Apache solution I implemented. After some quick digging I found out about Spring Cloud Gateway and Zuul. As I wanted to keep things simple with dependencies, I choose Spring's option.
After some tries in my local environment with an API I had for a different purpose, I managed to get the routing right and a static page when the root is hit. Then I rolled it to my test environment and after dealing with some slightly annoying things I didn't know about Spring Cloud, the proxy worked with another API I have in that environment. I must add, this test were done in curl.
The problem I have now is that the Gateway is supposed to be used to proxy to other, non-boot application deployed in Tomcat. The routing itself works as stated in the title, but nothing is displayed. I double checked the servers were up and access to them properly directly from my browser. Then I tried to hit the test API, also deployed in a Tomcat, with my browser and found that the Get request worked ok but the Post request return 405 error (No error is logged in the prompt).
I've been looking around about this but haven't found anything yet. My initial, uneducated guess was that Spring Cloud Gateway was ment/designed to work with API based applications and/or the front end framework we use is not supported somehow, but I highly doubt that is the case.
As you see, I'm diving into this a bit blindly but the examples I've seen so far aren't particulary deep either, probably because it is fairly simple to understand.
My Java code is nothing but the Bean necesary for the Static content. I moved from Java config to yaml config as this gateway will need to be implemented in two servers with different apps on them. I'll share it anyway for the sake of completeness.
Java code:
#SpringBootApplication
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
#Bean
public RouterFunction<ServerResponse> statucResourceLocator(#Value("classpath:/static/index.html") Resource index) {
return route(GET("/"), request -> ok().contentType(MediaType.TEXT_HTML).bodyValue(index));
}
}
application.yml
server:
port: 8080
spring:
cloud:
gateway:
routes:
# Non-boot app
- id: app1
uri: localhost:8081
predicates:
- Path=/app1/**
# Non-boot app
- id: app2 <- Non-boot app
uri: localhost:8082
predicates:
- Path=/app2/**
- id: api
uri: http://localhost:8000
predicates:
- Path=/api/**
Is there something I missed from the Spring tutorial on this? Or is there a certain filter I need to add for other type of content to be displayed? We are using ZK Framework, Java 8 and our Spring version for the current projects is 4.3.8. Yes, we have a bit too much work done to make drastic updates or to change the backend.
Quick update:
I guess this was obvious, but the behaviour is the same if I test this on my local machine with an app that is not an API. I'll try to find the limitations Spring Gateway currently has, as it's still pretty new technology as far as I know.
I am facing an issue in spring boot. I developed a micro service and setup the infrastructure for it in kubernetes. I verified that my service is up and running by hitting a public URL which i exposed ( Example : https://abc/status).
But, now when i try to hit the get call which needs a header to be passed, I am receiving an exception which goes like this
Missing request header 'app_id' for method parameter of type String
While I execute this in local/within the pod, it is working fine.
Though I can confirm that the request has hit the service from the server logs. If you have faced something like this please help.
I logged all the request headers and found out that only the headers with '_' is getting dropped. Then, when I explored in the same angle, I stumbled upon this link - Spring Boot request header return null value and found out that nginx is the culprit.
So, changing the nginx config or removing '_' from the service will fix this one.
I've asked the same question at Vaadin's forum, but noone responds there, so maybe someone here can help.
I've developed a Vaadin Spring Boot app that works perfectly when I run it as is, but when I tried to run it behind Apache Proxy (so that requests to http://website/vaadin-app/ are forwarded to http://website:8080), I've got a problem: UI is rendered successfully, but the data can't be fetched from the server. The error is: The requested URL /vaadinServlet/UIDL/ was not found on this server.
It looks like Vaadin doesn't make relative requests, but rather absolute ones, so it tries to load http://website/vaadinServlet/UIDL/ instead of http://website/vaadin-app/vaadinServlet/UIDL/
What kind of configuration should I add to address this issue?
I have been Googling a lot lately, but I find myself coming up short on answers.
I have a complete Spring MVC application secured by Spring Security and with services exposing logic to controllers (controllers -> service -> repository -> POJO's).
Currently all my controllers, except the login controller, serve nothing but JSON/XML and I want it to stay this way. I do not want to render different views on each controller.
However, what I want to be able to, is to separate the web application from the backend because in time I want to be able to integration with my service using more platforms than just a web browser.
Currently I have the regular Spring MVC application:
Configuration
Domain(POJO's)
Repository
Service
Controller
Login is done using a Thymeleaf rendered view and Spring Security which does nothing more than filtering all urls under the application root. After this, it is just a bunch of static files being served as resources:
Spring Controllers send a "{ontrollerName}/layout" to serve the AngularJS HTML partial used for all data under that given Spring Controller.
What I want, is a way to separate everything in the /webapp directory from the rest of my project. I have looked into a few different solutions here such as using Apache Proxy where my Apache Http server hosts the client code which communicate with the backend using Ajax to rest controllers, and Tomcat hosting the backend. However, I hear that proxying like this is not safe. I could however be dead wrong here.
So, the questions I hope to receive answers to are:
1. Is it fine to just write a client that uses Apache http server's Proxy to provide access to Ajax on the server?
If not; How should I proceed? Is it any point in trying to extract the client side from the /webapp directory or is this just some stupid idea I created because it seemed cool to be able to deploy them without having to relay on each others?
Is there any best practices in regards to how I structure a project with separate modules? Think Gradle build scripts for multi modules.
Should I think in different terms and use an approach not based on Spring MVC at all? If so, please advice me.
I hope this was clear enough to make sense for you guys.
The solution was to use the simpler approach of a restful API that did authentication over OAuth 2.
Basically the two best alternatives are a hybrid solution (part restful API and part server side rendering of pages) or a full blown restful API where you implement all functionality in a static web client. This way there is no need for multi-module projects and packing things together in one package.