Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stackdriver logging #68 #81

Merged
merged 112 commits into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
e748691
Issue #68 added request context scope
gregw Nov 9, 2016
f6d1488
Issue #68 added request context scope
gregw Nov 9, 2016
2ad99b0
Issue #68 added skeleton Logging Handler
gregw Nov 9, 2016
30b3e80
Issue #68 work in progress
gregw Nov 11, 2016
7ec8ff3
Issue #68 work in progress
gregw Nov 16, 2016
1d3ca8a
working implementation using a threadlocal to stop looping
gregw Nov 17, 2016
3b5c3a7
Merge remote-tracking branch 'origin/master' into master-68
gregw Nov 17, 2016
aa81e13
Issue #68 update to latest google-cloud-java LoggingHandler
gregw Nov 17, 2016
141bae3
Merge branch 'master' into master-68
gregw Nov 30, 2016
48df809
Issue #68
gregw Nov 30, 2016
1e38c88
Issue #68 Use same labels as nginx
gregw Dec 1, 2016
f19135d
Merge branch 'master' into master-68
gregw Dec 1, 2016
4a0886e
Merge branch 'master' into master-68
gregw Dec 5, 2016
df430d6
Issue #68
gregw Dec 5, 2016
fe02767
Merge branch 'master' into master-68
gregw Dec 6, 2016
2005182
Merge branch 'master' into master-68
gregw Dec 7, 2016
3d2baec
Merge branch 'master' into master-68
gregw Dec 12, 2016
563140f
Merge branch 'master' into master-68
gregw Dec 13, 2016
3206abf
Merge branch 'master' into master-68
gregw Dec 23, 2016
9de4fc1
Issue #68
gregw Dec 23, 2016
f884043
Merge branch 'master' into master-68
meltsufin Dec 28, 2016
9ea5c97
Merge branch 'master' into master-68
meltsufin Dec 28, 2016
abc7b09
renamed traceid to traceId
gregw Dec 29, 2016
9318aa1
gcloud api not currently used
gregw Dec 29, 2016
2dc88d0
Merge branch 'master' into master-68
gregw Jan 1, 2017
d50f5ae
Tunnel traceId in parameters #68
gregw Jan 4, 2017
9e5e2db
Simplified with traceId lookup in formatter #68
gregw Jan 4, 2017
c6d8df8
Merge branch 'master' into master-68
gregw Jan 12, 2017
d5f5613
Use 8.2 beta stackdriver
gregw Jan 12, 2017
9a22c3d
Improved formatting
gregw Jan 12, 2017
4f738b7
use logger name rather than source
gregw Jan 13, 2017
34e9103
run jetty from the webapp working directory so logging configuration …
gregw Jan 13, 2017
f255ee1
Testing logging
gregw Jan 18, 2017
fc0ed8d
Merge branch 'master' into master-68
gregw Jan 23, 2017
24a9055
use released 9.4.1
gregw Jan 24, 2017
9182d7e
Issue #68
gregw Jan 24, 2017
688ed8e
Do not CD to non existant directory
gregw Jan 25, 2017
b4d7add
Merge branch 'master' into master-68
gregw Jan 26, 2017
d3e5d9d
Merge branch 'master' into master-68
gregw Jan 26, 2017
06b1a2e
improved README
gregw Jan 31, 2017
9f64c08
fixed Cloud SDK
gregw Jan 31, 2017
8fb26f2
Merge branch 'master' into master-68
meltsufin Feb 2, 2017
22e7518
Released beta of google-cloud-logging
gregw Feb 2, 2017
e7a8fcb
Merge branch 'master-68' of github.com:GoogleCloudPlatform/jetty-runt…
gregw Feb 2, 2017
4032481
Merge branch 'master' into master-68
gregw Feb 2, 2017
80ee54e
Merge branch 'master' into master-68
gregw Feb 8, 2017
4835abc
updated google-cloud API to 0.8.3-beta
gregw Feb 8, 2017
f1e55dc
added remote test to check logging
gregw Feb 10, 2017
64a0a20
Stackdriver logging testing
gregw Feb 13, 2017
cb4b5f8
Merge remote-tracking branch 'origin/master' into master-68
gregw Feb 14, 2017
cb852d3
upgrade to 0.9.2
gregw Feb 14, 2017
f3ef369
Test for zone
gregw Feb 15, 2017
72636e8
Merge branch 'master' into master-68
gregw Feb 21, 2017
912d09d
Merge branch 'master' into master-68
gregw Mar 7, 2017
eb6eddb
Merge branch 'master' into master-68
gregw Mar 9, 2017
1976930
Merge branch 'master' into master-68
gregw Mar 17, 2017
2c022d7
upgrade to 10.0 gcloud API
gregw Mar 23, 2017
cd8bdf8
enable gae module only of GAE_INSTANCE environment variable is set
gregw Mar 24, 2017
6ad4bd8
improved gae.mod documentation
gregw Mar 24, 2017
9080fc7
GCP module
gregw Mar 29, 2017
63d986d
fixed warnings
gregw Mar 29, 2017
cda775a
turn off stackdriver logging by default. Added instructions to enable.
gregw Mar 29, 2017
57613d6
Merge branch 'master' into master-gae-optional
gregw Apr 1, 2017
edc450d
Merge branch 'master' into master-68
gregw Apr 1, 2017
c1225ec
Merge branch 'master' into master-gae-optional
meltsufin Apr 5, 2017
1c4c5a9
Merge branch 'master' into master-68
meltsufin Apr 5, 2017
3a2bfa9
Updates
gregw Apr 13, 2017
1fc1244
Merge branch 'master' into master-update
gregw Apr 13, 2017
974bb28
Merge branch 'master' into master-gae-optional
gregw Apr 13, 2017
7a76e45
Merge branch 'master-update' into master-gae-optional
gregw Apr 13, 2017
c58bbaf
Use the PLATFORM env var
gregw Apr 13, 2017
c3d5f0d
Improved jetty startup
gregw Apr 13, 2017
17e3af9
Merge branch 'master' into master-gae-optional
gregw Apr 13, 2017
87cf4ae
use launcher URL
gregw Apr 13, 2017
8ea1238
Trimmed GCP specific configuration
gregw Apr 13, 2017
4766ae5
Added structure tests for jetty setup script
gregw Apr 14, 2017
aafc67a
Merge branch 'master-gae-optional' into master-68
gregw Apr 14, 2017
441a3fb
Support passing just args
gregw Apr 14, 2017
0def22a
Merge branch 'master-gae-optional' into master-68
gregw Apr 14, 2017
81014f6
fix merge
gregw Apr 14, 2017
90ca817
Merge branch 'master' into master-gae-optional
gregw Apr 14, 2017
bdad80a
Fixed test workspace paths for cloud build
Apr 14, 2017
d9a19a9
Merge branch 'master-gae-optional' into master-68
gregw Apr 14, 2017
bc4d478
Merge branch 'master' into master-68
gregw Apr 18, 2017
3240d37
review feedback
gregw Apr 18, 2017
0fc1215
working directory is the root webapp
gregw Apr 18, 2017
42ba89c
Improve handling of various types of command line.
gregw Apr 18, 2017
1c73bb6
upgrade cgloud API version to 0.13.0-beta
gregw Apr 18, 2017
21fe0cd
use package target
gregw Apr 18, 2017
151d496
tested with FINE log level
gregw Apr 19, 2017
a7e7f37
Simplify entrypoint args processing
gregw Apr 19, 2017
5a57c6d
remove debug
gregw Apr 19, 2017
d1d9a47
remove debug
gregw Apr 19, 2017
86f8154
Merge branch 'master' into master-68
gregw Apr 19, 2017
e75419d
Merge branch 'master-68' into master-68-docker-args
gregw Apr 20, 2017
3f32e54
Test that the logging dependencies are hidden from webapp classpath
gregw Apr 20, 2017
37f5bd4
update README.md with instructions to keep INFO level on io.grpc.nett…
gregw Apr 20, 2017
4754bc4
Updated to lasted openjdk-runtime
gregw Apr 22, 2017
8615410
fixed classloader test
gregw Apr 26, 2017
115759a
fixed TODO
gregw Apr 26, 2017
aa91b0b
Merge branch 'master' into master-68
gregw May 3, 2017
91a62d8
Update to jetty 9.4.5 and gcloud 1.0.1-SNAPSHOT
gregw May 3, 2017
2f7dc9c
Merge branch 'master' into master-68
gregw May 3, 2017
ac00fd1
Merge branch 'master' into master-68
gregw May 3, 2017
187cac8
Merge branch 'master-68' of github.com:GoogleCloudPlatform/jetty-runt…
gregw May 3, 2017
376481f
Merge branch 'master' into master-68
gregw May 9, 2017
4b80727
upgraded to gcloud-logging 1.0.1
gregw May 9, 2017
ae6b9ce
turn off debug
gregw May 9, 2017
21404d7
Merge branch 'master' into master-68
meltsufin May 9, 2017
de07ed9
Merge branch 'master' into master-68
gregw May 10, 2017
df47a07
updated README for latest 1.0.1 gcloud-logging
gregw May 10, 2017
bfc9e45
update classpath exclusion
gregw May 11, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions jetty9-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,9 @@
</parent>
<name>Google App Engine Image Jetty (jetty9-base)</name>
<artifactId>jetty9-base</artifactId>
<packaging>pom</packaging>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>com.google.cloud.runtimes</groupId>
<artifactId>logging</artifactId>
<version>0.1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
Expand All @@ -43,15 +37,27 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.cloud.runtimes</groupId>
<artifactId>openjdk8</artifactId>
<version>${project.version}</version>
<type>pom</type>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-logging</artifactId>
<version>${gcloud.api.version}</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<outputDirectory>${project.build.directory}/jetty-base/lib/gae</outputDirectory>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
Expand Down Expand Up @@ -135,7 +141,9 @@
<arguments>
<argument>-jar</argument>
<argument>../jetty-distribution-${jetty9.version}/start.jar</argument>
<argument>--add-to-startd=http,deploy,jsp,jstl,http-forwarded,resources,gae</argument>
<argument>--create-startd</argument>
<argument>--add-to-start=http,deploy,jsp,jstl,http-forwarded,resources,gae,gcloud,jcl-slf4j,logging-jul</argument>
<argument>--approve-all-licenses</argument>
</arguments>
</configuration>
</plugin>
Expand All @@ -161,5 +169,6 @@
</plugin>
</plugins>
</build>

</project>

7 changes: 0 additions & 7 deletions jetty9-base/src/main/assembly/assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,5 @@
<exclude>**/META-INF/**</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>jetty-base/lib/gae</outputDirectory>
<includes>
<include>${artifactId}-${version}.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package com.google.cloud.runtimes.jetty9;

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandler.Context;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.logging.Level;
import java.util.logging.Logger;

public class RequestContextScope implements ContextHandler.ContextScopeListener {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some javadocs to explain the purpose of the class?

static final Logger logger = Logger.getLogger(RequestContextScope.class.getName());

private static final String X_CLOUD_TRACE = "x-cloud-trace-context";
private static final ThreadLocal<String> traceid = new ThreadLocal<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use camel case traceId.

private static final ThreadLocal<Deque<Request>> requestStack =
new ThreadLocal<Deque<Request>>() {
@Override
protected Deque<Request> initialValue() {
return new ArrayDeque<>();
}
};

@Override
public void enterScope(Context context, Request request, Object reason) {
if (request != null) {
Deque<Request> stack = requestStack.get();
if (stack.isEmpty()) {
String id = (String) request.getAttribute(X_CLOUD_TRACE);
if (id == null) {
id = request.getHeader(X_CLOUD_TRACE);
if (id != null) {
int slash = id.indexOf('/');
if (slash >= 0) {
id = id.substring(0, slash);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we just dropping the span id? I'm not sure this is what we're supposed to be doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not sure. The compat version we inherited did a scan for the first non hex character and split there, so I just simplified and inherited that behaviour. Can you investigate if we can leave it in.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will find out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got a response from the logging team indicating that we should only log the trace id without the span id. So, this is good.

}
request.setAttribute(X_CLOUD_TRACE, id);
}
}
traceid.set(id);
}
stack.push(request);
}
if (logger.isLoggable(Level.FINE)) {
logger.fine("enterScope " + context);
}
}

@Override
public void exitScope(Context context, Request request) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("exitScope " + context);
}
if (request != null) {
requestStack.get().pop();
}
}

/** Run a Runnable in the scope of a traceid.
* @param traceid The trace ID
* @param runnable the runnable
*/
public static void runWith(String traceid, Runnable runnable) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method used somewhere, or just provided as a utility?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a utility that I thought we might need. I will drop for now as it will be trivial to readd if there ever is a need.

String original = RequestContextScope.traceid.get();
RequestContextScope.traceid.set(traceid);
try {
runnable.run();
} finally {
RequestContextScope.traceid.set(original);
}
}

public static Request getCurrentRequest() {
return requestStack.get().peek();
}

public static String getCurrentTraceid() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: getCurrentTraceId(). Other places have the same issue where id is not Id. Just do a global search for [Tt]raceid.

return traceid.get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package com.google.cloud.runtimes.jetty9;

import static com.google.common.base.MoreObjects.firstNonNull;

import com.google.cloud.MonitoredResource;
import com.google.cloud.logging.AsyncLoggingHandler;
import com.google.cloud.logging.LogEntry.Builder;
import com.google.cloud.logging.LoggingOptions;

import org.eclipse.jetty.server.Request;

import java.util.logging.LogManager;
import java.util.logging.LogRecord;

/**
* A Google Cloud Logging Handler extended with a request traceid label.
*/
public class TracingLogHandler extends AsyncLoggingHandler {

private final ThreadLocal<Boolean> flushing = new ThreadLocal<>();
private final MonitoredResource monitored;
private final String instanceid;

/**
* Construct a TracingLogHandler for "jetty.log"
*/
public TracingLogHandler() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this class anymore, correct?

this(firstNonNull(
LogManager.getLogManager().getProperty(TracingLogHandler.class.getName() + ".log"),
"jetty.log"), null, null);
}

/**
* Construct a TracingLogHandler.
*
* @param logName Name of the log
* @param options LoggingOptions to access Google cloud API
* @param resource The resource to log against
*/
public TracingLogHandler(String logName, LoggingOptions options, MonitoredResource resource) {
super(logName, options, resource);
monitored = MonitoredResource.newBuilder("gae_app")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're sort of overwriting the resource that is passed in here. Maybe create the resource only in the no-arg constructor instead?

.addLabel("project_id", System.getenv("GCLOUD_PROJECT"))
.addLabel("module_id", System.getenv("GAE_SERVICE"))
.addLabel("version_id", System.getenv("GAE_VERSION"))
.build();
instanceid = System.getenv("GAE_INSTANCE");
}

@Override
public synchronized void publish(LogRecord record) {
// check we are not already flushing logs
if (Boolean.TRUE.equals(flushing.get())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a matter of style, but I would save a line and write it as:

   // check we are not already flushing logs
   if (!Boolean.TRUE.equals(flushing.get())) {
     super.publish(record);
    }

return;
}
super.publish(record);
}

@Override
protected void enhanceLogEntry(Builder builder, LogRecord record) {
super.enhanceLogEntry(builder, record);
String traceid = RequestContextScope.getCurrentTraceid();
builder.setResource(monitored);
if (traceid != null) {
builder.addLabel("appengine.googleapis.com/trace_id", traceid);
} else {
Request request = RequestContextScope.getCurrentRequest();
if (request != null) {
builder.addLabel("http-scheme", request.getScheme());
builder.addLabel("http-method", request.getMethod());
builder.addLabel("http-uri", request.getOriginalURI());
builder.addLabel("http-remote-addr", request.getRemoteAddr());
}
}
if (instanceid != null) {
builder.addLabel("appengine.googleapis.com/instance_name", instanceid);
}
}

@Override
public synchronized void flush() {
try {
flushing.set(Boolean.TRUE);
super.flush();
} finally {
flushing.set(Boolean.FALSE);
}
}
}
15 changes: 5 additions & 10 deletions jetty9-base/src/main/jetty-base/etc/gae-web.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">

<!-- Protect app.yaml -->
<Get id="protected" name="ProtectedTargets"/>
<Set name="ProtectedTargets">
<Call class="org.eclipse.jetty.util.ArrayUtil" name="addToArray">
<Arg><Ref refid="protected"/></Arg>
<Arg>/app.yaml</Arg>
<Arg></Arg>
</Call>
</Set>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces on empty line?

<!-- Add listener to capture request context to be used by logging -->
<Call name="addEventListener">
<Arg><New class="com.google.cloud.runtimes.jetty9.RequestContextScope"/></Arg>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add this listener conditionally based on an environment variable? For example, if the image is used outside of GCP, this won't make sense.

</Call>

</Configure>

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.level = INFO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does one overwrite this configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently they have to replace the file in a Custom image. However, as we discussed on the call last week, we should look at some way of allowing a logging.properties file to be included in the application, to either be merged with this one or simply to replace it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a minimum, we need to make sure that this still works to overwrite the logging configuration:

env_variables:
  JAVA_USER_OPTS: -Djava.util.logging.config.file=/var/lib/jetty/webapps/root/WEB-INF/logging.properties

See discussion in issue #101

Also, maybe update the README.md as part of this PR specifying how to overwrite the default JUL config.

io.netty.level = INFO
io.gcr.level = INFO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to set log levels for netty and gcr here if we have the flushing guard in TracingLogHandler.publish()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it because netty logs from background threads. However there is still the issue that not all of netty's log mechanism appears not to see these settings anyway, so perhaps we just need an explicit filter in the publish method?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would an explicit filter work so that it deals with the Netty background threads?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the approach taken by the gcloud-java client library is to have fixed list of known log names that it explicitly scans for and removes the stackdriver handler from.

This is the approach that should also stop looping, but it not.

The same list could simply be applied within the log handler and any logs from those handlers would be discarded. This list could either be a complete list, in which case we would not need either the threadlocal approach nor the handler deregistration.

Alternately the list can just be limited to the loggers that are not reacting to the logging properties configuration.

Currently I don't like any solution. My preference would be to have no filtering and just loop protection. Overly verbose logging should be handled gracefully (with discarded logs and a message to that effect) and then the user can just configure logging to only log what they are interested in.

So I need to investigate why those netty classes are ignoring the properties file.


handlers = com.google.cloud.runtimes.jetty9.TracingLogHandler
com.google.cloud.runtimes.jetty9.TracingLogHandler.level = INFO

# handlers = com.google.cloud.runtimes.jetty9.TracingLogHandler,java.util.logging.ConsoleHandler
# java.util.logging.ConsoleHandler.level = INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//

package com.google.cloud.runtimes.jetty9;

import java.io.IOException;
import java.util.logging.Logger;

import javax.annotation.PostConstruct;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@SuppressWarnings("serial")
@WebServlet(urlPatterns = {"/", "/test/*"}, name = "TestServlet")
public class TestServlet extends HttpServlet {
static final Logger log = Logger.getLogger(TestServlet.class.getName());

@PostConstruct
private void myPostConstructMethod() {
log.info("preconstructed");
}

@Override
public void init() throws ServletException {
log.info("init info");
getServletContext().log("init ServletContext.log");
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
log.info("doGet info");
getServletContext().log("doGet ServletContext.log");

if (request.getParameter("ex") != null) {
try {
throw (Throwable) Class.forName(request.getParameter("ex")).newInstance();
} catch (ServletException | IOException e) {
throw e;
} catch (Throwable e) {
throw new ServletException(e);
}
}
response.getWriter().println("Log Test");
}
}
Loading