Spring Boot redirect port 8080 to 8443

In Spring Boot 2.x, we can create a ServletWebServerFactory to redirect a port from HTTP 8080 to HTTPS 8443. Access localhost:8080, it will redirect to localhost:8443 1. ServletWebServerFactory For Spring Boot 2.x, try this: pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> StartApplication.java package com.mkyong; import org.apache.catalina.Context; import org.apache.catalina.connector.Connector; import org.apache.tomcat.util.descriptor.web.SecurityCollection; import org.apache.tomcat.util.descriptor.web.SecurityConstraint; import …

Read more

Java 11 HttpClient Examples

This article shows you how to use the new Java 11 HttpClient APIs to send HTTP GET/POST requests, and some frequent used examples. HttpClient httpClient = HttpClient.newBuilder() .version(HttpClient.Version.HTTP_2) .followRedirects(HttpClient.Redirect.NORMAL) .connectTimeout(Duration.ofSeconds(20)) .proxy(ProxySelector.of(new InetSocketAddress("proxy.yourcompany.com", 80))) .authenticator(Authenticator.getDefault()) .build(); 1. Synchronous Example This example sends a GET request to https://httpbin.org/get, and print out the response header, status code, and …

Read more

OkHttp – How to send HTTP requests

This article shows you how to use the OkHttp library to send an HTTP GET/POST requests and some frequent used examples. P.S Tested with OkHttp 4.2.2 pom.xml <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>okhttp</artifactId> <version>4.2.2</version> </dependency> 1. Synchronous Get Request OkHttpExample1.java package com.mkyong.http; import okhttp3.Headers; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; import java.io.IOException; public class OkHttpExample1 { // only …

Read more

JavaScript – How to redirect a page

In JavaScript, we can use either location.replace() or location.href to redirect a page. Normally, we use location.replace() to simulate an HTTP redirect. <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> <h1>JavaScript – How to redirect a page</h1> <h3>1. location.replace</h3> <button onclick="httpRedirect()">location.replace</button> <h3>2. location.href</h3> <button onclick="mouseClick()">location.href</button> <script> // Simulate an HTTP redirect function httpRedirect() { location.replace("https://www.mkyong.com") …

Read more

Nginx + WordPress ERR_TOO_MANY_REDIRECTS

Fresh installs a WordPress on Windows for development, and hits the ERR_TOO_MANY_REDIRECTS error message? Tested URL : http://localhost/index.php/wp-admin/install.php Tested : PHP 7.1.10 WordPress 4.8.3 Nginx 1.12.1 MySQL 5.7.17 Windows 10 your-nginx\conf\nginx.conf upstream php { server 127.0.0.1:9999; } server { listen 80; server_name localhost; root www/wordpress; location / { try_files $uri $uri/ /index.php?$args; } location ~ …

Read more

Mac OSX – Redirect .htaccess is not working ?

Here is the .htaccess file. /Library/WebServer/Documents/.htaccess # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /mkyong/ RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /mkyong/index.php [L] </IfModule> # END WordPress Solution Find the Apache config file in /etc/apache2/httpd.conf, make sure the following settings are configured properly : 1. The mod_rewrite.so is loaded. …

Read more

Spring @ExceptionHandler and RedirectAttributes

Since Spring 4.3.5 and 5.0 M4, it supports RedirectAttributes argument in the @ExceptionHandler method. @ExceptionHandler(MyCustomException.class) public String handleError1(MyCustomException e, RedirectAttributes redirectAttributes) { redirectAttributes.addFlashAttribute("message", "abcdefg"); return "redirect:/viewName"; } @ExceptionHandler(MultipartException.class) public String handleError2(MultipartException e, RedirectAttributes redirectAttributes) { redirectAttributes.addFlashAttribute("message", e.getCause().getMessage()); return "redirect:/viewName"; } P.S Read this SPR-14651 Noted If you are using Spring < 4.3.5, do not add ...

Read more