diff options
author | emusic <emina.music@egiz.gv.at> | 2018-11-22 13:14:28 +0100 |
---|---|---|
committer | emusic <emina.music@egiz.gv.at> | 2018-11-22 13:14:28 +0100 |
commit | f76f559c8c1437a152a4f51b441e4cebe25430f1 (patch) | |
tree | 8930f89863cdc7e564f6a97ac777c133384a8730 /pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/sl20/SL20HttpBindingUtils.java | |
parent | cd6ff625d48a63e024b05ed1a253be3551e41599 (diff) | |
parent | c87c82009fb07e285d6c9acfd4686efc2cbf21c9 (diff) | |
download | pdf-as-4-f76f559c8c1437a152a4f51b441e4cebe25430f1.tar.gz pdf-as-4-f76f559c8c1437a152a4f51b441e4cebe25430f1.tar.bz2 pdf-as-4-f76f559c8c1437a152a4f51b441e4cebe25430f1.zip |
Merge branch 'SL20_development'
# Conflicts:
# build.gradle
# pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java
# pdf-as-lib/src/configuration/cfg/advancedconfig.properties
# pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java
# pdf-as-lib/src/main/resources/config/config.zip
# pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java
# pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PDFData.java
Diffstat (limited to 'pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/sl20/SL20HttpBindingUtils.java')
-rw-r--r-- | pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/sl20/SL20HttpBindingUtils.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/sl20/SL20HttpBindingUtils.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/sl20/SL20HttpBindingUtils.java new file mode 100644 index 00000000..e43ebfcf --- /dev/null +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/sl20/SL20HttpBindingUtils.java @@ -0,0 +1,48 @@ +package at.gv.egiz.pdfas.web.sl20; + +import java.io.IOException; +import java.io.StringWriter; +import java.net.URISyntaxException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.entity.ContentType; +import org.jose4j.base64url.Base64Url; +import org.slf4j.LoggerFactory; + +import com.google.gson.JsonObject; + +import at.gv.egiz.sl20.utils.SL20Constants; + +public class SL20HttpBindingUtils { + private static final org.slf4j.Logger log = LoggerFactory.getLogger(SL20HttpBindingUtils.class); + + public static void writeIntoResponse(HttpServletRequest request, HttpServletResponse response, JsonObject sl20Forward, String redirectURL) throws IOException, URISyntaxException { + //forward SL2.0 command + log.trace("SL20 command: " + sl20Forward.toString()); + if (request.getHeader(SL20Constants.HTTP_HEADER_SL20_CLIENT_TYPE) != null && + request.getHeader(SL20Constants.HTTP_HEADER_SL20_CLIENT_TYPE).equals(SL20Constants.HTTP_HEADER_VALUE_NATIVE)) { + log.debug("Client request containts 'native client' header ... "); + StringWriter writer = new StringWriter(); + writer.write(sl20Forward.toString()); + final byte[] content = writer.toString().getBytes("UTF-8"); + response.setStatus(HttpServletResponse.SC_OK); + response.setContentLength(content.length); + response.setContentType(ContentType.APPLICATION_JSON.toString()); + response.getOutputStream().write(content); + + } else { + log.debug("Client request containts is no native client ... "); + URIBuilder clientRedirectURI = new URIBuilder(redirectURL); + clientRedirectURI.addParameter( + SL20Constants.PARAM_SL20_REQ_COMMAND_PARAM, + Base64Url.encode(sl20Forward.toString().getBytes())); + response.setStatus(307); + response.setHeader("Location", clientRedirectURI.build().toString()); + + } + + } +} |