Swaraj
Swaraj

Reputation: 353

org.xml.sax.SAXParseException.publicId accessible: module java.xml does not opens org.xml.sax to unnamed module - JDK17

Not sure what is wrong with the Implementation while validating the XML.

I am trying to convert the SAX Exception for the fields to json response - And it is failing at return new Gson().toJson(this);

"InaccessibleObjectException","stack":"com.google.gson.JsonIOException: Failed making field 'org.xml.sax.SAXParseException#publicId' accessible; either increase its visibility or write a custom TypeAdapter for its declaring type.    
---
---
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private java.lang.String org.xml.sax.SAXParseException.publicId accessible: module java.xml does not \"opens org.xml.sax\" to unnamed module @14555e0a\r\n\tat java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)\r\n\tat java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)\r\n\tat java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)\r\n\tat java.base/java.lang.reflect.Field.setAccessible(Field.java:172)\r\n\tat com.google.gson.internal.reflect.ReflectionHelper.makeAccessible(ReflectionHelper.java:35)\r\n\t... 164 common frames omitted\r\n"}

JDK17, SpringBoot 3.2.4

WSDL Codegen Module -

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.test.testing</groupId>
<artifactId>test-ws</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>test-ws</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <jakarta.xml.ws-api.version>4.0.2</jakarta.xml.ws-api.version>
    <jaxws.version>4.0.2</jaxws.version>
</properties>

<dependencies>
    <dependency>
        <groupId>jakarta.xml.ws</groupId>
        <artifactId>jakarta.xml.ws-api</artifactId>
        <version>${jakarta.xml.ws-api.version}</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-rt</artifactId>
        <version>${jaxws.version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-ri</artifactId>
        <version>${jaxws.version}</version>
        <type>pom</type>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>${jaxws.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <wsdlUrls>
                            <wsdlUrl>${basedir}/src/main/resources/UtilityService.wsdl</wsdlUrl>
                            <wsdlUrl>${basedir}/src/main/resources/2021/Sample2.wsdl</wsdlUrl>
                            <wsdlUrl>${basedir}/src/main/resources/2022/Sample2.wsdl</wsdlUrl>
                            <wsdlUrl>${basedir}/src/main/resources/2023/Sample2.wsdl</wsdlUrl>
                        </wsdlUrls>
                    <bindingFiles>
                            <bindingFile>binding.xml</bindingFile>
                    </bindingFiles> 
                    <sourceDestDir>${basedir}/src/main/java</sourceDestDir>
                    <destDir>${basedir}/target/jaxws</destDir>
                    <staleFile>${project.build.directory}/jaxws/stale/wsdl.stale.done</staleFile>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.13.0</version>
            <configuration>
                <source>17</source>
                <target>17</target>
            </configuration>
        </plugin>
    </plugins>
</build>

This is generating code fine, Then in Document Parser - Added ResourceResolver

public class ResourceResolver implements LSResourceResolver {

private String year;

private ResourceLoader resourceLoader;

public ResourceResolver (String year,ResourceLoader resourceLoader){
    this.year = year;
    this.resourceLoader = resourceLoader;
}



@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
    // TODO Auto-generated method stub
    InputStream resourceAsStream;
    try {
        resourceAsStream = resourceLoader.getClassLoader().getResourceAsStream("EFAST_"+year+"/"+systemId); 
        return new Input(publicId, systemId, resourceAsStream);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

}

Public id is null and systemid is wsdl files.

Can someone helps to find root cause of the issue...

Tried to find the "org.xml.sax" and found in "spring-xml - 4.0.2".

EDIT :-

Following started working locally

Added following in maven-compiler-plugin :: configuration element

<compilerArgs>
    <arg>--add-opens</arg>
    <arg>java.base/java.util=ALL-UNNAMED</arg>
    <arg>--add-opens</arg>
    <arg>java.base/java.lang=ALL-UNNAMED</arg>
    <arg>--add-opens</arg>
    <arg>java.xml/org.xml.sax=ALL-UNNAMED</arg>
</compilerArgs>

Wondering how to provide these to JVM Args when deployed to Cloud through POM file?

Upvotes: 0

Views: 182

Answers (0)

Related Questions