Servlet class for JAX-RS REST Servlet Plugin to allow use OpenNTF Domino API

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.openntf.domino.AutoMime;
import org.openntf.domino.ext.Session.Fixes;
import org.openntf.domino.utils.Factory;
import org.openntf.domino.utils.Factory.SessionType;
import org.openntf.domino.utils.Factory.ThreadConfig;
import org.openntf.domino.xsp.ODAPlatform;
import org.openntf.domino.xsp.session.DasCurrentSessionFactory;

import com.ibm.domino.das.servlet.DasServlet;

public class ODADataServlet extends DasServlet {
	private static final long serialVersionUID = 1L;

	public ODADataServlet() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void doInit() throws ServletException {
		ODAPlatform.start();
		super.doInit();
	}

	@Override
	public void doDestroy() {
		super.doDestroy();
		ODAPlatform.stop();
	}

	protected ThreadConfig getDataServiceConfig() {
		final Fixes[] fixes = Fixes.values();
		final AutoMime autoMime = AutoMime.WRAP_32K;
		final boolean bubbleExceptions = false;
		return new ThreadConfig(fixes, autoMime, bubbleExceptions);
	}

	@Override
	public void doService(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
		Factory.initThread(getDataServiceConfig());
		Factory.setSessionFactory(new DasCurrentSessionFactory(), SessionType.CURRENT);
		super.doService(request, response);
		Factory.termThread();
	}

}





Requires ODA 2.0.0 or higher
Remember to include com.ibm.domino.das, org.openntf.domino and org.openntf.domino.xsp plugins on Dependencies tab of plugin
Also point to this servlet class in web.xml, e.g.:
 <servlet-class>com.paulwithers.demoservlet.ODADataServlet</servlet-class>

Use Factory.getSession(SessionType.CURRENT) for current user session instead of ContextInfo.getUserSession()
Use Factory.getSession(SessionType.NATIVE) for session running under server authority

Java
Paul S Withers
October 20, 2015 4:31 PM
Rating
25

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



No comments yetLogin first to comment...