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

ELEXIS-REST X-API-Key header #7

Open
kernc opened this issue Feb 13, 2021 · 1 comment
Open

ELEXIS-REST X-API-Key header #7

kernc opened this issue Feb 13, 2021 · 1 comment

Comments

@kernc
Copy link

kernc commented Feb 13, 2021

I successfully run the server with ./gradlew bootRun, a server on localhost:8080.

Separately, I run an Elexis REST API node on localhost:8000.

I issue:

% json='{"source":{"endpoint":"http://127.0.0.1:8000", "id":"602749a25065b828f3bfc671", "apiKey":"test"}, "target":{"endpoint":"http://127.0.0.1:8000", "id":"602749a25065b828f3bfc671", "apiKey":"test"}}'

% curl -v -H "Content-Type: application/json" --data "$json" http://localhost:8080/submit 

> POST /submit HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.64.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 190
> 
* upload completely sent off: 190 out of 190 bytes
< HTTP/1.1 500 
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Sat, 13 Feb 2021 04:20:03 GMT
< Connection: close

In the other window, I see:

Feb 13, 2021 5:20:47 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Tomcat]
Feb 13, 2021 5:20:47 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet engine: [Apache Tomcat/9.0.30]
Feb 13, 2021 5:20:47 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring embedded WebApplicationContext
Feb 13, 2021 5:20:50 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring DispatcherServlet 'dispatcherServlet'
Feb 13, 2021 5:20:50 AM org.insightcentre.uld.naisc.elexis.Controller.SubmitLink submitLinkRequest
INFO: [ Loading details for submit request for 8f6824ee-dea9-4b33-a943-05cf558e6380 ]
Feb 13, 2021 5:20:50 AM org.insightcentre.uld.naisc.elexis.Controller.SubmitLink submitLinkRequest
INFO: [ Initiating submit request for 8f6824ee-dea9-4b33-a943-05cf558e6380 ]
Feb 13, 2021 5:20:50 AM org.insightcentre.uld.naisc.elexis.Helper.AsyncDictionaryLinkingHelper prepareAsyncRun
INFO: [ Loading Source details for request: 8f6824ee-dea9-4b33-a943-05cf558e6380 ]
Feb 13, 2021 5:20:50 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: Failed : HTTP error code : 422] with root cause
java.lang.RuntimeException: Failed : HTTP error code : 422
        at org.insightcentre.uld.naisc.elexis.RestService.APIConnection.executeAPICall(APIConnection.java:39)
        at org.insightcentre.uld.naisc.elexis.RestService.ELEXISRest.getAllLemmas(ELEXISRest.java:104)
        at org.insightcentre.uld.naisc.elexis.Helper.AsyncDictionaryLinkingHelper.processDictionary(AsyncDictionaryLinkingHelper.java:108)
        at org.insightcentre.uld.naisc.elexis.Helper.AsyncDictionaryLinkingHelper.prepareAsyncRun(AsyncDictionaryLinkingHelper.java:174)
        at org.insightcentre.uld.naisc.elexis.Helper.AsyncDictionaryLinkingHelper.asyncExecute(AsyncDictionaryLinkingHelper.java:206)
        at org.insightcentre.uld.naisc.elexis.Controller.SubmitLink.submitLinkRequest(SubmitLink.java:77)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:888)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1598)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.base/java.lang.Thread.run(Thread.java:834)

Calling a REST API node, this works:

% curl -H 'X-API-Key: test' -v http://127.0.0.1:8000/list/602749a25065b828f3bfc671

> GET /list/602749a25065b828f3bfc671 HTTP/1.1
> Host: 127.0.0.1:8000
> User-Agent: curl/7.64.0
> Accept: */*
> X-API-Key: test
> 
< HTTP/1.1 200 OK
< date: Sat, 13 Feb 2021 04:38:05 GMT
< server: uvicorn
< content-length: 203
< content-type: application/json
< set-cookie: session=eyJkaWN0cyI6IFsiNjAyNzQ5YTI1MDY1YjgyOGYzYmZjNjcxIl19.YCdXrQ.ZDuLuo-8reEIB8QDVTWHmN0XOkU; path=/; Max-Age=86400; httponly; samesite=lax
< 
* Connection #0 to host 127.0.0.1 left intact
[{"lemma":"cat","id":"602749a4cf2854678d1baea8","partOfSpeech":"NOUN","language":"en","formats":null},{"lemma":"cat","id":"602749a4cf2854678d1baea9","partOfSpeech":"VERB","language":"en","formats":null}]

But without X-API-Key header, a 422 error:

% curl -v http://localhost:8000/list/602749a25065b828f3bfc671

> GET /list/602749a25065b828f3bfc671 HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.64.0
> Accept: */*
> 
< HTTP/1.1 422 Unprocessable Entity
< date: Sat, 13 Feb 2021 04:39:38 GMT
< server: uvicorn
< content-length: 95
< content-type: application/json
< 
* Connection #0 to host localhost left intact
{"detail":[{"loc":["header","X-API-Key"],"msg":"field required","type":"value_error.missing"}]}

as reported by the java.lang.RuntimeException.

Does Naisc ELEXIS/REST API possibly not support apiKey/X-API-Key header?

@jmccrae
Copy link
Collaborator

jmccrae commented Feb 16, 2021

What are you using to implement the ELEXIS API. The reference implementation at https://github.com/elexis-eu/dictionary-service does not implement the X-API-Key aspect of the service.

I am not sure what the issue here is exactly then.

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

No branches or pull requests

2 participants