com.vaadin.terminal.gwt.server
Class AbstractCommunicationManager

java.lang.Object
  extended by com.vaadin.terminal.gwt.server.AbstractCommunicationManager
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
CommunicationManager, PortletCommunicationManager

public abstract class AbstractCommunicationManager
extends Object
implements Serializable

This is a common base class for the server-side implementations of the communication system between the client code (compiled with GWT into JavaScript) and the server side components. Its client side counterpart is ApplicationConnection. TODO Document better!

See Also:
Serialized Form

Nested Class Summary
static interface AbstractCommunicationManager.Callback
          TODO Document me!
 class AbstractCommunicationManager.ErrorHandlerErrorEvent
           
protected  class AbstractCommunicationManager.InvalidUIDLSecurityKeyException
           
static class AbstractCommunicationManager.SimpleMultiPartInputStream
          Stream that extracts content from another stream until the boundary string is encountered.
 
Field Summary
static char VAR_BURST_SEPARATOR
           
static char VAR_ESCAPE_CHARACTER
           
 
Constructor Summary
AbstractCommunicationManager(Application application)
          TODO New constructor - document me!
 
Method Summary
protected  void changeVariables(Object source, VariableOwner owner, Map<String,Object> m)
           
protected abstract  void cleanStreamVariable(ClientConnector owner, String name)
           
protected  void closeJsonMessage(PrintWriter outWriter)
           
protected abstract  BootstrapHandler createBootstrapHandler()
           
protected  void doHandleSimpleMultipartFileUpload(WrappedRequest request, WrappedResponse response, StreamVariable streamVariable, String variableName, ClientConnector owner, String boundary)
          Method used to stream content from a multipart request (either from servlet or portlet request) to given StreamVariable
protected  void doHandleXhrFilePost(WrappedRequest request, WrappedResponse response, StreamVariable streamVariable, String variableName, ClientConnector owner, int contentLength)
          Used to stream plain file post (aka XHR2.post(File))
protected  Application getApplication()
           
protected  ClientConnector getConnector(Root root, String connectorId)
           
protected  String getInitialUIDL(WrappedRequest request, Root root)
          Generates the initial UIDL message that can e.g.
protected  String getRequestPayload(WrappedRequest request)
          Reads the request data from the Request and returns it converted to an UTF-8 string.
protected  String getSecurityKey(WrappedRequest request)
          Gets the security key (and generates one if needed).
 String getSecurityKeyUIDL(WrappedRequest request)
          Gets the security key (and generates one if needed) as UIDL.
protected abstract  InputStream getThemeResourceAsStream(Root root, String themeName, String resource)
           
protected  boolean handleApplicationRequest(WrappedRequest request, WrappedResponse response)
           
 void handleBrowserDetailsRequest(WrappedRequest request, WrappedResponse response, Application application)
           
 boolean handleBurst(WrappedRequest source, Root root, String burst)
          Processes a message burst received from the client.
 void handleUidlRequest(WrappedRequest request, WrappedResponse response, AbstractCommunicationManager.Callback callback, Root root)
          Internally process a UIDL request from the client.
protected  void highlightConnector(Connector highlightedConnector)
           
 boolean isXSRFEnabled(Application application)
          Returns false if the cross site request forgery protection is turned off.
protected  void openJsonMessage(PrintWriter outWriter, WrappedResponse response)
          Writes the opening of JSON message to be sent to client.
protected  void postPaint(Root root)
          Method called after the paint phase while still being synchronized on the application
protected  void printHighlightedComponentHierarchy(StringBuilder sb, AbstractComponent component)
           
 void requireLocale(String value)
          Queues a locale to be sent to the client (browser) for date and time entry etc.
protected  void sendUploadResponse(WrappedRequest request, WrappedResponse response)
          TODO document
 void serveConnectorResource(String resourceName, WrappedRequest request, WrappedResponse response, String mimetype)
          Serve a connector resource from the classpath if the resource has previously been registered by calling registerResource(String, Class).
protected  boolean streamToReceiver(InputStream in, StreamVariable streamVariable, String filename, String type, int contentLength)
           
protected  String unescapeBurst(String encodedValue)
          Unescape encoded burst separator characters in a burst received from the client.
 void writeUidlResponse(WrappedRequest request, boolean repaintAll, PrintWriter outWriter, Root root, boolean analyzeLayouts)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VAR_BURST_SEPARATOR

public static final char VAR_BURST_SEPARATOR
See Also:
Constant Field Values

VAR_ESCAPE_CHARACTER

public static final char VAR_ESCAPE_CHARACTER
See Also:
Constant Field Values
Constructor Detail

AbstractCommunicationManager

public AbstractCommunicationManager(Application application)
TODO New constructor - document me!

Parameters:
application -
Method Detail

getApplication

protected Application getApplication()

doHandleSimpleMultipartFileUpload

protected void doHandleSimpleMultipartFileUpload(WrappedRequest request,
                                                 WrappedResponse response,
                                                 StreamVariable streamVariable,
                                                 String variableName,
                                                 ClientConnector owner,
                                                 String boundary)
                                          throws IOException
Method used to stream content from a multipart request (either from servlet or portlet request) to given StreamVariable

Parameters:
request -
response -
streamVariable -
owner -
boundary -
Throws:
IOException

doHandleXhrFilePost

protected void doHandleXhrFilePost(WrappedRequest request,
                                   WrappedResponse response,
                                   StreamVariable streamVariable,
                                   String variableName,
                                   ClientConnector owner,
                                   int contentLength)
                            throws IOException
Used to stream plain file post (aka XHR2.post(File))

Parameters:
request -
response -
streamVariable -
owner -
contentLength -
Throws:
IOException

streamToReceiver

protected final boolean streamToReceiver(InputStream in,
                                         StreamVariable streamVariable,
                                         String filename,
                                         String type,
                                         int contentLength)
                                  throws UploadException
Parameters:
in -
streamVariable -
filename -
type -
contentLength -
Returns:
true if the streamvariable has informed that the terminal can forget this variable
Throws:
UploadException

sendUploadResponse

protected void sendUploadResponse(WrappedRequest request,
                                  WrappedResponse response)
                           throws IOException
TODO document

Parameters:
request -
response -
Throws:
IOException

handleUidlRequest

public void handleUidlRequest(WrappedRequest request,
                              WrappedResponse response,
                              AbstractCommunicationManager.Callback callback,
                              Root root)
                       throws IOException,
                              AbstractCommunicationManager.InvalidUIDLSecurityKeyException,
                              JSONException
Internally process a UIDL request from the client. This method calls handleVariables(WrappedRequest, WrappedResponse, Callback, Application, Root) to process any changes to variables by the client and then repaints affected components using #paintAfterVariableChanges(). Also, some cleanup is done when a request arrives for an application that has already been closed. The method handleUidlRequest(...) in subclasses should call this method. TODO better documentation

Parameters:
request -
response -
callback -
root - target window for the UIDL request, can be null if target not found
Throws:
IOException
AbstractCommunicationManager.InvalidUIDLSecurityKeyException
JSONException

postPaint

protected void postPaint(Root root)
Method called after the paint phase while still being synchronized on the application

Parameters:
root -

highlightConnector

protected void highlightConnector(Connector highlightedConnector)

printHighlightedComponentHierarchy

protected void printHighlightedComponentHierarchy(StringBuilder sb,
                                                  AbstractComponent component)

getSecurityKeyUIDL

public String getSecurityKeyUIDL(WrappedRequest request)
Gets the security key (and generates one if needed) as UIDL.

Parameters:
request -
Returns:
the security key UIDL or "" if the feature is turned off

getSecurityKey

protected String getSecurityKey(WrappedRequest request)
Gets the security key (and generates one if needed).

Parameters:
request -
Returns:
the security key

writeUidlResponse

public void writeUidlResponse(WrappedRequest request,
                              boolean repaintAll,
                              PrintWriter outWriter,
                              Root root,
                              boolean analyzeLayouts)
                       throws PaintException,
                              JSONException
Throws:
PaintException
JSONException

getThemeResourceAsStream

protected abstract InputStream getThemeResourceAsStream(Root root,
                                                        String themeName,
                                                        String resource)

isXSRFEnabled

public boolean isXSRFEnabled(Application application)
Returns false if the cross site request forgery protection is turned off.

Parameters:
application -
Returns:
false if the XSRF is turned off, true otherwise

handleBurst

public boolean handleBurst(WrappedRequest source,
                           Root root,
                           String burst)
Processes a message burst received from the client. A burst can contain any number of RPC calls, including legacy variable change calls that are processed separately. Consecutive changes to the value of the same variable are combined and changeVariables() is only called once for them. This preserves the Vaadin 6 semantics for components and add-ons that do not use Vaadin 7 RPC directly.

Parameters:
source -
root - the root receiving the burst
burst - the content of the burst as a String to be parsed
Returns:
true if the processing of the burst was successful and there were no messages to non-existent components

changeVariables

protected void changeVariables(Object source,
                               VariableOwner owner,
                               Map<String,Object> m)

getConnector

protected ClientConnector getConnector(Root root,
                                       String connectorId)

getRequestPayload

protected String getRequestPayload(WrappedRequest request)
                            throws IOException
Reads the request data from the Request and returns it converted to an UTF-8 string.

Parameters:
request -
Returns:
Throws:
IOException

unescapeBurst

protected String unescapeBurst(String encodedValue)
Unescape encoded burst separator characters in a burst received from the client. This protects from separator injection attacks.

Parameters:
encodedValue - to decode
Returns:
decoded value

closeJsonMessage

protected void closeJsonMessage(PrintWriter outWriter)

openJsonMessage

protected void openJsonMessage(PrintWriter outWriter,
                               WrappedResponse response)
Writes the opening of JSON message to be sent to client.

Parameters:
outWriter -
response -

requireLocale

public void requireLocale(String value)
Queues a locale to be sent to the client (browser) for date and time entry etc. All locale specific information is derived from server-side Locale instances and sent to the client when needed, eliminating the need to use the Locale class and all the framework behind it on the client.

Parameters:
value -
See Also:
Locale.toString()

cleanStreamVariable

protected abstract void cleanStreamVariable(ClientConnector owner,
                                            String name)

createBootstrapHandler

protected abstract BootstrapHandler createBootstrapHandler()

handleApplicationRequest

protected boolean handleApplicationRequest(WrappedRequest request,
                                           WrappedResponse response)
                                    throws IOException
Throws:
IOException

handleBrowserDetailsRequest

public void handleBrowserDetailsRequest(WrappedRequest request,
                                        WrappedResponse response,
                                        Application application)
                                 throws IOException
Throws:
IOException

getInitialUIDL

protected String getInitialUIDL(WrappedRequest request,
                                Root root)
                         throws PaintException,
                                JSONException
Generates the initial UIDL message that can e.g. be included in a html page to avoid a separate round trip just for getting the UIDL.

Parameters:
request - the request that caused the initialization
root - the root for which the UIDL should be generated
Returns:
a string with the initial UIDL message
Throws:
PaintException - if an exception occurs while painting
JSONException - if an exception occurs while encoding output

serveConnectorResource

public void serveConnectorResource(String resourceName,
                                   WrappedRequest request,
                                   WrappedResponse response,
                                   String mimetype)
                            throws IOException
Serve a connector resource from the classpath if the resource has previously been registered by calling registerResource(String, Class). Sending arbitrary files from the classpath is prevented by only accepting resource names that have explicitly been registered. Resources can currently only be registered by including a JavaScript or StyleSheet annotation on a Connector class.

Parameters:
resourceName -
request -
response -
mimetype -
Throws:
IOException


Copyright © 2000-2011 Vaadin Ltd. All Rights Reserved.