You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2025/03/01 12:58:07 UTC
(olingo-odata2) 19/29: use java 8
This is an automated email from the ASF dual-hosted git repository.
mibo pushed a commit to branch OLINGO-1636-jdk_upgrade
in repository https://gitbox.apache.org/repos/asf/olingo-odata2.git
commit 0872ed9bb28b6ad769dadfdc5d9bd6705fea7ce7
Author: Iliyan Velichkov <ve...@gmail.com>
AuthorDate: Wed Dec 13 14:42:01 2023 +0200
use java 8
Signed-off-by: Iliyan Velichkov <ve...@gmail.com>
---
odata2-jpa-processor/jpa-core/pom.xml | 5 +-
.../olingo/odata2/core/commons/XmlHelperTest.java | 366 ++++++++++-----------
odata2-lib/odata-testutil/pom.xml | 1 +
.../src/main/resources/archetype-resources/pom.xml | 5 +-
.../src/main/resources/archetype-resources/pom.xml | 4 +-
pom.xml | 5 +-
6 files changed, 188 insertions(+), 198 deletions(-)
diff --git a/odata2-jpa-processor/jpa-core/pom.xml b/odata2-jpa-processor/jpa-core/pom.xml
index ee4d22cd..47d162a3 100644
--- a/odata2-jpa-processor/jpa-core/pom.xml
+++ b/odata2-jpa-processor/jpa-core/pom.xml
@@ -69,8 +69,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
- <source>17</source>
- <target>17</target>
+ <source>1.8</source>
+ <target>1.8</target>
+ <verbose>true</verbose>
</configuration>
</plugin>
</plugins>
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/XmlHelperTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/XmlHelperTest.java
index e633e66a..56c184d3 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/XmlHelperTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/XmlHelperTest.java
@@ -1,20 +1,16 @@
/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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
- *
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to you 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.
+ *
+ * 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.apache.olingo.odata2.core.commons;
@@ -22,16 +18,13 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
-
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
-
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.ep.EntityProvider;
import org.apache.olingo.odata2.api.ep.EntityProviderException;
@@ -41,202 +34,195 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
-
import com.ctc.wstx.exc.WstxParsingException;
public class XmlHelperTest {
- public static String XML =
- "<?xml version=\"1.0\"?>" +
- "<extract>" +
- " <data>&rules;</data>" +
- "</extract>";
-
- public static String XML_XXE =
- "<?xml version=\"1.0\"?>" +
- " <!DOCTYPE foo [" +
- " <!ENTITY rules SYSTEM \"" + XmlHelperTest.class.getResource("/xxe.xml").toString() + "\">" +
- " ]>" +
- "<extract>" +
- " <data>&rules;</data>" +
- "</extract>";
-
- public static String XML_LOL =
- "<?xml version=\"1.0\"?>" +
- " <!DOCTYPE lolz [" +
- " <!ENTITY lol \"lol\">" +
- " <!ELEMENT lolz (#PCDATA)>" +
- " <!ENTITY lol1 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">" +
- " <!ENTITY lol2 \"&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;\">" +
- " <!ENTITY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">" +
- " <!ENTITY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">" +
- " <!ENTITY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">" +
- " <!ENTITY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">" +
- " <!ENTITY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">" +
- " <!ENTITY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">" +
- " <!ENTITY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">" +
- " ]>" +
- " <lolz>&lol9;</lolz>";
-
- public static String XML_DOCTYPE =
- "<?xml version=\"1.0\" standalone=\"yes\"?>" +
- "<!DOCTYPE hallo [<!ELEMENT hallo (#PCDATA)>]>" +
- "<hallo>Hallo Welt!</hallo>";
-
- public static String XML_PROCESSING =
- "<?xml version=\"1.0\"?>" +
- "<?apache include file=\"somefile.html\" ?>" +
- "<extract>" +
- " <data>&rules;</data>" +
- "</extract>";
-
- private static Object beforeXmlInputFactory;
-
- @BeforeClass
- public static void beforeClass() {
- // CHECKSTYLE:OFF
- System.setProperty("javax.xml.stream.XMLInputFactory", "com.ctc.wstx.stax.WstxInputFactory"); // NOSONAR
- //
- beforeXmlInputFactory = replaceXmlInputFactoryInstance(XMLInputFactory.newInstance());
- // CHECKSTYLE:ON
- }
-
- @AfterClass
- public static void afterClass() {
- replaceXmlInputFactoryInstance(beforeXmlInputFactory);
- }
-
- private static Object replaceXmlInputFactoryInstance(Object newInstance) {
- try {
- Field field = XmlHelper.XmlInputFactoryHolder.class.getDeclaredField("INSTANCE");
- field.setAccessible(true);
-
- Field modifiersField = Field.class.getDeclaredField("modifiers");
- modifiersField.setAccessible(true);
- modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
-
- Object replaced = field.get(null);
- field.set(null, newInstance);
- return replaced;
- } catch (NoSuchFieldException e) {
- throw new RuntimeException(e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
+ public static String XML = "<?xml version=\"1.0\"?>" + "<extract>" + " <data>&rules;</data>" + "</extract>";
+
+ public static String XML_XXE = "<?xml version=\"1.0\"?>"
+ + " <!DOCTYPE foo [" + " <!ENTITY rules SYSTEM \"" + XmlHelperTest.class.getResource("/xxe.xml")
+ .toString()
+ + "\">" + " ]>" + "<extract>" + " <data>&rules;</data>" + "</extract>";
+
+ public static String XML_LOL = "<?xml version=\"1.0\"?>" + " <!DOCTYPE lolz [" + " <!ENTITY lol \"lol\">"
+ + " <!ELEMENT lolz (#PCDATA)>" + " <!ENTITY lol1 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">"
+ + " <!ENTITY lol2 \"&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;\">"
+ + " <!ENTITY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">"
+ + " <!ENTITY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">"
+ + " <!ENTITY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">"
+ + " <!ENTITY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">"
+ + " <!ENTITY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">"
+ + " <!ENTITY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">"
+ + " <!ENTITY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">" + " ]>"
+ + " <lolz>&lol9;</lolz>";
+
+ public static String XML_DOCTYPE =
+ "<?xml version=\"1.0\" standalone=\"yes\"?>" + "<!DOCTYPE hallo [<!ELEMENT hallo (#PCDATA)>]>" + "<hallo>Hallo Welt!</hallo>";
+
+ public static String XML_PROCESSING = "<?xml version=\"1.0\"?>" + "<?apache include file=\"somefile.html\" ?>" + "<extract>"
+ + " <data>&rules;</data>" + "</extract>";
+
+ private static Object beforeXmlInputFactory;
+
+ @BeforeClass
+ public static void beforeClass() {
+ // CHECKSTYLE:OFF
+ System.setProperty("javax.xml.stream.XMLInputFactory", "com.ctc.wstx.stax.WstxInputFactory"); // NOSONAR
+ //
+ beforeXmlInputFactory = replaceXmlInputFactoryInstance(XMLInputFactory.newInstance());
+ // CHECKSTYLE:ON
}
- }
- @Test
- public void createReader() throws Exception {
- InputStream content = new ByteArrayInputStream(XML.getBytes("UTF-8"));
- XMLStreamReader streamReader = XmlHelper.createStreamReader(content);
- assertNotNull(streamReader);
- }
+ @AfterClass
+ public static void afterClass() {
+ replaceXmlInputFactoryInstance(beforeXmlInputFactory);
+ }
- @Test
- public void xxeWithoutProtection() throws Exception {
- InputStream content = new ByteArrayInputStream(XML_XXE.getBytes("UTF-8"));
- XMLStreamReader streamReader = createStreamReaderWithExternalEntitySupport(content);
+ private static Object replaceXmlInputFactoryInstance(Object newInstance) {
+ try {
+ Field field = XmlHelper.XmlInputFactoryHolder.class.getDeclaredField("INSTANCE");
+ field.setAccessible(true);
+
+ Field modifiersField = Field.class.getDeclaredField("modifiers");
+ modifiersField.setAccessible(true);
+ modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
+
+ Object replaced = field.get(null);
+ field.set(null, newInstance);
+ return replaced;
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
- boolean foundExternalEntity = false;
+ @Test
+ public void createReader() throws Exception {
+ InputStream content = new ByteArrayInputStream(XML.getBytes("UTF-8"));
+ XMLStreamReader streamReader = XmlHelper.createStreamReader(content);
+ assertNotNull(streamReader);
+ }
- while (streamReader.hasNext()) {
- streamReader.next();
+ @Test
+ public void xxeWithoutProtection() throws Exception {
+ InputStream content = new ByteArrayInputStream(XML_XXE.getBytes("UTF-8"));
+ XMLStreamReader streamReader = createStreamReaderWithExternalEntitySupport(content);
- if (streamReader.hasText() && "some text".equals(streamReader.getText())) {
- foundExternalEntity = true;
- break;
- }
+ boolean foundExternalEntity = false;
- }
- assertTrue(foundExternalEntity);
- }
+ while (streamReader.hasNext()) {
+ streamReader.next();
- @Test(expected = XMLStreamException.class)
- public void xxeWithProtection() throws Exception {
- InputStream content = new ByteArrayInputStream(XML_XXE.getBytes("UTF-8"));
- XMLStreamReader streamReader = XmlHelper.createStreamReader(content);
+ if (streamReader.hasText() && "some text".equals(streamReader.getText())) {
+ foundExternalEntity = true;
+ break;
+ }
- while (streamReader.hasNext()) {
- streamReader.next();
+ }
+ assertTrue(foundExternalEntity);
}
- }
-
- public XMLStreamReader createStreamReaderWithExternalEntitySupport(final InputStream content) throws Exception {
- XMLStreamReader streamReader;
- XMLInputFactory factory = XMLInputFactory.newInstance();
- factory.setProperty(XMLInputFactory.IS_VALIDATING, false);
- factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
- factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, true);
- factory.setProperty(XMLInputFactory.SUPPORT_DTD, true);
-
- streamReader = factory.createXMLStreamReader(content, "UTF-8");
- return streamReader;
- }
-
- @Test(expected = XMLStreamException.class)
- public void lolWithProtection() throws Exception {
- InputStream content = new ByteArrayInputStream(XML_LOL.getBytes("UTF-8"));
- XMLStreamReader streamReader = XmlHelper.createStreamReader(content);
-
- while (streamReader.hasNext()) {
- streamReader.next();
- }
- }
-
- @Test
- public void lolApiWithProtection() throws Exception {
- try {
- InputStream content = new ByteArrayInputStream(XML_LOL.getBytes("UTF-8"));
- EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
- EntityProvider.readEntry("application/xml", entitySet, content, EntityProviderReadProperties.init().build());
-
- fail();
- } catch (EntityProviderException e) {
- assertEquals(WstxParsingException.class, e.getCause().getClass());
- }
- }
- @Test
- public void xxeApiWithProtection() throws Exception {
- try {
- InputStream content = new ByteArrayInputStream(XML_XXE.getBytes("UTF-8"));
- EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
+ @Test(expected = XMLStreamException.class)
+ public void xxeWithProtection() throws Exception {
+ InputStream content = new ByteArrayInputStream(XML_XXE.getBytes("UTF-8"));
+ XMLStreamReader streamReader = XmlHelper.createStreamReader(content);
+
+ while (streamReader.hasNext()) {
+ streamReader.next();
+ }
+ }
- EntityProvider.readEntry("application/xml", entitySet, content, EntityProviderReadProperties.init().build());
+ public XMLStreamReader createStreamReaderWithExternalEntitySupport(final InputStream content) throws Exception {
+ XMLStreamReader streamReader;
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ factory.setProperty(XMLInputFactory.IS_VALIDATING, false);
+ factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
+ factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, true);
+ factory.setProperty(XMLInputFactory.SUPPORT_DTD, true);
- fail();
- } catch (EntityProviderException e) {
- assertEquals(WstxParsingException.class, e.getCause().getClass());
+ return factory.createXMLStreamReader(content, "UTF-8");
}
- }
- @Test
- public void xmlDoctypeApiWithProtection() throws Exception {
- try {
- InputStream content = new ByteArrayInputStream(XML_DOCTYPE.getBytes("UTF-8"));
- EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
+ @Test(expected = XMLStreamException.class)
+ public void lolWithProtection() throws Exception {
+ InputStream content = new ByteArrayInputStream(XML_LOL.getBytes("UTF-8"));
+ XMLStreamReader streamReader = XmlHelper.createStreamReader(content);
- EntityProvider.readEntry("application/xml", entitySet, content, EntityProviderReadProperties.init().build());
+ while (streamReader.hasNext()) {
+ streamReader.next();
+ }
+ }
- fail();
- } catch (EntityProviderException e) {
- assertEquals(WstxParsingException.class, e.getCause().getClass());
+ @Test
+ public void lolApiWithProtection() throws Exception {
+ try {
+ InputStream content = new ByteArrayInputStream(XML_LOL.getBytes("UTF-8"));
+ EdmEntitySet entitySet = MockFacade.getMockEdm()
+ .getDefaultEntityContainer()
+ .getEntitySet("Employees");
+ EntityProvider.readEntry("application/xml", entitySet, content, EntityProviderReadProperties.init()
+ .build());
+
+ fail();
+ } catch (EntityProviderException e) {
+ assertEquals(WstxParsingException.class, e.getCause()
+ .getClass());
+ }
}
- }
- @Test
- @Ignore("not way to disable in parser")
- public void xmlProcessingApiWithProtection() throws Exception {
- try {
- InputStream content = new ByteArrayInputStream(XML_PROCESSING.getBytes("UTF-8"));
- EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
+ @Test
+ public void xxeApiWithProtection() throws Exception {
+ try {
+ InputStream content = new ByteArrayInputStream(XML_XXE.getBytes("UTF-8"));
+ EdmEntitySet entitySet = MockFacade.getMockEdm()
+ .getDefaultEntityContainer()
+ .getEntitySet("Employees");
+
+ EntityProvider.readEntry("application/xml", entitySet, content, EntityProviderReadProperties.init()
+ .build());
+
+ fail();
+ } catch (EntityProviderException e) {
+ assertEquals(WstxParsingException.class, e.getCause()
+ .getClass());
+ }
+ }
- EntityProvider.readEntry("application/xml", entitySet, content, EntityProviderReadProperties.init().build());
+ @Test
+ public void xmlDoctypeApiWithProtection() throws Exception {
+ try {
+ InputStream content = new ByteArrayInputStream(XML_DOCTYPE.getBytes("UTF-8"));
+ EdmEntitySet entitySet = MockFacade.getMockEdm()
+ .getDefaultEntityContainer()
+ .getEntitySet("Employees");
+
+ EntityProvider.readEntry("application/xml", entitySet, content, EntityProviderReadProperties.init()
+ .build());
+
+ fail();
+ } catch (EntityProviderException e) {
+ assertEquals(WstxParsingException.class, e.getCause()
+ .getClass());
+ }
+ }
- fail();
- } catch (EntityProviderException e) {
- e.printStackTrace();
- assertEquals(WstxParsingException.class, e.getCause().getClass());
+ @Test
+ @Ignore("not way to disable in parser")
+ public void xmlProcessingApiWithProtection() throws Exception {
+ try {
+ InputStream content = new ByteArrayInputStream(XML_PROCESSING.getBytes("UTF-8"));
+ EdmEntitySet entitySet = MockFacade.getMockEdm()
+ .getDefaultEntityContainer()
+ .getEntitySet("Employees");
+
+ EntityProvider.readEntry("application/xml", entitySet, content, EntityProviderReadProperties.init()
+ .build());
+
+ fail();
+ } catch (EntityProviderException e) {
+ e.printStackTrace();
+ assertEquals(WstxParsingException.class, e.getCause()
+ .getClass());
+ }
}
- }
}
diff --git a/odata2-lib/odata-testutil/pom.xml b/odata2-lib/odata-testutil/pom.xml
index 6d0d63da..04805cba 100644
--- a/odata2-lib/odata-testutil/pom.xml
+++ b/odata2-lib/odata-testutil/pom.xml
@@ -82,6 +82,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
+ <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
diff --git a/odata2-sample/cars-annotation-archetype/src/main/resources/archetype-resources/pom.xml b/odata2-sample/cars-annotation-archetype/src/main/resources/archetype-resources/pom.xml
index fe4a1e75..d5d584f7 100644
--- a/odata2-sample/cars-annotation-archetype/src/main/resources/archetype-resources/pom.xml
+++ b/odata2-sample/cars-annotation-archetype/src/main/resources/archetype-resources/pom.xml
@@ -58,8 +58,9 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.compiler-plugin}</version>
<configuration>
- <source>17</source>
- <target>17</target>
+ <source>1.8</source>
+ <target>1.8</target>
+ <verbose>true</verbose>
</configuration>
</plugin>
<plugin>
diff --git a/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/pom.xml b/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/pom.xml
index 7320df85..b6789c78 100644
--- a/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/pom.xml
+++ b/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/pom.xml
@@ -50,8 +50,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
- <source>17</source>
- <target>17</target>
+ <source>1.8</source>
+ <target>1.8</target>
</configuration>
</plugin>
<plugin>
diff --git a/pom.xml b/pom.xml
index 326fbbb5..8b4614c1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -193,8 +193,9 @@ governing permissions and limitations under
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
- <source>17</source>
- <target>17</target>
+ <source>1.8</source>
+ <target>1.8</target>
+ <verbose>true</verbose>
</configuration>
</plugin>
<plugin>