Clears requests and responses on new ip auth
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / Pz2ProxyBean.java
index 751e919..87daf80 100644 (file)
@@ -2,6 +2,8 @@ package com.indexdata.mkjsf.pazpar2;
 \r
 import java.io.IOException;\r
 import java.io.UnsupportedEncodingException;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
 \r
 import javax.annotation.PostConstruct;\r
 import javax.enterprise.context.SessionScoped;\r
@@ -68,7 +70,13 @@ public class Pz2ProxyBean extends Pz2Bean implements ServiceProxyInterface {
   }\r
   \r
   public void ipAuthenticate (ServiceProxyUser user) {\r
-    if (!user.isAuthenticated()) {\r
+    if (!user.isIpAuthenticated()) {\r
+      if (user.isAuthenticated()) {\r
+        user.clear();\r
+      }\r
+      pzreq.getRecord().removeParametersInState();\r
+      pzreq.getSearch().removeParametersInState();\r
+      pzresp.reset();\r
       ((ServiceProxyClient)searchClient).ipAuthenticate(user);\r
     }\r
   }\r
@@ -88,6 +96,17 @@ public class Pz2ProxyBean extends Pz2Bean implements ServiceProxyInterface {
   public String getServiceProxyUrl() {\r
     return ((ServiceProxyClient)searchClient).getServiceProxyUrl();\r
   }\r
+  \r
+  public boolean getServiceProxyUrlIsDefined() {\r
+    return ((ServiceProxyClient)searchClient).getServiceProxyUrl().length()>0;\r
+  }\r
+  \r
+  public List<String> getServiceProxyUrls() {\r
+    List<String> urls = new ArrayList<String>();\r
+    urls.add("");\r
+    urls.addAll(((ServiceProxyClient)searchClient).getServiceProxyUrls());\r
+    return urls;\r
+  }\r
     \r
   public String getInitDocPath () {\r
     return searchClient.getConfiguration().get("INIT_DOC_PATH");\r
@@ -106,7 +125,7 @@ public class Pz2ProxyBean extends Pz2Bean implements ServiceProxyInterface {
 \r
   @Override\r
   public String postInit() throws UnsupportedEncodingException, IOException {    \r
-    String initDocPath = ((ServiceProxyClient)searchClient).getInitDocPaths()[0];\r
+    String initDocPath = ((ServiceProxyClient)searchClient).getInitDocPaths().get(0);\r
     logger.info("Paths: " + ((ServiceProxyClient)searchClient).getInitDocPaths());\r
     logger.info("Path: " + initDocPath);\r
     pzresp.reset();\r
@@ -116,14 +135,13 @@ public class Pz2ProxyBean extends Pz2Bean implements ServiceProxyInterface {
   }\r
   \r
   @Override\r
-  public String postInit(byte[] initDoc) throws UnsupportedEncodingException, IOException {    \r
+  public String postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException {    \r
     pzresp.reset();\r
-    byte[] response = ((ServiceProxyClient)searchClient).postInitDoc(initDoc);\r
+    byte[] response = ((ServiceProxyClient)searchClient).postInitDoc(initDoc,includeDebug);\r
     initDocResponse = new String(response,"UTF-8");\r
     return initDocResponse;\r
   }\r
 \r
-\r
   @Override\r
   public String getInitResponse() {\r
     return initDocResponse;\r