{"id":44,"date":"2011-08-10T14:38:42","date_gmt":"2011-08-10T14:38:42","guid":{"rendered":"http:\/\/www.corrspt.com\/blog\/?p=44"},"modified":"2011-08-10T14:48:17","modified_gmt":"2011-08-10T14:48:17","slug":"xeo-framework-auto-login-jsp-save-time-developing","status":"publish","type":"post","link":"http:\/\/www.corrspt.com\/blog\/2011\/08\/10\/xeo-framework-auto-login-jsp-save-time-developing\/","title":{"rendered":"XEO Framework: Auto-Login JSP &#8211; Save time developing"},"content":{"rendered":"<p>I know it&#8217;s been a long time since my last post, but I&#8217;m back!<\/p>\n<p>One of the things I find myself doing a lot when developing an XEO application is taking down\/restarting the application server, because most of the time we&#8217;re changing the structure of Java class that&#8217;s already been loaded and the server cannot replace the class (at least it happens to me all the time using OC4J and JBoss). Not only you have to wait a while before it&#8217;s ready to roll but you have to login to the XEO application to check if what you tried worked or not.<\/p>\n<p>One of the most tedious tasks in this process is manually logging in to XEO (user\/pass and then profile). I usually create a small JSP file (FOR DEVELOPMENT PURPORSES ONLY) that automatically makes login, sets the appropriate profile and redirects me to the my desired viewer, usually a Main_Something.xvw viewer. I place in the JSP file in the webapps\/default folder and it becomes available at http:\/\/localhost:8080\/xeo\/Main.jsp (or 8888, if you&#8217;re using the default OC4J installation).<\/p>\n<p>Usually I place a link to this file in the browsers Bookmarks \ud83d\ude09<\/p>\n<p>Here you can have the JSP source-code (Download at the bottom)<\/p>\n<pre class=\"brush:java\">&lt;%@page import=\"netgest.bo.runtime.EboContext\"%&gt;\r\n&lt;%@page import=\"netgest.bo.runtime.boObjectList\"%&gt;\r\n&lt;%@page import=\"netgest.bo.runtime.boObject\"%&gt;\r\n&lt;%@page import=\"netgest.bo.system.boApplication\"%&gt;\r\n&lt;%@page import=\"netgest.bo.system.boSession\"%&gt;\r\n&lt;%@ page language=\"java\" contentType=\"text\/html; charset=UTF-8\"\r\n    pageEncoding=\"UTF-8\"%&gt;\r\n&lt;%\r\n\r\nHttpSession session2 = request.getSession(true);\r\n\/\/Check if a XEO session is already in place\r\nif (session2.getAttribute(\"boSession\") == null)\r\n{\r\n        \/\/Default SYSUSER Passwords\r\n\tString user = \"SYSUSER\";\r\n\tString pass = \"ABC\";\r\n\tString profile = \"admin\";\r\n        \/\/Check in the request for user\/password combination (and profile) \r\n\tif (request.getParameter(\"user\") != null &amp;&amp; request.getParameter(\"pass\") != null){\r\n\t\tuser = request.getParameter(\"user\");\r\n\t\tpass = request.getParameter(\"pass\");\r\n\t\tif (request.getParameter(\"profile\") != null)\r\n\t\t\tprofile = request.getParameter(\"profile\");\r\n\t}\r\n        \/\/If everything is ok, try to login\r\n\tif (user != null &amp;&amp; pass != null &amp;&amp; profile != null\r\n\t\t\t&amp;&amp; user.length() &gt; 0 &amp;&amp; pass.length() &gt; 0 &amp;&amp; profile.length() &gt; 0 )\r\n\t{\r\n\r\n\t\tboSession oXeoSession = boApplication.getApplicationFromStaticContext(\"XEO\").boLogin(user,pass);\r\n\r\n\t\tEboContext loginCtx = null;\r\n\t\tif( boApplication.currentContext().getEboContext() == null ) {\r\n\t\t\tloginCtx = oXeoSession.createRequestContext( null, null, null );\r\n\t\t\tboApplication.currentContext().addEboContext( loginCtx );\r\n\t\t}\r\n\t\telse {\r\n\t\t\tloginCtx = boApplication.currentContext().getEboContext();\r\n\t\t}\r\n                \/\/Find the profile given its name and set it\r\n\t\tboObject workPlace=null;\r\n\t\tboObjectList proflist=boObjectList.list(loginCtx, \"select uiWorkPlace where name='\"+profile+\"'\");\r\n\t\tif (proflist.next())\r\n\t\t\tworkPlace=proflist.getObject();\r\n\r\n\t\toXeoSession.setPerformerIProfileBoui( String.valueOf(workPlace.getBoui()) );\r\n\t\tsession2.setAttribute( \"boSession\", oXeoSession );\r\n\r\n\t\tif (loginCtx != null)\r\n\t\t\tloginCtx.close();\r\n\r\n\t}\r\n\telse{\r\n                \/\/Else redirect to Login\r\n\t\tresponse.sendRedirect(\"Login.xvw\");\r\n\t}\r\n}\r\n\/\/In the end, redirect to Viewer \r\nresponse.sendRedirect(\"Path_to_My_Viewer.xvw\"); \/\/CHANGE THIS TO YOUR VIEWER\r\n%&gt;<\/pre>\n<p>Download the <a href=\"http:\/\/www.corrspt.com\/blog\/wp-content\/uploads\/2011\/08\/AutoLoginXEO.zip\">AutoLoginXEO<\/a> JSP<\/p>\n<p>You can use this code at will, no need to credit me or anything. Although I would like to know if anyone&#8217;s using it, feel free to do so.<\/p>\n<p>Stay tunned for more tips on XEO.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I know it&#8217;s been a long time since my last post, but I&#8217;m back! One of the things I find myself doing a lot when developing an XEO application is taking down\/restarting the application server, because most of the time &hellip; <a href=\"http:\/\/www.corrspt.com\/blog\/2011\/08\/10\/xeo-framework-auto-login-jsp-save-time-developing\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,9,3],"tags":[10,11,46,44,8],"_links":{"self":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/44"}],"collection":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/comments?post=44"}],"version-history":[{"count":18,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/44\/revisions"}],"predecessor-version":[{"id":66,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/44\/revisions\/66"}],"wp:attachment":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/media?parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/categories?post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/tags?post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}