Making room for a Service Proxy client
authorNiels Erik G. Nielsen <nielserik@indexdata.com>
Thu, 14 Mar 2013 17:11:09 +0000 (13:11 -0400)
committerNiels Erik G. Nielsen <nielserik@indexdata.com>
Thu, 14 Mar 2013 17:11:09 +0000 (13:11 -0400)
Work in progress for building in SP support alongside straight
Pazpar2 support, generalizing a 'SearchClient' for the purpose

pom.xml
src/main/java/com/indexdata/pz2utils4jsf/pazpar2/CommandResponse.java [new file with mode: 0644]
src/main/java/com/indexdata/pz2utils4jsf/pazpar2/CommandThread.java
src/main/java/com/indexdata/pz2utils4jsf/pazpar2/ProxyPz2Client.java [new file with mode: 0644]
src/main/java/com/indexdata/pz2utils4jsf/pazpar2/ProxyPz2ClientCommandResponse.java [new file with mode: 0644]
src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java
src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java
src/main/java/com/indexdata/pz2utils4jsf/pazpar2/SearchClient.java [new file with mode: 0644]
src/main/java/com/indexdata/pz2utils4jsf/pazpar2/StraightPz2Client.java [new file with mode: 0644]
src/main/java/com/indexdata/pz2utils4jsf/pazpar2/StraightPz2CommandResponse.java [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index bd9c16d..5eda446 100644 (file)
--- a/pom.xml
+++ b/pom.xml
       <groupId>org.jboss.weld.servlet</groupId>\r
       <artifactId>weld-servlet</artifactId>\r
       <version>1.1.10.Final</version>      \r
-    </dependency>\r
+    </dependency>    \r
+    <dependency>\r
+      <groupId>org.apache.httpcomponents</groupId>\r
+      <artifactId>httpclient</artifactId>\r
+      <version>4.0-beta1</version>\r
+    </dependency>    \r
     \r
     <dependency>\r
       <groupId>com.indexdata</groupId>\r
diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/CommandResponse.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/CommandResponse.java
new file mode 100644 (file)
index 0000000..7a92019
--- /dev/null
@@ -0,0 +1,7 @@
+package com.indexdata.pz2utils4jsf.pazpar2;\r
+\r
+public interface CommandResponse {\r
+  public int getStatusCode();\r
+  public String getContentType();\r
+  public String getResponseString();\r
+}\r
index 95dcf1e..a2c10b8 100644 (file)
@@ -5,9 +5,6 @@ import java.io.IOException;
 \r
 import org.apache.log4j.Logger;\r
 \r
-import com.indexdata.masterkey.pazpar2.client.ClientCommand;\r
-import com.indexdata.masterkey.pazpar2.client.Pazpar2Client;\r
-import com.indexdata.masterkey.pazpar2.client.Pazpar2HttpResponse;\r
 import com.indexdata.masterkey.pazpar2.client.exceptions.Pazpar2ErrorException;\r
 import com.indexdata.pz2utils4jsf.pazpar2.data.CommandError;\r
 \r
@@ -15,11 +12,11 @@ public class CommandThread extends Thread {
 \r
   private static Logger logger = Logger.getLogger(CommandThread.class);\r
   Pazpar2Command command;\r
-  Pazpar2Client client;\r
+  SearchClient client;\r
   private ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
   private StringBuilder response = new StringBuilder("");  \r
   \r
-  public CommandThread (Pazpar2Command command, Pazpar2Client client) {\r
+  public CommandThread (Pazpar2Command command, SearchClient client) {\r
     this.command = command;\r
     this.client = client;\r
   }\r
@@ -35,22 +32,22 @@ public class CommandThread extends Thread {
    *  \r
    */\r
   public void run() {\r
-    ClientCommand clientCommand = new ClientCommand(command.getName(), command.getEncodedQueryString());\r
+    \r
     if (command.getName().equals("search")) {\r
-      client.setSearchCommand(clientCommand);\r
+      client.setSearchCommand(command);\r
     }\r
     try {\r
       long start = System.currentTimeMillis();\r
-      Pazpar2HttpResponse httpResponse = client.executeCommand(clientCommand, baos);\r
-      if (httpResponse.getStatusCode()==200) {\r
-        response.append(baos.toString("UTF-8"));  \r
-      } else if (httpResponse.getStatusCode()==417) {\r
+      CommandResponse commandResponse = client.executeCommand(command, baos);\r
+      if (commandResponse.getStatusCode()==200) {\r
+        response.append(commandResponse.getResponseString());  \r
+      } else if (commandResponse.getStatusCode()==417) {\r
         logger.error("Pazpar2 status code 417: " + baos.toString("UTF-8"));\r
         response.append(CommandError.insertPazpar2ErrorXml(command.getName(), "Expectation failed (417)", baos.toString("UTF-8")));        \r
       } else {\r
         String resp = baos.toString("UTF-8");\r
-        logger.error("Pazpar2 status code was " + httpResponse.getStatusCode() + ": " + resp);\r
-        throw new Pazpar2ErrorException(resp,httpResponse.getStatusCode(),resp,null);\r
+        logger.error("Pazpar2 status code was " + commandResponse.getStatusCode() + ": " + resp);\r
+        throw new Pazpar2ErrorException(resp,commandResponse.getStatusCode(),resp,null);\r
       }       \r
       long end = System.currentTimeMillis();      \r
       logger.debug("Executed " + command.getName() + " in " + (end-start) + " ms." );\r
diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/ProxyPz2Client.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/ProxyPz2Client.java
new file mode 100644 (file)
index 0000000..349b0ff
--- /dev/null
@@ -0,0 +1,102 @@
+package com.indexdata.pz2utils4jsf.pazpar2;\r
+\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.IOException;\r
+\r
+import javax.enterprise.context.SessionScoped;\r
+import javax.enterprise.inject.Alternative;\r
+import javax.inject.Named;\r
+\r
+import org.apache.http.HttpEntity;\r
+import org.apache.http.HttpResponse;\r
+import org.apache.http.StatusLine;\r
+import org.apache.http.client.ClientProtocolException;\r
+import org.apache.http.client.HttpClient;\r
+import org.apache.http.client.ResponseHandler;\r
+import org.apache.http.client.methods.HttpGet;\r
+import org.apache.http.impl.client.DefaultHttpClient;\r
+import org.apache.http.util.EntityUtils;\r
+import org.apache.log4j.Logger;\r
+\r
+import com.indexdata.masterkey.pazpar2.client.exceptions.Pazpar2ErrorException;\r
+import com.indexdata.pz2utils4jsf.config.Pz2Configurator;\r
+import com.indexdata.pz2utils4jsf.utils.Utils;\r
+\r
+@Named @SessionScoped @Alternative\r
+public class ProxyPz2Client implements SearchClient {\r
+\r
+  private static final long serialVersionUID = -4031644009579840277L;\r
+  private static Logger logger = Logger.getLogger(ProxyPz2Client.class);\r
+  \r
+  ProxyPz2ResponseHandler handler = new ProxyPz2ResponseHandler();\r
+  HttpClient client = new DefaultHttpClient();  \r
+\r
+  public ProxyPz2Client(HttpClient client) {\r
+  }\r
+  \r
+  @Override\r
+  public void configure (Pz2Configurator configurator) {\r
+    logger.info(Utils.objectId(this) + " is configuring itself using the provided " + Utils.objectId(configurator));\r
+\r
+  }\r
+  \r
+  /**\r
+   * Makes the request\r
+   * @param request\r
+   * @return HTTP response as a String\r
+   * @throws ClientProtocolException\r
+   * @throws IOException\r
+   */\r
+  private String send(Pazpar2Command command) throws ClientProtocolException, IOException {\r
+    String url = command.getEncodedQueryString(); \r
+    logger.debug("Sending request "+url);    \r
+    HttpGet httpget = new HttpGet(url);     \r
+    byte[] response = client.execute(httpget, handler);    \r
+    return new String(response);\r
+  }\r
+\r
+  \r
+  public class ProxyPz2ResponseHandler implements ResponseHandler<byte[]> {\r
+    private StatusLine statusLine = null;\r
+    public byte[] handleResponse(HttpResponse response) throws ClientProtocolException, IOException {\r
+      HttpEntity entity = response.getEntity();      \r
+      statusLine = response.getStatusLine();\r
+      if (entity != null) {        \r
+        return EntityUtils.toByteArray(entity);\r
+      } else {\r
+        return null;\r
+      }\r
+    }\r
+    public int getStatusCode() {\r
+      return statusLine.getStatusCode();\r
+    }    \r
+    public String getReasonPhrase() {\r
+      return statusLine.getReasonPhrase();\r
+    }\r
+  }\r
+\r
+  public int getStatusCode () {\r
+    return handler.getStatusCode();\r
+  }\r
+  \r
+  public String getReasonPhrase() {\r
+    return handler.getReasonPhrase();\r
+  }\r
+\r
+  @Override\r
+  public void setSearchCommand(Pazpar2Command command) {\r
+    // Do nothing, Service Proxy is handling this    \r
+  }\r
+\r
+  @Override\r
+  public CommandResponse executeCommand(Pazpar2Command command,\r
+      ByteArrayOutputStream baos) throws Pazpar2ErrorException, IOException {\r
+    String response = send(command);\r
+    return new ProxyPz2ClientCommandResponse(getStatusCode(), response);    \r
+  }\r
+\r
+  public ProxyPz2Client cloneMe() {\r
+    return this;\r
+  }\r
+\r
+}\r
diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/ProxyPz2ClientCommandResponse.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/ProxyPz2ClientCommandResponse.java
new file mode 100644 (file)
index 0000000..67cbe45
--- /dev/null
@@ -0,0 +1,28 @@
+package com.indexdata.pz2utils4jsf.pazpar2;\r
+\r
+public class ProxyPz2ClientCommandResponse implements CommandResponse {\r
+\r
+  private int statusCode = 0;\r
+  private String content = null;\r
+  \r
+  public ProxyPz2ClientCommandResponse(int statusCode, String content) {\r
+    this.statusCode = statusCode;\r
+    this.content = content;\r
+  }\r
+\r
+  @Override\r
+  public int getStatusCode() {\r
+    return statusCode;\r
+  }\r
+\r
+  @Override\r
+  public String getContentType() {\r
+    return "text/xml;charset=UTF-8";    \r
+  }\r
+\r
+  @Override\r
+  public String getResponseString() {\r
+    return content;\r
+  }\r
+\r
+}\r
index fd3e478..dff3142 100644 (file)
@@ -28,8 +28,9 @@ public class Pz2Bean implements Pz2Interface, Serializable {
   private static Logger logger = Logger.getLogger(Pz2Bean.class);\r
   \r
   Pz2Session pz2;  \r
-  @Inject Pz2Configurator pz2conf;\r
-  \r
+  @Inject Pz2Configurator configurator;\r
+  @Inject SearchClient    searchClient;\r
+    \r
   public Pz2Bean () {\r
     logger.info("Instantiating pz2 bean [" + Utils.objectId(this) + "]");\r
   }\r
@@ -38,8 +39,10 @@ public class Pz2Bean implements Pz2Interface, Serializable {
   public void initiatePz2Session() {\r
     logger.debug(Utils.objectId(this) + " will instantiate a Pz2Session next.");\r
     pz2 = new Pz2Session();\r
-    logger.debug(Utils.objectId(this) + " will forward configuration to the new Pz2Session [" + Utils.objectId(pz2) + "]");\r
-    pz2.init(pz2conf);\r
+    logger.info("Using [" + Utils.objectId(searchClient) + "] configured by [" \r
+                          + Utils.objectId(configurator) + "] on session [" \r
+                          + Utils.objectId(pz2) + "]" );\r
+    pz2.init(searchClient,configurator);\r
   }\r
   \r
   /* (non-Javadoc)\r
index 17f8545..58b296f 100644 (file)
@@ -1,7 +1,5 @@
 package com.indexdata.pz2utils4jsf.pazpar2;\r
 \r
-import java.io.ByteArrayOutputStream;\r
-import java.io.IOException;\r
 import java.util.ArrayList;\r
 import java.util.List;\r
 import java.util.Map;\r
@@ -13,15 +11,8 @@ import javax.inject.Named;
 \r
 import org.apache.log4j.Logger;\r
 \r
-import com.indexdata.masterkey.pazpar2.client.ClientCommand;\r
-import com.indexdata.masterkey.pazpar2.client.Pazpar2Client;\r
-import com.indexdata.masterkey.pazpar2.client.Pazpar2ClientConfiguration;\r
-import com.indexdata.masterkey.pazpar2.client.Pazpar2ClientGeneric;\r
-import com.indexdata.masterkey.pazpar2.client.exceptions.Pazpar2ErrorException;\r
-import com.indexdata.masterkey.pazpar2.client.exceptions.ProxyErrorException;\r
 import com.indexdata.pz2utils4jsf.config.Pz2Configurator;\r
 import com.indexdata.pz2utils4jsf.controls.ResultsPager;\r
-import com.indexdata.pz2utils4jsf.errors.ConfigurationError;\r
 import com.indexdata.pz2utils4jsf.errors.ConfigurationException;\r
 import com.indexdata.pz2utils4jsf.errors.ErrorHelper;\r
 import com.indexdata.pz2utils4jsf.errors.ErrorInterface;\r
@@ -40,53 +31,42 @@ import com.indexdata.pz2utils4jsf.utils.Utils;
 \r
 @Named @SessionScoped  \r
 public class Pz2Session implements Pz2Interface {\r
-  \r
+    \r
+  private static final long serialVersionUID = 3947514708343320514L;\r
   private static Logger logger = Logger.getLogger(Pz2Session.class);\r
   \r
   private Map<String,Pazpar2ResponseData> dataObjects = new ConcurrentHashMap<String,Pazpar2ResponseData>();\r
   private QueryStates queryStates = new QueryStates();\r
+  private ErrorHelper errorHelper = null;\r
   \r
-  private static final long serialVersionUID = 3947514708343320514L;  \r
-  private Pazpar2ClientConfiguration cfg = null;\r
-  private Pazpar2Client client = null;   \r
+  private List<ErrorInterface> configurationErrors = null;\r
+  private SearchClient searchClient = null;   \r
   private TargetFilter targetFilter = null;  \r
   private ResultsPager pager = null; \r
-  private ErrorHelper errorHelper = null;\r
-  private List<ErrorInterface> configurationErrors = null;\r
-  \r
+    \r
   public Pz2Session () {\r
     logger.info("Instantiating pz2 session object [" + Utils.objectId(this) + "]");      \r
   }\r
     \r
-  public void init(Pz2Configurator pz2conf) {\r
-    if (client==null) {\r
-      configurationErrors = new ArrayList<ErrorInterface>();\r
-      errorHelper = new ErrorHelper(pz2conf);\r
-      logger.info(Utils.objectId(this) + " is configuring itself using the provided " + Utils.objectId(pz2conf));\r
-      try {\r
-        cfg = new Pazpar2ClientConfiguration(pz2conf.getConfig());\r
-      } catch (ProxyErrorException pe) {\r
-        logger.error("Could not configure Pazpar2 client: " + pe.getMessage());\r
-        configurationErrors.add(new ConfigurationError("Pz2Client Config","ProxyError","Could not configure Pazpar2 client: " + pe.getMessage(),errorHelper));\r
-      } catch (ConfigurationException io) {\r
-        logger.error("Could not configure Pazpar2 client: " + io.getMessage());\r
-        configurationErrors.add(new ConfigurationError("Pz2Client Config","ProxyError","Could not configure Pazpar2 client: " + io.getMessage(),errorHelper));\r
-      }\r
-      if (cfg != null) {\r
-        try {\r
-          client = new Pazpar2ClientGeneric(cfg);  \r
-        } catch (ProxyErrorException pe) {\r
-          logger.error("Could not instantiate Pazpar2 client: " + pe.getMessage());\r
-          configurationErrors.add(new ConfigurationError("Pz2Client error","ProxyError","Could not create Pazpar2 client: " +pe.getMessage(),errorHelper));                \r
-        } \r
-        if (hasConfigurationErrors()) {\r
-          logger.info("Found " + configurationErrors.size() + " configuration errors");\r
-        }\r
-      }\r
-      resetDataObjects();\r
-    } else {\r
-      logger.warn("Attempt to configure session but it already has a configured client");\r
-    }\r
+  public void init(SearchClient searchClient, Pz2Configurator configurator) {\r
+    configurationErrors = new ArrayList<ErrorInterface>();\r
+    errorHelper = new ErrorHelper(configurator);    \r
+    logger.debug(Utils.objectId(this) + " will configure search client for the session");\r
+    try {\r
+      searchClient.configure(configurator);\r
+      \r
+      // The cloning is a hack: \r
+      // At the time of writing this search client is injected using Weld. \r
+      // However, the client is used for asynchronously sending off requests\r
+      // to the server AND propagation of context to threads is not supported.\r
+      // Trying so will throw a WELD-001303 error. To avoid that, a context\r
+      // free client is spawned from the context dependent one. \r
+      this.searchClient = searchClient.cloneMe();\r
+      \r
+    } catch (ConfigurationException e) {\r
+      logger.info("Found " + configurationErrors.size() + " configuration errors");    \r
+    }        \r
+    resetDataObjects();\r
   }\r
     \r
   public void doSearch(String query) {\r
@@ -126,7 +106,7 @@ public class Pz2Session implements Pz2Interface {
         List<CommandThread> threadList = new ArrayList<CommandThread>();\r
         StringTokenizer tokens = new StringTokenizer(commands,",");\r
         while (tokens.hasMoreElements()) {\r
-          threadList.add(new CommandThread(getCommand(tokens.nextToken()),client));            \r
+          threadList.add(new CommandThread(getCommand(tokens.nextToken()),searchClient));            \r
         }\r
         for (CommandThread thread : threadList) {\r
           thread.start();\r
@@ -140,7 +120,9 @@ public class Pz2Session implements Pz2Interface {
         }\r
         for (CommandThread thread : threadList) {\r
            String commandName = thread.getCommand().getName();\r
-           Pazpar2ResponseData responseObject = Pazpar2ResponseParser.getParser().getDataObject(thread.getResponse());\r
+           String response = thread.getResponse();\r
+           logger.debug("Response was: " + response);\r
+           Pazpar2ResponseData responseObject = Pazpar2ResponseParser.getParser().getDataObject(response);\r
            dataObjects.put(commandName, responseObject);        \r
         }\r
         return getActiveClients();\r
diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/SearchClient.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/SearchClient.java
new file mode 100644 (file)
index 0000000..7534150
--- /dev/null
@@ -0,0 +1,20 @@
+package com.indexdata.pz2utils4jsf.pazpar2;\r
+\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.IOException;\r
+import java.io.Serializable;\r
+\r
+import com.indexdata.masterkey.pazpar2.client.Pazpar2HttpResponse;\r
+import com.indexdata.masterkey.pazpar2.client.exceptions.Pazpar2ErrorException;\r
+import com.indexdata.pz2utils4jsf.config.Pz2Configurator;\r
+import com.indexdata.pz2utils4jsf.errors.ConfigurationException;\r
+\r
+\r
+public interface SearchClient extends Serializable {\r
+\r
+  public void configure(Pz2Configurator configurator) throws ConfigurationException;\r
+  public void setSearchCommand(Pazpar2Command command);\r
+  public CommandResponse executeCommand(Pazpar2Command command, ByteArrayOutputStream baos) throws Pazpar2ErrorException, IOException;\r
+  public SearchClient cloneMe();\r
+  \r
+}\r
diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/StraightPz2Client.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/StraightPz2Client.java
new file mode 100644 (file)
index 0000000..187b928
--- /dev/null
@@ -0,0 +1,76 @@
+package com.indexdata.pz2utils4jsf.pazpar2;\r
+\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.IOException;\r
+\r
+import javax.enterprise.context.SessionScoped;\r
+import javax.enterprise.inject.Alternative;\r
+import javax.inject.Named;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import com.indexdata.masterkey.pazpar2.client.ClientCommand;\r
+import com.indexdata.masterkey.pazpar2.client.Pazpar2Client;\r
+import com.indexdata.masterkey.pazpar2.client.Pazpar2ClientConfiguration;\r
+import com.indexdata.masterkey.pazpar2.client.Pazpar2ClientGeneric;\r
+import com.indexdata.masterkey.pazpar2.client.Pazpar2HttpResponse;\r
+import com.indexdata.masterkey.pazpar2.client.exceptions.Pazpar2ErrorException;\r
+import com.indexdata.masterkey.pazpar2.client.exceptions.ProxyErrorException;\r
+import com.indexdata.pz2utils4jsf.config.Pz2Configurator;\r
+import com.indexdata.pz2utils4jsf.errors.ConfigurationException;\r
+import com.indexdata.pz2utils4jsf.utils.Utils;\r
+\r
+@Named @SessionScoped @Alternative\r
+public class StraightPz2Client implements SearchClient {\r
+\r
+  private static final long serialVersionUID = 5414266730169982028L;\r
+  private static Logger logger = Logger.getLogger(StraightPz2Client.class);\r
+  private Pazpar2Client client = null;\r
+  private Pazpar2ClientConfiguration cfg = null;  \r
+  \r
+  public StraightPz2Client() {}\r
+  \r
+  public void configure(Pz2Configurator configurator) throws ConfigurationException {\r
+    logger.info(Utils.objectId(this) + " is configuring itself using the provided " + Utils.objectId(configurator));\r
+    try {\r
+      cfg = new Pazpar2ClientConfiguration(configurator.getConfig());\r
+    } catch (ProxyErrorException pe) {\r
+      logger.error("Could not configure Pazpar2 client: " + pe.getMessage());\r
+      throw new ConfigurationException("Could not configure StraightPz2Client:  "+ pe.getMessage(),pe);\r
+    } \r
+    if (cfg != null) {\r
+      try {\r
+        client = new Pazpar2ClientGeneric(cfg);  \r
+      } catch (ProxyErrorException pe) {\r
+        logger.error("Could not configure Pazpar2 client: " + pe.getMessage());\r
+        throw new ConfigurationException("Could not configure StraightPz2Client:  "+ pe.getMessage(),pe);\r
+      }\r
+    } else {\r
+      logger.error("There was a problem creating StraightPz2Client. Client is null after configuration.");\r
+      throw new ConfigurationException("Pazpar2Client is null after configuration");\r
+    } \r
+  }\r
+\r
+  @Override\r
+  public void setSearchCommand(Pazpar2Command command) {\r
+    ClientCommand clientCommand = new ClientCommand(command.getName(), command.getEncodedQueryString());\r
+    client.setSearchCommand(clientCommand);\r
+    \r
+  }\r
+\r
+  @Override\r
+  public CommandResponse executeCommand(Pazpar2Command command, ByteArrayOutputStream baos) \r
+       throws Pazpar2ErrorException, IOException {\r
+    ClientCommand clientCommand = new ClientCommand(command.getName(), command.getEncodedQueryString());\r
+    Pazpar2HttpResponse pz2HttpResponse = client.executeCommand(clientCommand, baos);\r
+    return new StraightPz2CommandResponse(pz2HttpResponse,baos);\r
+  }\r
+\r
+  public StraightPz2Client cloneMe() {\r
+    logger.debug("Cloning StraightPz2Client");\r
+    StraightPz2Client clone = new StraightPz2Client();\r
+    clone.client = this.client;\r
+    clone.cfg = this.cfg;\r
+    return clone;\r
+  }\r
+}\r
diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/StraightPz2CommandResponse.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/StraightPz2CommandResponse.java
new file mode 100644 (file)
index 0000000..d744e7b
--- /dev/null
@@ -0,0 +1,39 @@
+package com.indexdata.pz2utils4jsf.pazpar2;\r
+\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.UnsupportedEncodingException;\r
+\r
+import com.indexdata.masterkey.pazpar2.client.Pazpar2HttpResponse;\r
+\r
+public class StraightPz2CommandResponse implements CommandResponse {\r
+  \r
+  private Pazpar2HttpResponse pz2httpResponse = null;\r
+  private ByteArrayOutputStream content = null;\r
+  \r
+  public StraightPz2CommandResponse(Pazpar2HttpResponse pz2response, ByteArrayOutputStream content) {\r
+    pz2httpResponse = pz2response;\r
+    this.content = content;\r
+  }\r
+\r
+  @Override\r
+  public int getStatusCode() {    \r
+    return pz2httpResponse.getStatusCode();\r
+  }\r
+\r
+  @Override\r
+  public String getContentType() {\r
+    return pz2httpResponse.getContentType();\r
+  }\r
+\r
+  @Override\r
+  public String getResponseString() {\r
+    try {\r
+      return content.toString("UTF-8");\r
+    } catch (UnsupportedEncodingException e) {      \r
+      e.printStackTrace();\r
+      return null;\r
+    }\r
+  }\r
+\r
+\r
+}\r