2222import com .google .gwt .user .client .rpc .IncompatibleRemoteServiceException ;
2323import com .google .gwt .user .client .rpc .RpcTokenException ;
2424import com .google .gwt .user .client .rpc .SerializationException ;
25- import com .google .gwt .user .server .rpc .logging .LogManager ;
26- import com .google .gwt .user .server .rpc .logging .Logger ;
25+ import com .google .gwt .user .server .rpc .logging .RpcLogManager ;
26+ import com .google .gwt .user .server .rpc .logging .RpcLogger ;
2727
2828import java .io .IOException ;
2929import java .io .InputStream ;
4747public class RemoteServiceServlet extends AbstractRemoteServiceServlet
4848 implements SerializationPolicyProvider {
4949
50- private static final Logger logger = LogManager .getLogger (RemoteServiceServlet .class );
50+ private static final RpcLogger logger = RpcLogManager .getLogger (RemoteServiceServlet .class );
5151
5252 /**
5353 * Loads a serialization policy stored as a servlet resource in the same
@@ -66,7 +66,7 @@ static SerializationPolicy loadSerializationPolicy(HttpServlet servlet,
6666 modulePath = new URL (moduleBaseURL ).getPath ();
6767 } catch (MalformedURLException ex ) {
6868 // log the information, we will default
69- logger .error ("Malformed moduleBaseURL: " + moduleBaseURL , ex );
69+ logger .error ("Malformed moduleBaseURL: " + moduleBaseURL , ex , servlet . getServletContext () );
7070 }
7171 }
7272
@@ -82,15 +82,16 @@ static SerializationPolicy loadSerializationPolicy(HttpServlet servlet,
8282 + modulePath
8383 + ", is not in the same web application as this servlet, "
8484 + contextPath
85- + ". Your module may not be properly configured or your client and server code maybe out of date." ;
86- logger .error (message );
85+ + ". Your module may not be properly configured " +
86+ "or your client and server code maybe out of date." ;
87+ logger .error (message , servlet .getServletContext ());
8788 } else {
8889 // Strip off the context path from the module base URL. It should be a
8990 // strict prefix.
9091 String contextRelativePath = modulePath .substring (contextPath .length ());
9192
92- String serializationPolicyFilePath = SerializationPolicyLoader .getSerializationPolicyFileName (contextRelativePath
93- + strongName );
93+ String serializationPolicyFilePath = SerializationPolicyLoader .getSerializationPolicyFileName (
94+ contextRelativePath + strongName );
9495
9596 // Open the RPC resource file and read its contents.
9697 InputStream is = servlet .getServletContext ().getResourceAsStream (
@@ -102,34 +103,32 @@ static SerializationPolicy loadSerializationPolicy(HttpServlet servlet,
102103 null );
103104 if (serializationPolicy .hasClientFields ()) {
104105 if (ENABLE_ENHANCED_CLASSES ) {
105- logger .warn (
106- "Service deserializes enhanced JPA/JDO classes, which is " +
107- "unsafe. See https://github.com/gwtproject/gwt/issues/9709 for more " +
108- "detail on the vulnerability that this presents." );
106+ logger .warn ("Service deserializes enhanced JPA/JDO classes, which is " +
107+ "unsafe. See https://github.com/gwtproject/gwt/issues/9709 for more " +
108+ "detail on the vulnerability that this presents." ,
109+ servlet . getServletContext () );
109110 } else {
110- logger .error (
111- "Service deserializes enhanced JPA/JDO classes, which is " +
112- "unsafe. Review build logs to see which classes are affected, or set " +
113- ENABLE_GWT_ENHANCED_CLASSES_PROPERTY + " to true to allow using this " +
114- "service. See https://github.com/gwtproject/gwt/issues/9709 for more " +
115- "detail." );
111+ logger .error ("Service deserializes enhanced JPA/JDO classes, which is " +
112+ "unsafe. Review build logs to see which classes are affected, or set " +
113+ ENABLE_GWT_ENHANCED_CLASSES_PROPERTY + " to true to allow using this " +
114+ "service. See https://github.com/gwtproject/gwt/issues/9709 for more " +
115+ "detail." ,
116+ servlet . getServletContext () );
116117 serializationPolicy = null ;
117118 }
118119 }
119120 } catch (ParseException e ) {
120- logger .error (
121- "Failed to parse the policy file '"
122- + serializationPolicyFilePath + "'" , e );
121+ logger .error ("Failed to parse the policy file '"
122+ + serializationPolicyFilePath + "'" , e , servlet .getServletContext ());
123123 } catch (IOException e ) {
124- logger .error (
125- "Could not read the policy file '"
126- + serializationPolicyFilePath + "'" , e );
124+ logger .error ("Could not read the policy file '"
125+ + serializationPolicyFilePath + "'" , e , servlet .getServletContext ());
127126 }
128127 } else {
129128 String message = "The serialization policy file '"
130129 + serializationPolicyFilePath
131130 + "' was not found; did you forget to include it in this deployment?" ;
132- logger .error (message );
131+ logger .error (message , servlet . getServletContext () );
133132 }
134133 } finally {
135134 if (is != null ) {
@@ -152,7 +151,8 @@ static SerializationPolicy loadSerializationPolicy(HttpServlet servlet,
152151 * A cache of moduleBaseURL and serialization policy strong name to
153152 * {@link SerializationPolicy}.
154153 */
155- private final Map <String , SerializationPolicy > serializationPolicyCache = new HashMap <String , SerializationPolicy >();
154+ private final Map <String , SerializationPolicy > serializationPolicyCache =
155+ new HashMap <String , SerializationPolicy >();
156156
157157 /**
158158 * The implementation of the service.
@@ -185,27 +185,17 @@ public RemoteServiceServlet(Object delegate) {
185185 }
186186
187187 /**
188- * Overridden to load the gwt.codeserver.port system property.
188+ * Overridden to load the gwt.codeserver.port system property and initialize the
189+ * {@link RpcLogManager} with a provider name from system properties or the servlet config.
189190 */
190191 @ Override
191192 public void init (ServletConfig config ) throws ServletException {
192193 super .init (config );
193- String providerName = getProviderName (config );
194- LogManager .initialize (providerName , config . getServletContext () );
194+ String providerName = RpcLogManager . getProviderName (config );
195+ RpcLogManager .initialize (providerName );
195196 codeServerPort = getCodeServerPort ();
196197 }
197198
198- private String getProviderName (ServletConfig config ) {
199- String parameterName = "gwt.rpc.logging" ;
200- if (System .getProperty (parameterName ) != null ) {
201- return System .getProperty (parameterName );
202- } else if (config .getInitParameter (parameterName ) != null ) {
203- return config .getInitParameter (parameterName );
204- } else {
205- return config .getServletContext ().getInitParameter (parameterName );
206- }
207- }
208-
209199 /**
210200 * Returns the value of the gwt.codeserver.port system property, or zero if not defined.
211201 *
@@ -281,12 +271,13 @@ public final SerializationPolicy getSerializationPolicy(String moduleBaseURL,
281271
282272 if (serializationPolicy == null ) {
283273 // Failed to get the requested serialization policy; use the default
284- logger .warn (
285- "Failed to get the SerializationPolicy '"
274+ logger .warn ("Failed to get the SerializationPolicy '"
286275 + strongName
287276 + "' for module '"
288277 + moduleBaseURL
289- + "'; a legacy, 1.3.3 compatible, serialization policy will be used. You may experience SerializationExceptions as a result." );
278+ + "'; a legacy, 1.3.3 compatible, serialization policy will be used. " +
279+ "You may experience SerializationExceptions as a result." ,
280+ getServletContext ());
290281 serializationPolicy = RPC .getDefaultSerializationPolicy ();
291282 }
292283
@@ -334,7 +325,7 @@ public String processCall(String payload) throws SerializationException {
334325 } catch (IncompatibleRemoteServiceException ex ) {
335326 logger .error (
336327 "An IncompatibleRemoteServiceException was thrown while processing this call." ,
337- ex );
328+ ex , getServletContext () );
338329 return RPC .encodeResponseForFailedRequest (null , ex );
339330 }
340331 return processCall (rpcRequest );
@@ -373,12 +364,12 @@ public String processCall(RPCRequest rpcRequest) throws SerializationException {
373364 } catch (IncompatibleRemoteServiceException ex ) {
374365 logger .error (
375366 "An IncompatibleRemoteServiceException was thrown while processing this call." ,
376- ex );
367+ ex ,
368+ getServletContext ());
377369 return RPC .encodeResponseForFailedRequest (rpcRequest , ex );
378370 } catch (RpcTokenException tokenException ) {
379- logger .error (
380- "An RpcTokenException was thrown while processing this call." ,
381- tokenException );
371+ logger .error ("An RpcTokenException was thrown while processing this call." ,
372+ tokenException , getServletContext ());
382373 return RPC .encodeResponseForFailedRequest (rpcRequest , tokenException );
383374 }
384375 }
@@ -486,7 +477,7 @@ protected String getCodeServerPolicyUrl(String strongName) {
486477 * no authentication. It should only be used during development.</p>
487478 */
488479 protected SerializationPolicy loadPolicyFromCodeServer (String url ) {
489- return CODE_SERVER_CLIENT .loadPolicy (url );
480+ return CODE_SERVER_CLIENT .loadPolicy (url , getServletContext () );
490481 }
491482
492483 /**
@@ -550,6 +541,6 @@ private void writeResponse(HttpServletRequest request,
550541 boolean gzipEncode = RPCServletUtils .acceptsGzipEncoding (request )
551542 && shouldCompressResponse (request , response , responsePayload );
552543
553- RPCServletUtils .writeResponse (response , responsePayload , gzipEncode );
544+ RPCServletUtils .writeResponse (getServletContext (), response , responsePayload , gzipEncode );
554545 }
555546}
0 commit comments