package org.jscookie.test.integration.encoding;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jscookie.Cookies;

import com.fasterxml.jackson.databind.ObjectMapper;

@WebServlet( "/encoding" )
public class EncodingServlet extends HttpServlet {
	private static final long serialVersionUID = 1;
	@Override
	public void doGet( HttpServletRequest request, HttpServletResponse response )
	throws ServletException, IOException {
		String name = request.getParameter( "name" );

		System.out.println( "--------------------" );
		System.out.println( "Testing: " + name );

		Cookies cookies = Cookies.initFromServlet( request, response );
		String value = cookies.get( name );

		if ( value == null ) {
			throw new NullPointerException( "Cookie not found with name: " + name );
		}

		System.out.println( "Value: " + value );
		System.out.println( "--------------------" );

		cookies.set( name, value );

		response.setContentType( "application/json" );
		new ObjectMapper()
			.writeValue( response.getOutputStream(), new Result( name, value ) );
	}
}

class Result {
	private String name;
	private String value;
	Result( String name, String value ) {
		this.name = name;
		this.value = value;
	}
	public String getName() {
		return name;
	}
	public String getValue() {
		return value;
	}
}
@@ -69,16 +69,131 @@
 ception;
+%0Aimport java.io.UnsupportedEncodingException;%0Aimport java.net.URLDecoder;%0Aimport java.nio.charset.StandardCharsets;
 %0A%0Aimport
@@ -762,36 +762,28 @@
 e = 
-request.get
+getUTF8
 Param
-eter
 ( %22name%22
  );%0A
@@ -778,16 +778,25 @@
 ( %22name%22
+, request
  );%0A%0A%09%09S
@@ -1289,16 +1289,16 @@
 apper()%0A
-
 %09%09%09.writ
@@ -1364,16 +1364,476 @@
  ) );%0A%09%7D
+%0A%0A%09/**%0A%09 * Retrieves the parameter using UTF-8 charset since the server default is ISO-8859-1%0A%09 */%0A%09private String getUTF8Param( String name, HttpServletRequest request ) throws UnsupportedEncodingException %7B%0A%09%09String query = request.getQueryString();%0A%09%09for ( String pair : query.split( %22&%22 ) ) %7B%0A%09%09%09if ( name.equals( pair.split( %22=%22 )%5B 0 %5D ) ) %7B%0A%09%09%09%09return URLDecoder.decode( pair.split( %22=%22 )%5B 1 %5D, StandardCharsets.UTF_8.name() );%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return null;%0A%09%7D
 %0A%7D%0A%0Aclas

Fix the retrieval of UTF-8 characters from the server