Note that there are some explanatory texts on larger screens.

plurals
  1. POWebapp behaves as expected when run from eclipse while when exported as war fails
    primarykey
    data
    text
    <p>This has been driving me nuts.</p> <p>So I have a (very simple vanilla servlet 3) web app. When I run it in eclipse all is fine. Among others I am able to <em>register an account with Unicode (greek) username</em> and then log in as site admin and visit the user's profile alright. When I export war to <code>$CATALINA_HOME\webapps</code>, launch <code>$CATALINA_HOME\bin\startup.bat</code>, open the site in the browser, login as admin and try to visit the user profile the username etc display as blank.<br> The files in <code>...\apache-tomcat-7.0.32\conf</code> and the ones in <code>...\eclipse_workspaces\javaEE\Servers\Tomcat v7.0 Server at localhost-config</code> differ only in the line (in <code>server.xml</code>) :</p> <pre><code>&lt;Context docBase="ted2012" path="/ted2012" reloadable="true" source="org.eclipse.jst.jee.server:ted2012"/&gt; </code></pre> <p>which is an eclipse thing.</p> <p>The doGet method (slimmed) in the profile servlet :</p> <pre class="lang-java prettyprint-override"><code>protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String username = Helpers.decodeRequest(request .getParameter("user")); if (username != null) { User user = null; try { System.out .println("ProfileController.doGet() user name DECODED : " + username); user = userService.getUserWithUsername(username); // THIS FAILS System.out.println("ProfileController.doGet() user : " + user); request.setAttribute("userToShow", user); } catch (ServiceExDBFailure e) { log.debug("ProfileController::doGet", e); request.setAttribute("ErrorString", e.getMessage()); } sc.getRequestDispatcher(OTHERPROFILE_JSP) .forward(request, response); return; } else { //does not apply } } </code></pre> <p>The decode method is :</p> <pre class="lang-java prettyprint-override"><code>public static String decodeRequest(String parameter) throws UnsupportedEncodingException { if (parameter == null) return null; System.out.println("decode - request.getBytes(\"iso-8859-1\"):" + new String(parameter.getBytes("iso-8859-1"))); System.out.println("decode - request.getBytes(\"iso-8859-1\") BYTES:" + parameter.getBytes("iso-8859-1")); for (byte iterable_element : parameter.getBytes("iso-8859-1")) { System.out.println(iterable_element); } System.out.println("decode - request.getBytes(\"UTF-8\"):" + new String(parameter.getBytes(CHARSET_FOR_URL_ENCODING))); // UTF-8 return URLDecoder.decode(new String(parameter.getBytes("iso-8859-1")), CHARSET_FOR_URL_ENCODING); } </code></pre> <p>While the db call is :</p> <pre class="lang-java prettyprint-override"><code> statement = conn.prepareStatement(query); statement.setString(1, username); System.out.println("ελληναρα"); System.out.println(statement); set = statement.executeQuery(); if (set.next()) { User user = new User(); // user.setId(set.getInt("ID")); user.setUsername(set.getString("username")); user.setName(set.getString("name")); user.setSurname(set.getString("surname")); user.setPassword(set.getString("password")); user.setEmail(set.getString("email")); user.setRole(RolesENUM.values()[set.getInt("role")]); return user; // if the set is empty null is returned } </code></pre> <p>Tomcat prints :</p> <pre><code>decode - request.getBytes("iso-8859-1"):╧à╧â╧ä╬╡╧?╬╣╬▒ decode - request.getBytes("iso-8859-1") BYTES:[B@529b9ed -49 -123 -49 -125 -49 -124 -50 -75 -49 -127 -50 -71 -50 -79 decode - request.getBytes("UTF-8"):├?┬à├?┬â├?┬ä├Ä┬╡├?┬?├Ä┬╣├Ä┬▒ ProfileController.doGet() user name DECODED : ╧à╧â╧ä╬╡╧?╬╣╬▒ com.mysql.jdbc.JDBC4PreparedStatement@766d7940: SELECT * FROM users WHERE username='╧à╧â╧ä╬╡╧?╬╣╬▒' ???????? ProfileController.doGet() user : null </code></pre> <p>while Eclipse prints :</p> <pre><code>decode - request.getBytes("iso-8859-1"):υστερια decode - request.getBytes("iso-8859-1") BYTES:[B@4b6a6bdf -49 -123 -49 -125 -49 -124 -50 -75 -49 -127 -50 -71 -50 -79 decode - request.getBytes("UTF-8"):ÏÏÏεÏια ProfileController.doGet() user name DECODED : υστερια com.mysql.jdbc.JDBC4PreparedStatement@37d02427: SELECT * FROM users WHERE username='υστερια' ελληναρα ProfileController.doGet() user : com.ted.domain.User@63144ceb </code></pre> <p>I believe for some reason the query that gets to the db is something crazy - notice that where in eclipse prints ελληναρα in tomcat prints ???????? while the unicode username (υστερια) prints as ╧à╧â╧ä╬╡╧?╬╣╬▒ and not as ???????.</p> <p>So the question is - what changes between the Eclipse deployment and the tomcat deployment ? Why the hell the DB returns null ? I have really really tried to debug this in vain</p> <p>Help</p> <p>EDIT : replacing the line <code>statement.setString(1, username);</code> with <code>statement.setString(1, "υστερια");</code> there is NO failure. So by the time this line is run the bytes are mangled up - notice though that the bytes are the same one by one</p> <p><strong>EDIT2 :</strong> Tomcat v7.0 Server at localhost Eclipse launch VM args (split for readability) :</p> <pre><code>-Dcatalina.base="C:\Dropbox\eclipse_workspaces\javaEE\.metadata\.plugins \org.eclipse.wst.server.core\tmp1" -Dcatalina.home="C:\_\apache-tomcat-7.0.32" -Dwtp.deploy="C:\Dropbox\eclipse_workspaces\javaEE\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps" -Djava.endorsed.dirs="C:\_\apache-tomcat-7.0.32\endorsed" </code></pre> <p><strong>NB</strong> : <a href="https://stackoverflow.com/questions/13103550/eclipse-launch-configuration-for-web-project">the launch for the app is created dynamically</a></p> <p><strong>EDIT 2013.03.30</strong> : this is now on <a href="https://github.com/Utumno/ted2012" rel="nofollow noreferrer">github</a> - and see my more general question <a href="https://stackoverflow.com/questions/12913264/eclipse-vs-tomcat-deployment-exported-war-partially-fails-while-the-project">here</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload