简体   繁体   中英

Working HTTP query in Postman not working in Spring Boot Apache Camel 3.1

I'm new to Apache Camel and I'm struggling with this issue. I want to replicate a simple query working in Postman:

https://{{baseurl}}/v3/company/{{companyid}}/query?query=SELECT id, Metadata.LastUpdatedTime FROM Payment WHERE Metadata.LastUpdatedTime>='2018-01-01' ORDERBY Metadata.LastUpdatedTime, Id STARTPOSITION 1 MAXRESULTS 10 &minorversion=47

The GET request includes the following headers:

Accept: application/json
Authorization: Bearer {very long auth token}

where {very long auth token} is an actual value in practice. I try to replicate this with Apache Camel:

        from("timer:foo?repeatCount=1")
            .setHeader(Exchange.HTTP_METHOD, constant(HttpMethods.GET))
            .setHeader(Exchange.HTTP_PATH, constant("v3/company/{companyid}/query"))
            .setHeader(Exchange.HTTP_QUERY, constant("query=SELECT id, Metadata.LastUpdatedTime FROM Payment WHERE Metadata.LastUpdatedTime>='2018-01-01' " + 
                    "ORDERBY Metadata.LastUpdatedTime, Id STARTPOSITION 1 MAXRESULTS 10 &minorversion=47"))
            .setHeader("Accept", constant("application/json"))
            .setHeader("Authorization", constant("Bearer {very long auth code}"))
            .to("log://PoCMainApp?showBody=true&showBodyType=true&showHeaders=true&showProperties=true")
            .to("http://quickbooks.api.intuit.com")
        ;

where {companyid} and {very long auth token} are actual values in practice. At runtime, the query hangs and eventually timesout. The same happens when the query is pasted in a browser, which evidently doesn't supply the Accept and Authorization headers.

This leads me to think that there could be a problem with the overall payload that Camel constructs.

The log showHeaders=true only shows the same values as in the code - it doesn't show what's actually sent in the request. I have tried to get more debug to sysout without much success. This is a Spring Boot project so log4j.properties are ignored (in my setup at least). Instead, I have transposed log4j settings to application.properties as follows:

camel.springboot.tracing = true

# https://springframework.guru/using-logback-spring-boot
logging.level.httpclient.wire.header=TRACE
logging.level.org.apache.camel.component.http=TRACE
logging.level.org.apache.camel.http.common=TRACE
logging.level.org.apache.camel.http=TRACE
logging.level.org.apache.commons.httpclient=TRACE

This is all the information I get back in sysout:

INFO 51071 --- [1 - timer://foo] PoCMainApp                               : Exchange[ExchangePattern: InOnly
Properties: {
    CamelTimerCounter=1
    CamelTimerFiredTime=Mon Mar 30 16:49:28 BST 2020
    CamelTimerName=foo
    CamelTimerPeriod=1000
    CamelToEndpoint=log://PoCMainApp?showBody=true&showBodyType=true&showHeaders=true&showProperties=true
}
Headers: {
    Accept=application/json
    Authorization=Bearer {very long auth token}
    CamelHttpMethod=GET
    CamelHttpPath=v3/company/193514690594249/query
    CamelHttpQuery=query=SELECT id
    Metadata.LastUpdatedTime FROM Payment WHERE Metadata.LastUpdatedTime>='2018-01-01' ORDERBY Metadata.LastUpdatedTime, Id STARTPOSITION 1 MAXRESULTS 10 &minorversion=47
    firedTime=Mon Mar 30 16:49:28 BST 2020}
BodyType: null
Body: [Body is null]]

INFO 51071 --- [1 - timer://foo] org.apache.camel.Tracing                 :      [route1      ] [http://quickbooks.api.intuit.com ] Exchange[Id: ID-ub18dm-1585583368149-0-1, BodyType: null, Body: [Body is null]]

TRACE 51071 --- [1 - timer://foo] o.a.camel.component.http.HttpProducer    : Using URL: http://quickbooks.api.intuit.com/v3/company/193514690594249/query?query=SELECT%20id,%20Metadata.LastUpdatedTime%20FROM%20Payment%20WHERE%20Metadata.LastUpdatedTime%3E='2018-01-01'%20ORDERBY%20Metadata.LastUpdatedTime,%20Id%20STARTPOSITION%201%20MAXRESULTS%2010%20&minorversion=47 with method: GET http://quickbooks.api.intuit.com/v3/company/193514690594249/query?query=SELECT%20id,%20Metadata.LastUpdatedTime%20FROM%20Payment%20WHERE%20Metadata.LastUpdatedTime%3E='2018-01-01'%20ORDERBY%20Metadata.LastUpdatedTime,%20Id%20STARTPOSITION%201%20MAXRESULTS%2010%20&minorversion=47 HTTP/1.1

DEBUG 51071 --- [1 - timer://foo] o.a.camel.component.http.HttpProducer    : Executing http GET method: http://quickbooks.api.intuit.com/v3/company/193514690594249/query?query=SELECT%20id,%20Metadata.LastUpdatedTime%20FROM%20Payment%20WHERE%20Metadata.LastUpdatedTime%3E='2018-01-01'%20ORDERBY%20Metadata.LastUpdatedTime,%20Id%20STARTPOSITION%201%20MAXRESULTS%2010%20&minorversion=47

This has been driving me nuts so I'd be grateful for any assistance.

Thanks in advance, - suitej

As Adam points out above, Intuit only accepts HTTPS.

The solution is:

.to("https://quickbooks.api.intuit.com")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM