How to set the servers property of openapi with Apache Camel? - spring

I am trying to setup a openapi specification and publish the API with Apache Camel and Spring. I tried using restConfiguration, adding the property in the application.yaml, and using the #OpenApiProperty on the app. Everytime the generated yaml reads:
- servers
- url: ""
platform:
# not used
urlrewrite:
enabled: false
token: ${LOCAL_TOKEN:}
apim:
token_ep: ${x/token}
client:
username: ${apim_client_username:}
password: ${apim_client_password:}
consumerKey: ${apim_client_id:}
consumerSecret: ${apim_client_secret:}
endpointsOrchestrated:
server: myServer
emr-endpoint: xxxxxxxx
triggerName: ${PLATFORM_MODULE_ID}
env: dev
domain: ${PLATFORM_MODULE_DOMAIN}
openapi:
title: My Sample api
version: 1.0.0
camel:
dataformat:
jackson:
auto-discover-object-mapper: true
springboot:
tracing: false
rest:
host: myhost.com
port: 8080
spring:
application:
name: aaa
profiles:
active: ${ENV:local}
server:
servlet:
context-path: /
port: ${TOMCAT_PORT:8080}
host: localhost
# MAX HTTP THREADS
tomcat:
threads:
max: ${MAIN_HTTP_THREADS:200}

Related

Failed to bind properties under 'eureka.client.enabled' to boolean

why is the new spring-cloud-config so complicated?
I would like to do the following: enable eureka on default and add it in some profiles (not in all).
no matter in which way I tried it, it didn't work.
I get this error Failed to bind properties under 'eureka.client.enabled' to boolean.
first way:
server:
port: 8080
eureka:
client:
enabled: false # default disabled
instance:
leaseRenewalIntervalInSeconds: 10
prefer-ip-address: false
hostname: 127.0.0.1
spring:
application:
name: app
main:
banner-mode: off
cloud:
config:
enabled: false
discovery:
enabled: true
service-id: config-server
fail-fast: true
retry:
max-attempts: 5
application:
value: app-default
---
spring:
config:
activate:
on-profile: dev
application:
value: app-dev
---
spring:
config:
activate:
on-profile: qa
import: "configserver:"
cloud:
config:
enabled: true
eureka:
client:
enabled: true # enable it in profile "qa"
serviceUrl:
defaultZone: http://127.0.0.1:8761/eureka/
application:
value: app-qa
second way:
server:
port: 8080
eureka:
client:
enabled: true # default enabled
instance:
leaseRenewalIntervalInSeconds: 10
prefer-ip-address: false
hostname: 127.0.0.1
spring:
application:
name: app
main:
banner-mode: off
cloud:
config:
enabled: false
discovery:
enabled: true
service-id: config-server
fail-fast: true
retry:
max-attempts: 5
application:
value: app-default
---
spring:
config:
activate:
on-profile: dev
eureka:
client:
enabled: false # disable in profile "dev"
application:
value: app-dev
---
spring:
config:
activate:
on-profile: qa
import: "configserver:"
cloud:
config:
enabled: true
eureka:
client:
serviceUrl:
defaultZone: http://127.0.0.1:8761/eureka/ # I also need a profile specific url
application:
value: app-qa
if I activate eureka once and never use eureka.client.enabled again, then the error with the url occurs: Failed to bind properties under 'eureka.client.serviceUrl. defaultZone' to String - but I need this profile specific url in any case!
all this has to do with the new spring-cloud-config. because after I deleted all the lines for the config-server and commented out the spring-cloud-starter-config dependency, both variants with eureka worked!
or do i have an error according to this spring-cloud-config stuff?
versions:
<spring-boot.version>2.5.2</spring-boot.version>
<spring-cloud.version>2020.0.3</spring-cloud.version>

Problem with unknown ports on Spring Eureka Client registration

Well, a have tried ALL tutorials, ALL answer on Stackoverflow. But I still face the same error:
On Heroku, Eureka Clients are receiving random ports that I don't know where they come from.
And these random ports are different from Heroku Environment variable $PORT. I know that $PORT is the container Dyno port, not the host port xxxxx.herokuapp.com that the out side world can access. Again, I don't know where these ports come from!!!
The link clients in the Eureka Dashboard stay like this:
hdfb2324-8jfw-83ud-dkdf-9ej90jefj201.qwer.dyno.rt.heroku.com:inight-ws-gateway:${RANDOM PORT}
When I click, go to https://inight-ws-gateway.herokuapp.com:${RANDOM PORT}/actuator/info. I take the Timeout because the correct port is 443, Https default.
I have 3 applications, 1 Eureka Server and 2 Eureka Clients (Zuul Gateway and a trivial Rest API).
Every works ok when I run in my localhost, but when I deploy in Heroku, it's happen.
Eureka Server application.yaml:
server:
port: ${PORT}
spring:
application:
name: '#project.artifactId#' # inight-ws-discovery
version: '#project.version#'
eureka:
client:
fetch-registry: false
register-with-eureka: false
management:
endpoints:
enabled-by-default: false
web:
exposure:
include:
- health
- info
endpoint:
health:
enabled: true
info:
enabled: true
Eureka Client (Zuul gateway) application.yaml:
server:
port: ${PORT}
spring:
application:
name: '#project.artifactId#' # inight-ws-gateway
version: '#project.version#'
eureka:
instance:
hostname: ${INIGHT_EUREKA_INSTANCE_HOSTNAME} # inight-ws-gateway.herokuapp.com
client:
enabled: true
fetch-registry: true
register-with-eureka: true
service-url:
defaultZone: ${INIGHT_EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE} # https://inight-ws-discovery.herokuapp.com/eureka/
healthcheck:
enabled: true
zuul:
sensitive-headers:
- Cookie
management:
endpoints:
enabled-by-default: false
web:
exposure:
include:
- health
- info
- routes
endpoint:
health:
enabled: true
info:
enabled: true
routes:
enabled: true
jwt:
config:
privateKey: ${INIGHT_JWT_CONFIG_PRIVATEKEY}
Eureka Client (Rest API) application.yaml:
server:
port: ${PORT}
spring:
application:
name: '#project.artifactId#' # inight-ws-auth
version: '#project.version#'
datasource:
hikari:
schema: inight
jdbc-url: ${INIGHT_DATASOURCE_JDBC_URL}
username: ${INIGHT_DATASOURCE_USERNAME}
password: ${INIGHT_DATASOURCE_PASSWORD}
driver-class-name: ${INIGHT_DATASOURCE_DRIVER_CLASS_NAME}
jpa:
show-sql: ${INIGHT_JPA_SHOW_SQL}
hibernate:
ddl-auto: ${INIGHT_JPA_HIBERNATE_DDL_AUTO}
eureka:
instance:
hostname: ${INIGHT_EUREKA_INSTANCE_HOSTNAME} inight-ws-auth.herokuapp.com
client:
enabled: true
service-url:
defaultZone: ${INIGHT_EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE} https://inight-ws-discovery.herokuapp.com/eureka/
healthcheck:
enabled: true
management:
endpoints:
enabled-by-default: false
web:
exposure:
include:
- health
- info
endpoint:
health:
enabled: true
info:
enabled: true
jwt:
config:
privateKey: ${INIGHT_JWT_CONFIG_PRIVATEKEY}
swagger.basePackage: br.com.bz.inight.auth.controller
my fault!!!!!
I have a couple of microservices on Heroku:
Eureka Server
Zuul Gateway
Some app services
The link on Eureka Server Dashboard, doesn't matter. Whats matter is the https://GATEWAY.herokuapp.com/actuator/routes and the <port enabled="true">80</port> on https://EUREKA_SERVER.herokuapp.com/eureka/apps.
But for this happen (<port enabled="true">80</port> on app services) you MUST ,EXPLICITLY, declare in application.yaml
eureka:
instance:
non-secure-port: 80
hostname: ${EUREKA_CLIENT_INSTANCE_HOSTNAME} # herokuapp_name.herokuapp.com
If you read the documentation, you will see that the property eureka.instance.non-secure-port has the default value 80. I don't know why, but, if you don't declare it, the <port enabled="true">80</port> are not set up on microservices applications on Eureka Server.
Check the tutorial https://blog.heroku.com/managing_your_microservices_on_heroku_with_netflix_s_eureka.
Well, these are my architecture application.yaml:
coffee-eureka-server application.yaml
spring:
application:
name: '#project.artifactId#'
server:
port: ${PORT}
eureka:
instance:
hostname: ${EUREKA_CLIENT_INSTANCE_HOSTNAME} # herokuapp_name.herokuapp.com
client:
fetch-registry: false
register-with-eureka: false
service-url:
defaultZone: ${EUREKA_SERVER_URI}/eureka/ # in this case, same value of eureka.instance.hostname, but with https:// prefix, of course
coffee-zuul-gateway application.yaml
spring:
application:
name: '#project.artifactId#'
server:
port: ${PORT}
eureka:
instance:
hostname: ${EUREKA_CLIENT_INSTANCE_HOSTNAME} # herokuapp_name.herokuapp.com
client:
fetch-registry: true
register-with-eureka: true
service-url:
defaultZone: ${EUREKA_SERVER_URI}/eureka/
management:
endpoints:
enabled-by-default: true
web:
exposure:
include:
- routes
- info
- health
coffee-simple-ms application.yaml
spring:
application:
name: '#project.artifactId#'
server:
port: ${PORT}
eureka:
instance:
non-secure-port: 80 # <<<<<<<<< HERE
hostname: ${EUREKA_CLIENT_INSTANCE_HOSTNAME} # herokuapp_name.herokuapp.com
client:
fetch-registry: true
register-with-eureka: true
service-url:
defaultZone: ${EUREKA_SERVER_URI}/eureka/
When I click, go to https://inight-ws-gateway.herokuapp.com:${RANDOM PORT}/actuator/info. I take the Timeout because the correct port is
443, Https default.
When you are hosting on localhost the link would be: http://localhost:${PORT}/actuator/info
On Heroku this link is: https://inight-ws-gateway.herokuapp.com/actuator/info
The difference:
It is using http secure, https
The port number is "gone"
The hostname inight-ws-gateway.herokuapp.com is automatically translated into a ${IP_ADDRESS}:${PORT}.
You will need to adjust your source code for the https URL generation.
Your web application will run on a port different from the usual http/https port. It does not have to be 80, 8080 or 443. It can be any port. And that port is specified by Heroku through $PORT.

Unable to resolve values from spring boot application yaml files

Hi I am haveing a spring boot rest based application . I have added a couple of properties related to elastic search in my application-dev.yml and application-prod.yml file . These properties are injected into my PerformanceReportingRepository class . however they are set to null .
so following is my yml definition .
# ===================================================================
# Standard Spring Boot properties.
# Full reference is available at:
# http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
# ===================================================================
logging:
level:
ROOT: TRACE
com.openmind.primecast: DEBUG
io.github.jhipster: TRACE
spring:
profiles:
active: dev
include: swagger
devtools:
restart:
enabled: true
livereload:
enabled: false # we use gulp + BrowserSync for livereload
jackson:
serialization.indent_output: true
data:
cassandra:
contactPoints: localhost
protocolVersion: V4
compression: LZ4
keyspaceName: Openmind
mail:
host: localhost
port: 25
username:
password:
properties:
mail:
smtp:
auth: true
starttls.enable: true
messages:
cache-seconds: 1
thymeleaf:
cache: false
http:
multipart:
maxFileSize: 150MB
maxRequestSize: 150MB
# ===================================================================
# To enable SSL, generate a certificate using:
# keytool -genkey -alias primecast -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore keystore.p12 -validity 3650
#
# You can also use Let's Encrypt:
# https://maximilian-boehm.com/hp2121/Create-a-Java-Keystore-JKS-from-Let-s-Encrypt-Certificates.htm
#
# Then, modify the server.ssl properties so your "server" configuration looks like:
#
# server:
# port: 8443
# ssl:
# key-store: keystore.p12
# key-store-password: <your-password>
# key-store-type: PKCS12
# key-alias: primecast
# ===================================================================
server:
port: 8080
# ===================================================================
# JHipster specific properties
#
# Full reference is available at: http://www.jhipster.tech/common-application-properties/
# ===================================================================
jhipster:
http:
version: V_1_1 # To use HTTP/2 you will need SSL support (see above the "server.ssl" configuration)
cache: # Cache configuration
hazelcast: # Hazelcast distributed cache
time-to-live-seconds: 3600
backup-count: 1
management-center: # Full reference is available at: http://docs.hazelcast.org/docs/management-center/3.9/manual/html/Deploying_and_Starting.html
enabled: false
update-interval: 3
url: http://localhost:8180/mancenter
# CORS is only enabled by default with the "dev" profile, so BrowserSync can access the API
cors:
allowed-origins: "*"
allowed-methods: "*"
allowed-headers: "*"
exposed-headers: "Authorization,Link,X-Total-Count"
allow-credentials: true
max-age: 1800
security:
authentication:
jwt:
secret: my-secret-token-to-change-in-production
# Token is valid 24 hours
token-validity-in-seconds: 86400
token-validity-in-seconds-for-remember-me: 2592000
mail: # specific JHipster mail property, for standard properties see MailProperties
from: primecast#localhost
base-url: http://127.0.0.1:8080
metrics: # DropWizard Metrics configuration, used by MetricsConfiguration
jmx.enabled: true
graphite: # Use the "graphite" Maven profile to have the Graphite dependencies
enabled: false
host: localhost
port: 2003
prefix: primecast
prometheus: # Use the "prometheus" Maven profile to have the Prometheus dependencies
enabled: false
endpoint: /prometheusMetrics
logs: # Reports Dropwizard metrics in the logs
enabled: false
report-frequency: 60 # in seconds
logging:
logstash: # Forward logs to logstash over a socket, used by LoggingConfiguration
enabled: false
host: localhost
port: 5000
queue-size: 512
google:
accessToken: AIzaSyBasWNyK7ELbLlopD3anXrJCgtXUPRZYN8
endpoint: https://www.googleapis.com/urlshortener/v1/url
urlshortener:
is.gd:
endpoint: https://is.gd
http:
proxyEnabled: false
proxyHost:
proxyPort:
password:
expiryInDays: 90
historyCount: 3
expiryEmailAlertInDays: 3
policy: '^(?!.*(.)\1\1)(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!#$%^&*-]).{8,}.*$'
file:
size: 5242880
elasticsearch:
host: localhost
port: 9200
and my repository class is
#Repository
public class PerformanceReportingRepository {
#Value("${elasticsearch.host}")
private String host;
#Value("${elasticsearch.port}")
private Integer port;
#Value("${file.size}")
private long fileUploadSizeLimit;
private RestHighLevelClient elasticSearchClient;
public PerformanceReportingRepository() {
System.out.println(this.fileUploadSizeLimit);
this.elasticSearchClient = new RestHighLevelClient(RestClient.builder(new HttpHost(host, port)));
}
public void setElasticSearchClient(RestHighLevelClient elasticSearchClient) {
this.elasticSearchClient = elasticSearchClient;
}
}
However the bean creation fails because host and port are not resolved from the yaml file.
I am sharing the project in https://github.com/prasanthmp500/mep.git
please checkout the branch ENG-170-performance-reports
appreciate any help
thanks a lot

Spring Cloud Gateway : disable default routes

I'm using spring cloud to manage my microservices.
For security reasons, for one specific microservice (name it ms_secure), I want to use custom route choose a specific microservice version depending on client IP.
My gateway config looks like this:
spring:
cloud:
gateway:
discovery:
locator:
enabled: true
routes:
- id: ms_secure_v1
uri: lb://ms_secure_v1
predicates:
- Path=/ms_secure/**
filters:
- RewritePath=/ms_secure/(?<segment>.*), /$\{segment}
- name: <my filter>
args:
xForwardedForHeaderName: X-Forwarded-For
hosts:
- <IP1>
- <IP2>
- id: ms_secure
uri: lb://ms_secure_v2
predicates:
- Path=/ms_secure/**
filters:
- RewritePath=/ms_secure/(?<segment>.*), /$\{segment}
- name: <my filter>
args:
xForwardedForHeaderName: X-Forwarded-For
hosts:
- <IP3>
- <IP4>
When when requesting /ms_secure:
IP1 and IP2 will be redirected to ms_secure_v1
IP3 and IP4 will be redirected to ms_secure_v2
My problem is that all my clients will also be able to access directly ms_secure_v1 or ms_secure_v2 by using the default routes:
http:///ms_secure_v1/...
http:///ms_secure_v2/...
I tried to disable these routes by using SetStatus GatewayFilter:
- id: setstatusstring_route
uri: lb://ms-gateway
predicates:
- Path=/ms_secure_v**
filters:
- SetStatus=403
But this route is not matched.
Is there a way to disable these default routes in spring gateway?
The following creates routes in gateway based on services registered:
spring:
cloud:
gateway:
discovery:
locator:
enabled: true
Set it to false (which is the default), if you don't want this.

Spring cloud config client Could not locate PropertySource

My config server use natie file system works fine and the dev profile configured contextPath: /config
spring:
application:
name: dcit-config
profiles:
active: native
management:
endpoints:
web:
exposure:
include: info, health, metrics
metrics:
export:
atlas:
enabled: true
---
spring:
profiles: native
application:
name: dcit-config
cloud:
config:
server:
native:
searchLocations: classpath:/config/
server:
port: 2003
eureka:
instance:
prefer-ip-address: true
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 20
client:
serviceUrl:
defaultZone: http://dcit:dcit#localhost:1023/eureka
registry-fetch-interval-seconds: 10
---
spring:
profiles: dev
application:
name: dcit-config
cloud:
config:
server:
git:
uri: http://xxx/git/Arch/dcit.git
username: user
password: pass
searchPaths: dcit-config/src/main/resources/config/
clone-on-start: true
fail-fast: true
server:
port: 2002
contextPath: /config
eureka:
instance:
prefer-ip-address: true
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 20
client:
serviceUrl:
defaultZone: http://dc:dc#localhost:1023/eureka
registry-fetch-interval-seconds: 10
The native profile serve configs like this url: http://hostname:2003/config/app-profile.yml and my client works fine.
But if I use dev profile the url http://hostname:2002/config/app-profile.yml also works, but my client got error:
java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing
My client config:
spring:
application:
name: dcit-auth
profiles:
active: dev
cloud:
config:
fail-fast: true
discovery:
service-id: dcit-config
enabled: true
profile: ${spring.profiles.active}
label: ${spring.profiles.active}
---
spring:
profiles: dev
eureka:
instance:
prefer-ip-address: true
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 20
client:
serviceUrl:
defaultZone: http://dc:dc#localhost:1023/eureka
registry-fetch-interval-seconds: 10
solved by remove contextPath: /config and label configure

Resources