Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Error 404 with CORS enabled(After Enabling CORS on the jetty server xtext-services can not be found)
Error 404 with CORS enabled [message #1770461] Fri, 11 August 2017 21:24 Go to next message
Alan Frye is currently offline Alan FryeFriend
Messages: 41
Registered: January 2017
Member
I am running xtext web using the code mirror ide and when the editor is served from one domain and the xtext server is running inside Jetty from on a different domain I am getting the following error:

jquery.js:9203 GET http://10.39.83.243:8084/xtext-service/occurrences?resource=47c9d7fc.stext&caretOffset=0 404 (The requested resource was not found.)
I am seeing this error after enabling the Jetty Cors Filter and using the following parameters.

<filter>
        <filter-name>cross-origin</filter-name>
        <filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
        

        <init-param>
        <param-name>allowedOrigins</param-name>
        <param-value>*</param-value>
    </init-param>
    <init-param>
        <param-name>allowedMethods</param-name>
        <param-value>GET,POST,HEAD,PUT,OPTIONS</param-value>
    </init-param>
  
    <init-param>
        <param-name>allowedHeaders</param-name>
        <param-value>X-Requested-With,Content-Type,Accept,Origin,Access-Control-Allow-Origin</param-value>
    </init-param>
    <init-param>
    <param-name>exposedHeaders</param-name>
    <param-value>X-Requested-With,Content-Type,Accept,Origin,Access-Control-Allow-Origin</param-value>
    </init-param>
    
    </filter>
   
    <filter-mapping>
        <filter-name>cross-origin</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


Before I enabled CORS I was see this message in the browsers console

XMLHttpRequest cannot load http://10.39.83.243:8084/xtext-service/update?resource=61e94e99.stext. Method PUT is not allowed by Access-Control-Allow-Methods in preflight response.


Re: Error 404 with CORS enabled [message #1770473 is a reply to message #1770461] Sat, 12 August 2017 05:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Does this affect all services or the occurrences only.
Unfortunately I have no idea and setting this up
Is a lot of work

Did you try to debug into the server side?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Error 404 with CORS enabled [message #1770558 is a reply to message #1770473] Mon, 14 August 2017 12:27 Go to previous messageGo to next message
Alan Frye is currently offline Alan FryeFriend
Messages: 41
Registered: January 2017
Member
Yes is does affect all the xtext services. What is odd is that I do not see the Error 404 until after I enable the CORS filter on the Jetty server. I will update you as I get more information.

Thanks
Re: Error 404 with CORS enabled [message #1770573 is a reply to message #1770558] Mon, 14 August 2017 15:40 Go to previous messageGo to next message
Alan Frye is currently offline Alan FryeFriend
Messages: 41
Registered: January 2017
Member
After debugging the server code I an getting the following error from the XtextServlet class


org.eclipse.xtext.web.server.InvalidRequestException$ResourceNotFoundException: The requested resource was not found
Re: Error 404 with CORS enabled [message #1770574 is a reply to message #1770573] Mon, 14 August 2017 15:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
looks like not all request are sent to the server.

so you should compare the communication in both cases


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Error 404 with CORS enabled [message #1770580 is a reply to message #1770574] Mon, 14 August 2017 15:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
(maybe its a session thingy, and there is no correct relation of sessions in both servers)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Error 404 with CORS enabled [message #1770586 is a reply to message #1770580] Mon, 14 August 2017 16:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
here is some logging of what happens by default

0    [qtp109961541-13] TRACE org.eclipse.xtext.web.server.XtextServiceDispatcher  - xtext-service/update: fullText=, resource=34b64416.mydsl, serviceType=update
88   [qtp109961541-16] TRACE org.eclipse.xtext.web.server.XtextServiceDispatcher  - xtext-service/validate: requiredStateId=-80000000, resource=34b64416.mydsl, serviceType=validate
20523 [qtp109961541-15] TRACE org.eclipse.xtext.web.server.XtextServiceDispatcher  - xtext-service/update: deltaOffset=0, deltaReplaceLength=0, deltaText=He, requiredStateId=-80000000, resource=34b64416.mydsl, serviceType=update
20559 [qtp109961541-13] TRACE org.eclipse.xtext.web.server.XtextServiceDispatcher  - xtext-service/validate: requiredStateId=-7fffffff, resource=34b64416.mydsl, serviceType=validate
20580 [qtp109961541-16] TRACE org.eclipse.xtext.web.server.XtextServiceDispatcher  - xtext-service/occurrences: caretOffset=2, requiredStateId=-7fffffff, resource=34b64416.mydsl, serviceType=occurrences
20852 [qtp109961541-20] TRACE org.eclipse.xtext.web.server.XtextServiceDispatcher  - xtext-service/assist: caretOffset=2, requiredStateId=-7fffffff, resource=34b64416.mydsl, serviceType=assist
21807 [qtp109961541-12] TRACE org.eclipse.xtext.web.server.XtextServiceDispatcher  - xtext-service/assist: caretOffset=6, deltaOffset=2, deltaReplaceLength=0, deltaText='llo ', requiredStateId=-7fffffff, resource=34b64416.mydsl, serviceType=assist
21861 [qtp109961541-10] TRACE org.eclipse.xtext.web.server.XtextServiceDispatcher  - xtext-service/validate: requiredStateId=-7ffffffe, resource=34b64416.mydsl, serviceType=validate
22175 [qtp109961541-10] TRACE org.eclipse.xtext.web.server.XtextServiceDispatcher  - xtext-service/occurrences: caretOffset=6, requiredStateId=-7ffffffe, resource=34b64416.mydsl, serviceType=occurrences
22724 [qtp109961541-14] TRACE org.eclipse.xtext.web.server.XtextServiceDispatcher  - xtext-service/assist: caretOffset=11, deltaOffset=6, deltaReplaceLength=0, deltaText='name ', requiredStateId=-7ffffffe, resource=34b64416.mydsl, serviceType=assist
22770 [qtp109961541-21] TRACE org.eclipse.xtext.web.server.XtextServiceDispatcher  - xtext-service/validate: requiredStateId=-7ffffffd, resource=34b64416.mydsl, serviceType=validate
23081 [qtp109961541-24] TRACE org.eclipse.xtext.web.server.XtextServiceDispatcher  - xtext-service/occurrences: caretOffset=11, requiredStateId=-7ffffffd, resource=34b64416.mydsl, serviceType=occurrences
23981 [qtp109961541-15] TRACE org.eclipse.xtext.web.server.XtextServiceDispatcher  - xtext-service/update: deltaOffset=11, deltaReplaceLength=0, deltaText=!, requiredStateId=-7ffffffd, resource=34b64416.mydsl, serviceType=update
24002 [qtp109961541-13] TRACE org.eclipse.xtext.web.server.XtextServiceDispatcher  - xtext-service/validate: requiredStateId=-7ffffffc, resource=34b64416.mydsl, serviceType=validate
24024 [qtp109961541-16] TRACE org.eclipse.xtext.web.server.XtextServiceDispatcher  - xtext-service/occurrences: caretOffset=12, requiredStateId=-7ffffffc, resource=34b64416.mydsl, serviceType=occurrences



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Error 404 with CORS enabled [message #1770736 is a reply to message #1770586] Wed, 16 August 2017 15:45 Go to previous messageGo to next message
Alan Frye is currently offline Alan FryeFriend
Messages: 41
Registered: January 2017
Member
The issue appears to be session related. Even when I access the editor and server from same machine using a different ip address I get 2 different sessions.


Thanks for your help!
Re: Error 404 with CORS enabled [message #1770737 is a reply to message #1770736] Wed, 16 August 2017 15:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
How do your requests look like

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Error 404 with CORS enabled [message #1770762 is a reply to message #1770737] Wed, 16 August 2017 20:33 Go to previous messageGo to next message
Alan Frye is currently offline Alan FryeFriend
Messages: 41
Registered: January 2017
Member
After further testing I was able to confirm that each request to a xtext-service is generating a new SessionID.

I was also able to test and confirm that I do not see this issue when I am using Xtext v 2.11.0 . The CORS errors start showing up after I upgraded to Xtext 2.12.
Re: Error 404 with CORS enabled [message #1770771 is a reply to message #1770762] Thu, 17 August 2017 03:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Did you check the differences in webjArs being used

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Error 404 with CORS enabled [message #1770834 is a reply to message #1770771] Thu, 17 August 2017 13:51 Go to previous messageGo to next message
Alan Frye is currently offline Alan FryeFriend
Messages: 41
Registered: January 2017
Member
Yes I am using the same version of codemirror and requires js in both cases.
Should webjars have been upgraded was well.?

Re: Error 404 with CORS enabled [message #1770835 is a reply to message #1770834] Thu, 17 August 2017 13:52 Go to previous messageGo to next message
Alan Frye is currently offline Alan FryeFriend
Messages: 41
Registered: January 2017
Member
I am using requires,js 2,2.0 , codemirror 5.22.0 and jquery 2.2.3
Re: Error 404 with CORS enabled [message #1770836 is a reply to message #1770835] Thu, 17 August 2017 13:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
maybe something changed with these. i cannot help you since i dont have the two hours i need to create a reproducible example

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Error 404 with CORS enabled [message #1770852 is a reply to message #1770836] Thu, 17 August 2017 22:18 Go to previous messageGo to next message
Alan Frye is currently offline Alan FryeFriend
Messages: 41
Registered: January 2017
Member
Thanks! Here some more information.

I have recently discovered that when it is fails the browser does not allow for the cookie with a jsesionID to be enabled.
Re: Error 404 with CORS enabled [message #1771491 is a reply to message #1770852] Fri, 25 August 2017 15:32 Go to previous messageGo to next message
Alan Frye is currently offline Alan FryeFriend
Messages: 41
Registered: January 2017
Member
It appears that when the you are in a cross domain situation(the editor is served from one address and the Xtext servlets are being served from another address that the server sends a Set-Cookie header to the browser,however the browser ignores it and does not set the cookie. This behavior has only started happening after Chrome 45.

I have also discovered in that adding the following to your jquery ajax calls that is will allow the browser to respect the SET-COOKIE header
crossDomain: true,
			xhrFields: {
				withCredentials: true
			}


I tested this using my own servlet and JS code inside a page and it appears to work. Is there a way to tell the xtext-codemirror.js to use these same settings.

Re: Error 404 with CORS enabled [message #1771494 is a reply to message #1771491] Fri, 25 August 2017 15:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Can you open an issue at Xtext web maybe with a pull request

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Error 404 with CORS enabled [message #1771499 is a reply to message #1771494] Fri, 25 August 2017 18:27 Go to previous messageGo to next message
Alan Frye is currently offline Alan FryeFriend
Messages: 41
Registered: January 2017
Member
Yes I can do that
Re: Error 404 with CORS enabled [message #1771719 is a reply to message #1771494] Tue, 29 August 2017 20:08 Go to previous messageGo to next message
Alan Frye is currently offline Alan FryeFriend
Messages: 41
Registered: January 2017
Member
Christian

Not sure of the process you want me follow here.


Should open issued on the repository and then fork the repo to make the change and then create a pull request.
Re: Error 404 with CORS enabled [message #1771732 is a reply to message #1771719] Wed, 30 August 2017 04:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Yes. But I am not sure if we want this feature. So pull request only if the feature is easily toggleable

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Error 404 with CORS enabled [message #1772114 is a reply to message #1771732] Tue, 05 September 2017 16:32 Go to previous message
Alan Frye is currently offline Alan FryeFriend
Messages: 41
Registered: January 2017
Member
Christian,

I have created a pull request for this request.
Previous Topic:Xtext standalone generator output configuration
Next Topic:How to Integrate Xtext into other projects
Goto Forum:
  


Current Time: Tue Mar 19 03:16:41 GMT 2024

Powered by FUDForum. Page generated in 0.02779 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top