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

Older Jersey versions failing when scanning classes due to inclusion of a few Java 8 class files #1142

Merged
merged 1 commit into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ shadowJar {
relocate 'org.xmlpull', "${dependenciesPrefix}.xmlpull"

exclude '**/*.proto'

// these files are compiled with Java 8, which can cause issues for applications that perform jar file scanning with
// old version of ASM that doesn't support Java 8 yet
exclude 'com/thoughtworks/xstream/converters/time/*.class'
exclude 'com/thoughtworks/xstream/converters/reflection/LambdaConverter.class'
exclude 'com/thoughtworks/xstream/mapper/LambdaMapper.class'
exclude 'com/thoughtworks/xstream/core/util/ISO8601JavaTimeConverter.class'
}

jar {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import javax.xml.stream.XMLStreamReader;

import com.microsoft.applicationinsights.internal.logger.InternalLogger;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;
import com.thoughtworks.xstream.io.xml.Xpp3Driver;
import org.apache.commons.lang3.exception.ExceptionUtils;
Expand All @@ -49,11 +48,11 @@ public ApplicationInsightsXmlConfiguration build(InputStream resourceFile) {
}

try {
XStream xstream = new XStream(new PureJavaReflectionProvider(), new Xpp3Driver());
Java7SaferXStream xstream = new Java7SaferXStream(new PureJavaReflectionProvider(), new Xpp3Driver());

xstream.ignoreUnknownElements(); // backwards compatible with jaxb behavior

XStream.setupDefaultSecurity(xstream);
Java7SaferXStream.setupDefaultSecurity(xstream);
xstream.allowTypesByWildcard(new String[] {
"com.microsoft.applicationinsights.internal.config.*"
});
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ include ':test:smoke:testApps:CustomInstrumentation'
include ':test:smoke:testApps:WebAuto'
include ':test:smoke:testApps:SpringBoot1_3Auto'
include ':test:smoke:testApps:SpringBootAuto'
include ':test:smoke:testApps:VerifyJava7'


22 changes: 22 additions & 0 deletions test/smoke/testApps/VerifyJava7/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apply plugin: 'war'

sourceCompatibility = 1.7
targetCompatibility = 1.7
compileSmokeTestJava.sourceCompatibility = 1.8
compileSmokeTestJava.targetCompatibility = 1.8

ext.testAppArtifactDir = war.destinationDirectory
ext.testAppArtifactFilename = war.archiveFileName.get()

dependencies {
compile aiWebAutoJar
compileOnly aiCoreJar

compile (group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.7.RELEASE') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
compile 'org.ow2.asm:asm:7.2'
compile 'com.google.guava:guava:20.0'

providedCompile 'javax.servlet:javax.servlet-api:3.0.1'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.microsoft.ajl.simple;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

@SpringBootApplication
public class SpringBootApp extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) {
return applicationBuilder.sources(SpringBootApp.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.microsoft.ajl.simple;

import com.google.common.base.Joiner;
import com.microsoft.applicationinsights.TelemetryClient;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Opcodes;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;

@RestController
public class TestController {

@GetMapping("/")
public String root() {
return "OK";
}

@GetMapping("/verifyJava7")
public String verifyJava7() throws IOException {

URL url = TelemetryClient.class.getProtectionDomain().getCodeSource().getLocation();

InputStream in = url.openStream();
JarInputStream jarIn = new JarInputStream(in);

List<String> java8Classnames = new ArrayList<>();

JarEntry jarEntry;
while ((jarEntry = jarIn.getNextJarEntry()) != null) {
String name = jarEntry.getName();
if (name.endsWith(".class")) {
VersionCapturingClassVisitor cv = new VersionCapturingClassVisitor();
new ClassReader(jarIn).accept(cv, 0);
if (name.equals("com/microsoft/applicationinsights/core/dependencies/xmlpull/mxp1/MXParser.class") && cv.version == 196653) {
// strange..
continue;
}
if (cv.version > 51) {
java8Classnames.add(name.replace('/', '.'));
}
}
}

jarIn.close();
in.close();

if (!java8Classnames.isEmpty()) {
throw new AssertionError("Found Java 8+ classes: " + Joiner.on(", ").join(java8Classnames));
}
return "OK";
}

static class VersionCapturingClassVisitor extends ClassVisitor {

int version;

private VersionCapturingClassVisitor() {
super(Opcodes.ASM7);
}

public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
this.version = version;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings" schemaVersion="2014-05-30">

<!-- The key from the portal: -->

<ConnectionString>InstrumentationKey=00000000-0000-0000-0000-0FEEDDADBEEF;IngestionEndpoint=http://fakeingestion:60606</ConnectionString>

<SDKLogger type="CONSOLE">
<enabled>true</enabled>
<UniquePrefix>JavaSDKLog</UniquePrefix>
</SDKLogger>

<QuickPulse enabled="false" />
<!-- HTTP request component (not required for bare API) -->

<TelemetryModules>
<Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebRequestTrackingTelemetryModule" />
<Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebSessionTrackingTelemetryModule" />
<Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebUserTrackingTelemetryModule" />
</TelemetryModules>

<!-- Events correlation (not required for bare API) -->
<!-- These initializers add context data to each event -->

<TelemetryInitializers>
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebOperationIdTelemetryInitializer" />
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebOperationNameTelemetryInitializer" />
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebSessionTelemetryInitializer" />
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebUserTelemetryInitializer" />
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebUserAgentTelemetryInitializer" />
<Add type="com.microsoft.applicationinsights.extensibility.initializer.docker.DockerContextInitializer" />
</TelemetryInitializers>

<Channel>
<DeveloperMode>true</DeveloperMode>
<FlushIntervalInSeconds>1</FlushIntervalInSeconds>
</Channel>
</ApplicationInsights>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.microsoft.applicationinsights.smoketest;

import com.microsoft.applicationinsights.internal.schemav2.Data;
import com.microsoft.applicationinsights.internal.schemav2.Envelope;
import com.microsoft.applicationinsights.internal.schemav2.RequestData;
import org.junit.Test;

import java.util.List;

import static org.junit.Assert.assertTrue;

public class VerifyJava7Test extends AiSmokeTest {

@Test
@TargetUri("/verifyJava7")
public void verifyJava7() throws Exception {
List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);

Envelope rdEnvelope = rdList.get(0);

RequestData rd = (RequestData) ((Data) rdEnvelope.getData()).getBaseData();

assertTrue(rd.getSuccess());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`appServers.txt` excludes Tomcat 7 because Spring Boot 2 does not support Tomcat 7
`jre.excludes.txt` is needed because Spring Boot 2 does not support Java 7
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tomcat85
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
openjdk:7-jre
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="warn">
<appender-ref ref="CONSOLE" />
</root>
</configuration>