Skip to content

Commit

Permalink
[RESTEASY-3379] Initial work with version of Jakarta REST 4.0
Browse files Browse the repository at this point in the history
https://issues.redhat.com/browse/RESTEASY-3379
Signed-off-by: James R. Perkins <jperkins@redhat.com>
  • Loading branch information
jamezp committed Apr 2, 2024
1 parent a45dd4c commit a6f15eb
Show file tree
Hide file tree
Showing 38 changed files with 247 additions and 97 deletions.
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,23 @@
<maven.test.redirectTestOutputToFile>false</maven.test.redirectTestOutputToFile>
</properties>
</profile>
<!-- Enable only with caution and delete download artifacts when completed -->
<profile>
<id>jakarta-staging</id>
<repositories>
<repository>
<id>jakarta-sonatype-nexus-staging</id>
<name>Jakarta Sonatype Nexus Staging</name>
<url>https://jakarta.oss.sonatype.org/content/repositories/staging/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>

<contributors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.function.Predicate;

import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientRequestContext;
Expand Down Expand Up @@ -198,6 +199,19 @@ public String getHeaderString(String name) {
return invocation.getHeaders().getHeader(name);
}

@Override
public boolean containsHeaderString(final String name, final Predicate<String> valuePredicate) {
// TODO (jrp) implement
throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public boolean containsHeaderString(final String name, final String valueSeparatorRegex,
final Predicate<String> valuePredicate) {
// TODO (jrp) implement
throw new UnsupportedOperationException("Not yet implemented");
}

/**
* exposes the client invocation for easier integration with other libraries
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;

import jakarta.ws.rs.client.ClientResponseContext;
import jakarta.ws.rs.core.EntityTag;
Expand Down Expand Up @@ -138,6 +139,19 @@ public String getHeaderString(String name) {
return response.getHeaderString(name);
}

@Override
public boolean containsHeaderString(final String name, final Predicate<String> valuePredicate) {
// TODO (jrp) implement
throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public boolean containsHeaderString(final String name, final String valueSeparatorRegex,
final Predicate<String> valuePredicate) {
// TODO (jrp) implement
throw new UnsupportedOperationException("Not yet implemented");
}

// hack for MP exception mapping. TODO revisit this implementation
public ClientResponse getClientResponse() {
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,11 @@ protected void doComplete() {
// we can be done by exception before we've even subscribed
if (subscription != null)
subscription.cancel();
sseEventSink.close();
try {
sseEventSink.close();
} catch (IOException e) {
complete(e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Predicate;

import jakarta.ws.rs.container.ContainerResponseFilter;
import jakarta.ws.rs.core.EntityTag;
Expand Down Expand Up @@ -257,6 +258,19 @@ public String getHeaderString(String name) {
return jaxrsResponse.getHeaderString(name);
}

@Override
public boolean containsHeaderString(final String name, final Predicate<String> valuePredicate) {
// TODO (jrp) implement
throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public boolean containsHeaderString(final String name, final String valueSeparatorRegex,
final Predicate<String> valuePredicate) {
// TODO (jrp) implement
throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public synchronized void suspend() {
if (continuation == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.function.Predicate;
import java.util.function.Supplier;

import jakarta.ws.rs.container.ContainerRequestFilter;
Expand Down Expand Up @@ -198,6 +199,19 @@ public String getHeaderString(String name) {
return httpRequest.getHttpHeaders().getHeaderString(name);
}

@Override
public boolean containsHeaderString(final String name, final Predicate<String> valuePredicate) {
// TODO (jrp) implement
throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public boolean containsHeaderString(final String name, final String valueSeparatorRegex,
final Predicate<String> valuePredicate) {
// TODO (jrp) implement
throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public synchronized void suspend() {
if (continuation == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public void close(final boolean cascading) {
writeLock.lock();
try {
//Javadoc says close the broadcaster and all subscribed {@link SseEventSink} instances.
//is it necessay to close the subsribed SseEventSink ?
//is it necessary to close the subscribed SseEventSink ?
outputQueue.forEach(eventSink -> {
try {
eventSink.close();
} catch (RuntimeException e) {
} catch (IOException | RuntimeException e) {
LogMessages.LOGGER.debug(e.getLocalizedMessage());
} finally {
notifyOnCloseListeners(eventSink);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.function.Predicate;

import jakarta.ws.rs.core.Cookie;
import jakarta.ws.rs.core.HttpHeaders;
Expand Down Expand Up @@ -149,6 +150,19 @@ public String getHeaderString(String name) {
return builder.toString();
}

@Override
public boolean containsHeaderString(final String name, final Predicate<String> valuePredicate) {
// TODO (jrp) implement
throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public boolean containsHeaderString(final String name, final String valueSeparatorRegex,
final Predicate<String> valuePredicate) {
// TODO (jrp) implement
throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public Locale getLanguage() {
String obj = requestHeaders.getFirst(HttpHeaders.CONTENT_LANGUAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ public URI relativize(URI uri) {
return ResteasyUriBuilderImpl.relativize(from, to);
}

@Override
public String getMatchedResourceTemplate() {
throw new UnsupportedOperationException("Not yet implemented");
}

/**
* Holds the data that is needed to initialize ResteasyUriInfo
* The reason to extract this data into a separate class is that it's expensive
Expand Down
2 changes: 1 addition & 1 deletion resteasy-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<version.jakarta.ejb.ejb-api>4.0.1</version.jakarta.ejb.ejb-api>
<version.jakarta.interceptor.interceptor-api>2.1.0</version.jakarta.interceptor.interceptor-api>
<version.jakarta.jms.jms-api>3.1.0</version.jakarta.jms.jms-api>
<version.jakarta.ws.rs>3.1.0</version.jakarta.ws.rs>
<version.jakarta.ws.rs>4.0.0</version.jakarta.ws.rs>
<version.jakarta.xml.bind.bind-api>3.0.1</version.jakarta.xml.bind.bind-api>
<version.jakarta.servlet.servlet-api>6.0.0</version.jakarta.servlet.servlet-api>
<version.org.mockito>5.10.0</version.org.mockito>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package dev.resteasy.embedded.server;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collections;
Expand Down Expand Up @@ -316,7 +317,13 @@ public CompletionStage<?> sse(@Context final SseEventSink eventSink) {
throw new WebApplicationException("No client connected.");
}
return eventSink.send(sse.newEvent("test"))
.whenComplete((BiConsumer<Object, Throwable>) (unused, throwable) -> eventSink.close());
.whenComplete((BiConsumer<Object, Throwable>) (unused, throwable) -> {
try {
eventSink.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}

@GET
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.jboss.resteasy.test.asyncio;

import java.io.IOException;
import java.io.UncheckedIOException;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
Expand Down Expand Up @@ -30,28 +33,32 @@ public void reset(@Context SseEventSink sink, @Context Sse sse) {
public void send(@Context SseEventSink sink, @Context Sse sse) {
Thread t = new Thread(new Runnable() {
public void run() {
SseEventSink s = sink;
s.send(sse.newEvent("HELLO"));
s.close();
isClosed = s.isClosed();
if (!isClosed)
return;
s.close();
isClosed = s.isClosed();
if (!isClosed)
return;
s.close();
isClosed = s.isClosed();
if (!isClosed)
return;
try {
s.send(sse.newEvent("SOMETHING")).exceptionally(t -> {
if (t instanceof IllegalStateException)
exception = true;
return null;
});
} catch (IllegalStateException ise) {
exception = true;
SseEventSink s = sink;
s.send(sse.newEvent("HELLO"));
s.close();
isClosed = s.isClosed();
if (!isClosed)
return;
s.close();
isClosed = s.isClosed();
if (!isClosed)
return;
s.close();
isClosed = s.isClosed();
if (!isClosed)
return;
try {
s.send(sse.newEvent("SOMETHING")).exceptionally(t -> {
if (t instanceof IllegalStateException)
exception = true;
return null;
});
} catch (IllegalStateException ise) {
exception = true;
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ public static URI generateUri(final URI base, final String path) throws URISynta
}

/**
* Creates a {@code beans.xml} file which uses a {@code bean-discovery-mode} of "all".
* Creates a {@code beans.xml} file which uses a {@code bean-discovery-mode} of "annotated".
*
* @return a {@code beans.xml} asset
*/
Expand All @@ -561,7 +561,7 @@ public static Asset createBeansXml() {
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
" xsi:schemaLocation=\"https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_4_0.xsd\"\n"
+
" version=\"4.0\" bean-discovery-mode=\"all\">\n" +
" version=\"4.0\" bean-discovery-mode=\"annotated\">\n" +
"</beans>");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import jakarta.ejb.Asynchronous;
import jakarta.ejb.Stateless;
import jakarta.enterprise.context.Dependent;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
Expand All @@ -14,6 +15,7 @@
import jakarta.ws.rs.core.Response;

@Stateless
@Dependent
@Path("/")
public class AsynchronousResource {
@Inject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.jboss.resteasy.test.cdi.basic.resource;

import jakarta.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class BeanReaderWriterConfigBean {
public String version() {
return "1.1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.jboss.arquillian.junit5.ArquillianExtension;
import org.jboss.logging.Logger;
import org.jboss.resteasy.spi.HttpResponseCodes;
import org.jboss.resteasy.test.cdi.inheritence.resource.BookProducer;
import org.jboss.resteasy.test.cdi.inheritence.resource.CDIInheritenceBook;
import org.jboss.resteasy.test.cdi.inheritence.resource.CDIInheritenceInheritanceResource;
import org.jboss.resteasy.test.cdi.inheritence.resource.CDIInheritenceSelectBook;
Expand Down Expand Up @@ -39,7 +40,7 @@ public class VanillaInheritanceTest {
public static Archive<?> createTestArchive() {
WebArchive war = TestUtil.prepareArchive(VanillaInheritanceTest.class.getSimpleName());
war.addClasses(UtilityProducer.class, CDIInheritenceBook.class, CDIInheritenceSelectBook.class,
CDIInheritenceInheritanceResource.class)
CDIInheritenceInheritanceResource.class, BookProducer.class)
.addAsWebInfResource(TestUtil.createBeansXml(), "beans.xml");
return TestUtil.finishContainerPrepare(war, null, (Class<?>[]) null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2024 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.resteasy.test.cdi.inheritence.resource;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;

/**
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
@ApplicationScoped
public class BookProducer {

@CDIInheritenceSelectBook
@Produces
public CDIInheritenceBook book() {
return new CDIInheritenceBook();
}
}

0 comments on commit a6f15eb

Please sign in to comment.