Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 404546
Collapse All | Expand All

(-)a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/Display.js (+8 lines)
Lines 44-49 Link Here
44
44
45
  init : function() {
45
  init : function() {
46
    this._server.getMessageWriter().appendHead( "rwt_initialize", true );
46
    this._server.getMessageWriter().appendHead( "rwt_initialize", true );
47
    this._appendQueryString();
47
    this._appendWindowSize();
48
    this._appendWindowSize();
48
    this._appendSystemDPI();
49
    this._appendSystemDPI();
49
    this._appendColorDepth();
50
    this._appendColorDepth();
Lines 211-216 Link Here
211
    var clientObject = rwt.remote.ObjectRegistry.getObject( "rwt.client.ClientInfo" );
212
    var clientObject = rwt.remote.ObjectRegistry.getObject( "rwt.client.ClientInfo" );
212
    var remoteObject = rwt.remote.Server.getInstance().getRemoteObject( clientObject );
213
    var remoteObject = rwt.remote.Server.getInstance().getRemoteObject( clientObject );
213
    remoteObject.set( "timezoneOffset", clientObject.getTimezoneOffset() );
214
    remoteObject.set( "timezoneOffset", clientObject.getTimezoneOffset() );
215
  },
216
217
  _appendQueryString : function() {
218
    var queryString = window.location.search;
219
    if( queryString !== "" ) {
220
      this._server.getMessageWriter().appendHead( "queryString", queryString.substr( 1 ) );
221
    }
214
  }
222
  }
215
223
216
};
224
};
(-)a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/service/LifeCycleServiceHandler.java (-8 / +1 lines)
Lines 13-19 Link Here
13
13
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.text.MessageFormat;
15
import java.text.MessageFormat;
16
import java.util.Map;
17
16
18
import javax.servlet.ServletRequest;
17
import javax.servlet.ServletRequest;
19
import javax.servlet.ServletResponse;
18
import javax.servlet.ServletResponse;
Lines 81-88 Link Here
81
  private void handleGetRequest( ServletRequest request, HttpServletResponse response )
80
  private void handleGetRequest( ServletRequest request, HttpServletResponse response )
82
    throws IOException
81
    throws IOException
83
  {
82
  {
84
    Map<String, String[]> parameters = request.getParameterMap();
85
    RequestParameterBuffer.store( parameters );
86
    if( RWT.getClient() instanceof WebClient ) {
83
    if( RWT.getClient() instanceof WebClient ) {
87
      startupPage.send( response );
84
      startupPage.send( response );
88
    } else {
85
    } else {
Lines 105-111 Link Here
105
        reinitializeUISession( request );
102
        reinitializeUISession( request );
106
        reinitializeServiceStore();
103
        reinitializeServiceStore();
107
      }
104
      }
108
      RequestParameterBuffer.merge();
105
      UrlParameters.merge();
109
      runLifeCycle();
106
      runLifeCycle();
110
    }
107
    }
111
    writeProtocolMessage( response );
108
    writeProtocolMessage( response );
Lines 167-181 Link Here
167
164
168
  private static void reinitializeUISession( HttpServletRequest request ) {
165
  private static void reinitializeUISession( HttpServletRequest request ) {
169
    UISessionImpl uiSession = ( UISessionImpl )ContextProvider.getUISession();
166
    UISessionImpl uiSession = ( UISessionImpl )ContextProvider.getUISession();
170
    Map<String, String[]> bufferedParameters = RequestParameterBuffer.getBufferedParameters();
171
    ApplicationContextImpl applicationContext = uiSession.getApplicationContext();
167
    ApplicationContextImpl applicationContext = uiSession.getApplicationContext();
172
    uiSession.shutdown();
168
    uiSession.shutdown();
173
    UISessionBuilder builder = new UISessionBuilder( applicationContext, request );
169
    UISessionBuilder builder = new UISessionBuilder( applicationContext, request );
174
    uiSession = builder.buildUISession();
170
    uiSession = builder.buildUISession();
175
    ContextProvider.getContext().setUISession( uiSession );
171
    ContextProvider.getContext().setUISession( uiSession );
176
    if( bufferedParameters != null ) {
177
      RequestParameterBuffer.store( bufferedParameters );
178
    }
179
  }
172
  }
180
173
181
  private static void reinitializeServiceStore() {
174
  private static void reinitializeServiceStore() {
(-)a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/service/RequestParameterBuffer.java (-79 lines)
Lines 1-79 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002, 2012 Innoopract Informationssysteme GmbH and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Innoopract Informationssysteme GmbH - initial API and implementation
10
 *    EclipseSource - ongoing development
11
 ******************************************************************************/
12
package org.eclipse.rap.rwt.internal.service;
13
14
import java.util.HashMap;
15
import java.util.Map;
16
17
import javax.servlet.http.HttpServletRequest;
18
19
import org.eclipse.rap.rwt.service.UISession;
20
21
22
/**
23
 * This class serves as a session-wide buffer to store and later on merge the
24
 * once stored request parameters with those of the current request.
25
 */
26
final class RequestParameterBuffer {
27
28
  private static final String BUFFER = RequestParameterBuffer.class.getName() + "#buffer:-)";
29
30
  /**
31
   * Buffers the given <code>parameters</code> within the session for later use
32
   * with <code>merge</code>. If the session has already parameters stored, the
33
   * method returns immediately.
34
   */
35
  static void store( Map<String, String[]> parameters ) {
36
    // [rst] The following if statement is a fix for bug 265008, but later lead to bug 369549,
37
    //       commented since according to bug 265008, the fix is not needed anymore.
38
    // [if] Store parameters only once.
39
    //      Workaround for bug 265008
40
    // if( getBufferedParameters() == null ) {
41
    HashMap<String, String[]> buffer = new HashMap<String, String[]>( parameters );
42
    UISession uiSession = ContextProvider.getUISession();
43
    uiSession.setAttribute( BUFFER, buffer );
44
    // }
45
  }
46
47
  /**
48
   * Merges previously <code>store</code>d request parameters with those of the
49
   * current request. Parameters of the current request take precedence over the
50
   * stored parameters.
51
   * <p>
52
   * If there are no stored parameters, this method does nothing.
53
   * </p>
54
   * <p>
55
   * After this method has completed, the buffered request parameters are
56
   * discarded.
57
   * </p>
58
   */
59
  static void merge() {
60
    Map<String, String[]> bufferedParams = getBufferedParameters();
61
    if( bufferedParams != null ) {
62
      HttpServletRequest request = ContextProvider.getRequest();
63
      WrappedRequest wrappedRequest = new WrappedRequest( request, bufferedParams );
64
      ServiceContext context = ContextProvider.getContext();
65
      context.setRequest( wrappedRequest );
66
    }
67
    ContextProvider.getUISession().removeAttribute( BUFFER );
68
  }
69
70
  @SuppressWarnings("unchecked")
71
  static Map<String, String[]> getBufferedParameters() {
72
    return ( Map<String, String[]> )ContextProvider.getUISession().getAttribute( BUFFER );
73
  }
74
75
  private RequestParameterBuffer() {
76
    // prevent instantiation
77
  }
78
79
}
(-)a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/service/RequestParams.java (+1 lines)
Lines 15-20 Link Here
15
15
16
  public static final String RWT_INITIALIZE = "rwt_initialize";
16
  public static final String RWT_INITIALIZE = "rwt_initialize";
17
  public static final String RWT_SHUTDOWN = "rwt_shutdown";
17
  public static final String RWT_SHUTDOWN = "rwt_shutdown";
18
  public static final String QUERY_STRING = "queryString";
18
19
19
  private RequestParams() {
20
  private RequestParams() {
20
    // prevent instantiation
21
    // prevent instantiation
(-)a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/service/UrlParameters.java (+81 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 EclipseSource and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    EclipseSource - initial API and implementation
10
 ******************************************************************************/
11
package org.eclipse.rap.rwt.internal.service;
12
13
import static org.eclipse.rap.rwt.internal.protocol.ProtocolUtil.readHeadPropertyValue;
14
15
import java.io.UnsupportedEncodingException;
16
import java.net.URLDecoder;
17
import java.util.HashMap;
18
import java.util.Map;
19
20
import javax.servlet.http.HttpServletRequest;
21
22
import org.eclipse.rap.rwt.internal.util.HTTP;
23
24
25
final class UrlParameters {
26
27
  static void merge() {
28
    if( hasInitializeParameter() ) {
29
      Map<String, String[]> parameters = getAll();
30
      if( parameters != null ) {
31
        HttpServletRequest request = ContextProvider.getRequest();
32
        WrappedRequest wrappedRequest = new WrappedRequest( request, parameters );
33
        ServiceContext context = ContextProvider.getContext();
34
        context.setRequest( wrappedRequest );
35
      }
36
    }
37
  }
38
39
  private static Map<String, String[]> getAll() {
40
    String queryString = readHeadPropertyValue( RequestParams.QUERY_STRING );
41
    return queryString == null ? null : createParametersMap( queryString );
42
  }
43
44
  static Map<String, String[]> createParametersMap( String queryString ) {
45
    Map<String, String[]> result = new HashMap<String, String[]>();
46
    String[] parameters = queryString.split( "&" );
47
    for( String parameter : parameters ) {
48
      String[] parts = parameter.split( "=" );
49
      try {
50
        String name = URLDecoder.decode( parts[ 0 ], HTTP.CHARSET_UTF_8 );
51
        String value = parts.length == 1 ? "" : URLDecoder.decode( parts[ 1 ], HTTP.CHARSET_UTF_8 );
52
        String[] oldValues = result.get( name );
53
        result.put( name, appendValue( oldValues, value ) );
54
      } catch( UnsupportedEncodingException exception ) {
55
        // should never happens
56
      }
57
    }
58
    return result;
59
  }
60
61
  private static String[] appendValue( String[] oldValues, String newValue ) {
62
    String[] result = null;
63
    if( oldValues == null ) {
64
      result = new String[] { newValue };
65
    } else {
66
      result = new String[ oldValues.length + 1 ];
67
      System.arraycopy( oldValues, 0, result, 0, oldValues.length );
68
      result[ result.length - 1 ] = newValue;
69
    }
70
    return result;
71
  }
72
73
  private static boolean hasInitializeParameter() {
74
    return "true".equals( readHeadPropertyValue( RequestParams.RWT_INITIALIZE ) );
75
  }
76
77
  private UrlParameters() {
78
    // prevent instantiation
79
  }
80
81
}
(-)a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/rap/rwt/internal/service/LifeCycleServiceHandler_Test.java (-15 / +1 lines)
Lines 11-20 Link Here
11
 ******************************************************************************/
11
 ******************************************************************************/
12
package org.eclipse.rap.rwt.internal.service;
12
package org.eclipse.rap.rwt.internal.service;
13
13
14
import static junit.framework.Assert.assertNotSame;
15
import static org.eclipse.rap.rwt.internal.service.ContextProvider.getApplicationContext;
14
import static org.eclipse.rap.rwt.internal.service.ContextProvider.getApplicationContext;
16
import static org.junit.Assert.assertEquals;
15
import static org.junit.Assert.assertEquals;
17
import static org.junit.Assert.assertFalse;
16
import static org.junit.Assert.assertFalse;
17
import static org.junit.Assert.assertNotSame;
18
import static org.junit.Assert.assertNull;
18
import static org.junit.Assert.assertNull;
19
import static org.junit.Assert.assertSame;
19
import static org.junit.Assert.assertSame;
20
import static org.junit.Assert.assertTrue;
20
import static org.junit.Assert.assertTrue;
Lines 220-239 Link Here
220
220
221
    UISessionImpl uiSession = ( UISessionImpl )ContextProvider.getUISession();
221
    UISessionImpl uiSession = ( UISessionImpl )ContextProvider.getUISession();
222
    assertSame( applicationContext, uiSession.getApplicationContext() );
222
    assertSame( applicationContext, uiSession.getApplicationContext() );
223
  }
224
225
  @Test
226
  public void testRequestParametersAreBufferedAfterSessionRestart() throws IOException {
227
    initializeUISession();
228
    TestRequest request = Fixture.fakeNewGetRequest();
229
    request.setParameter( "foo", "bar" );
230
    service( new LifeCycleServiceHandler( getLifeCycleFactory(), mockStartupPage() ) );
231
232
    LifeCycleServiceHandler.markSessionStarted();
233
    simulateInitialUiRequest();
234
    service( new LifeCycleServiceHandler( getLifeCycleFactory(), mockStartupPage() ) );
235
236
    assertEquals( "bar", ContextProvider.getRequest().getParameter( "foo" ) );
237
  }
223
  }
238
224
239
  /*
225
  /*
(-)a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/rap/rwt/internal/service/RequestParameterBuffer_Test.java (-103 lines)
Lines 1-103 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2012 EclipseSource and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    EclipseSource - initial API and implementation
10
 *    Frank Appel - replaced singletons and static fields (Bug 337787)
11
 ******************************************************************************/
12
package org.eclipse.rap.rwt.internal.service;
13
14
import static org.junit.Assert.assertArrayEquals;
15
import static org.junit.Assert.assertEquals;
16
import static org.junit.Assert.assertNotSame;
17
import static org.junit.Assert.assertNull;
18
19
import java.util.HashMap;
20
import java.util.Map;
21
22
import org.eclipse.rap.rwt.testfixture.Fixture;
23
import org.eclipse.rap.rwt.testfixture.TestRequest;
24
import org.junit.After;
25
import org.junit.Before;
26
import org.junit.Test;
27
28
29
public class RequestParameterBuffer_Test {
30
31
  @Before
32
  public void setUp() {
33
    Fixture.setUp();
34
  }
35
36
  @After
37
  public void tearDown() {
38
    Fixture.tearDown();
39
  }
40
41
  @Test
42
  public void testStore() {
43
    Map<String, String[]> originalParameters = new HashMap<String, String[]>();
44
    originalParameters.put( "key", new String[] { "value" } );
45
46
    RequestParameterBuffer.store( originalParameters );
47
48
    Map bufferedParameters = RequestParameterBuffer.getBufferedParameters();
49
    assertNotSame( originalParameters, bufferedParameters );
50
    assertArrayEquals( new String[]{ "value" }, ( String[] )bufferedParameters.get( "key" ) );
51
  }
52
53
  @Test
54
  public void testStoreOverridesBuffer() {
55
    // see bug 369549
56
    Map<String, String[]> originalParameters = new HashMap<String, String[]>();
57
    originalParameters.put( "key1", new String[] { "value1" } );
58
    originalParameters.put( "key2", new String[] { "value2" } );
59
    Map<String, String[]> newParameters = new HashMap<String, String[]>();
60
    newParameters.put( "key2", new String[] { "value2a" } );
61
    newParameters.put( "key3", new String[] { "value3" } );
62
63
    RequestParameterBuffer.store( originalParameters );
64
    RequestParameterBuffer.store( newParameters );
65
66
    Map bufferedParameters = RequestParameterBuffer.getBufferedParameters();
67
    assertNull( bufferedParameters.get( "key1" ) );
68
    assertArrayEquals( new String[] { "value2a" }, (String[])bufferedParameters.get( "key2" ) );
69
    assertArrayEquals( new String[] { "value3" }, (String[])bufferedParameters.get( "key3" ) );
70
  }
71
72
  @Test
73
  public void testMerge() {
74
    Map<String, String[]> parameters = new HashMap<String, String[]>();
75
    parameters.put( "key1", new String[] { "value1" } );
76
    parameters.put( "key2", new String[] { "value2" } );
77
    RequestParameterBuffer.store( parameters );
78
79
    TestRequest request = Fixture.fakeNewRequest();
80
    request.setParameter( "key2", "value2a" );
81
    request.setParameter( "key3", "value3" );
82
    RequestParameterBuffer.merge();
83
84
    assertEquals( "value1", ContextProvider.getRequest().getParameter( "key1" ) );
85
    assertEquals( "value2a", ContextProvider.getRequest().getParameter( "key2" ) );
86
    assertEquals( "value3", ContextProvider.getRequest().getParameter( "key3" ) );
87
  }
88
89
  @Test
90
  public void testMergeOnlyOnce() {
91
    Map<String, String[]> parameters = new HashMap<String, String[]>();
92
    parameters.put( "key1", new String[] { "value1" } );
93
    RequestParameterBuffer.store( parameters );
94
95
    Fixture.fakeNewRequest();
96
    RequestParameterBuffer.merge();
97
    Fixture.fakeNewRequest();
98
    RequestParameterBuffer.merge();
99
100
    assertNull( ContextProvider.getRequest().getParameter( "key1" ) );
101
  }
102
103
}
(-)a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/rap/rwt/internal/service/UrlParameters_Test.java (+110 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 EclipseSource and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    EclipseSource - initial API and implementation
10
 ******************************************************************************/
11
package org.eclipse.rap.rwt.internal.service;
12
13
import static org.junit.Assert.assertEquals;
14
import static org.junit.Assert.assertNull;
15
16
import java.util.Map;
17
18
import org.eclipse.rap.rwt.testfixture.Fixture;
19
import org.junit.After;
20
import org.junit.Before;
21
import org.junit.Test;
22
23
24
public class UrlParameters_Test {
25
26
  @Before
27
  public void setUp() {
28
    Fixture.setUp();
29
    Fixture.fakeNewRequest();
30
  }
31
32
  @After
33
  public void tearDown() {
34
    Fixture.tearDown();
35
  }
36
37
  @Test
38
  public void testMerge_InitialPostRequest() {
39
    Fixture.fakeHeadParameter( RequestParams.RWT_INITIALIZE, "true" );
40
    Fixture.fakeHeadParameter( RequestParams.QUERY_STRING, "key1=value1&key2=value2" );
41
42
    UrlParameters.merge();
43
44
    assertEquals( "value1", ContextProvider.getRequest().getParameter( "key1" ) );
45
    assertEquals( "value2", ContextProvider.getRequest().getParameter( "key2" ) );
46
  }
47
48
  @Test
49
  public void testMerge_NotInitialPostRequest() {
50
    Fixture.fakeHeadParameter( RequestParams.QUERY_STRING, "key1=value1&key2=value2" );
51
52
    UrlParameters.merge();
53
54
    assertNull( ContextProvider.getRequest().getParameter( "key1" ) );
55
    assertNull( ContextProvider.getRequest().getParameter( "key2" ) );
56
  }
57
58
  @Test
59
  public void testCreateParametersMap() {
60
    String queryString = "key1=value1&key2=value2";
61
    Map<String, String[]> parametersMap = UrlParameters.createParametersMap( queryString );
62
63
    assertEquals( 2, parametersMap.size() );
64
    assertEquals( "value1", parametersMap.get( "key1" )[ 0 ] );
65
    assertEquals( "value2", parametersMap.get( "key2" )[ 0 ] );
66
  }
67
68
  @Test
69
  public void testCreateParametersMap_MultipleValues() {
70
    String queryString = "key1=value1&key1=value2";
71
    Map<String, String[]> parametersMap = UrlParameters.createParametersMap( queryString );
72
73
    assertEquals( 1, parametersMap.size() );
74
    assertEquals( "value1", parametersMap.get( "key1" )[ 0 ] );
75
    assertEquals( "value2", parametersMap.get( "key1" )[ 1 ] );
76
  }
77
78
  @Test
79
  public void testCreateParametersMap_WithoutValue() {
80
    String queryString = "key1=";
81
    Map<String, String[]> parametersMap = UrlParameters.createParametersMap( queryString );
82
83
    assertEquals( "", parametersMap.get( "key1" )[ 0 ] );
84
  }
85
86
  @Test
87
  public void testCreateParametersMap_WithoutEqualAndValue() {
88
    String queryString = "key1";
89
    Map<String, String[]> parametersMap = UrlParameters.createParametersMap( queryString );
90
91
    assertEquals( "", parametersMap.get( "key1" )[ 0 ] );
92
  }
93
94
  @Test
95
  public void testCreateParametersMap_DecodeParameterName() {
96
    String queryString = "key%2F1=value1";
97
    Map<String, String[]> parametersMap = UrlParameters.createParametersMap( queryString );
98
99
    assertEquals( "value1", parametersMap.get( "key/1" )[ 0 ] );
100
  }
101
102
  @Test
103
  public void testCreateParametersMap_DecodeParameterValue() {
104
    String queryString = "key1=value%2F1";
105
    Map<String, String[]> parametersMap = UrlParameters.createParametersMap( queryString );
106
107
    assertEquals( "value/1", parametersMap.get( "key1" )[ 0 ] );
108
  }
109
110
}
(-)a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/rap/rwt/internal/service/WrappedRequest_Test.java (-5 / +2 lines)
Lines 109-122 Link Here
109
  public void testStartupRequestWithParameter() throws Exception {
109
  public void testStartupRequestWithParameter() throws Exception {
110
    ApplicationContextImpl applicationContext = getApplicationContext();
110
    ApplicationContextImpl applicationContext = getApplicationContext();
111
    applicationContext.getEntryPointManager().register( "/rap", DefaultEntryPoint.class, null );
111
    applicationContext.getEntryPointManager().register( "/rap", DefaultEntryPoint.class, null );
112
    TestRequest getRequest = Fixture.fakeNewGetRequest();
113
    getRequest.setParameter( "param", "value" );
114
    ServiceHandler handler = getApplicationContext().getServiceManager().getHandler();
112
    ServiceHandler handler = getApplicationContext().getServiceManager().getHandler();
115
    handler.service( ContextProvider.getRequest(), ContextProvider.getResponse() );
116
113
117
    TestRequest uiRequest = Fixture.fakeNewRequest();
114
    Fixture.fakeNewRequest();
118
    uiRequest.setParameter( "param", null );
119
    Fixture.fakeHeadParameter( RequestParams.RWT_INITIALIZE, "true" );
115
    Fixture.fakeHeadParameter( RequestParams.RWT_INITIALIZE, "true" );
116
    Fixture.fakeHeadParameter( RequestParams.QUERY_STRING, "param=value" );
120
    handler.service( ContextProvider.getRequest(), ContextProvider.getResponse() );
117
    handler.service( ContextProvider.getRequest(), ContextProvider.getResponse() );
121
118
122
    assertEquals( "value", ContextProvider.getRequest().getParameter( "param" ) );
119
    assertEquals( "value", ContextProvider.getRequest().getParameter( "param" ) );

Return to bug 404546