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:
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 itsGenericServlet.init()
method:@WebServlet(name = "Xtext Services", urlPatterns = "/xtext-service/*") class MyXtextServlet extends XtextServlet { override init() { super.init(); MyDslWebSetup.doSetup(); } }
Use theWebServlet
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
-
-
-
-
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 classjavax.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 classjavax.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 classjavax.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 classjavax.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 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 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
-
-