Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using REST as consumer and producer appends PATH to producer URL #2867

Closed
juliuskrah opened this issue Jan 11, 2022 · 2 comments
Closed

Using REST as consumer and producer appends PATH to producer URL #2867

juliuskrah opened this issue Jan 11, 2022 · 2 comments

Comments

@juliuskrah
Copy link

Camel K: 1.7.0
Dependencies: camel-jackson, camel-netty-http

I built an integration using rest component that serves as a consumer and also a producer:

primeValidator.groovy

// camel-k: language=groovy dependency=camel:jackson dependency=camel:netty-http property=file:application.properties

rest {
    path('/validate') {
        post {
            consumes 'application/json'
            produces 'application/json'
            to 'direct:postToPrime'
        }
    }
}
  
from('direct:postToPrime')
    .process { 
        it.in.body = [
            username: it.context.resolvePropertyPlaceholders('{{prime.username}}'), 
            password: it.context.resolvePropertyPlaceholders('{{prime.password}}')
        ] 
    }
    .marshal().json()
    .log(org.apache.camel.LoggingLevel.INFO, 'com.example.validation.PrimeValidation', 'JSON produced: ${body}')
    .to('rest://post:{{prime.auth-path}}?host={{prime.base-url}}&routeId=primeAuthenticate')
    .to('log:com.example.validation.PrimeValidation?level=INFO')

application.properties

prime.username=user
prime.password=pass
prime.base-url=https://example.prime.com
prime.auth-path=api/auth

camel.component.netty-http.client-mode=true
camel.rest.component=platform-http
camel.rest.producer-component=netty-http
camel.rest.client-request-validation=true
camel.rest.binding-mode=json
camel.rest.host=0.0.0.0
camel.rest.port=8080

camel.component.rest.consumerComponentName=platform-http
> kamel run --dependency camel-jackson --dependency camel-netty-http --property file:application.properties --trait service.node-port=false primeValidator.groovy --dev
> kubectl port-forward service/prime-validator 8080:80
> curl --location --request POST 'localhost:8080/validate' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "julius"
}'

Expectation: Producer request should be sent to https://example.prime.com/api/auth

Actual behaviour: Producer request is sent to https://example.prime.com/api/auth/validate.

⚠️ Note validate is appended

@JPMoresmau
Copy link

Calling .removeHeaders("CamelHttpPath") before the second rest call solved this issue for me

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale due to 90 days of inactivity.
It will be closed if no further activity occurs within 15 days.
If you think that’s incorrect or the issue should never stale, please simply write any comment.
Thanks for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants