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

Wrapped java.lang.IllegalAccessException when trying to make https request #1409

Closed
mise93 opened this issue Sep 8, 2023 · 10 comments
Closed

Comments

@mise93
Copy link

mise93 commented Sep 8, 2023

We are making https requests in our data sources to fetch data from our APIs.

We've been using following code to achieve this:

        var url = new URL(urlString);
	var uc = url.openConnection();
	uc.setRequestProperty ("Authorization", "Bearer " + params["TokenV2"]);
	uc.setRequestProperty ("Content-Type", "application/json");
	uc.setRequestProperty ("X-Date-Format", "dd.MM.yyyy");
		
	var inStream = uc.getInputStream();
	var inStreamReader = new InputStreamReader(inStream, "UTF-8");
	var bufferedReader = new BufferedReader(inStreamReader);
	var line;
	var result = "";
		
	while ((line = bufferedReader.readLine()) != null)
	result += line;
	inStream.close();
	var json = JSON.parse(result)

Yesterday we downloaded new designer from 4.13 release and now running report viewer throws following exception:

A BIRT exception occurred. See next exception for more information.
Wrapped java.lang.IllegalAccessException: class org.mozilla.javascript.MemberBox cannot access class sun.net.www.protocol.https.HttpsURLConnectionImpl (in module java.base) because module java.base does not export sun.net.www.protocol.https to unnamed module @56729f24 (/report/data-sources/script-data-source[@id="646"]/method[@name="open"]#29)
   at org.eclipse.birt.data.engine.script.JSMethodRunner.runScript(JSMethodRunner.java:123)
   at org.eclipse.birt.report.engine.script.internal.DtEScriptExecutor.handleJS(DtEScriptExecutor.java:88)
... 102 more
Caused by: org.eclipse.birt.data.engine.core.DataException: A BIRT exception occurred. See next exception for more information.
Wrapped java.lang.IllegalAccessException: class org.mozilla.javascript.MemberBox cannot access class sun.net.www.protocol.https.HttpsURLConnectionImpl (in module java.base) because module java.base does not export sun.net.www.protocol.https to unnamed module @56729f24 (/report/data-sources/script-data-source[@id="646"]/method[@name="open"]#29)
   at org.eclipse.birt.data.engine.core.DataException.wrap(DataException.java:120)
   at org.eclipse.birt.data.engine.api.script.BaseScriptEvalUtil.evaluateJSAsExpr(BaseScriptEvalUtil.java:806)
   at org.eclipse.birt.data.engine.script.JSMethodRunner.runScript(JSMethodRunner.java:120)
... 103 more
Caused by: org.eclipse.birt.core.exception.CoreException: Wrapped java.lang.IllegalAccessException: class org.mozilla.javascript.MemberBox cannot access class sun.net.www.protocol.https.HttpsURLConnectionImpl (in module java.base) because module java.base does not export sun.net.www.protocol.https to unnamed module @56729f24 (/report/data-sources/script-data-source[@id="646"]/method[@name="open"]#29)
   at org.eclipse.birt.core.script.JavascriptEvalUtil.wrapRhinoException(JavascriptEvalUtil.java:263)
   at org.eclipse.birt.core.script.JavascriptEvalUtil.evaluateRawScript(JavascriptEvalUtil.java:103)
   at org.eclipse.birt.core.script.JavascriptEvalUtil.evaluateScript(JavascriptEvalUtil.java:128)
   at org.eclipse.birt.data.engine.api.script.BaseScriptEvalUtil.evaluateJSAsExpr(BaseScriptEvalUtil.java:804)
... 104 more
Caused by: org.mozilla.javascript.WrappedException: Wrapped java.lang.IllegalAccessException: class org.mozilla.javascript.MemberBox cannot access class sun.net.www.protocol.https.HttpsURLConnectionImpl (in module java.base) because module java.base does not export sun.net.www.protocol.https to unnamed module @56729f24 (/report/data-sources/script-data-source[@id="646"]/method[@name="open"]#29)
   at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1932)
   at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:134)
   at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:225)
   at org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:42)
   at org.mozilla.javascript.gen._report_data_sources_script_data_source__id__646___method__name__open___8._c___bm_OPEN_1(/report/data-sources/script-data-source[@id="646"]/method[@name="open"]:29)
   at org.mozilla.javascript.gen._report_data_sources_script_data_source__id__646___method__name__open___8.call(/report/data-sources/script-data-source[@id="646"]/method[@name="open"])
   at org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRuntime.java:74)
   at org.mozilla.javascript.gen._report_data_sources_script_data_source__id__646___method__name__open___9._c_script_0(/report/data-sources/script-data-source[@id="646"]/method[@name="open"]:0)
   at org.mozilla.javascript.gen._report_data_sources_script_data_source__id__646___method__name__open___9.call(/report/data-sources/script-data-source[@id="646"]/method[@name="open"])
   at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:405)
   at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3508)
   at org.mozilla.javascript.gen._report_data_sources_script_data_source__id__646___method__name__open___9.call(/report/data-sources/script-data-source[@id="646"]/method[@name="open"])
   at org.mozilla.javascript.gen._report_data_sources_script_data_source__id__646___method__name__open___9.exec(/report/data-sources/script-data-source[@id="646"]/method[@name="open"])
   at org.eclipse.birt.core.script.JavascriptEvalUtil.evaluateRawScript(JavascriptEvalUtil.java:98)
... 106 more
Caused by: java.lang.IllegalAccessException: class org.mozilla.javascript.MemberBox cannot access class sun.net.www.protocol.https.HttpsURLConnectionImpl (in module java.base) because module java.base does not export sun.net.www.protocol.https to unnamed module @56729f24
   at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:392)
   at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:674)
   at java.base/java.lang.reflect.Method.invoke(Method.java:560)
@claesrosell
Copy link
Contributor

claesrosell commented Sep 8, 2023

This is probably a problem with Rhino, the JavaScript engine that Birt uses.
I searched the web and found this issue: mozilla/rhino#462

... looks related. If it indeed is the same problem it should be fixed in Rhino now. I do not know which version of Rhino that Birt 4.13 uses, nor, if we have updated that dependency with Birt 4.14, but generally I would say: Test this in a 4.14 build and see if it works there.

@claesrosell
Copy link
Contributor

It looks like we are using Rhino 1.7.10 in Birt 4.14. The issue mentioned above is solved in Rhino 1.7.14, so we will need to update Rhino to solve this issue.
Earlier we depended on an Eclipse Web Tools feature to pull this dependency, hopefully, this has changed with the work Ed did, earlier this year.

@merks
Copy link
Contributor

merks commented Sep 8, 2023

Yes, orbit itself is still "stuck" on this older versions

image

I am in the process of restructuring Orbit so that we can more easily and automatically update to newer dependency versions:

https://github.com/orgs/eclipse-orbit/discussions/49

So I will get around to looking at this dependency in the coming weeks...

@hvbtup
Copy link
Contributor

hvbtup commented Sep 8, 2023

This is basically the same as #1138, a result of the modularization in Java 9 and is now enforced by default in Java 17 (this is probably not exactly correct, but should suffice as an explanation).

Two different workaround are possible (I tested both for similar problems):

Either you can write a little Java class that implements the functionality of the script and call this Java class from the script.

Or you can add VM arguments to your BIRT Java process which allow the classes to be used.

Eg. for a report which creates charts using JFreeChart I had to add

--add-opens=java.desktop/sun.java2d=ALL-UNNAMED
--add-opens=java.desktop/sun.awt.image=ALL-UNNAMED

The packages you have to specify can be seen in the error messages. In your case I guess it should read

--add-opens=java.base/sun.net.www.protocol.https=ALL-UNNAMED

Maybe this results in a similar error message with different pacakes/classes, so maybe you have to add more add-opens.

@speckyspooky
Copy link
Contributor

Yes, the core problem is this part of the stack trace "(in module java.base)"
which means the jar is now located in a different "module" and not longer part of the Java-core.

But Rhino doesn't know that he has to search into a "module" therefore the jars cannot be loaded.
It would be great if we could update Rhino to this version and then we can test it.
Because there isn't any guaranty that the improvement will work in every case.

I have special reports too which use Web-Requests and currently I plan to create report-jars as external resources to handle this problem. But it would be great if I can avoid this step.
So @merks, it would be realy very good if you could find the time to take a look into it.

@speckyspooky
Copy link
Contributor

speckyspooky commented Sep 8, 2023

Workaround option: tested
I started today a test session for my we-request report (BIRT 4.12 JDK17)
with the workaround option "--add-options" according to @hvbtup suggestion.

The result is that the configuration is working. For the configuration I added the 2 following lines
at the end of the BIRT.in:

--add-opens=java.base/sun.net.www.protocol.https=ALL-UNNAMED
--add-opens=java.base/sun.net.www.http=ALL-UNNAMED

The both lines solved the problems:

class:	sun.net.www.protocol.https.HttpsURLConnectionImpl
module:	java.base
export:	sun.net.www.protocol.https

and

class:	sun.net.www.http.PosterOutputStream
module:	java.base
export:	sun.net.www.http 

Perhaps this would be realy an option at first to get your report running.

I see you work with JSON which is good.
In my case I got a xml-response and then I have to add another modules to the configuration
because also many of the xml parser classes and xml classes are separated into new modules.

@mise93
Copy link
Author

mise93 commented Sep 11, 2023

Adding those options did get me further but this time it's throwing this:

org.eclipse.birt.report.service.api.ReportServiceException: Error happened while running the report.
   at org.eclipse.birt.report.service.ReportEngineService.throwDummyException(ReportEngineService.java:914)
   at org.eclipse.birt.report.service.ReportEngineService.renderReport(ReportEngineService.java:1267)
   at org.eclipse.birt.report.service.BirtViewerReportService.getPage(BirtViewerReportService.java:176)
   at org.eclipse.birt.report.service.actionhandler.BirtChangeParameterActionHandler.doRenderPage(BirtChangeParameterActionHandler.java:70)
   at org.eclipse.birt.report.service.actionhandler.AbstractChangeParameterActionHandler.__execute(AbstractChangeParameterActionHandler.java:85)
   at org.eclipse.birt.report.service.actionhandler.AbstractBaseActionHandler.execute(AbstractBaseActionHandler.java:88)
   at org.eclipse.birt.report.soapengine.processor.AbstractBaseDocumentProcessor.__executeAction(AbstractBaseDocumentProcessor.java:45)
   at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.executeAction(AbstractBaseComponentProcessor.java:132)
   at org.eclipse.birt.report.soapengine.processor.BirtDocumentProcessor.handleChangeParameter(BirtDocumentProcessor.java:96)
   at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
   at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.base/java.lang.reflect.Method.invoke(Method.java:568)
   at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.process(AbstractBaseComponentProcessor.java:107)
   at org.eclipse.birt.report.soapengine.endpoint.BirtSoapBindingImpl.getUpdatedObjects(BirtSoapBindingImpl.java:67)
   at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
   at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.base/java.lang.reflect.Method.invoke(Method.java:568)
   at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
   at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
   at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:321)
   at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
   at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
   at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
   at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:420)
   at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
   at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:684)
   at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.doPost(BirtSoapMessageDispatcherServlet.java:227)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:517)
   at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:332)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:584)
   at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.service(BirtSoapMessageDispatcherServlet.java:115)
   at org.eclipse.jetty.servlet.ServletHolder$NotAsync.service(ServletHolder.java:1419)
   at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)
   at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1665)
   at org.eclipse.birt.report.filter.ViewerFilter.doFilter(ViewerFilter.java:71)
   at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:210)
   at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
   at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:527)
   at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:131)
   at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:578)
   at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
   at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:223)
   at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1571)
   at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
   at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1378)
   at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)
   at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:484)
   at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1544)
   at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
   at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1300)
   at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
   at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:149)
   at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:141)
   at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
   at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:822)
   at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
   at org.eclipse.jetty.server.Server.handle(Server.java:562)
   at org.eclipse.jetty.server.HttpChannel.lambda$handle$0(HttpChannel.java:505)
   at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:762)
   at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:497)
   at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:282)
   at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:319)
   at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
   at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
   at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:412)
   at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:381)
   at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:268)
   at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.lambda$new$0(AdaptiveExecutionStrategy.java:138)
   at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:407)
   at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:894)
   at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1038)
   at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.eclipse.birt.report.engine.api.EngineException: Error happened while running the report.
   at org.eclipse.birt.report.engine.api.impl.EngineTask.handleFatalExceptions(EngineTask.java:1867)
   at org.eclipse.birt.report.engine.api.impl.RenderTask.render(RenderTask.java:275)
   at org.eclipse.birt.report.service.ReportEngineService.renderReport(ReportEngineService.java:1263)
... 72 more
Caused by: java.io.IOException: org/mozilla/javascript/Undefined
   at org.eclipse.birt.core.util.IOUtil.readObject(IOUtil.java:541)
   at org.eclipse.birt.core.util.IOUtil.readObject(IOUtil.java:458)
   at org.eclipse.birt.report.engine.internal.document.v3.PageHintReaderV3.readPageVariable(PageHintReaderV3.java:353)
   at org.eclipse.birt.report.engine.internal.document.v3.PageHintReaderV3.readPageVariables(PageHintReaderV3.java:345)
   at org.eclipse.birt.report.engine.internal.document.v3.PageHintReaderV3.getPageVariables(PageHintReaderV3.java:227)
   at org.eclipse.birt.report.engine.internal.document.PageHintReader.getPageVariables(PageHintReader.java:71)
   at org.eclipse.birt.report.engine.api.impl.RenderTask.loadReportVariable(RenderTask.java:176)
   at org.eclipse.birt.report.engine.api.impl.RenderTask.render(RenderTask.java:243)
... 73 more
Caused by: java.lang.ClassNotFoundException: org/mozilla/javascript/Undefined
   at java.base/java.lang.Class.forName0(Native Method)
   at java.base/java.lang.Class.forName(Class.java:467)
   at org.eclipse.birt.core.util.IOUtil$1.resolveClass(IOUtil.java:535)
   at java.base/java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:2034)
   at java.base/java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1898)
   at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2224)
   at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1733)
   at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:509)
   at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:467)
   at org.eclipse.birt.core.util.IOUtil.readObject(IOUtil.java:539)
... 80 more

@hvbtup
Copy link
Contributor

hvbtup commented Sep 11, 2023

I guess this is an error of your REST call, unrelated to the original issue or the workaround.

@speckyspooky
Copy link
Contributor

I have tested your script in a light modified version with one of my test pages: "https://httpbin.org/post"
Here is my test example based on your version and the result of it.
Perhaps it will help you with your next steps.

var url = new URL("https://httpbin.org/post");
var uc = url.openConnection();
uc.setRequestProperty("Authorization"	, "Bearer TokenV2");
uc.setRequestProperty("Content-Type"	, "application/json");
uc.setRequestProperty("X-Date-Format"	, "dd.MM.yyyy");
uc.setRequestProperty("charset"		, "utf-8");

uc.setRequestMethod("POST");										//	request method:		POST, GET
uc.setDoOutput(true);												//	request output:		stream to target
uc.setDoInput(true);												//	request response:	stream from target

var respMsg			= "";
var respStreamLine	= "";
var respStream = new BufferedReader(new InputStreamReader(uc.getInputStream(), java.nio.charset.StandardCharsets.UTF_8));
while ( (respStreamLine = respStream.readLine() ) != null )
	respMsg += respStreamLine;
	
respStream.close();
uc.disconnect();
var json = JSON.parse(respMsg)

2023-09-11 21_41_28-workspace - reports_rest_post_request rptdesign - BIRT Report Designer All-In-On

@wimjongman
Copy link
Contributor

Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants