Package org.eclipse.xtext.web.servlet
Class XtextServlet
java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.eclipse.xtext.web.servlet.XtextServlet
- All Implemented Interfaces:
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:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected 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 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
-
Constructor Details
-
XtextServlet
public XtextServlet()
-
-
Method Details
-
service
protected void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException - Overrides:
service
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
IOException
-
doGet
protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException - Overrides:
doGet
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
IOException
-
doPut
protected void doPut(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException - Overrides:
doPut
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
IOException
-
doPost
protected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException - Overrides:
doPost
in classjavax.servlet.http.HttpServlet
- Throws:
javax.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(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 theXtextServiceDispatcher
, 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 forIUnwrappableServiceResult
: 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
-