<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Atanas Roussev - Senior Java Developer, UI Engineer, Web Developer Resume - Vancouver &#187; GWT</title>
	<atom:link href="http://www.roussev.org/category/google-web-toolkit-gwt-ajax-javascript-js-jquery-vaadin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.roussev.org</link>
	<description>a Web Developer creating elegant aesthetic software</description>
	<lastBuildDate>Mon, 31 May 2010 22:07:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>HTML 5 &#8211; Bad days for Flash</title>
		<link>http://www.roussev.org/2010/04/html-5-canvas-gwt-flash/</link>
		<comments>http://www.roussev.org/2010/04/html-5-canvas-gwt-flash/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 18:17:27 +0000</pubDate>
		<dc:creator>atanas</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://www.roussev.org/?p=996</guid>
		<description><![CDATA[Just found another great example of HTML 5.
http://code.google.com/p/quake2-gwt-port/
Those guys have  ported Quake via GWT to pure HTML and JavaScript. I am pretty sure it will behave well only on WebKit, yet it shows the new approach the web is going, &#8220;sadly&#8221; without Adobe Flash.

]]></description>
			<content:encoded><![CDATA[<p>Just found another great example of HTML 5.</p>
<p><a href="http://code.google.com/p/quake2-gwt-port/">http://code.google.com/p/quake2-gwt-port/</a></p>
<p>Those guys have  ported Quake via GWT to pure HTML and JavaScript. I am pretty sure it will behave well only on WebKit, yet it shows the new approach the web is going, &#8220;sadly&#8221; without Adobe Flash.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="440" height="305" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://www.youtube.com/v/XhMN0wlITLk&amp;rel=0&amp;color1=0xb1b1b1&amp;color2=0xcfcfcf&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="440" height="305" src="http://www.youtube.com/v/XhMN0wlITLk&amp;rel=0&amp;color1=0xb1b1b1&amp;color2=0xcfcfcf&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.roussev.org/2010/04/html-5-canvas-gwt-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>REST client HTTP4e version 3 released &#8211; code generation for Ruby, C#, Flex, ActionScript, jQuery, Java, Prototype, Cocoa</title>
		<link>http://www.roussev.org/2010/03/rest-client-http4e-version-3-released-code-generation-for-ruby-c-flex-actionscript-jquery-java-prototype-cocoa/</link>
		<comments>http://www.roussev.org/2010/03/rest-client-http4e-version-3-released-code-generation-for-ruby-c-flex-actionscript-jquery-java-prototype-cocoa/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 07:13:29 +0000</pubDate>
		<dc:creator>atanas</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[GWT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[REST Client]]></category>

		<guid isPermaLink="false">http://www.roussev.org/?p=991</guid>
		<description><![CDATA[Great news. HTTP4e was released few weeks ago. Today I found some time to post it.
New features:


Introducing @file abilities to load external payload to body by simply passing @/file/path
Export HTTP sessions report as HTML
Export and import HTTP4e replay script
Importing raw HTTP packets
Importing http packets directly from Firefox’s Live HTTPHeaders
Enhancing tabs
Fixing Pretty view XML formatting
JMeterone click [...]]]></description>
			<content:encoded><![CDATA[<p>Great news. HTTP4e was released few weeks ago. Today I found some time to post it.</p>
<p>New features:</p>
<div id="_mcePaste">
<ul>
<li>Introducing @file abilities to load external payload to body by simply passing @/file/path</li>
<li>Export HTTP sessions report as HTML</li>
<li>Export and import HTTP4e replay script</li>
<li>Importing raw HTTP packets</li>
<li>Importing http packets directly from Firefox’s Live HTTPHeaders</li>
<li>Enhancing tabs</li>
<li>Fixing Pretty view XML formatting</li>
<li>JMeterone click script generation</li>
<li>PHP, Flex/ActionScript, Cocoa/Objective-C, Ruby, Pythonone click script generation</li>
<li>C#, Visual Basic.NETone click script generation</li>
<li>JavaScript, Prototype, jQuery one click script generation</li>
<li>Apache HTTP Components 4.x one click code generation</li>
</ul>
</div>
<p>Stay tuned for more news and examples.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.roussev.org/2010/03/rest-client-http4e-version-3-released-code-generation-for-ruby-c-flex-actionscript-jquery-java-prototype-cocoa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beautiful GWT animation libraries</title>
		<link>http://www.roussev.org/2010/03/beautiful-gwt-animation-libraries/</link>
		<comments>http://www.roussev.org/2010/03/beautiful-gwt-animation-libraries/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 07:09:06 +0000</pubDate>
		<dc:creator>atanas</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.roussev.org/?p=988</guid>
		<description><![CDATA[Probably many of you needed to add Mootools, jQuery or Scriptaculous kinda effects within your GWT code.
I came across those two and I am spreading them to web:
Brand new, dead-easy to use library called GWT-FX:
http://code.google.com/p/gwt-fx/
A GWT wrapper over Mootools:
http://www.amateurinmotion.com/projects/gwt-mootools.html
]]></description>
			<content:encoded><![CDATA[<p>Probably many of you needed to add Mootools, jQuery or Scriptaculous kinda effects within your GWT code.</p>
<p>I came across those two and I am spreading them to web:</p>
<p>Brand new, dead-easy to use library called GWT-FX:<br />
<a href="http://code.google.com/p/gwt-fx/">http://code.google.com/p/gwt-fx/</a></p>
<p>A GWT wrapper over Mootools:<br />
<a href="http://www.amateurinmotion.com/projects/gwt-mootools.html">http://www.amateurinmotion.com/projects/gwt-mootools.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.roussev.org/2010/03/beautiful-gwt-animation-libraries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vaadin &#8211; the Java web framewrok</title>
		<link>http://www.roussev.org/2010/02/vaadin-the-java-web-framewrok/</link>
		<comments>http://www.roussev.org/2010/02/vaadin-the-java-web-framewrok/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 07:23:02 +0000</pubDate>
		<dc:creator>atanas</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Ruby, Scala, Groovy]]></category>

		<guid isPermaLink="false">http://www.roussev.org/?p=898</guid>
		<description><![CDATA[I keep spreading the message. While Java gurus are still faithing on those religious best web framework wars , there is hidden winner already.
The best Java web framework award goes to &#8230; drumrolls &#8230; Finland.
Vaadin &#8211; When I saw it for a first time few months back, I was shocked. That what Java is meant to [...]]]></description>
			<content:encoded><![CDATA[<p>I keep spreading the message. While Java gurus are still faithing on those religious best web framework wars , there is hidden winner already.</p>
<h3>The best Java web framework award goes to &#8230; drumrolls &#8230; Finland.</h3>
<p><a style="font-size: 18px;" title="Java Web Framework" href="http://www.vaadin.com" target="_blank"><strong>Vaadin</strong></a> &#8211; When I saw it for a first time few months back, I was shocked. That what Java is meant to be &#8211; Innovative, slick, sexy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.roussev.org/2010/02/vaadin-the-java-web-framewrok/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Living Without Sessions and persisting the state on the client</title>
		<link>http://www.roussev.org/2010/02/restful-stateless-without-sessions-no-stateful/</link>
		<comments>http://www.roussev.org/2010/02/restful-stateless-without-sessions-no-stateful/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 05:43:23 +0000</pubDate>
		<dc:creator>atanas</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.roussev.org/?p=743</guid>
		<description><![CDATA[An interesting idea. A blog post suggesting abandoning Stateful layer in favour of completly Stateless RESTful approach.
http://www.peej.co.uk/articles/no-sessions.html
&#8220;Developers became used to having sessions available to them, so when systems grew, became more complex, and started spreading over multiple servers, more and more hacks had to be introduced to keep the session support working, when in reality, [...]]]></description>
			<content:encoded><![CDATA[<p>An interesting idea. A <a href="http://www.peej.co.uk/articles/no-sessions.html" target="_blank">blog post</a> suggesting abandoning Stateful layer in favour of completly Stateless RESTful approach.</p>
<p><a href="http://www.peej.co.uk/articles/no-sessions.html">http://www.peej.co.uk/articles/no-sessions.html</a></p>
<p><em><span style="color: #333333;">&#8220;Developers became used to having sessions available to them, so when systems grew, became more complex, and started spreading over multiple servers, more and more hacks had to be introduced to keep the session support working, when in reality, sessions should never have been introduced in the first place.&#8221;</span></em></p>
<p><em><span style="color: #333333;">&#8220;</span></em><strong><em><span style="color: #333333;">Cart on the client</span></em></strong></p>
<div id="_mcePaste"><em><span style="color: #333333;">When you think about someone in real life going into a shop and placing items into their shopping basket, where is the basket? It&#8217;s with the user. So why don&#8217;t we model our online shop to mirror the real life scenario.</span></em></div>
<div id="_mcePaste"><em><span style="color: #333333;">Web browsers used to be a document reader for displaying hypertext documents transfered over the HTTP protocol, but nowerdays they are an application platform thanks to the development and deployment of Javascript within the HTML document and the browser. So we can use Javascript to extend our clients browser to be able to store their shopping cart until they reach the checkout.&#8221;</span></em></div>
<p>Using web2.0 RIA clients such as GWT, <a href="http://vaadin.com/" target="_blank">Vaadin </a>or <a href="http://cappuccino.org/" target="_blank">Cappuccino</a> fit just perfect. I would only disagree with using the REST as a remedy for everything. While REST is great general purpose service architecture, decision should rather be based per technology. GWT f.i. has its first class optimized RPC API, so it&#8217;s natural for GWT to use its RPC over REST JSON.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.roussev.org/2010/02/restful-stateless-without-sessions-no-stateful/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GWT Dynamic Exception Handling</title>
		<link>http://www.roussev.org/2010/02/gwt-dynamic-exception-handling/</link>
		<comments>http://www.roussev.org/2010/02/gwt-dynamic-exception-handling/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 01:02:52 +0000</pubDate>
		<dc:creator>atanas</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.roussev.org/?p=625</guid>
		<description><![CDATA[Having explored the GWT RPC exception limitations, on this post we will take another route of simplifying GWT exception handling. In short the idea is by extending the parent RemoteServiceServlet we will inject a code so the RPC Servlet treat our business runtimes as a good friend. We are lazy developers and we would like to [...]]]></description>
			<content:encoded><![CDATA[<p>Having <a title="GWT exception handling limitations" href="http://www.roussev.org/2010/02/gwt-exception-handling-limitations/">explored the GWT RPC exception limitations</a>, on this post we will take another route of simplifying GWT exception handling. In short the idea is by extending the parent <a href="http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/server/rpc/RemoteServiceServlet.html" target="_blank">RemoteServiceServlet</a> we will inject a code so the RPC Servlet treat our business runtimes as a good friend. We are lazy developers and we would like to be able to throw business exceptions without having to declare them on the each RPC method (Which probably contradicts the whole Java exception contract.. <img src='http://www.roussev.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ).</p>
<h3><strong>Hooking the business exception / Injecting it into GWT SerializationPolicy (aka fooling the GWT SerializationPolicy).</strong></h3>
<p>When an error propagates within a GWT service this error needs to be declared within the RPC method signature, otherwise bad things happen. The GWT SerilizablePolicy marshaling will complain about the type not being recognized and return 500 Server error response. Well we could easily overcome this limitation by creating a dummy hook method with only purpose of white-listing the business exception type within the given RPC signature Serialization policy:</p>
<pre style="background: none repeat scroll 0% 0% #ececda;"><span style="color: #993300;">
interface <strong>AbstractRemoteServiceAsync </strong>{
   void <strong><span style="color: #ff0000;">hookException</span></strong>(AsyncCallback&lt;Void&gt; callback);
}

interface <strong>AbstractRemoteService </strong>extends RemoteService {
   void <strong><span style="color: #ff0000;">hookException</span></strong>() throws <strong><span style="color: #ff0000;">MyException</span></strong>;
}

class <strong>AbstractRemoteServiceServlet </strong>extends RemoteServiceServlet
                 implements <strong>AbstractRemoteService </strong>{
<span style="color: #888888;">   /**
    * This method only reson vivre is to hook our business MyException type
    * into GWT Serialization policy
    */</span>
   @Override
   public String <strong><span style="color: #ff0000;">hookException</span></strong>() throws <span style="color: #ff0000;"><strong>MyException </strong></span>{
      // Blank
   }
}
<span style="color: #888888;">/**
 * The business exception
 */</span>
public class <strong><span style="color: #ff0000;">MyException </span></strong>extends RuntimeException {
	private static final long serialVersionUID = 1L;
}
</span></pre>
<p>From that point on, AbstractRemoteServiceServlet methods will treat MyException as a white-listed friend and no more SerializationPolicy warnings will happen.</p>
<p>Next thing we want to do is, automate this process so we don&#8217;t have to declare those hook methods on every RPC Servlet right? Well polymorphism on help.</p>
<p><strong>Overriding RemoteServiceServlet default exception flow.</strong></p>
<p>Let&#8217;s open the <a title="GWT RemoteServiceServlet" href="http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/user/server/rpc/RemoteServiceServlet.java?spec=svn5045&amp;r=5045" target="_blank">RemoteServiceServlet</a> implementation. Luckily this class follows a template method pattern with hook methods ready for extending. What we will acomplish is extending RemoteServiceServlet class and <span style="color: #ff0000;">inject a behaviour handling our business exceptions (code in red)</span>.</p>
<p>And this is my humble contribution to GWT community. All <a title="GWT Dynamic Exception Handling" href="https://code.google.com/p/gwt-dynamic-exception-nadling/" target="_blank">sources and project are hosted at Google Code</a>:</p>
<pre style="background: none repeat scroll 0% 0% #ececda;"><span style="color: #993300;"><span style="color: #888888;">/**
 * This class overrides RemoteServiceServlet to provide automatic exception
 * handling for known business exceptions
 */</span>
public class <strong>AbstractRemoteServiceServlet </strong>extends <strong>RemoteServiceServlet</strong>
    implements <strong>AbstractRemoteService </strong>{

<span style="color: #888888;">  /**
   * Overriding method so we can inject business exception type discovery
   * and handling
   */</span>
  @Override
  public String <strong><span style="color: #333399;">processCall</span></strong>(String payload) throws SerializationException {
    try {
      RPCRequest rpcRequest = RPC.decodeRequest(payload, this.getClass(),
          this);
      return handleProcessCall(this, rpcRequest);
    } catch (IncompatibleRemoteServiceException ex) {
      log("Incompatible error was thrown while processing this call.", ex);
      return RPC.encodeResponseForFailure(null, ex);
    }
  }
  <span style="color: #888888;">/**
   * Tis method digest the given throwable and tries to find any know business
   * exception. When a known business error is found it is being flushed (the
   * business type) to response stream, thus client callback receives the known
   * type but not the default GWT UnexpectedException.
   */</span>
  @Override
  protected void <strong><span style="color: #333399;">doUnexpectedFailure</span></strong>(Throwable e) {
    discoverAndWriteError(e, e);
  }

<span style="color: #888888;">  /**
   * This method reson vivre is to hook the recognized MyException type into
   * GWT Serialization policy
   */</span>
  @Override
  public void <strong><span style="color: #333399;">hookException</span></strong>() throws MyException {
    <span style="color: #888888;">// Blank</span>
  }
<span style="color: #888888;">  /**
   * Method handles GWT RPC call and on failure it digests the error,
   * finds supported business exception and handles them gracefully.
   */</span>
  private String <strong><span style="color: #333399;">handleProcessCall</span></strong>(Object target, RPCRequest rpcRequest)
      throws SerializationException {

    Method serviceMethod = rpcRequest.getMethod();
    Object[] params = rpcRequest.getParameters();
    SerializationPolicy serializationPolicy = rpcRequest
        .getSerializationPolicy();
    try {
      return RPC.invokeAndEncodeResponse(target, serviceMethod, params,
          serializationPolicy);
    } catch (UnexpectedException ex) {
      Throwable cause = ex.getCause();
      <span style="color: #888888;">// This could be a list of supported types ..etc..
      // Leaving it up to your imagination</span>
<strong><span style="color: #ff0000;">      if (cause.getClass().equals(MyException.class)) {
        throw new MyException();
      }</span></strong>
      return encodeResponse(cause.getClass(), cause, true,
          serializationPolicy);
    }
  }

<span style="color: #888888;">  /**
   * This method recursively iterates through given 'masterError'
   * finding any supported failures and handling the latter
   * appropriately.
   */</span>
  private void <strong><span style="color: #333399;">discoverAndWriteError</span></strong>(Throwable masterError, Throwable e) {
    if (e == null) {
      writeError(new UnexpectedException(masterError.getMessage(),
          masterError));
      return;
    }

    Throwable cause = e.getCause();
    if (cause == null) {
      writeError(new UnexpectedException(masterError.getMessage(),
          masterError));
      return;
    }
    <span style="color: #888888;">// This could be a list of supported types, etc..
    // Leaving it up to your imagination</span>
    <strong><span style="color: #ff0000;">if (cause.getClass().equals(MyException.class)) {
      writeError((MyException)cause);
      return;
    }</span></strong> else {
      <span style="color: #888888;">// continue with 'recursion' cause discovery</span>
      discoverAndWriteError(masterError, cause);
    }
  }

<span style="color: #888888;">  /**
   * This method writes known business exception the response HTTP packet
   * Code borrowed from com.google.gwt.user.server.rpc.RPCServletUtils
   */</span>
  private void <strong><span style="color: #333399;">writeError</span></strong>(Throwable cause) {
    <span style="color: #808080;">// Send SC_OK/200 status, serialize the gwt error, flush it to response,
    // and let the client deal with the business error</span>
    HttpServletResponse resp = getThreadLocalResponse();
    try {
      resp.setContentType("text/plain");
      resp.setStatus(HttpServletResponse.SC_OK);
      String excMsg = RPC.encodeResponseForFailure(null, cause);
      resp.getWriter().write(excMsg);

    } catch (IOException e) {
      log("Failed to send failure to client", e);

    } catch (SerializationException e) {
      log("Failed to send failure to client", e);
    }
  }

<span style="color: #888888;">  /**
   * Borrowed from RPC.java. Returns a string that encodes the results of an
   * RPC call. Private overload that takes a flag signaling the preamble of
   * the response payload.
   */</span>
  private static String <strong><span style="color: #333399;">encodeResponse</span></strong>(Class responseClass, Object object,
      boolean wasThrown, SerializationPolicy serializationPolicy)
      throws SerializationException {

    ServerSerializationStreamWriter stream = new
              ServerSerializationStreamWriter(serializationPolicy);
    stream.prepareToWrite();
    if (responseClass != void.class) {
      stream.serializeValue(object, responseClass);
    }
    String bufferStr = (wasThrown ? "//EX" : "//OK") + stream.toString();
    return bufferStr;
  }
}
</span></pre>
<p>With the new RemoteService classes being created above, our GWT Services will derive from them as bellow:</p>
<pre style="background: none repeat scroll 0% 0% #ececda;"><span style="color: #993300;">
@RemoteServiceRelativePath("greet")
interface GreetingService extends AbstractRemoteService {
  <span style="color: #888888;">/* Notice, no exception is being declared*/</span>
  String greetServer(String name);
}

interface GreetingServiceAsync extends AbstractRemoteServiceAsync {
  <span style="color: #888888;">/* Notice, no exception is being declared*/</span>
  void greetServer(String input, AsyncCallback callback);
}

class GreetingServiceImpl extends AbstractRemoteServiceServlet implements
    GreetingService {
  <span style="color: #888888;">/* Notice, no exception is being declared*/</span>
  public String greetServer(String input) {
    {
      throw <strong><span style="color: #ff0000;">new MyException</span></strong>();
    }
  }
}
</span></pre>
<p>The last piece of course is executing the service and see it in real browser:</p>
<p><a href="http://www.roussev.org/blog/wp-content/uploads/2010/02/GWT-dynamic-exception-handling.png"><img class="alignnone size-full wp-image-661" title="GWT-dynamic-exception-handling" src="http://www.roussev.org/blog/wp-content/uploads/2010/02/GWT-dynamic-exception-handling.png" alt="" width="480" height="430" /></a></p>
<p>Feel free to explore <a title="GWT Exception Handling at Google Code" href="https://code.google.com/p/gwt-dynamic-exception-nadling/" target="_blank">project sources at Google Code</a>.</p>
<p>Something else not directly related to this post. You may have noticed, GWT RPC exceptions are being transmitted to browser as a JSON HTTP packet of 200 OK response with //EX[org.roussev.MyException|1|23|4|5] signature.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.roussev.org/2010/02/gwt-dynamic-exception-handling/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>GWT Exception Handling Limitations</title>
		<link>http://www.roussev.org/2010/02/gwt-exception-handling-limitations/</link>
		<comments>http://www.roussev.org/2010/02/gwt-exception-handling-limitations/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 06:23:20 +0000</pubDate>
		<dc:creator>atanas</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.roussev.org/?p=594</guid>
		<description><![CDATA[While developing GWT Remote Procedure Calls(RPC), many of you have experienced the limitations of the default GWT exception handling model. I will demonstrate this with a sample application. If you create the default GWT hello world application you will notice three RPC service classes being created for you:

interface GreetingServiceAsync {
   void greetServer(String input, AsyncCallback&#60;String&#62; callback)
 [...]]]></description>
			<content:encoded><![CDATA[<p>While developing GWT Remote Procedure Calls(RPC), many of you have experienced the limitations of the default GWT exception handling model. I will demonstrate this with a sample application. If you<a title="GWT Hello World" href="http://code.google.com/webtoolkit/gettingstarted.html#creating" target="_blank"> create the default GWT hello world application</a> you will notice three RPC service classes being created for you:</p>
<pre style="background: none repeat scroll 0% 0% #ececda;"><span style="color: #993300;">
interface <strong>GreetingServiceAsync </strong>{
   void <strong>greetServer</strong>(String input, AsyncCallback&lt;String&gt; callback)
          throws <strong><span style="color: #ff0000;">IllegalArgumentException</span></strong>;
}

@RemoteServiceRelativePath("greet")
interface <strong>GreetingService </strong>extends RemoteService {
   String <strong>greetServer</strong>(String name) throws <strong><span style="color: #ff0000;">IllegalArgumentException</span></strong>;
}

class <strong>GreetingServiceImpl </strong>extends RemoteServiceServlet
                 implements GreetingService {
   public String <strong>greetServer</strong>(String input) throws <strong><span style="color: #ff0000;">IllegalArgumentException </span></strong>{
      { // let's just throw an error for demonstration
         throw new <strong><span style="color: #ff0000;">IllegalArgumentException </span></strong>("Bad arguments passed");
      }
   }
}
</span></pre>
<p>So, the error handling works this way. GreetingServiceImpl captures an error and throws a runtime failure, in our case IllegalArgumentException. So far so good. But, what if we need to throw a different error. Let&#8217;s say MyIllegalArgumentException? Well by design (GWT design), we need to declare it on each three RPC methods:</p>
<pre style="background: none repeat scroll 0% 0% #ececda;"><span style="color: #993300;">
interface GreetingServiceAsync {
   void greetServer(String input, AsyncCallback&lt;String&gt; callback)
            throws <strong><span style="color: #ff0000;">MyIllegalArgumentException</span></strong>;
}

@RemoteServiceRelativePath("greet")
interface GreetingService extends RemoteService {
   String greetServer(String name) throws <strong><span style="color: #ff0000;">MyIllegalArgumentException</span></strong>;
}

class GreetingServiceImpl extends RemoteServiceServlet
                 implements GreetingService {
   public String greetServer(String input) throws <strong><span style="color: #ff0000;">MyIllegalArgumentException</span></strong>{
      { // let's just throw an error for demonstration
         throw new <strong><span style="color: #ff0000;">MyIllegalArgumentException</span></strong>("Bad arguments passed");
      }
   }
}
</span></pre>
<p>Which is not fun. It&#8217;s quite cumbersome. You need to declare the exception on each RPC method in 3 places &#8211; the Service, ServiceAsync and ServiceImp classes. To make the matter even worse as long as you have multiple methods and variety of exception types you end up into the &#8220;exception over-declaring hell&#8221; with methods looking this way <strong>myMethod() throws Exception1, Exception2, Exception3, Exception4</strong> (and don&#8217;t forget, you need to declare this in three places &#8211; 3 RPC classes).</p>
<p>Being curious (and lazy) you may wonder what will happen if:</p>
<div>A. We simply skip declaring the errors from the method signature:</div>
<pre style="background: none repeat scroll 0% 0% #ececda;"><span style="color: #993300;">/* no exception being declared*/
greetServer(String input, AsyncCallback&lt;String&gt; callback)
</span></pre>
<div>B. Or derive and throw a business failure from the declared Exception. We create a derived exception from IllegalArgumentException and the method throws the child error, while the method signature has the parent one:</div>
<pre style="background: none repeat scroll 0% 0% #ececda;"><span style="color: #993300;">
class <strong><span style="color: #ff0000;">AnotherBusinessException </span></strong>extends <strong><span style="color: #ff0000;">IllegalArgumentException </span></strong>{
   ..
}
class GreetingServiceImpl extends RemoteServiceServlet
                 implements GreetingService {
   public String greetServer(String input) throws <strong><span style="color: #ff0000;">IllegalArgumentException</span></strong>{
      { // let's just throw an error for demonstration
         throw new <strong><span style="color: #ff0000;">AnotherBusinessException</span></strong>("Bad arguments passed");
      }
   }
</span></pre>
<div>Testing those cases against GWT RPC results with:</div>
<div>
<ul>
<li>A.   <span style="color: #ff0000;">HTTP/1.1 500 Internal Error<br />
[WARN] Exception while dispatching incoming RPC call com.google.gwt.user.server.rpc.UnexpectedException: Service method &#8216;public abstract java.lang.String GreetingService.greetServer(java.lang.String)&#8217; threw an unexpected exception: java.lang.IllegalArgumentException..</span></li>
<li>B.    <span style="color: #ff0000;">HTTP/1.1 500 Internal Error<br />
[WARN] Exception while dispatching incoming RPC call com.google.gwt.user.client.rpc.SerializationException: Type &#8216;org.roussev.hello.client.AnotherBusinessException&#8217; was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized&#8230;</span></li>
</ul>
</div>
<div>Which is not very promising. GWT doesn&#8217;t like it and spit us with 500 Server Errors. In case A, GWT the exception type was not recognized defaulting to UnexpectedException. In case B. GWT kinda liked the type, but refused to load it for security purposes. Go figure..</p>
<p>All said, GWT exception handling forces us to declare all those business errors as part of the method signatures in all three RPC classes. And this is a tedious, error prone and repetitive process. Instead we (the lazy developers) are looking for more dynamic approach. We are looking for an approach where:</p>
<ol>
<li>An RPC Service method should not have to declare any runtime business failures.</li>
<li>The server should handle the runtime business failures gracefully with <strong>200 OK</strong>, instead of <strong>500 Error </strong></li>
<li>And lastly, UI should receive the exact error type (not some gwt StatusCodeException or an UnexpectedException) directly into the consuming callback <strong>void onFailure(Throwable e)</strong>.</li>
</ol>
</div>
<div>Next post is <a title="GWT Dynamic Exception Handling" href="http://www.roussev.org/2010/02/gwt-exception-handling-limitations/">GWT Dynamic Exception Handling</a> overcoming GWT exception limitations.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.roussev.org/2010/02/gwt-exception-handling-limitations/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Tampering GWT RPC packets</title>
		<link>http://www.roussev.org/2009/07/tampering-intercepting-gwt-rpc-http-packets/</link>
		<comments>http://www.roussev.org/2009/07/tampering-intercepting-gwt-rpc-http-packets/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 22:08:49 +0000</pubDate>
		<dc:creator>atanas</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[REST Client]]></category>
		<category><![CDATA[gwt http tampering packets eclipse tomcat]]></category>
		<category><![CDATA[http client]]></category>

		<guid isPermaLink="false">http://www.roussev.org/?p=315</guid>
		<description><![CDATA[The purpose of this post is to demonstrate interecepting GWT RPC native calls. This would help GWT developers better understand the low level packet communications, as well as help with debugging and and tampering the requests.
The post is based on the GWT 1.6 StockWatcher example. Tools used are:

Fiddler (a web debugging proxy)
HTTP4E (Eclipse HTTP RESTful client)

Assuming you successfully [...]]]></description>
			<content:encoded><![CDATA[<p>The purpose of this post is to demonstrate interecepting GWT RPC native calls. This would help GWT developers better understand the low level packet communications, as well as help with debugging and and tampering the requests.</p>
<p>The post is based on the GWT 1.6 <a title="GWT example" href="http://code.google.com/webtoolkit/tutorials/1.6/create.html" target="_blank">StockWatcher</a> example. Tools used are:</p>
<ul>
<li><a title="Web Debugging Proxy" href="http://www.fiddler2.com/" target="_blank">Fiddler</a> (a web debugging proxy)</li>
<li><a title="Eclipse HTTP RESTful client" href="http://code.google.com/p/http4e/" target="_blank">HTTP4E</a> (Eclipse HTTP RESTful client)</li>
</ul>
<p>Assuming you successfully downloaded and installed the <a title="GWT example" href="http://code.google.com/webtoolkit/tutorials/1.6/create.html" target="_blank">Google StockWatcher example</a> and set the project into your Eclipse IDE, run the given StockWatcher.launch task.</p>
<p><a rel="facebox" href="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets.png"> <img class="alignnone size-full wp-image-323" title="gwt-rpc-intercepting-http-packets" src="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets.png" alt="gwt-rpc-intercepting-http-packets" width="434" height="281" /></a></p>
<p>And the regular hosted mode shows up.</p>
<p><a rel="facebox" href="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets3.png"> <img class="alignnone size-full wp-image-329" title="gwt-rpc-intercepting-http-packets3" src="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets3.png" alt="gwt-rpc-intercepting-http-packets3" width="389" height="324" /></a></p>
<p>Clicking SEND makes an AJAX call with a response popup being returned back.</p>
<p><a rel="facebox" href="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets2.png"> <img class="alignnone size-full wp-image-327" title="gwt-rpc-intercepting-http-packets2" src="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets2.png" alt="gwt-rpc-intercepting-http-packets2" width="445" height="370" /></a></p>
<p>So the question is, what kind of call is that GWT &#8220;Remote Procedure Call&#8221;? A regular XMLHttpRequest call, JSON, XML, binary? To anylize it, we need to intercept the http packets. So, let&#8217;s compile the project using the project ANT build.xml task and a fully compiled web project shows up</p>
<pre>/StockWatcher
     /war
          __html's and css's__
          /stockwatcher
                 __compiled JavaScripts's__
          /WEB-INF
                 __servlets, libs, classes, etc..__</pre>
<p>Deploy the web project to your favourite WEB container. I am lazy and I simply moved the /StockWatcher/war directory to /tomcat/webapps. Alternatively I could have created a WAR, etc.. That&#8217;s not important, the point is you need to have the StockWatcher example running on a web server. To test the app, open a web browser and run the URL <a href="http://localhost:8080/gwt/">http://localhost:8080/&lt;the-name-you-gave-for-this-webapp&gt;/</a></p>
<p>You should see the page bellow:</p>
<p><a rel="facebox" href="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets31.png"><img class="alignnone size-full wp-image-333" title="gwt-rpc-intercepting-http-packets31" src="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets31.png" alt="gwt-rpc-intercepting-http-packets31" width="405" height="327" /></a></p>
<p>So far so good. What we want to accomplish is once again, intercept and tamper that native GWT Remote Procedure Call.</p>
<h2>Intercepting GWT RPC call</h2>
<p>Open Fiddler and attach it to your browser. Run the application again from your browser and Fiddler should list the GET HTTP calls being transmitted to server:</p>
<p><a rel="facebox" href="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets21.png"><br />
<img class="alignnone size-full wp-image-338" title="gwt-rpc-intercepting-http-packets21" src="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets21.png" alt="gwt-rpc-intercepting-http-packets21" width="458" height="244" /></a></p>
<p>Click the [Send] button again and observe the HTTP call in Fiddler.</p>
<p><a rel="facebox" href="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets4.png"> <img class="alignnone size-full wp-image-340" title="gwt-rpc-intercepting-http-packets4" src="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets4.png" alt="gwt-rpc-intercepting-http-packets4" width="665" height="383" /></a></p>
<p>Having the RPC call in Fiddler, we want to dissect it, so let&#8217;s switch to HTTP4E, so we can replay it. Copy all the headers from Fiddler to Http4e/Headers Editor. Same for the packet body, copy it to Http4e/Body editor. Hit Run.</p>
<p>And Voila. Running the call from Eclipse HTTP client produced exactly the same response we received while intercepting it with Fiddler.</p>
<p><a rel="facebox" href="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets5.png"> <img class="alignnone size-full wp-image-342" title="gwt-rpc-intercepting-http-packets5" src="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets5.png" alt="gwt-rpc-intercepting-http-packets5" width="691" height="364" /></a></p>
<p>Few things to notice here:</p>
<ul>
<li>The response received is gibberish as it is gzipped.</li>
<li>There are tons of headers being transmitted, but are they really needed?</li>
<li>The content-type being send is: <span style="font-family: 'Courier New'; line-height: 18px; font-size: 12px; white-space: pre; "><strong>Content-Type: text/x-</strong><strong>gwt</strong><strong>-</strong><strong>rpc</strong><strong>; </strong><strong>charset</strong><strong>=</strong><strong>utf-8</strong></span>, And this is the most important GWT header. Without it GWT Servlet is not happy and errors out.</li>
<li>Did you notice the Accept-Encoding: gzip. header? Yes, that&#8217;s the one that tells the server we are cool with gzip and GWT server gets back with gzip payload. Removing it stripes out the GWT to a bare regular text</li>
</ul>
<h2>Tampering GWT RPC call</h2>
<p>Let&#8217;s cut the weed headers and leave just the required <strong>content-type</strong>. What we are aiming is making a successful tampered GWT RPC call.</p>
<p><a rel="facebox" href="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets6.png"> <img class="alignnone size-full wp-image-345" title="gwt-rpc-intercepting-http-packets6" src="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets6.png" alt="gwt-rpc-intercepting-http-packets6" width="691" height="364" /></a></p>
<p>Eureka! The call returned <strong>200 Success</strong> along with the unzipped RPC content. What&#8217;s interesting is that the native RPC response format is actually &#8230; drum rolls&#8230; JSON !!</p>
<p>There is the //OK or //EX prefix to indicate that response was Success //OK, or Error //EX. Other than that, it&#8217;s a well formatted JSON.</p>
<p><a rel="facebox" href="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets8.png"><br />
<img class="size-full wp-image-348 alignnone" title="gwt-rpc-intercepting-http-packets8" src="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets8.png" alt="gwt-rpc-intercepting-http-packets8" width="368" height="146" /></a></p>
<p>What we want to do next is,  tamperig the request and pretend we are a JavaScript native GWT client. The idea is to proove that we can fool the native RPC Servlet. So, modify the RPC argument String &#8220;GWT User&#8221; to &#8220;TAMPERED-REQUEST&#8221; and run it again.</p>
<p>RPC responds with <strong>200 //OK !</strong></p>
<p><a rel="facebox" href="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets7.png"> <img class="alignnone size-full wp-image-347" title="gwt-rpc-intercepting-http-packets7" src="http://www.roussev.org/blog/wp-content/uploads/2009/07/gwt-rpc-intercepting-http-packets7.png" alt="gwt-rpc-intercepting-http-packets7" width="691" height="364" /></a></p>
<p>And that&#8217;s all folks. For you, I leave the exercise of:</p>
<ul>
<li>exporting the HTTP call to Java (HTTP4E/Export-to-Java)</li>
<li>make an infinite loop</li>
<li>and use that expertise when bringing your favourite russian server down with DoS attack <img src='http://www.roussev.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </li>
</ul>
<p>Cheers</p>
]]></content:encoded>
			<wfw:commentRss>http://www.roussev.org/2009/07/tampering-intercepting-gwt-rpc-http-packets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
