Class XtextServlet

java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
org.eclipse.xtext.web.servlet.XtextServlet
All Implemented Interfaces:
jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, Serializable

public class XtextServlet extends jakarta.servlet.http.HttpServlet
An HTTP servlet for publishing the Xtext services. Include this into your web server by creating a subclass that executes the standalone setups of your languages in its GenericServlet.init() method:
 @WebServlet(name = "Xtext Services", urlPatterns = "/xtext-service/*")
 class MyXtextServlet extends XtextServlet {
        override init() {
                super.init();
                MyDslWebSetup.doSetup();
        }
 }
 
Use the WebServlet annotation to register your servlet. The default URL pattern for Xtext services is "/xtext-service/*".
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    doGet(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp)
     
    protected void
    doPost(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp)
     
    protected void
    doPut(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp)
     
    protected void
    doService(org.eclipse.xtext.web.server.XtextServiceDispatcher.ServiceDescriptor service, jakarta.servlet.http.HttpServletResponse response)
    Invoke the service function of the given service descriptor and write its result to the servlet response in Json format.
    protected String
    getEncoding(org.eclipse.xtext.web.server.XtextServiceDispatcher.ServiceDescriptor service, org.eclipse.xtext.web.server.IServiceResult result)
    Determine the encoding to apply to servlet responses.
    protected com.google.inject.Injector
    Resolve the Guice injector for the language associated with the given context.
    protected org.eclipse.xtext.web.server.XtextServiceDispatcher.ServiceDescriptor
    getService(jakarta.servlet.http.HttpServletRequest request)
    Retrieve the service metadata for the given request.
    protected boolean
    hasTextInput(org.eclipse.xtext.web.server.XtextServiceDispatcher.ServiceDescriptor service)
     
    protected void
    service(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp)
     

    Methods inherited from class jakarta.servlet.http.HttpServlet

    doDelete, doHead, doOptions, doTrace, getLastModified, service

    Methods inherited from class jakarta.servlet.GenericServlet

    destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • XtextServlet

      public XtextServlet()
  • Method Details

    • service

      protected void service(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp) throws jakarta.servlet.ServletException, IOException
      Overrides:
      service in class jakarta.servlet.http.HttpServlet
      Throws:
      jakarta.servlet.ServletException
      IOException
    • doGet

      protected void doGet(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp) throws jakarta.servlet.ServletException, IOException
      Overrides:
      doGet in class jakarta.servlet.http.HttpServlet
      Throws:
      jakarta.servlet.ServletException
      IOException
    • doPut

      protected void doPut(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp) throws jakarta.servlet.ServletException, IOException
      Overrides:
      doPut in class jakarta.servlet.http.HttpServlet
      Throws:
      jakarta.servlet.ServletException
      IOException
    • doPost

      protected void doPost(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp) throws jakarta.servlet.ServletException, IOException
      Overrides:
      doPost in class jakarta.servlet.http.HttpServlet
      Throws:
      jakarta.servlet.ServletException
      IOException
    • hasTextInput

      protected boolean hasTextInput(org.eclipse.xtext.web.server.XtextServiceDispatcher.ServiceDescriptor service)
    • getService

      protected org.eclipse.xtext.web.server.XtextServiceDispatcher.ServiceDescriptor getService(jakarta.servlet.http.HttpServletRequest request) throws org.eclipse.xtext.web.server.InvalidRequestException
      Retrieve the service metadata for the given request. This involves resolving the Guice injector for the respective language, querying the XtextServiceDispatcher, and checking the permission to invoke the service.
      Throws:
      org.eclipse.xtext.web.server.InvalidRequestException
    • doService

      protected void doService(org.eclipse.xtext.web.server.XtextServiceDispatcher.ServiceDescriptor service, jakarta.servlet.http.HttpServletResponse response)
      Invoke the service function of the given service descriptor and write its result to the servlet response in Json format. An exception is made for IUnwrappableServiceResult: here the document itself is written into the response instead of wrapping it into a Json object.
    • getEncoding

      protected String getEncoding(org.eclipse.xtext.web.server.XtextServiceDispatcher.ServiceDescriptor service, org.eclipse.xtext.web.server.IServiceResult result)
      Determine the encoding to apply to servlet responses. The default is UTF-8.
    • getInjector

      protected com.google.inject.Injector getInjector(HttpServiceContext serviceContext) throws org.eclipse.xtext.web.server.InvalidRequestException.UnknownLanguageException
      Resolve the Guice injector for the language associated with the given context.
      Throws:
      org.eclipse.xtext.web.server.InvalidRequestException.UnknownLanguageException