Source:
<code>public void onHTTPRequest(IVHost inVhost, IHTTPRequest req, IHTTPResponse resp) { httpSessionId = "[" + System.currentTimeMillis() / 1000L + "]"; HashMap<String, Object> entryData = new HashMap<String,Object>(); try { List<String> vhostNames = VHostSingleton.getVHostNames(); logger.debug(httpSessionId + "Getting vhostNames" + vhostNames); Iterator<String> iter = vhostNames.iterator(); while (iter.hasNext()) { String vhostName = iter.next(); IVHost vhost = (IVHost)VHostSingleton.getInstance(vhostName); if (vhost == null) { continue; } List<String> appNames = vhost.getApplicationNames(); logger.debug(httpSessionId + "Getting appNames" + appNames); Iterator<String> appNameIterator = appNames.iterator(); while (appNameIterator.hasNext()) { String applicationName = appNameIterator.next(); IApplication application = vhost.getApplication(applicationName); if (application == null) continue; List<String> appInstances = application.getAppInstanceNames(); logger.debug(httpSessionId + "Getting appInstances" + appInstances); Iterator<String> iterAppInstances = appInstances.iterator(); while (iterAppInstances.hasNext()) { String appInstanceName = iterAppInstances.next(); IApplicationInstance appInstance = application.getAppInstance(appInstanceName); if (appInstance == null) continue; String queryStr = req.getQueryString(); <START> if (queryStr.equals("errors")) { <END> WMSProperties props = appInstance.getProperties(); if (props == null || ! props.containsKey(Constants.KALTURA_REJECTED_STREAMS)){ return; } ArrayList <HashMap<String,String> > rejectedStreams = (ArrayList <HashMap<String,String> >) props.getProperty(Constants.KALTURA_REJECTED_STREAMS); addAllRejectedSession(rejectedStreams, entryData); } else { List<IMediaStream> streamList = appInstance.getStreams().getStreams(); addAllStreamsProperties(streamList, entryData); } } } } } catch (Exception e) { logger.error(httpSessionId+"HTTPServerInfoXML.onHTTPRequest: "+e.toString()); } writeAnswer(resp, entryData); }</code><technical_language>please refactor this, a map a query string a function</technical_language>

Target:
public void onHTTPRequest(IVHost inVhost, IHTTPRequest req, IHTTPResponse resp) { httpSessionId = "[" + System.currentTimeMillis() / 1000L + "]"; HashMap<String, Object> entryData = new HashMap<String,Object>(); try { String requestURL = req.getRequestURL(); String arg = getArgument(requestURL, requestRegex); if (arg == null){ logger.error("Wrong requestURL, should be " + requestRegex + ", got "+ requestURL); return; } List<String> vhostNames = VHostSingleton.getVHostNames(); logger.debug(httpSessionId + "Getting vhostNames" + vhostNames); Iterator<String> iter = vhostNames.iterator(); while (iter.hasNext()) { String vhostName = iter.next(); IVHost vhost = (IVHost) VHostSingleton.getInstance(vhostName); if (vhost == null) { continue; } List<String> appNames = vhost.getApplicationNames(); logger.debug(httpSessionId + "Getting appNames" + appNames); Iterator<String> appNameIterator = appNames.iterator(); while (appNameIterator.hasNext()) { String applicationName = appNameIterator.next(); IApplication application = vhost.getApplication(applicationName); if (application == null) continue; List<String> appInstances = application.getAppInstanceNames(); logger.debug(httpSessionId + "Getting appInstances" + appInstances); Iterator<String> iterAppInstances = appInstances.iterator(); while (iterAppInstances.hasNext()) { String appInstanceName = iterAppInstances.next(); IApplicationInstance appInstance = application.getAppInstance(appInstanceName); if (appInstance == null) continue; switch (arg) { case DIAGNOSTICS_ERROR: writeRejectedSession(entryData); break; case DIAGNOSTICS_LIVE_ENTRIES: List<IMediaStream> streamList = appInstance.getStreams().getStreams(); writeStreamsProperties(streamList, entryData); break; default: writeError(entryData, arg); } } } } } catch (Exception e) { logger.error(httpSessionId+"HTTPServerInfoXML.onHTTPRequest: "+e.toString()); } writeAnswer(resp, entryData); }