Class XtextServlet

  • All Implemented Interfaces:
    java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

    public class XtextServlet
    extends javax.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:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      XtextServlet()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void doGet​(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)  
      protected void doPost​(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)  
      protected void doPut​(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)  
      protected void doService​(org.eclipse.xtext.web.server.XtextServiceDispatcher.ServiceDescriptor service, javax.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 java.lang.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 getInjector​(HttpServiceContext serviceContext)
      Resolve the Guice injector for the language associated with the given context.
      protected org.eclipse.xtext.web.server.XtextServiceDispatcher.ServiceDescriptor getService​(javax.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​(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)  
      • Methods inherited from class javax.servlet.http.HttpServlet

        doDelete, doHead, doOptions, doTrace, getLastModified, service
      • Methods inherited from class javax.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 Detail

      • XtextServlet

        public XtextServlet()
    • Method Detail

      • service

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

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

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

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

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

        protected org.eclipse.xtext.web.server.XtextServiceDispatcher.ServiceDescriptor getService​(javax.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,
                                 javax.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 java.lang.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