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

Bug Report: ModelValidationException when resource class and its inte… #4849

Open
wants to merge 4 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021 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 @@ -103,9 +103,14 @@ private void checkIntersectingMediaTypes(
}

if (consumesFails && producesFails) {
// fatal
Errors.fatal(runtimeResource, LocalizationMessages.AMBIGUOUS_FATAL_RMS(httpMethod, m1.getInvocable()
.getHandlingMethod(), m2.getInvocable().getHandlingMethod(), runtimeResource.getRegex()));
boolean interfaceM1 = isInterface(m1);
boolean interfaceM2 = isInterface(m2);
// Fails when both are interfaces or both are not interfaces
if (interfaceM1 == interfaceM2) {
// fatal
Errors.fatal(runtimeResource, LocalizationMessages.AMBIGUOUS_FATAL_RMS(httpMethod, m1.getInvocable()
.getHandlingMethod(), m2.getInvocable().getHandlingMethod(), runtimeResource.getRegex()));
}
} else if ((producesFails && consumesOnlyIntersects)
|| (consumesFails && producesOnlyIntersects)
|| (consumesOnlyIntersects && producesOnlyIntersects)) {
Expand All @@ -122,6 +127,10 @@ private void checkIntersectingMediaTypes(
}
}

private boolean isInterface(ResourceMethod m1) {
return m1.getData().getInvocable().getHandler().getHandlerClass().isInterface();
}

private static final List<MediaType> StarTypeList = Arrays.asList(new MediaType("*", "*"));

private List<MediaType> getEffectiveInputTypes(final ResourceMethod resourceMethod) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2021 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.e2e.server;

import static org.junit.Assert.assertEquals;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;

public class Issue4780Resource1Test extends JerseyTest {

// 1 interface and 1 implementation having same @Path
@Test
public void resource1() throws Exception {
Response response = target().path("/resource1").request().get();
response.bufferEntity();
assertEquals(response.readEntity(String.class), 200, response.getStatus());
}

@Override
protected Application configure() {
return new ResourceConfig(Resource1_1.class, IResource1_2.class);
}

@Path("")
public static class Resource1_1 implements IResource1_2 {
@GET
@Path("/resource1")
@Override
public String get() {
return "";
}
}

@Path("")
public static interface IResource1_2 {
@GET
@Path("/resource1")
String get();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2021 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.e2e.server;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.model.ModelValidationException;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;

public class Issue4780Resource2Test {

// 2 interfaces having same @Path
@Test(expected = ModelValidationException.class)
public void resource2() throws Exception {
JerseyTest test = new JerseyTest(new ResourceConfig(IResource2_1.class, IResource2_2.class)) {};
try {
test.setUp();
} finally {
test.tearDown();
}
}

@Path("")
public static interface IResource2_1 {
@GET
@Path("/resource2")
String get();
}

@Path("")
public static interface IResource2_2 {
@GET
@Path("/resource2")
String get();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2021 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.e2e.server;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.model.ModelValidationException;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;

public class Issue4780Resource3Test {

// 2 classes having same @Path
@Test(expected = ModelValidationException.class)
public void resource3() throws Exception {
JerseyTest test = new JerseyTest(new ResourceConfig(Resource3_1.class, Resource3_2.class)) {};
try {
test.setUp();
} finally {
test.tearDown();
}
}

@Path("")
public static class Resource3_1 {
@GET
@Path("/resource3")
public String get() {
return "";
}
}

@Path("")
public static class Resource3_2 {
@GET
@Path("/resource3")
public String get() {
return "";
}
}

}