X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Fcom%2Findexdata%2Fpz2utils4jsf%2Fpazpar2%2FCommandThread.java;h=50ec2b6d41c608b5eec1c0192bf7b1f6685dc437;hb=45eb77e915522940923b9401b984bff004935686;hp=5764777447ff2a14dae005d56fdb49e2bc135d52;hpb=ab7a23c769e77affa25a47112d2e5e93ae23d7bc;p=mkjsf-moved-to-github.git
diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/CommandThread.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/CommandThread.java
index 5764777..50ec2b6 100644
--- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/CommandThread.java
+++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/CommandThread.java
@@ -5,12 +5,10 @@ import java.io.IOException;
import org.apache.log4j.Logger;
-import com.indexdata.pz2utils4jsf.pazpar2.CommandThread;
-import com.indexdata.pz2utils4jsf.pazpar2.Pazpar2Command;
-import com.indexdata.utils.XmlUtils;
import com.indexdata.masterkey.pazpar2.client.ClientCommand;
import com.indexdata.masterkey.pazpar2.client.Pazpar2Client;
import com.indexdata.masterkey.pazpar2.client.exceptions.Pazpar2ErrorException;
+import com.indexdata.pz2utils4jsf.pazpar2.data.ApplicationError;
public class CommandThread extends Thread {
@@ -25,6 +23,16 @@ public class CommandThread extends Thread {
this.client = client;
}
+ /**
+ * Runs the specified command using the specified Pazpar2 client
+ * Sets the Pazpar2 response as an XML response string to be retrieved by
+ * getResponse().
+ *
+ * In case of an exception, an error response is generated, the document
+ * element being the same as it would have been if successful (named after
+ * the command, that is).
+ *
+ */
public void run() {
ClientCommand clientCommand = new ClientCommand(command.getName(), command.getEncodedQueryString());
if (command.getName().equals("search")) {
@@ -37,20 +45,22 @@ public class CommandThread extends Thread {
long end = System.currentTimeMillis();
logger.debug("Executed " + command.getName() + " in " + (end-start) + " ms." );
} catch (IOException e) {
- logger.error("Message: " + e.getMessage());
- response = new StringBuilder("<"+command.getName()+">"+XmlUtils.escape(e.getMessage())+""+command.getName()+">");
+ response.append(ApplicationError.createErrorXml(command.getName(), "io", e.getMessage()));
logger.error(response.toString());
} catch (Pazpar2ErrorException e) {
- logger.error(e.getMessage());
- response = new StringBuilder("<"+command.getName()+">"+XmlUtils.escape(e.getMessage())+""+command.getName()+">");
+ response.append(ApplicationError.createErrorXml(command.getName(), "pazpar2error", e.getMessage()));
logger.error(response.toString());
}
}
+ /**
+ *
+ * @return Pazpar2 response as an XML string, possibly a generated error XML
+ */
public String getResponse () {
return response.toString();
}
-
+
public Pazpar2Command getCommand() {
return command;
}