@@ -551,6 +551,80 @@ public static String convertToPem(X509Certificate certificate) {
551551 LOGGER .debug ("Error converting certificate on PEM format: " + e .getMessage (), e );
552552 }
553553 return pemCert ;
554+ }
555+
556+ /**
557+ * Redirect to location url
558+ *
559+ * @param response
560+ * HttpServletResponse object to be used
561+ * @param location
562+ * target location url
563+ * @param parameters
564+ * GET parameters to be added
565+ *
566+ * @throws IOException
567+ *
568+ * @see javax.servlet.http.HttpServletResponse#sendRedirect(String)
569+ */
570+ public static void sendRedirect (HttpServletResponse response , String location , Map <String , String > parameters ) throws IOException {
571+ String target = location ;
572+
573+ if (!parameters .isEmpty ()) {
574+ boolean first = !location .contains ("?" );
575+ for (Map .Entry <String , String > parameter : parameters .entrySet ())
576+ {
577+ if (first ) {
578+ target += "?" ;
579+ first = false ;
580+ } else {
581+ target += "&" ;
582+ }
583+ target += parameter .getKey ();
584+ if (!parameter .getValue ().isEmpty ()) {
585+ target += "=" + Util .urlEncoder (parameter .getValue ());
586+ }
587+ }
588+ }
589+ response .sendRedirect (target );
590+ }
591+
592+ /**
593+ * Redirect to location url
594+ *
595+ * @param response
596+ * HttpServletResponse object to be used
597+ * @param location
598+ * target location url
599+ *
600+ * @throws IOException
601+ *
602+ * @see javax.servlet.http.HttpServletResponse#sendRedirect(String)
603+ */
604+ public static void sendRedirect (HttpServletResponse response , String location ) throws IOException {
605+ Map <String , String > parameters =new HashMap <String , String >();
606+ sendRedirect (response , location , parameters );
607+ }
608+
609+
610+ /**
611+ * Returns the protocol + the current host + the port (if different than
612+ * common ports).
613+ *
614+ * @param request
615+ * HttpServletRequest object to be processed
616+ *
617+ * @return the HOST URL
618+ */
619+ public static String getSelfURLhost (HttpServletRequest request ) {
620+ String hostUrl = StringUtils .EMPTY ;
621+ final int serverPort = request .getServerPort ();
622+ if ((serverPort == 80 ) || (serverPort == 443 ) || serverPort == 0 ) {
623+ hostUrl = String .format ("%s://%s" , request .getScheme (), request .getServerName ());
624+ } else {
625+ hostUrl = String .format ("%s://%s:%s" , request .getScheme (), request .getServerName (), serverPort );
626+ }
627+ return hostUrl ;
554628 }
555629
556630 /**
0 commit comments