From 60a7b8badc8af9b419bc2c5d36c8f44496d75baf Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Fri, 5 Apr 2013 12:20:52 -0400 Subject: [PATCH] Fixes npe when changing SP URL on the fly --- .../com/indexdata/pz2utils4jsf/pazpar2/Pz2ProxyBean.java | 11 ++++++++++- .../java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2ProxyBean.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2ProxyBean.java index 72dbccb..0f9e97d 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2ProxyBean.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2ProxyBean.java @@ -74,11 +74,20 @@ public class Pz2ProxyBean extends Pz2Bean implements ServiceProxyInterface { session().postInit(); return ""; } + + public String postInit(byte[] initDoc) throws UnsupportedEncodingException, IOException { + logger.info("Posting init: " + System.currentTimeMillis()); + session().postInit(initDoc); + return ""; + + } @Override public void setServiceProxyUrl(String url) { logger.info("Setting Service Proxy url: " + url); - session().setServiceProxyUrl(url); + session().setServiceProxyUrl(url); + session().setQuery(null); + session().resetDataObjects(); } @Override diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java index ed4c088..66063c3 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java @@ -107,7 +107,7 @@ public class Pz2Session implements Pz2Interface { logger.debug("Processing request for " + commands); List threadList = new ArrayList(); StringTokenizer tokens = new StringTokenizer(commands,","); - while (tokens.hasMoreElements()) { + while (tokens.hasMoreElements()) { threadList.add(new CommandThread(getCommand(tokens.nextToken()),searchClient)); } for (CommandThread thread : threadList) { @@ -353,7 +353,7 @@ public class Pz2Session implements Pz2Interface { } protected boolean hasQuery() { - return !(getCommand("search").getParameter("query") == null); + return getCommand("search").getParameter("query") != null && getCommand("search").getParameter("query").getValueWithExpressions().length()>0; } public boolean hasRecords () { @@ -379,7 +379,7 @@ public class Pz2Session implements Pz2Interface { } protected void handleQueryStateChanges (String commands) { - if (queryStates.hasPendingStateChange("search")) { + if (queryStates.hasPendingStateChange("search") && hasQuery()) { logger.debug("Found pending search change. Doing search before updating " + commands); doSearch(); } -- 1.7.10.4