aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-08-19 11:45:45 +0200
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-08-19 11:45:45 +0200
commit80686cc60dc0bccb7a42fddefefcf13dcabdd80a (patch)
tree98810b82688b0b4670351bdcfd0c3f145dd44c87 /pdf-as-web
parente1b810ee9221f6247c575c669bff2ba98552c65e (diff)
downloadpdf-as-4-80686cc60dc0bccb7a42fddefefcf13dcabdd80a.tar.gz
pdf-as-4-80686cc60dc0bccb7a42fddefefcf13dcabdd80a.tar.bz2
pdf-as-4-80686cc60dc0bccb7a42fddefefcf13dcabdd80a.zip
Fixed #18, Get Parameters in external urls are not discarded
Diffstat (limited to 'pdf-as-web')
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java2
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java7
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/UrlParameterExtractor.java46
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java6
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ProvidePDFServlet.java8
-rw-r--r--pdf-as-web/src/main/resources/template_error_redirect.html1
-rw-r--r--pdf-as-web/src/main/resources/template_generic_param.html1
-rw-r--r--pdf-as-web/src/main/resources/template_invoke_redirect.html1
8 files changed, 70 insertions, 2 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java
index 6306852e..0fbd9163 100644
--- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java
+++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java
@@ -143,7 +143,7 @@ public class WebConfiguration implements IConfigurationConstants {
}
File f = new File(pdfASDir);
-
+
if (!f.exists() || !f.isDirectory()) {
logger.error("Pdf As working directory does not exists or is not a directory!: "
+ pdfASDir);
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java
index 83dd2610..9e3fb3fe 100644
--- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java
+++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java
@@ -746,6 +746,13 @@ public class PdfAsHelper {
return xml;
}
+ public static String getGenericTemplate() throws IOException {
+ String xml = FileUtils.readFileToString(FileUtils
+ .toFile(PdfAsHelper.class
+ .getResource("/template_generic_param.html")));
+ return xml;
+ }
+
public static String getInvokeRedirectTemplateSL() throws IOException {
String xml = FileUtils.readFileToString(FileUtils
.toFile(PdfAsHelper.class
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/UrlParameterExtractor.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/UrlParameterExtractor.java
new file mode 100644
index 00000000..4c793524
--- /dev/null
+++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/UrlParameterExtractor.java
@@ -0,0 +1,46 @@
+package at.gv.egiz.pdfas.web.helper;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+public class UrlParameterExtractor {
+
+
+ public static Map<String, String> splitQuery(URL url) throws UnsupportedEncodingException {
+ Map<String, String> query_pairs = new LinkedHashMap<String, String>();
+ String query = url.getQuery();
+ String[] pairs = query.split("&");
+ for (String pair : pairs) {
+ int idx = pair.indexOf("=");
+ query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8"));
+ }
+ return query_pairs;
+ }
+
+ public static String buildParameterFormString(URL url) throws IOException {
+ Map<String, String> query_pairs = splitQuery(url);
+ Iterator<Entry<String, String>> entryIt = query_pairs.entrySet().iterator();
+
+ if(query_pairs.isEmpty()) {
+ return "";
+ }
+ String genericTemplate = PdfAsHelper.getGenericTemplate();
+ StringBuilder sb = new StringBuilder();
+ while(entryIt.hasNext()) {
+ Entry<String, String> entry = entryIt.next();
+
+ String current = genericTemplate.replace("##NAME##", entry.getKey());
+ current = current.replace("##VALUE##", entry.getValue());
+ sb.append(current);
+ }
+
+ return sb.toString();
+ }
+
+}
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java
index 12693797..8e59ff1c 100644
--- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java
+++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java
@@ -24,6 +24,7 @@
package at.gv.egiz.pdfas.web.servlets;
import java.io.IOException;
+import java.net.URL;
import java.net.URLEncoder;
import javax.servlet.ServletException;
@@ -37,6 +38,7 @@ import org.slf4j.LoggerFactory;
import at.gv.egiz.pdfas.web.config.WebConfiguration;
import at.gv.egiz.pdfas.web.helper.HTMLFormater;
import at.gv.egiz.pdfas.web.helper.PdfAsHelper;
+import at.gv.egiz.pdfas.web.helper.UrlParameterExtractor;
/**
* Servlet implementation class ErrorPage
@@ -93,6 +95,10 @@ public class ErrorPage extends HttpServlet {
template = template.replace("##ERROR_URL##",
errorURL);
+ URL url = new URL(errorURL);
+ String extraParams = UrlParameterExtractor.buildParameterFormString(url);
+ template = template.replace("##ADD_PARAMS##", extraParams);
+
String target = PdfAsHelper.getInvokeTarget(request, response);
if(target == null) {
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ProvidePDFServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ProvidePDFServlet.java
index 1ee96602..7909e926 100644
--- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ProvidePDFServlet.java
+++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ProvidePDFServlet.java
@@ -24,6 +24,7 @@
package at.gv.egiz.pdfas.web.servlets;
import java.io.IOException;
+import java.net.URL;
import java.net.URLEncoder;
import javax.servlet.ServletException;
@@ -37,6 +38,7 @@ import org.slf4j.LoggerFactory;
import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
import at.gv.egiz.pdfas.web.config.WebConfiguration;
import at.gv.egiz.pdfas.web.helper.PdfAsHelper;
+import at.gv.egiz.pdfas.web.helper.UrlParameterExtractor;
/**
* Servlet implementation class ProvidePDF
@@ -95,7 +97,11 @@ public class ProvidePDFServlet extends HttpServlet {
// Redirect Browser
String template = PdfAsHelper.getInvokeRedirectTemplateSL();
template = template.replace("##INVOKE_URL##", invokeURL);
-
+
+ URL url = new URL(invokeURL);
+ String extraParams = UrlParameterExtractor.buildParameterFormString(url);
+ template = template.replace("##ADD_PARAMS##", extraParams);
+
byte[] signedData = PdfAsHelper.getSignedPdf(request, response);
if (signedData != null) {
template = template.replace("##PDFLENGTH##",
diff --git a/pdf-as-web/src/main/resources/template_error_redirect.html b/pdf-as-web/src/main/resources/template_error_redirect.html
index b5ca858d..4d0ffb6a 100644
--- a/pdf-as-web/src/main/resources/template_error_redirect.html
+++ b/pdf-as-web/src/main/resources/template_error_redirect.html
@@ -47,6 +47,7 @@ div.content {
name="Senden"> <input type="hidden"
name="cause" value="##CAUSE##"> <input
type="hidden" name="error" value="##ERROR##">
+ ##ADD_PARAMS##
</form>
</div>
</div>
diff --git a/pdf-as-web/src/main/resources/template_generic_param.html b/pdf-as-web/src/main/resources/template_generic_param.html
new file mode 100644
index 00000000..1b67f201
--- /dev/null
+++ b/pdf-as-web/src/main/resources/template_generic_param.html
@@ -0,0 +1 @@
+<input type="hidden" name="##NAME##" value="##VALUE##"> \ No newline at end of file
diff --git a/pdf-as-web/src/main/resources/template_invoke_redirect.html b/pdf-as-web/src/main/resources/template_invoke_redirect.html
index fcd75008..15934157 100644
--- a/pdf-as-web/src/main/resources/template_invoke_redirect.html
+++ b/pdf-as-web/src/main/resources/template_invoke_redirect.html
@@ -45,6 +45,7 @@ div.content {
<form name="CustomizedForm" action="##INVOKE_URL##" method="GET" target="##TARGET##">
<input type="submit" value="Weiter"
name="Senden">
+ ##ADD_PARAMS##
<input type="hidden" name="pdfurl" value="##PDFURL##">
<input type="hidden" name="pdflength" value="##PDFLENGTH##">
</form>