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 ;
2527
2628import java .io .IOException ;
2729import java .io .InputStream ;
3032import java .text .ParseException ;
3133import java .util .HashMap ;
3234import java .util .Map ;
33- import java .util .logging .Level ;
34- import java .util .logging .Logger ;
3535
3636import javax .servlet .ServletConfig ;
3737import javax .servlet .ServletException ;
4747public class RemoteServiceServlet extends AbstractRemoteServiceServlet
4848 implements SerializationPolicyProvider {
4949
50- private static final Logger logger = Logger .getLogger (RemoteServiceServlet .class . getName () );
50+ private static final Logger logger = LogManager .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 .log ( Level . SEVERE , "Malformed moduleBaseURL: " + moduleBaseURL , ex );
69+ logger .error ( "Malformed moduleBaseURL: " + moduleBaseURL , ex );
7070 }
7171 }
7272
@@ -83,7 +83,7 @@ static SerializationPolicy loadSerializationPolicy(HttpServlet servlet,
8383 + ", is not in the same web application as this servlet, "
8484 + contextPath
8585 + ". Your module may not be properly configured or your client and server code maybe out of date." ;
86- logger .log ( Level . SEVERE , message );
86+ logger .error ( message );
8787 } else {
8888 // Strip off the context path from the module base URL. It should be a
8989 // strict prefix.
@@ -102,12 +102,12 @@ static SerializationPolicy loadSerializationPolicy(HttpServlet servlet,
102102 null );
103103 if (serializationPolicy .hasClientFields ()) {
104104 if (ENABLE_ENHANCED_CLASSES ) {
105- logger .log ( Level . WARNING ,
105+ logger .warn (
106106 "Service deserializes enhanced JPA/JDO classes, which is " +
107107 "unsafe. See https://github.com/gwtproject/gwt/issues/9709 for more " +
108108 "detail on the vulnerability that this presents." );
109109 } else {
110- logger .log ( Level . SEVERE ,
110+ logger .error (
111111 "Service deserializes enhanced JPA/JDO classes, which is " +
112112 "unsafe. Review build logs to see which classes are affected, or set " +
113113 ENABLE_GWT_ENHANCED_CLASSES_PROPERTY + " to true to allow using this " +
@@ -117,19 +117,19 @@ static SerializationPolicy loadSerializationPolicy(HttpServlet servlet,
117117 }
118118 }
119119 } catch (ParseException e ) {
120- logger .log ( Level . SEVERE ,
120+ logger .error (
121121 "Failed to parse the policy file '"
122122 + serializationPolicyFilePath + "'" , e );
123123 } catch (IOException e ) {
124- logger .log ( Level . SEVERE ,
124+ logger .error (
125125 "Could not read the policy file '"
126126 + serializationPolicyFilePath + "'" , e );
127127 }
128128 } else {
129129 String message = "The serialization policy file '"
130130 + serializationPolicyFilePath
131131 + "' was not found; did you forget to include it in this deployment?" ;
132- logger .log ( Level . SEVERE , message );
132+ logger .error ( message );
133133 }
134134 } finally {
135135 if (is != null ) {
@@ -190,9 +190,22 @@ public RemoteServiceServlet(Object delegate) {
190190 @ Override
191191 public void init (ServletConfig config ) throws ServletException {
192192 super .init (config );
193+ String providerName = getProviderName (config );
194+ LogManager .initialize (providerName , config .getServletContext ());
193195 codeServerPort = getCodeServerPort ();
194196 }
195197
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+
196209 /**
197210 * Returns the value of the gwt.codeserver.port system property, or zero if not defined.
198211 *
@@ -268,7 +281,7 @@ public final SerializationPolicy getSerializationPolicy(String moduleBaseURL,
268281
269282 if (serializationPolicy == null ) {
270283 // Failed to get the requested serialization policy; use the default
271- logger .log ( Level . WARNING ,
284+ logger .warn (
272285 "Failed to get the SerializationPolicy '"
273286 + strongName
274287 + "' for module '"
@@ -319,8 +332,7 @@ public String processCall(String payload) throws SerializationException {
319332 try {
320333 rpcRequest = RPC .decodeRequest (payload , delegate .getClass (), this );
321334 } catch (IncompatibleRemoteServiceException ex ) {
322- logger .log (
323- Level .SEVERE ,
335+ logger .error (
324336 "An IncompatibleRemoteServiceException was thrown while processing this call." ,
325337 ex );
326338 return RPC .encodeResponseForFailedRequest (null , ex );
@@ -359,12 +371,12 @@ public String processCall(RPCRequest rpcRequest) throws SerializationException {
359371 rpcRequest .getParameters (), rpcRequest .getSerializationPolicy (),
360372 rpcRequest .getFlags ());
361373 } catch (IncompatibleRemoteServiceException ex ) {
362- logger .log ( Level . SEVERE ,
374+ logger .error (
363375 "An IncompatibleRemoteServiceException was thrown while processing this call." ,
364376 ex );
365377 return RPC .encodeResponseForFailedRequest (rpcRequest , ex );
366378 } catch (RpcTokenException tokenException ) {
367- logger .log ( Level . SEVERE ,
379+ logger .error (
368380 "An RpcTokenException was thrown while processing this call." ,
369381 tokenException );
370382 return RPC .encodeResponseForFailedRequest (rpcRequest , tokenException );
@@ -474,19 +486,7 @@ protected String getCodeServerPolicyUrl(String strongName) {
474486 * no authentication. It should only be used during development.</p>
475487 */
476488 protected SerializationPolicy loadPolicyFromCodeServer (String url ) {
477- SerializationPolicyClient .Logger adapter = new SerializationPolicyClient .Logger () {
478-
479- @ Override
480- public void logInfo (String message ) {
481- logger .log (Level .INFO , message );
482- }
483-
484- @ Override
485- public void logError (String message , Throwable throwable ) {
486- logger .log (Level .SEVERE , message , throwable );
487- }
488- };
489- return CODE_SERVER_CLIENT .loadPolicy (url , adapter );
489+ return CODE_SERVER_CLIENT .loadPolicy (url );
490490 }
491491
492492 /**
0 commit comments