/** * This method can be overridden to change a request, the default implementation find * a defined connection and delegate request changes to it. * @param request the request to change * @return true if change was successful. */ public boolean changeRequest(HttpRequestBase request) { HttpSession session = null; if (connectionName != null) { log(Level.DEBUG, "looking for session %s", connectionName); session = find(HttpSession.class, connectionName); if (session != null) { if (!session.makeSession(request)) { log(Level.ERROR, "session failed"); } } } if (session == null && mandatorySession) { log(Level.ERROR, "missing session"); return false; } return true; }
/** * This method can be used to validate the response, the default implementation check * that the status code is 200. * @param response the responce to check * @return true if it's a valid response */ public boolean validateResponse(HttpResponse response) { if (response.getStatusLine().getStatusCode() != 200) { log(Level.ERROR, "Connection to %s fail with %s", getUrl(), response.getStatusLine().getReasonPhrase()); return false; } return true; }
@Override public Map<KeyType, Number> getNewSampleValues() { HttpClientStarter httpstarter = find(HttpClientStarter.class); if (! httpstarter.isStarted()) { return Collections.emptyMap(); HttpEntity entity = null; try { HttpRequestBase hg = new HttpGet(getUrl().toURI()); if (! changeRequest(hg)) { return Collections.emptyMap(); if (!validateResponse(response)) { EntityUtils.consumeQuietly(response.getEntity()); return Collections.emptyMap(); log(Level.ERROR, "Not response body to %s", getUrl()); return Collections.emptyMap(); Map<KeyType, Number> vars = parseStream(is); is.close(); return vars; } catch (IllegalStateException | IOException e) { log(Level.ERROR, e, "Unable to read %s because: %s", getUrl(), e.getMessage()); } catch (URISyntaxException e) { log(Level.ERROR, "unable to parse %s", getUrl()); } finally { if(entity != null) {
@Override public Boolean configure() { if("true".equalsIgnoreCase(getPd().getSpecific("mandatorySession"))) { mandatorySession = true; } return super.configure(); }
@Override protected boolean finishConfigure(List<Object> args) { log(Level.TRACE, "Configuring collect xpath with %s", args); CollectResolver<XPathExpression> cr = new XmlProvider.XmlResolver(); collectKeys = new HashMap<>(getPd().getCollectMapping().size()); for(Map.Entry<String, String> e: getPd().getCollectMapping().entrySet()) { String solved = Util.parseTemplate(String.format(e.getKey(), args != null ? args.toArray() : null), this, args); XPathExpression xpath = cr.resolve(solved); if (xpath == null) { log(Level.DEBUG, "unparsed xpath: %s", e.getKey()); continue; } else { collectKeys.put(xpath, solved); } } collectKeys = Collections.unmodifiableMap(collectKeys); log(Level.TRACE, "collect xpath mapping %s", collectKeys); return super.finishConfigure(args); }
return super.configure();