import java.io.IOException; import java.sql.*; import javax.inject.Inject; import javax.servlet.ServletException; import javax.servlet.http.*; import oracle.dbtools.plugin.api.di.annotations.Provides; import oracle.dbtools.plugin.api.http.annotations.*; import oracle.dbtools.plugin.api.routes.*; /** * This example plugin {@link HttpServlet} demonstrates: *
* http://server/ords/schema/demos/plugin?who=somebody ** * where: *
* http://localhost:8080/ords/test_schema/demos/plugin?who=Scott ** * @author cdivilly * */ @Provides @Dispatches(@PathTemplate("/demos/plugin")) class PluginDemo extends HttpServlet { @Inject PluginDemo(Connection conn, PathTemplates pathTemplates) { this.conn = conn; this.pathTemplates = pathTemplates; } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final PathTemplateMatch match = pathTemplates.matchedTemplate(request); try { String who = match.parameters().get("who"); who = null == who ? "anonymous" : who; PreparedStatement ps = conn .prepareStatement("select sys_context('USERENV','CURRENT_USER') from dual"); ResultSet rs = ps.executeQuery(); rs.next(); String user = rs.getString(1); response.getWriter().println(user + " says hello to: " + who); rs.close(); ps.close(); } catch (SQLException e) { throw new ServletException(e); } } private final Connection conn; private final PathTemplates pathTemplates; }