@Override public InputStream getInputStream( final ItsNatServletRequest itsNatServletRequest, final ItsNatServletResponse response) { final String domain; final InputStream returnVal; try { domain = new URI( ((HttpServletRequest) itsNatServletRequest.getServletRequest()) .getRequestURL() .toString()) .getHost(); if (domain.endsWith(ILIKEPLACES_COM) || domain.contains(LOCALHOST_8080)) { // Normal request on our website. Just forward. throw ExceptionCache.ILLEGAL_ACCESS_ERROR; } else { final URL url; TemplateSourceGeoBusinessType type = TemplateSourceGeoBusinessType.FullyImplementedHTML; switch (type) { case FullyImplementedHTML: url = new URL( type.toString().replace(WWW_ILIKEPLACES_COM, WWW_ILIKEPLACES_COM) + domain + SLASH + domain + HTML); URLConnection conn = url.openConnection(); HttpServletRequest httpRequest = (HttpServletRequest) itsNatServletRequest.getServletRequest(); String userAgent = httpRequest.getHeader(USER_AGENT); conn.setRequestProperty(USER_AGENT, userAgent); returnVal = conn.getInputStream(); break; case PiratesAttackingUsPirates: throw ExceptionCache .ILLEGAL_ACCESS_ERROR; // IMPLEMENT to string and redirect to pirate caught page // instead default: throw ExceptionCache.UNSUPPORTED_SWITCH; } } } catch (final URISyntaxException e) { Loggers.EXCEPTION.error(URISYNTAX_EXCEPTION, e); throw ExceptionCache.ILLEGAL_ACCESS_ERROR; } catch (final MalformedURLException e) { Loggers.EXCEPTION.error(MALFORMED_URLEXCEPTION, e); throw ExceptionCache.ILLEGAL_ACCESS_ERROR; } catch (final IOException e) { Loggers.EXCEPTION.error(IOEXCEPTION, e); throw ExceptionCache.ILLEGAL_ACCESS_ERROR; } return returnVal; }
public void processWithDocument(ItsNatAttachedClientEvent event) { int phase = event.getPhase(); if (phase == ItsNatAttachedClientEvent.REQUEST) { String[] msg = new String[1]; if (event instanceof ItsNatAttachedClientTimerEvent) { ItsNatAttachedClientTimerEvent timerEvent = (ItsNatAttachedClientTimerEvent) event; boolean accepted = (timerEvent.getRefreshInterval() >= 3000); event.setAccepted(accepted); if (!accepted) msg[0] = "Refresh interval too short: " + timerEvent.getRefreshInterval(); } else if (event instanceof ItsNatAttachedClientCometEvent) { event.setAccepted(true); } else // "none" refresh mode { event.setAccepted(true); } if (event.getWaitDocTimeout() > 30000) { event.setAccepted(false); msg[0] = "Too much time waiting for iframe/object/embed: " + event.getWaitDocTimeout(); } ItsNatServletRequest request = event.getItsNatServletRequest(); ServletRequest servRequest = request.getServletRequest(); if (!event.isAccepted()) { ItsNatServletResponse response = event.getItsNatServletResponse(); ItsNatServlet servlet = response.getItsNatServlet(); @SuppressWarnings("unchecked") Map<String, String[]> newParams = new HashMap<String, String[]>(servRequest.getParameterMap()); newParams.remove("itsnat_action"); // Removes: itsnat_action=attach_doc newParams.put("itsnat_doc_name", new String[] {"feashow.ext.core.misc.remCtrlReqRejected"}); newParams.put("reason", msg); // submitted as array servRequest = servlet.createServletRequest(servRequest, newParams); servlet.processRequest(servRequest, response.getServletResponse()); } } else if (phase == ItsNatAttachedClientEvent.REFRESH) { ClientDocument observer = event.getClientDocument(); if (observer.getItsNatDocument().isInvalid()) { observer.addCodeToSend("alert('Observed document was destroyed');"); } else { long initTime = observer.getCreationTime(); long currentTime = System.currentTimeMillis(); long limitMilisec = 15 * 60 * 1000; // 15 minutes (to avoid a long monitoring session) if (currentTime - initTime > limitMilisec) { event.setAccepted(false); observer.addCodeToSend("alert('Remote Control Timeout');\n"); } } } // ItsNatAttachedClientEvent.LOAD & UNLOAD : nothing to do if (!event.isAccepted()) event.getItsNatEventListenerChain().stop(); // Not really necessary }