Is it possible to refresh the configurations calling a java method instead to use the REST api:
curl localhost:8080/actuator/refresh -d {} -H "Content-Type: application/json"
You can use the ResartEndpoint class from spring-cloud-context:
#Autowired
private RestartEndpoint restartEndpoint;
...
Thread restartThread = new Thread(() -> restartEndpoint.restart());
restartThread.setDaemon(false);
restartThread.start();
This is how #alexbt suggests to do it. But note that the spring cloud documentation also says you can refresh individual beans provided they are RefreshScope.
Related
I basically followed the steps described here: https://docs.spring.io/spring-data/neo4j/docs/current/reference/html/#configure-spring-boot-project
My application.properties contains the following:
spring.neo4j.uri=neo4j://localhost:7687
spring.neo4j.authentication.username=neo4j
spring.neo4j.authentication.password=verySecret357
I have a Neo4jConfiguration Bean which only specifies the TransactionManager, rest is (supposedly) taken care of by spring-boot-starter-data-neo4j:
#Configuration
public class Neo4jConfiguration {
#Bean
public ReactiveNeo4jTransactionManager reactiveTransactionManager(Driver driver,
ReactiveDatabaseSelectionProvider databaseNameProvider) {
return new ReactiveNeo4jTransactionManager(driver, databaseNameProvider);
}
}
Neo4j (5.3.0) runs in a Docker container I started with
docker run -d --name neo4j -p 7474:7474 -p 7687:7687 -e 'NEO4J_AUTH=neo4j/verySecret357' neo4j:4.4.11-community
I can access it through HTTP on my localhost:7474 and can authenticate using the credentials above.
Now, when I run my springboot app and try to create Nodes in Neo4j, I keep getting the same exception:
org.neo4j.driver.exceptions.AuthenticationException: The client is unauthorized due to authentication failure.
Running in debug, it however seems the client authentication scheme is correctly set:
Any thoughts on what I might be doing wrong ?
Edit: one thing though, I would assume that the "authToken" would contain a base64-encoded String (username:password) as the scheme is basic auth. It looks like it's not the case (using neo4j-java-driver:5.2.0).
Edit: seems to be related to the Docker image. A standalone neo4j instance works fine.
I'm new in Spring and I have a problem when I run Spring WEB in VM.
Test on local computer works:
I run app mvn spring-boot:run -Dspring-boot.run.profiles=test and check request:
curl -X POST ``http://localhost:8080/api/v1/dictionary/yandex-alice-skill`` -H "Content-Type: application/json" -d "{}"
and get {"response":{"text":"Hi! I can help you to learn words.","end_session":false},"version":"1.0"}
When I run app in VM and try to get json in my VM everything works fine too:
BUT when I try to get json in my local computer I get 404
Page have 404, but why I can't get json? How to properly connect to my virtual machine?
Controller:
#RestController
#Slf4j
#RequestMapping("/api/v1/dictionary/yandex-alice-skill")
#RequiredArgsConstructor
public class DictionaryController {
#Autowired
private DictionaryService dictionaryService;
#PostMapping
public #ResponseBody talkYandexAlice(
#RequestBody YandexAliceRequest request) {
return dictionaryService.talkYandexAlice(request);
}
}
I want to get json, but I get HTML from server.
I'm trying to migrate a curl command with a username and password to a rest API consumer code of org.springframework.web.client.RestTemplate
curl -i -k --location -u username:userpass \
--request GET http://myserver:80/rest/api/2/project --header 'Accept: application/json' \
--header 'Content-Type: application/json' --data-raw ''
But such parameter username:password is not supported in RestTemplate (correct me if I'm wrong)
What other options can do this?
I'm using spring boot 2.4.3
If you use -u or --user, Curl will Encode the credentials into Base64 and produce a header like this: -H Authorization: Basic <Base64EncodedCredentials>
There is a way to build a RestTemplate with what you want to achieve. To do that just configure a singleton restTemplate bean in your configuration class.
Until version 2.1.0 it was available the basicAuthorization()
previous spring boot versions used basicAuthorization()
#Bean
RestTemplate rest(RestTemplateBuilder restTemplateBuilder) {
restTemplateBuilder.basicAuthorization("username", "userpass").build();
}
From 2.1.0 and forward the basicAuthorization() has been deprecated and in later versions removed. You can use basicAuthentication() instead
newer versions have only basicAuthentication()
#Bean
RestTemplate rest(RestTemplateBuilder restTemplateBuilder) {
restTemplateBuilder.basicAuthentication("username", "userpass").build();
}
I have simple rest controller
public void getMyIp(HttpServletRequest request)
{
final var ip = request.getRemoteAddr();
....
}
And I emulate request through proxy server
curl --location --request GET 'localhost:8080/api/myIp' \
--header 'X-Forwarded-For: 10.10.10.10' \
--header 'X-Real-Ip: 10.10.10.10'
I changed strategy in application.yml
server:
forward-headers-strategy: FRAMEWORK
The application runs from IDE with build-in tomcat server.
Why I gets my real ip address?
UPD: I changed strategy to native, and it works now!
It need to use strategy NATIVE
server:
forward-headers-strategy: NATIVE
I'm currently trying to trace two Spring Boot (2.1.1) applications with Jaeger using https://github.com/opentracing-contrib/java-spring-web
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-spring-web-starter</artifactId>
</dependency>
also tryed with no success
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-spring-jaeger-cloud-starter</artifactId>
</dependency>
The tracing of the Spans for every single service / app works fine, but not over REST requests on a global level.
There is no dependency shown between the services like you can see in the image.
Shouldn't this work out of the box through the library? Or do I have to implement some interceptors and request filters by my own and if so, how?
You can CHECKOUT a minimalistic project containing the problem here
Btw: Jaeger runs as all-in-one via docker and works as expected
docker run \
--rm \
--name jaeger \
-p5775:5775/udp \
-p6831:6831/udp \
-p6832:6832/udp \
-p5778:5778 \
-p16686:16686 \
-p14268:14268 \
-p9411:9411 \
jaegertracing/all-in-one:latest
The problem is that you are using RestTemplate template = new RestTemplate(); to get an instance of the RestTemplate to make a REST call.
Doing that means that Opentracing cannot instrument the call to add necessary HTTP headers.
Please consider using #Autowired RestTemplate restTemplate
Could you try using a more recent version of Jaeger: https://www.jaegertracing.io/docs/latest/getting-started/#all-in-one - actually 1.11 is now out, so could try that.