[ https://issues.apache.org/jira/browse/CXF-7670?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16402315#comment-16402315 ]
ASF GitHub Bot commented on CXF-7670: ------------------------------------- andymc12 closed pull request #388: [CXF-7670] create a single ClassResourceInfo per class + annotated method URL: https://github.com/apache/cxf/pull/388 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/core/src/main/java/org/apache/cxf/helpers/DOMUtils.java b/core/src/main/java/org/apache/cxf/helpers/DOMUtils.java index a8da8197fdb..5b793673799 100644 --- a/core/src/main/java/org/apache/cxf/helpers/DOMUtils.java +++ b/core/src/main/java/org/apache/cxf/helpers/DOMUtils.java @@ -99,6 +99,7 @@ private static DocumentBuilder getDocumentBuilder() throws ParserConfigurationEx DocumentBuilderFactory f = DocumentBuilderFactory.newInstance(); f.setNamespaceAware(true); f.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true); + f.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); return f.newDocumentBuilder(); } DocumentBuilder factory = DOCUMENT_BUILDERS.get(loader); @@ -106,6 +107,7 @@ private static DocumentBuilder getDocumentBuilder() throws ParserConfigurationEx DocumentBuilderFactory f2 = DocumentBuilderFactory.newInstance(); f2.setNamespaceAware(true); f2.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true); + f2.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); factory = f2.newDocumentBuilder(); DOCUMENT_BUILDERS.put(loader, factory); } diff --git a/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java b/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java index f9d1ff51819..a9de4123ac7 100644 --- a/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java +++ b/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java @@ -115,6 +115,11 @@ static { AEGIS_DOCUMENT_BUILDER_FACTORY = DocumentBuilderFactory.newInstance(); AEGIS_DOCUMENT_BUILDER_FACTORY.setNamespaceAware(true); + try { + AEGIS_DOCUMENT_BUILDER_FACTORY.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true); + } catch (javax.xml.parsers.ParserConfigurationException ex) { + // ignore + } String path = "/META-INF/cxf/aegis.xsd"; InputStream is = XMLTypeCreator.class.getResourceAsStream(path); diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java index 8f4316c489e..0f044e85d3b 100644 --- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java +++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java @@ -311,44 +311,55 @@ private static void evaluateResourceClass(ClassResourceInfo cri, boolean enableS MethodDispatcher md = new MethodDispatcher(); Class<?> serviceClass = cri.getServiceClass(); + final Set<Method> annotatedMethods = new HashSet<>(); + for (Method m : serviceClass.getMethods()) { Method annotatedMethod = AnnotationUtils.getAnnotatedMethod(serviceClass, m); - String httpMethod = AnnotationUtils.getHttpMethodValue(annotatedMethod); - Path path = AnnotationUtils.getMethodAnnotation(annotatedMethod, Path.class); + if (!annotatedMethods.contains(annotatedMethod)) { + evaluateResourceMethod(cri, enableStatic, md, m, annotatedMethod); + annotatedMethods.add(annotatedMethod); + } - if (httpMethod != null || path != null) { - if (!checkAsyncResponse(annotatedMethod)) { - continue; - } + } + cri.setMethodDispatcher(md); + } + + private static void evaluateResourceMethod(ClassResourceInfo cri, boolean enableStatic, MethodDispatcher md, + Method m, Method annotatedMethod) { + String httpMethod = AnnotationUtils.getHttpMethodValue(annotatedMethod); + Path path = AnnotationUtils.getMethodAnnotation(annotatedMethod, Path.class); + + if (httpMethod != null || path != null) { + if (!checkAsyncResponse(annotatedMethod)) { + return; + } - md.bind(createOperationInfo(m, annotatedMethod, cri, path, httpMethod), m); - if (httpMethod == null) { - // subresource locator - Class<?> subClass = m.getReturnType(); - if (subClass == Class.class) { - subClass = InjectionUtils.getActualType(m.getGenericReturnType()); + md.bind(createOperationInfo(m, annotatedMethod, cri, path, httpMethod), m); + if (httpMethod == null) { + // subresource locator + Class<?> subClass = m.getReturnType(); + if (subClass == Class.class) { + subClass = InjectionUtils.getActualType(m.getGenericReturnType()); + } + if (enableStatic) { + ClassResourceInfo subCri = cri.findResource(subClass, subClass); + if (subCri == null) { + ClassResourceInfo ancestor = getAncestorWithSameServiceClass(cri, subClass); + subCri = ancestor != null ? ancestor + : createClassResourceInfo(subClass, subClass, cri, false, enableStatic, + cri.getBus()); } - if (enableStatic) { - ClassResourceInfo subCri = cri.findResource(subClass, subClass); - if (subCri == null) { - ClassResourceInfo ancestor = getAncestorWithSameServiceClass(cri, subClass); - subCri = ancestor != null ? ancestor - : createClassResourceInfo(subClass, subClass, cri, false, enableStatic, - cri.getBus()); - } - if (subCri != null) { - cri.addSubClassResourceInfo(subCri); - } + if (subCri != null) { + cri.addSubClassResourceInfo(subCri); } } - } else { - reportInvalidResourceMethod(m, NOT_RESOURCE_METHOD_MESSAGE_ID, Level.FINE); } + } else { + reportInvalidResourceMethod(m, NOT_RESOURCE_METHOD_MESSAGE_ID, Level.FINE); } - cri.setMethodDispatcher(md); } private static void reportInvalidResourceMethod(Method m, String messageId, Level logLevel) { diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java index 9d6d9b30839..e98725d3676 100644 --- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java +++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java @@ -162,6 +162,48 @@ public void testClassResourceInfoWithOverride() throws Exception { assertEquals("GET", ori.getHttpMethod()); } + @Path("/synth-hello") + protected interface SyntheticHelloInterface<T> { + @GET + @Path("/{name}") + T getById(@PathParam("name") T name); + } + + protected abstract static class AbstractSyntheticHello implements SyntheticHelloInterface<String> { + public abstract String getById(String name); + } + + public static class SyntheticHelloInterfaceImpl + extends AbstractSyntheticHello + implements SyntheticHelloInterface<String> { + @Override + public String getById(String name) { + return "Hello " + name + "!"; + } + } + + @Test + public void testClassResourceInfoWithSyntheticMethod() throws Exception { + ClassResourceInfo cri = + ResourceUtils.createClassResourceInfo( + SyntheticHelloInterfaceImpl.class, + SyntheticHelloInterfaceImpl.class, + true, + true); + + Method synthetic = SyntheticHelloInterfaceImpl.class.getMethod("getById", new Class[]{Object.class}); + assertTrue(synthetic.isSynthetic()); + + assertNotNull(cri); + Method notSynthetic = SyntheticHelloInterfaceImpl.class.getMethod("getById", new Class[]{String.class}); + assertFalse(notSynthetic.isSynthetic()); + + cri.hasSubResources(); + assertEquals("there must be only one method, which is the getById(String)", + 1, + cri.getMethodDispatcher().getOperationResourceInfos().size()); + } + @Test public void shouldCreateApplicationWhichInheritsApplicationPath() throws Exception { JAXRSServerFactoryBean application = ResourceUtils.createApplication( diff --git a/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java b/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java index d98728bf06d..e343e870fec 100755 --- a/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java +++ b/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java @@ -224,7 +224,7 @@ public boolean isRepeatable() { Proxy p = proxyFactory.createProxy(csPolicy, uri); if (p != null && p.type() != Proxy.Type.DIRECT) { InetSocketAddress isa = (InetSocketAddress)p.address(); - HttpHost proxy = new HttpHost(isa.getHostName(), isa.getPort()); + HttpHost proxy = new HttpHost(isa.getHostString(), isa.getPort()); b.setProxy(proxy); } e.setConfig(b.build()); ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > synthetic methods: equal candidates for handling the current request > -------------------------------------------------------------------- > > Key: CXF-7670 > URL: https://issues.apache.org/jira/browse/CXF-7670 > Project: CXF > Issue Type: Bug > Components: JAX-RS > Affects Versions: 3.2.1, 3.2.2 > Environment: I have noticed this with kotlin projects. > Reporter: Laszlo Hornyak > Priority: Major > > When discovering JAX-RS annotations, CXF does not filter out synthetic > methods. If the compiler have created any synthetic methods out of the > annotated methods, it will store them as JAX-RS resource methods with > actually the same annotated method. > After startup, CXF will log each invocation on the duplicated resource > methods with a warning, which reduces performance, and generates quite some > log. -- This message was sent by Atlassian JIRA (v7.6.3#76005)