public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // tengo que eliminar al usuario de la sesión HttpSession session = request.getSession(false); String next = "/error.html"; if (session != null) { User user = (User) session.getAttribute("user"); session.removeAttribute("user"); session.invalidate(); next = "/login.html"; // JSP destino } RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(next); dispatcher.forward(request, response); }
/** all processing methods end up here */ private void startHereCommon() throws BeanException { // try to get the linkKey if already set in input properties try { hPubLinkKey = inputProps.getHPubLinkKey(); } catch (Exception e) { } // if running in Web environment and either the ejb access handle or // the linkKey are null, try to get them from the HttpSession if (oHttpServletRequest != null) { HttpSession theWebsession = oHttpServletRequest.getSession(false); if (theWebsession != null) { synchronized (theWebsession) { try { if (tracing == true) { traceArgs[0] = this; traceArgs[1] = "HttpSession.getId()=" + theWebsession.getId(); try { traceMethod.invoke(o, traceArgs); } catch (Exception x) { } } String theKey = KEY_WEBCONN + inputProps.getHPubStartChainName(); // if linkKey or access handle is null try to get it from Websession HPubEJB2HttpSessionBindingListener sbl = (HPubEJB2HttpSessionBindingListener) theWebsession.getAttribute(theKey); if ((hPubLinkKey == null) && (sbl != null)) { hPubLinkKey = sbl.getLinkKey(); if (tracing == true) { traceArgs[0] = this; traceArgs[1] = "HttpSession.getAttribute(hPubLinkKey)=" + hPubLinkKey; try { traceMethod.invoke(o, traceArgs); } catch (Exception x) { } } inputProps.setHPubLinkKey(hPubLinkKey); } if ((hPubAccessHandle == null) && (sbl != null)) { hPubAccessHandle = sbl.getEjbHandle(); if (tracing == true) { traceArgs[0] = this; traceArgs[1] = "HttpSession.getAttribute(hPubAccessHandle)=" + hPubAccessHandle; try { traceMethod.invoke(o, traceArgs); } catch (Exception x) { } } } // set the ejb handle to null before removing the Session Binding // Listener object if (auditing == true) { if (sbl != null) auditArgs[0] = "\n---\nOUT:" + this.getClass().getName() + " " + theKey + " " + hPubAccessHandle + " " + hPubLinkKey + " " + theWebsession.getId(); else // error - object not found in HttpSession auditArgs[0] = "\n---\nERR:" + this.getClass().getName() + " " + theKey + " " + theWebsession.getId(); auditArgs[1] = theWebsession; try { auditMethod.invoke(o, auditArgs); } catch (Exception x) { } } if (sbl != null) sbl.setEjbHandle(null); theWebsession.removeAttribute(theKey); } catch (IllegalStateException e) { } } } } // if either of required properties are still null then the ejb cannot // be accessed - throw an exception. if ((hPubAccessHandle == null) || (hPubLinkKey == null)) { String errMsg = (new Date(System.currentTimeMillis())).toString() + " HPS5951 " + this.getClass().getName() + ": hPubAccessHandle==null || hPubLinkKey==null"; System.err.println(errMsg); if (tracing == true) { traceArgs[0] = this; traceArgs[1] = errMsg; try { traceMethod.invoke(o, traceArgs); } catch (Exception x) { } } throw new BeanException(errMsg); } else { if (tracing == true) { traceArgs[0] = this; traceArgs[1] = "hPubAccessHandle=" + hPubAccessHandle + ",hPubLinkKey=" + hPubLinkKey; try { traceMethod.invoke(o, traceArgs); } catch (Exception x) { } } } // get the EJB object from the handle try { ejb = (com.ibm.HostPublisher.EJB.HPubEJB2) javax.rmi.PortableRemoteObject.narrow( hPubAccessHandle.getEJBObject(), com.ibm.HostPublisher.EJB.HPubEJB2.class); } catch (Exception e) { String errMsg = (new Date(System.currentTimeMillis())).toString() + " HPS5952 " + this.getClass().getName() + ": getEJBObject(): " + e.getClass().getName() + ": " + e.getMessage(); System.err.println(errMsg); if (tracing == true) { traceArgs[0] = this; traceArgs[1] = errMsg; try { traceMethod.invoke(o, traceArgs); } catch (Exception x) { } } throw new BeanException(errMsg); } // if ejb handle, go invoke the HPubEJB's main business method. if (ejb != null) { try { outputProps = (CrownCounselIndexGetList_Properties) ejb.processIO(inputProps); inputProps = outputProps; inputProps.setInitialCall(false); } catch (Exception e) { String errMsg = (new Date(System.currentTimeMillis())).toString() + " HPS5953 " + this.getClass().getName() + ": processIO(" + inputProps.getClass().getName() + "): " + e.getClass().getName() + ": " + e.getMessage(); System.err.println(errMsg); if (tracing == true) { traceArgs[0] = this; traceArgs[1] = errMsg; try { traceMethod.invoke(o, traceArgs); } catch (Exception x) { } } throw new BeanException(errMsg); } } endHereCommon(); return; }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); HttpSession session = request.getSession(false); String reseller = null; if (session != null && session.getAttribute("reseller") != null) reseller = "%" + session.getAttribute("reseller") + "%"; List<LicenseData> searchResult = null; if (reseller != null) { /* session.setAttribute("fieldsearch", true); session.removeAttribute("datesearch");*/ if (request.getParameter("so") != null && !request.getParameter("so").isEmpty()) { log.info( "Search Fields : Sales Order Search " + request.getParameter("so") + " for reseller " + session.getAttribute("reseller")); searchResult = getSearchByFieldResults(reseller, request.getParameter("so"), "so"); session.setAttribute("so", request.getParameter("so")); session.removeAttribute("enduser"); session.removeAttribute("ek"); session.setAttribute("label", "Sales Order"); session.setAttribute("value", request.getParameter("so")); } else if (request.getParameter("enduser") != null && !request.getParameter("enduser").isEmpty()) { log.info( "Search Fields : End User Search " + request.getParameter("enduser") + " for reseller " + session.getAttribute("reseller")); searchResult = getSearchByFieldResults(reseller, request.getParameter("enduser"), "enduser"); session.setAttribute("enduser", request.getParameter("enduser")); session.removeAttribute("so"); session.removeAttribute("sno"); session.removeAttribute("ek"); session.setAttribute("label", "End User"); session.setAttribute("value", request.getParameter("enduser")); } else if (request.getParameter("ek") != null && !request.getParameter("ek").isEmpty()) { log.info( "Search Fields : Entitlement Key Search " + request.getParameter("ek") + " for reseller " + session.getAttribute("reseller")); searchResult = getSearchByFieldResults(reseller, request.getParameter("ek"), "ek"); session.setAttribute("ek", request.getParameter("ek")); session.removeAttribute("so"); session.removeAttribute("sno"); session.removeAttribute("enduser"); session.setAttribute("label", "Entitlement Key"); session.setAttribute("value", request.getParameter("ek")); } else if (request.getParameter("sno") != null && !request.getParameter("sno").isEmpty()) { log.info( "Search Fields : Serial Number Search " + request.getParameter("sno") + " for reseller " + session.getAttribute("reseller")); searchResult = getSearchByFieldResults(reseller, request.getParameter("sno"), "sno"); session.setAttribute("sno", request.getParameter("sno")); session.removeAttribute("ek"); session.removeAttribute("so"); session.removeAttribute("enduser"); request.setAttribute("sno", 1); session.setAttribute("label", "Serial Number"); session.setAttribute("value", request.getParameter("sno")); } else if (request.getParameter("po") != null && !request.getParameter("po").isEmpty()) { log.info( "Search Fields : Purchase Order Search " + request.getParameter("po") + " for reseller " + session.getAttribute("reseller")); searchResult = getSearchByFieldResults(reseller, request.getParameter("po"), "po"); session.setAttribute("po", request.getParameter("po")); session.setAttribute("label", "Purchase Order"); session.setAttribute("value", request.getParameter("po")); } else if (request.getParameter("hm") != null && !request.getParameter("hm").isEmpty()) { log.info( "Search Fields : HM ID Search " + request.getParameter("hm") + " for reseller " + session.getAttribute("hm")); searchResult = getSearchByFieldResults(reseller, request.getParameter("hm"), "hm"); session.setAttribute("hm", request.getParameter("hm")); session.setAttribute("label", "Hive Manager ID"); session.setAttribute("value", request.getParameter("hm")); } session.setAttribute("fieldSearchList", searchResult); String nextJSP = "/viewFieldSearchResult.jsp"; RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP); dispatcher.forward(request, response); } else { log.info("Search Fields : Reseller Blank "); String nextJSP = "/login.jsp"; RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP); dispatcher.forward(request, response); } }
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); // All request in GET method must be certificated Object obj = session.getAttribute("device_id"); if (!(obj instanceof Long)) { // Client must be login first, then use Mobile service response.setStatus(404); return; } response.setContentType("text/plain"); PrintWriter out = response.getWriter(); // Here is tracked's id Long device_id = (Long) obj; // Determine operation type String op = request.getParameter("op"); if (op == null) op = ""; // Get current track Long track_id = null; obj = session.getAttribute("track_id"); if (obj instanceof Long) { track_id = (Long) obj; } if (op.equals("logout")) { // Client request a logout operation session.removeAttribute("device_id"); session.removeAttribute("track_id"); out.print("OK," + device_id); } else if (op.equals("latlng")) { // Client insert update it's location in latitude/longitude // If it's a first waypoint, create a new track if (track_id == null) { track_id = db.newTrack(device_id).getResult().getTrackID(); session.setAttribute("track_id", track_id); } // Parse latitude, longitude from request double lat = Double.parseDouble(request.getParameter("lat")); double lng = Double.parseDouble(request.getParameter("lng")); long speed = -1L; try { // Try to get speed from request speed = Long.parseLong(request.getParameter("spd")); } catch (Exception ex) { } if (speed < 0) { // Client don't send speed to server try { // Calculate speed manually double lastLat = (Double) session.getAttribute("latitude"); double lastLng = (Double) session.getAttribute("longitude"); long time = (Long) session.getAttribute("time"); long distance = Utils.getDistance(lastLat, lastLng, lat, lng); speed = distance * 1000 / Math.abs(time - System.currentTimeMillis()); } catch (Exception ex) { speed = 0L; } } // Insert new point into server ServiceResult<CWaypoint> result = db.insertWaypoint(track_id, lat, lng, speed); CWaypoint cwaypoint = result.getResult(); if (result.isOK()) { // OK,latitude,longitude,speed(m/s),time,trackid session.setAttribute("latitude", lat); session.setAttribute("longitude", lng); session.setAttribute("time", cwaypoint.getTime().getTime()); out.print( "OK," + cwaypoint.getLat() + "," + cwaypoint.getLng() + "," + cwaypoint.getSpeed() + "," + cwaypoint.getTime().getTime() + "," + cwaypoint.getTrackID()); } } else if (op.equals("cellid")) { // Client send it's location by cellular technique if (track_id == null) { track_id = db.newTrack(device_id).getResult().getTrackID(); session.setAttribute("track_id", track_id); } try { int cell = Integer.parseInt(request.getParameter("cell")); int lac = Integer.parseInt(request.getParameter("lac")); Geocode geocode = Utils.getLocation(cell, lac); out.println(geocode.getLatitude() + "," + geocode.getLongitude()); } catch (Exception ex) { } // TODO Implements cellular method to calculate location of a mobile out.println("Not implement"); } else if (op.equals("newtrack")) { // Client request to create a new track track_id = db.newTrack(device_id).getResult().getTrackID(); session.setAttribute("track_id", track_id); out.print("OK," + track_id); } else if (op.equals("changepass")) { String newpass = request.getParameter("newpass"); if (newpass != null) { CTracked ctracked = new CTracked(); ctracked.setUsername(device_id); ctracked.setPassword(newpass); if (db.updateTracked(ctracked).isOK()) { out.println("OK," + device_id); } } } else if (op.equals("config")) { CTracked ctracked = db.getTracked(device_id).getResult(); Integer interval = ctracked.getIntervalGps(); if (interval == null) interval = 10; out.print("OK," + interval + ","); byte[] b = ctracked.getSchedule(); if (b == null) { for (int i = 0; i < 23; i++) { out.print("1."); } out.println(1); } else { for (int i = 0; i < 23; i++) { out.print(b[i] + "."); } out.println(b[23]); } } else if (op.equals("amilogin")) { out.println("OK"); } }