Я вижу один подход, который будет работать для вас.
При получении 403 установите флаг в хранилище резервов (не уверен, используете ли вы его), если нет, вам нужно установить его где-нибудь, где он будет доступен для всех компонентов.
Теперь во всех компонентах вы можете сказать
{token ? null:<Redirect to="/login" />}
Теперь, когда 403 получено в axios, оно будет перенаправлено на страницу входа.
Смотря на различия в реализации, я вижу что:
[-a-zA-Z0-9._*~'()!]
Java 1.5.0 документации относительно URLEncoder
:
[-a-zA-Z0-9._*]
" "
преобразовывается в знак "плюс" "+"
. Так в основном, чтобы получить желаемый результат, использовать URLEncoder.encode(s, "UTF-8")
и затем сделать некоторую последующую обработку:
"+"
с "%20"
"%xx"
представление любого из [1 110] назад к их литеральным дубликатам Это - класс, который я придумал в конце:
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
/**
* Utility class for JavaScript compatible UTF-8 encoding and decoding.
*
* @see http://stackoverflow.com/questions/607176/java-equivalent-to-javascripts-encodeuricomponent-that-produces-identical-output
* @author John Topley
*/
public class EncodingUtil
{
/**
* Decodes the passed UTF-8 String using an algorithm that's compatible with
* JavaScript's <code>decodeURIComponent</code> function. Returns
* <code>null</code> if the String is <code>null</code>.
*
* @param s The UTF-8 encoded String to be decoded
* @return the decoded String
*/
public static String decodeURIComponent(String s)
{
if (s == null)
{
return null;
}
String result = null;
try
{
result = URLDecoder.decode(s, "UTF-8");
}
// This exception should never occur.
catch (UnsupportedEncodingException e)
{
result = s;
}
return result;
}
/**
* Encodes the passed String as UTF-8 using an algorithm that's compatible
* with JavaScript's <code>encodeURIComponent</code> function. Returns
* <code>null</code> if the String is <code>null</code>.
*
* @param s The String to be encoded
* @return the encoded String
*/
public static String encodeURIComponent(String s)
{
String result = null;
try
{
result = URLEncoder.encode(s, "UTF-8")
.replaceAll("\\+", "%20")
.replaceAll("\\%21", "!")
.replaceAll("\\%27", "'")
.replaceAll("\\%28", "(")
.replaceAll("\\%29", ")")
.replaceAll("\\%7E", "~");
}
// This exception should never occur.
catch (UnsupportedEncodingException e)
{
result = s;
}
return result;
}
/**
* Private constructor to prevent this class from being instantiated.
*/
private EncodingUtil()
{
super();
}
}
Используя механизм JavaScript, который поставляется с Java 6:
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
public class Wow
{
public static void main(String[] args) throws Exception
{
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
engine.eval("print(encodeURIComponent('\"A\" B ± \"'))");
}
}
Вывод: %22A%22%20B%20%c2%b1%20%22
случай отличается, но это ближе к тому, что Вы хотите.