Skip to content

Commit

Permalink
merge of master into 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
senivam authored Apr 8, 2022
2 parents f6af99b + a5c83ec commit 1295a7a
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -49,6 +49,7 @@
* <li>logger level: {@link Level#FINE}</li>
* <li>verbosity: {@link Verbosity#PAYLOAD_TEXT}</li>
* <li>maximum entity size: {@value #DEFAULT_MAX_ENTITY_SIZE}</li>
* <li>line separator: {@link #DEFAULT_SEPARATOR}</li>
* </ul>
* <p>
* Server configurable properties:
Expand Down Expand Up @@ -222,7 +223,6 @@ public LoggingFeature(Logger logger, Level level, Verbosity verbosity, Integer m
.level(level)
.verbosity(verbosity)
.maxEntitySize(maxEntitySize)
.separator(DEFAULT_SEPARATOR)
);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -305,7 +305,7 @@ public void write(byte[] ba, int off, int len) throws IOException {
if ((off | len | ba.length - (len + off) | off + len) < 0) {
throw new IndexOutOfBoundsException();
}
if ((baos.size() + len) <= maxEntitySize) {
if (baos.size() <= maxEntitySize) {
baos.write(ba, off, len);
}
out.write(ba, off, len);
Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/docbook/jersey.ent
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@
<!ENTITY lit.jersey.logging.LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_CLIENT "<literal>LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_CLIENT</literal>">
<!ENTITY lit.jersey.logging.LoggingFeature.LOGGING_FEATURE_VERBOSITY_CLIENT "<literal>LoggingFeature.LOGGING_FEATURE_VERBOSITY_CLIENT</literal>">
<!ENTITY lit.jersey.logging.LoggingFeature.LOGGING_FEATURE_MAX_ENTITY_SIZE_CLIENT "<literal>LoggingFeature.LOGGING_FEATURE_MAX_ENTITY_SIZE_CLIENT</literal>">
<!ENTITY lit.jersey.logging.LoggingFeature.LOGGING_FEATURE_SEPARATOR_CLIENT "<literal>LoggingFeature.LOGGING_FEATURE_SEPARATORE_CLIENT</literal>">
<!ENTITY lit.jersey.logging.LoggingFeature.LOGGING_FEATURE_SEPARATOR_CLIENT "<literal>LoggingFeature.LOGGING_FEATURE_SEPARATOR_CLIENT</literal>">
<!ENTITY lit.jersey.logging.LoggingFeature.LOGGING_FEATURE_LOGGER_NAME_SERVER "<literal>LoggingFeature.LOGGING_FEATURE_LOGGER_NAME_SERVER</literal>">
<!ENTITY lit.jersey.logging.LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_SERVER "<literal>LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_SERVER</literal>">
<!ENTITY lit.jersey.logging.LoggingFeature.LOGGING_FEATURE_VERBOSITY_SERVER "<literal>LoggingFeature.LOGGING_FEATURE_VERBOSITY_SERVER</literal>">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018 Payara Foundation and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -41,6 +41,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import jakarta.enterprise.inject.Vetoed;
import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.enterprise.inject.spi.BeforeBeanDiscovery;
import jakarta.inject.Singleton;
Expand Down Expand Up @@ -292,6 +293,10 @@ private boolean bind(final Class<?> clazz, final Set<Class<?>> providerContracts
return false;
}

if (clazz.isAnnotationPresent(Vetoed.class)) {
return false;
}

if (isJerseyOrDependencyType(clazz)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -269,11 +269,9 @@ public void testLoggingFeatureBuilderSeparator() {
@Test
public void testLoggingFeatureBuilderProperty() {
final Response response = target("/text")
.register(LoggingFeature
.builder()
.withLogger(Logger.getLogger(LOGGER_NAME))
.build()
).property(LoggingFeature.LOGGING_FEATURE_SEPARATOR, SEPARATOR)
.register(LoggingFeature.class)
.property(LoggingFeature.LOGGING_FEATURE_LOGGER_NAME, LOGGER_NAME)
.property(LoggingFeature.LOGGING_FEATURE_SEPARATOR, SEPARATOR)
.request()
.post(Entity.text(ENTITY));

Expand All @@ -284,6 +282,23 @@ public void testLoggingFeatureBuilderProperty() {
assertThat(record.getMessage(), containsString(SEPARATOR));
}

@Test
public void testLoggingFeatureMaxEntitySize() {
final Response response = target("/text")
.register(LoggingFeature.class)
.property(LoggingFeature.LOGGING_FEATURE_LOGGER_NAME, LOGGER_NAME)
.property(LoggingFeature.LOGGING_FEATURE_MAX_ENTITY_SIZE, 1)
.request()
.post(Entity.text(ENTITY));

// Correct response status.
assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
// Check logs for trimmedEntity.
String trimmedEntity = ENTITY.charAt(0) + "...more...";
List<LogRecord> logRecords = getLoggedRecords();
assertThat(getLoggingFilterRequestLogRecord(logRecords).getMessage(), containsString(trimmedEntity));
assertThat(getLoggingFilterResponseLogRecord(logRecords).getMessage(), containsString(trimmedEntity));
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.jersey.tests.cdi.resources;

import org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.jboss.weld.environment.se.Weld;
import org.junit.Test;

import jakarta.enterprise.inject.Vetoed;
import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.enterprise.inject.spi.CDI;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Application;
import java.util.Collections;

import static org.junit.Assert.assertFalse;

public class CdiComponentProviderTest extends JerseyTest {
Weld weld;

@Override
public void setUp() throws Exception {
weld = new Weld();
weld.initialize();
super.setUp();
}

@Override
public void tearDown() throws Exception {
weld.shutdown();
super.tearDown();
}

@Override
protected Application configure() {
return new ResourceConfig();
}

@Test
public void testVetoedClassIsNotBound() {
BeanManager beanManager = CDI.current().getBeanManager();
CdiComponentProvider provider = beanManager.getExtension(CdiComponentProvider.class);
assertFalse(provider.bind(VetoedResourceClass.class, Collections.singleton(Path.class)));
}

@Test
public void testInterfaceIsNotBound() {
BeanManager beanManager = CDI.current().getBeanManager();
CdiComponentProvider provider = beanManager.getExtension(CdiComponentProvider.class);
assertFalse(provider.bind(InterfaceResource.class, Collections.singleton(Path.class)));
}

@Path("/vetoed")
@Vetoed
public static class VetoedResourceClass {
@GET
public String get() {
return null;
}
}

@Path("/iface")
public static interface InterfaceResource {
@GET
public String get();
}
}

0 comments on commit 1295a7a

Please sign in to comment.