package sl12tutorial; import java.io.IOException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class PassOn extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { doGet(request, response); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { // Prüfen, woher der Aufruf kommt String useParam = request.getParameter("use"); if (useParam != null && "dataurl".equals(useParam)) { // Aufruf kommt von BKU, HTTP Request auswerten und finale Antwortseite senden processDataURL(request, response); } else { // Aufruf kommt nicht von BKU, Startseite erzeugen und senden processInitial(request, response); } } private void processInitial(HttpServletRequest request, HttpServletResponse response) throws IOException { String servletURL = request.getRequestURL().toString(); // String servletURL = "http://localhost:18080/SL12Tutorial/PassOn"; String bkuURL = "http://127.0.0.1:3495/http-security-layer-request"; // String bkuURL = "http://127.0.0.1:13495/http-security-layer-request"; // Startseite erzeugen und senden response.setStatus(200); response.setContentType("text/html"); printForm(response, servletURL, bkuURL); } private void processDataURL(HttpServletRequest request, HttpServletResponse response) throws IOException { // Weitergabe-Parameter und -Header aus Request holen String passOnParamValue = request.getParameter("WeitergabeParameter_"); String passOnHeaderValue = request.getHeader("X-Test-Weitergabe"); // Finale Antwortseite erzeugen und senden response.setStatus(200); response.setContentType("text/html"); printResponse(response, passOnParamValue, passOnHeaderValue); } private void printForm(HttpServletResponse response, String servletURL, String bkuURL) throws IOException { ServletOutputStream out = response.getOutputStream(); out.println(""); out.println("Weitergabe: Start"); out.println(""); out.println("
"); out.println("<NullOperationRequest xmlns='http://www.buergerkarte.at/namespaces/securitylayer/1.2#'/>\"/>"); out.println(""); out.println(""); out.println(""); out.println(""); out.println("
"); out.println(""); out.println(""); } private void printResponse(HttpServletResponse response, String passOnParamValue, String passOnHeaderValue) throws IOException { ServletOutputStream out = response.getOutputStream(); out.println(""); out.println(""); out.println("Weitergabe: Auswertung"); out.println(""); out.println(""); out.println("

Der Wert des Weitergabe-Parameters WeitergabeParameter_ lautet: " + passOnParamValue + "

"); out.println("

Der Wert des Weitergabe-Headers X-Test-Weitergabe lautet: " + passOnHeaderValue + "

"); out.println(""); out.println(""); } }