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

feat: introduces jakarta servlet protocol module #246

Merged
merged 4 commits into from Jul 6, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions bom/pom.xml
Expand Up @@ -177,6 +177,11 @@
<artifactId>arquillian-protocol-servlet</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet-jakarta</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-jmx</artifactId>
Expand Down
1 change: 1 addition & 0 deletions protocols/pom.xml
Expand Up @@ -21,6 +21,7 @@

<modules>
<module>servlet</module>
<module>servlet-jakarta</module>
<module>jmx</module>
</modules>
</project>
10 changes: 10 additions & 0 deletions protocols/servlet-jakarta/README.adoc
@@ -0,0 +1,10 @@
= Jakarta EE 9 Servlet 5 API Protocol

This is a port of the servlet protocol handler for communicating using a servlet / http following the Jakarta Servlet 5.x spec.

== Issues
This relies on a release of org.eclipse.jetty:jetty-server that supports the Jakarta Servlet 5.x spec. The current
11.0.0-alpha0 release in turn requires Java 11, so this module required Java 8 to compile the module artifact, but
it requires Java 11 to build and run the modules tests.

https://github.com/eclipse/jetty.project
134 changes: 134 additions & 0 deletions protocols/servlet-jakarta/pom.xml
@@ -0,0 +1,134 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<!-- Parent -->
<parent>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-build</artifactId>
<version>1.7.0.Final-SNAPSHOT</version>
<relativePath>../../build/pom.xml</relativePath>
</parent>

<!-- Model Version -->
<modelVersion>4.0.0</modelVersion>

<!-- Artifact Configuration -->
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet-jakarta</artifactId>
<name>Arquillian Protocol Servlet 5.x</name>
<description>Protocol handler for communicating using a servlet / http following the Servlet 5.x spec and jakarta.servlet.* apis
</description>

<!-- Properties -->
<properties>
<!-- Versioning -->
<version.jetty_jetty>11.0.0-alpha0</version.jetty_jetty>
<version.servlet-api>5.0.0-M1</version.servlet-api>
<!-- The protocol adaptor requires Java 8 -->
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>

<!-- Dependencies -->
<dependencies>

<!-- org.jboss.arquillian -->
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-spi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-test-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-test-spi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-test-impl-base</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-spi</artifactId>
<scope>compile</scope>
</dependency>

<!-- servlet api -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>${version.servlet-api}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-impl-base</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${version.jetty_jetty}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${version.jetty_jetty}</version>
<scope>test</scope>
</dependency>
</dependencies>

<!-- The test -->
<profiles>
<!-- Need to skip test compilation for Java8 and earlier since jetty-server is compiled under Java11 -->
<profile>
<id>jdk8</id>
<activation>
<jdk>[,9)</jdk>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>jdk11</id>
<activation>
<jdk>[11,)</jdk>
</activation>
<properties>
<!-- The tests need to be build and run the Java 11 due to the fact that jetty 11.x which
supports the Java EE 9 apis requires Java 11
-->
<maven.compiler.testSource>11</maven.compiler.testSource>
<maven.compiler.testTarget>11</maven.compiler.testTarget>
</properties>
</profile>
</profiles>
</project>
@@ -0,0 +1,66 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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 org.jboss.arquillian.protocol.servlet5;

import java.util.Collection;
import org.jboss.arquillian.container.spi.client.protocol.ProtocolDescription;
import org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext;
import org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData;
import org.jboss.arquillian.container.test.spi.client.protocol.Protocol;
import org.jboss.arquillian.container.test.spi.command.CommandCallback;

/**
* BaseServletProtocol
*
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
* @version $Revision: $
*/
public abstract class BaseServletProtocol implements Protocol<ServletProtocolConfiguration> {
/* (non-Javadoc)
* @see org.jboss.arquillian.spi.client.protocol.Protocol#getProtocolConfigurationClass()
*/
@Override
public Class<ServletProtocolConfiguration> getProtocolConfigurationClass() {
return ServletProtocolConfiguration.class;
}

/* (non-Javadoc)
* @see org.jboss.arquillian.spi.client.protocol.Protocol#getDescription()
*/
@Override
public ProtocolDescription getDescription() {
return new ProtocolDescription(getProtcolName());
}

/* (non-Javadoc)
* @see org.jboss.arquillian.spi.client.protocol.Protocol#getExecutor(org.jboss.arquillian.spi.client.protocol.ProtocolConfiguration, org.jboss.arquillian.spi.client.protocol.metadata.ProtocolMetaData)
*/
@Override
public ServletMethodExecutor getExecutor(ServletProtocolConfiguration protocolConfiguration,
ProtocolMetaData metaData, CommandCallback callback) {
Collection<HTTPContext> contexts = metaData.getContexts(HTTPContext.class);
if (contexts.size() == 0) {
throw new IllegalArgumentException(
"No " + HTTPContext.class.getName() + " found in " + ProtocolMetaData.class.getName() + ". " +
"Servlet protocol can not be used");
}
return new ServletMethodExecutor(protocolConfiguration, contexts, callback);
}

protected abstract String getProtcolName();
}
@@ -0,0 +1,44 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2009 Red Hat Inc. and/or its affiliates and other contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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 org.jboss.arquillian.protocol.servlet5;

import java.util.Collection;
import org.jboss.arquillian.container.test.spi.TestDeployment;
import org.jboss.arquillian.container.test.spi.client.deployment.ProtocolArchiveProcessor;
import org.jboss.shrinkwrap.api.Archive;

/**
* Processor
*
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
* @version $Revision: $
*/
public class Processor {
private TestDeployment deployment;
private Collection<ProtocolArchiveProcessor> processors;

public Processor(TestDeployment deployment, Collection<ProtocolArchiveProcessor> processors) {
this.deployment = deployment;
this.processors = processors;
}

public void process(Archive<?> protocol) {
for (ProtocolArchiveProcessor processor : processors) {
processor.process(deployment, protocol);
}
}
}
@@ -0,0 +1,40 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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 org.jboss.arquillian.protocol.servlet5;

import org.jboss.arquillian.container.test.spi.client.protocol.Protocol;
import org.jboss.arquillian.core.spi.LoadableExtension;
import org.jboss.arquillian.protocol.servlet5.runner.ServletContextResourceProvider;
import org.jboss.arquillian.test.spi.enricher.resource.ResourceProvider;

/**
* ServletExtension
*
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
* @version $Revision: $
*/
public class Servlet5Extension implements LoadableExtension {
@Override
public void register(ExtensionBuilder builder) {
builder.service(Protocol.class, org.jboss.arquillian.protocol.servlet5.v_5.ServletProtocol.class);

if (Validate.classExists("jakarta.servlet.ServletContext")) {
builder.service(ResourceProvider.class, ServletContextResourceProvider.class);
}
}
}