[
https://issues.apache.org/jira/browse/CXF-8801?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
panda2021 updated CXF-8801:
---------------------------
Attachment: image-2022-12-09-19-59-12-250.png
> BaseUrl contains usless '/' causing AssertionError When generated unformatted
> service listing
> ---------------------------------------------------------------------------------------------
>
> Key: CXF-8801
> URL: https://issues.apache.org/jira/browse/CXF-8801
> Project: CXF
> Issue Type: Bug
> Environment: windows10,maven 3.6.1,jdk1.8,
> Reporter: panda2021
> Priority: Minor
> Fix For: 3.5.2
>
> Attachments: image-2022-12-09-19-15-51-793.png,
> image-2022-12-09-19-32-58-892.png, image-2022-12-09-19-33-26-948.png,
> image-2022-12-09-19-40-31-329.png, image-2022-12-09-19-41-48-802.png,
> image-2022-12-09-19-58-05-156.png, image-2022-12-09-19-59-12-250.png
>
>
> When I looked at the CXF project code, I found that there might be a bug in
> org.apache.cxf.transport.servlet.BaseUrlHelper.getBaseURL.
> !image-2022-12-09-19-16-17-418.png!
> if the request.url was
> [http://localhost:8080/services/|http://localhost:8080/services/,] and the
> url-pattern was `<url-pattern>/service/*</url-pattern>`, the pathInfo would
> be '/' which result in the *rePrefix* be
> [http://localhost:8080/services/|http://localhost:8080/services/,].
> When I looking at the class that uses this method, I found two calls.
> org.apache.cxf.jaxrs.utils.toAbsoluteUri used getBaseURL and concatenated
> with an extra parameter, but toAbsoluteUri was not used in HTTP request so
> that less impact.
> !image-2022-12-09-19-32-58-892.png!
> !image-2022-12-09-19-33-26-948.png!
> The other call was in
> org.apache.cxf.transport.servlet.ServletController.getBaseURL.
> I simulated a test case and reported the following error:
> the use case was:
>
> {code:java}
> // code placeholder
> @Test
> public void testGenerateUnformattedServiceListing1() throws Exception {
> req.getPathInfo();
> EasyMock.expectLastCall().andReturn("/").anyTimes();
> req.getContextPath();
> EasyMock.expectLastCall().andReturn("").anyTimes();
> req.getServletPath();
> EasyMock.expectLastCall().andReturn("/services").anyTimes();
> req.getRequestURI();
> EasyMock.expectLastCall().andReturn("/services/").times(2);
> req.getParameter("stylesheet");
> EasyMock.expectLastCall().andReturn(null);
> req.getParameter("formatted");
> EasyMock.expectLastCall().andReturn("false");
> req.getRequestURL();
> EasyMock.expectLastCall().andReturn(new
> StringBuffer("http://localhost:8080/services/"));
> req.setAttribute(Message.BASE_PATH, "http://localhost:8080");
> EasyMock.expectLastCall().anyTimes();
> registry.getDestinationsPaths();
> EasyMock.expectLastCall().andReturn(Collections.emptySet()).atLeastOnce();
> registry.getDestinationForPath("/", true);
> EasyMock.expectLastCall().andReturn(null).anyTimes();
> expectServiceListGeneratorCalled();
> EasyMock.replay(req, registry, serviceListGenerator);
> TestServletController sc = new TestServletController(registry,
> serviceListGenerator);
> sc.invoke(req, res);
> assertFalse(sc.invokeDestinationCalled());
> } {code}
> the errors:
>
>
> {code:java}
> java.lang.AssertionError:
> Unexpected method call
> HttpServletRequest.setAttribute("org.apache.cxf.message.Message.BASE_PATH",
> "http://localhost:8080/services/"):
> HttpServletRequest.getParameter("stylesheet"): expected: 1, actual: 0
> HttpServletRequest.getParameter("formatted"): expected: 1, actual: 0
> at
> org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:44)
> at
> org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:102)
> at com.sun.proxy.$Proxy4.setAttribute(Unknown Source)
> at
> org.apache.cxf.transport.servlet.ServletController.setBaseURLAttribute(ServletController.java:78)
> at
> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:176)
> at
> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
> at
> org.apache.cxf.transport.servlet.ServletControllerTest.testGenerateUnformattedServiceListing1(ServletControllerTest.java:139)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:498)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
> at
> org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
> at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
> at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
> at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
> at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
> at
> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
> at
> com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
> at
> com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
> at
> com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
> at
> com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
> at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54) {code}
>
>
> I was trying to optimize
> org.apache.cxf.transport.servlet.BaseUrlHelper.getBaseURL by adding a
> judgment to avoid this problem, and it doesn't affect the original use case.
> {code:java}
> if (!"/".equals(pathInfo) || reqPrefix.contains(";") ||
> reqPrefix.endsWith("/")){code}
> But the new case still throwed exception
> !image-2022-12-09-19-58-05-156.png!
>
>
>
>
>
>
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)