\r
import static com.indexdata.pz2utils4jsf.utils.Utils.nl;\r
\r
+import java.io.BufferedWriter;\r
import java.io.ByteArrayOutputStream;\r
import java.io.File;\r
+import java.io.FileWriter;\r
import java.io.IOException;\r
+import java.nio.file.Path;\r
+import java.nio.file.Paths;\r
import java.util.ArrayList;\r
import java.util.HashMap;\r
import java.util.List;\r
import java.util.Map;\r
+import java.util.Scanner;\r
\r
import javax.enterprise.context.SessionScoped;\r
import javax.inject.Named;\r
public static final String SP_INIT_DOC_PATHS = "SP_INIT_DOC_PATHS";\r
private String serviceUrl = "undefined";\r
private String[] initDocPaths = null;\r
+ private Configuration config = null;\r
\r
ProxyPz2ResponseHandler handler = new ProxyPz2ResponseHandler();\r
private HttpClient client;\r
public void configure (ConfigurationReader configReader) {\r
logger.info(Utils.objectId(this) + " is configuring using the provided " + Utils.objectId(configReader));\r
try {\r
- Configuration config = configReader.getConfiguration(this); \r
+ config = configReader.getConfiguration(this); \r
serviceUrl = config.getMandatory(SERVICE_PROXY_URL); \r
this.initDocPaths = getMultiProperty(config.get(SP_INIT_DOC_PATHS)); \r
} catch (ConfigurationException c) {\r
byte[] response = client.execute(httpget, handler); \r
return response;\r
}\r
-\r
\r
public class ProxyPz2ResponseHandler implements ResponseHandler<byte[]> {\r
private StatusLine statusLine = null;\r
logger.info("Looking to post the file in : [" + filePath +"]");\r
HttpPost post = new HttpPost(serviceUrl+"?command=init&includeDebug=yes");\r
File initDoc = new File(filePath);\r
+ logger.info("Posting to SP: ");\r
+ Path path = Paths.get(filePath);\r
+ if (logger.isDebugEnabled()) {\r
+ try (Scanner scanner = new Scanner(path, "UTF-8")){\r
+ while (scanner.hasNextLine()){\r
+ System.out.println(scanner.nextLine());\r
+ } \r
+ } \r
+ }\r
post.setEntity(new FileEntity(initDoc));\r
byte[] response = client.execute(post, handler);\r
- logger.info("Response on POST was: " + new String(response,"UTF-8"));\r
+ logger.info("Response on POST was: " + new String(response,"UTF-8")); \r
return response;\r
}\r
\r
public String getServiceProxyUrl () {\r
return serviceUrl;\r
}\r
-\r
+ \r
+ public Configuration getConfiguration () {\r
+ return config;\r
+ }\r
+ \r
}\r