Package org.mycore.frontend.servlets
Class MCRServlet
java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
org.mycore.frontend.servlets.MCRServlet
- All Implemented Interfaces:
jakarta.servlet.Servlet
,jakarta.servlet.ServletConfig
,Serializable
- Direct Known Subclasses:
MCRActionMappingServlet
,MCRBasketServlet
,MCRCASServlet
,MCRClassificationBrowser2
,MCRCompressServlet
,MCRContainerLoginFormServlet
,MCRContainerLoginServlet
,MCRContentServlet
,MCRCreateDerivateServlet
,MCRCreateObjectServlet
,MCRDeleteDerivateServlet
,MCRDeleteObjectServlet
,MCRDerivateLinkServlet
,MCRDerivateServlet
,MCRDFGLinkServlet
,MCRDisplayHideDerivateServlet
,MCRExportServlet
,MCRGoogleSitemapServlet
,MCRLockServlet
,MCRLoginServlet
,MCRMailer
,MCRMETSServlet
,MCROAIDataProvider
,MCROAuthServlet
,MCRPackerServlet
,MCRQLSearchServlet
,MCRRoleServlet
,MCRShibbolethLoginServlet
,MCRSolrProxyServlet
,MCRSolrSearchServlet
,MCRStaticXMLFileServlet
,MCRThumbnailServlet
,MCRTileCombineServlet
,MCRUpdateDerivateServlet
,MCRUpdateObjectServlet
,MCRUploadViaFormServlet
,MCRUserServlet
,MCRXEditorServlet
,MCRXSLInfoServlet
public class MCRServlet
extends jakarta.servlet.http.HttpServlet
This is the superclass of all MyCoRe servlets. It provides helper methods for logging and managing the current
session data. Part of the code has been taken from MilessServlet.java written by Frank Lützenkirchen.
- Version:
- $Revision$ $Date$
- Author:
- Detlev Degenhardt, Frank Lützenkirchen, Thomas Scheffler (yagee)
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
Returns true if this servlet allows Cross-domain requests.protected String
buildRedirectURL
(String baseURL, Properties parameters) This method builds a URL that can be used to redirect the client browser to another page, thereby including http request parameters.static void
cleanupMCRSession
(jakarta.servlet.http.HttpServletRequest req, String servletName) Code to cleanup a MyCoRe Session may be reused in ServletFilter, MVC controller, etc.void
doGet
(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) protected void
doGet
(MCRServletJob job) protected void
doGetPost
(MCRServletJob job) This method should be overwritten by other servlets.void
doPost
(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) protected void
doPost
(MCRServletJob job) protected String
getErrorI18N
(String prefix, String subIdentifier, Object... args) returns a translated error message for the current Servlet.protected long
getLastModified
(jakarta.servlet.http.HttpServletRequest request) allows browser to cache requests.static MCRLayoutService
static String
getProperty
(jakarta.servlet.http.HttpServletRequest request, String name) protected URL
getReferer
(jakarta.servlet.http.HttpServletRequest request) Returns the referer of the given request.static String
Returns the servlet base URL of the mycore systemstatic MCRSession
getSession
(jakarta.servlet.http.HttpServletRequest req) protected void
Handles an exception by reporting it and its embedded exceptionvoid
init()
static void
initializeMCRSession
(jakarta.servlet.http.HttpServletRequest req, String servletName) Code to initialize a MyCoRe Session may be reused in ServletFilter, MVC controller, etc.protected void
render
(MCRServletJob job, Exception ex) 2nd phase of doGetPost This method has a seperate transaction and gets the same MCRServletJob from the first phase (think) and any exception that occurs at the first phase.protected void
Reports an exception to the logprotected void
think
(MCRServletJob job) 1st phase of doGetPost.protected void
toReferrer
(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) If a referrer is available this method redirects to the url given by the referrer otherwise method redirects to the application base url.protected void
toReferrer
(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String altURL) If a referrer is available this method redirects to the url given by the referrer otherwise method redirects to the alternative-url.Methods inherited from class jakarta.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, service, service
Methods inherited from class jakarta.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Field Details
-
ATTR_MYCORE_SESSION
- See Also:
-
CURRENT_THREAD_NAME_KEY
- See Also:
-
INITIAL_SERVLET_NAME_KEY
- See Also:
-
-
Constructor Details
-
MCRServlet
public MCRServlet()
-
-
Method Details
-
getLayoutService
-
init
public void init() throws jakarta.servlet.ServletException- Overrides:
init
in classjakarta.servlet.GenericServlet
- Throws:
jakarta.servlet.ServletException
-
getServletBaseURL
Returns the servlet base URL of the mycore system -
doGet
public void doGet(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) throws jakarta.servlet.ServletException, IOException - Overrides:
doGet
in classjakarta.servlet.http.HttpServlet
- Throws:
jakarta.servlet.ServletException
IOException
-
doGet
- Throws:
Exception
-
doPost
public void doPost(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) throws jakarta.servlet.ServletException, IOException - Overrides:
doPost
in classjakarta.servlet.http.HttpServlet
- Throws:
jakarta.servlet.ServletException
IOException
-
doPost
- Throws:
Exception
-
getSession
-
initializeMCRSession
public static void initializeMCRSession(jakarta.servlet.http.HttpServletRequest req, String servletName) throws IOException Code to initialize a MyCoRe Session may be reused in ServletFilter, MVC controller, etc.- Parameters:
req
- - the HTTP requestservletName
- - the servletName- Throws:
IOException
-
cleanupMCRSession
public static void cleanupMCRSession(jakarta.servlet.http.HttpServletRequest req, String servletName) Code to cleanup a MyCoRe Session may be reused in ServletFilter, MVC controller, etc.- Parameters:
req
- - the HTTP RequestservletName
- - the Servlet name
-
think
1st phase of doGetPost. This method has a seperate transaction. Per default id does nothing as a fallback to the old behaviour.- Throws:
Exception
- See Also:
-
allowCrossDomainRequests
protected boolean allowCrossDomainRequests()Returns true if this servlet allows Cross-domain requests. The default value defined byMCRServlet
isfalse
. -
render
2nd phase of doGetPost This method has a seperate transaction and gets the same MCRServletJob from the first phase (think) and any exception that occurs at the first phase. By default this method calls doGetPost(MCRServletJob) as a fallback to the old behaviour.- Parameters:
job
- same instance as of think(MCRServlet job)ex
- any exception thrown by think(MCRServletJob) or transaction commit- Throws:
Exception
- if render could not handleex
to produce a nice user page
-
doGetPost
This method should be overwritten by other servlets. As a default response we indicate the HTTP 1.1 status code 501 (Not Implemented).- Throws:
Exception
-
handleException
Handles an exception by reporting it and its embedded exception -
reportException
Reports an exception to the log- Throws:
Exception
-
buildRedirectURL
This method builds a URL that can be used to redirect the client browser to another page, thereby including http request parameters. The request parameters will be encoded as http get request.- Parameters:
baseURL
- the base url of the target webpageparameters
- the http request parameters
-
getLastModified
protected long getLastModified(jakarta.servlet.http.HttpServletRequest request) allows browser to cache requests. This method is usefull as it allows browsers to cache content that is not changed. Please overwrite this method in every Servlet that depends on "remote" data.- Overrides:
getLastModified
in classjakarta.servlet.http.HttpServlet
-
getProperty
-
getErrorI18N
returns a translated error message for the current Servlet. I18N keys are of form {prefix}'.'{SimpleServletClassName}'.'{subIdentifier}- Parameters:
prefix
- a prefix of the message property like component.base.errorsubIdentifier
- last part of I18n keyargs
- any arguments that should be passed toMCRTranslation.translate(String, Object...)
-
getReferer
Returns the referer of the given request. -
toReferrer
protected void toReferrer(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException If a referrer is available this method redirects to the url given by the referrer otherwise method redirects to the application base url.- Throws:
IOException
-
toReferrer
protected void toReferrer(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String altURL) throws IOException If a referrer is available this method redirects to the url given by the referrer otherwise method redirects to the alternative-url.- Throws:
IOException
-