Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I resolve "Packages is not defined" in WSO2 Carbon 4.0.3 with Application Server Features?

I am attempting to upgrade from WSO2 Carbon 3.0.0 to Carbon 4.0.3. Using Carbon 3.0.0, after installing the necessary features, I'm able to write JavaScript Mashup services that can call external Java libraries--and since WSO2 carbon uses Rhino, I'm able to use importPackage. I have not been able to get the same functionality working on Carbon 4.0.3.

The procedure I've followed is:

  1. Download and unzip WSO2 Carbon 4.0.3
  2. Start Carbon
  3. Navigate to the "Feature Management" page
  4. Add the 4.0.3 Carbon p2 repository (http://dist.wso2.org/p2/carbon/releases/4.0.3/)
  5. Search for and install the "Application Server" feature
  6. Restart Carbon
  7. Deploy my test Mashup service
  8. Execute the echo operation of my test Mashup service using the "tryit" tool.

My test Mashup service (TestMashup.js):

this.serviceName = "TestMashup";

echo.inputTypes = "#raw";
echo.outputType = "#raw";
function echo(parameter) {
    var javaDate = new Packages.java.util.Date();
    var response = "<echo><value>" + parameter.toXMLString() + "</value><timestamp>" + javaDate.getTime() + "</timestamp></echo>";

    return new XML(response);
}

I've installed this Mashup service to CARBON_HOME/repository/deployment/server/jsservices/admin/

When I run this operation on Carbon 3.0.0, I get the following response:

<echo>
  <value>
    <r>test</r>
  </value>
  <timestamp>1360699125311</timestamp>
</echo>

When I attempt to run this operation on Carbon 4.0.3, I get the following stack-trace:

[2013-02-12 14:46:32,511] ERROR {org.jaggeryjs.scriptengine.engine.RhinoEngine} -  org.mozilla.javascript.EcmaError: ReferenceError: "Packages" is not defined.(//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js#6)
[2013-02-12 14:46:32,512] ERROR {org.jaggeryjs.scriptengine.engine.RhinoEngine} -  org.jaggeryjs.scriptengine.exceptions.ScriptException: org.mozilla.javascript.EcmaError: ReferenceError: "Packages" is not defined. (//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js#6)
[2013-02-12 14:46:32,512] ERROR {org.apache.axis2.receivers.AbstractMessageReceiver} -  org.jaggeryjs.scriptengine.exceptions.ScriptException: org.mozilla.javascript.EcmaError: ReferenceError: "Packages" is not defined. (//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js#6)
org.apache.axis2.AxisFault: org.jaggeryjs.scriptengine.exceptions.ScriptException: org.mozilla.javascript.EcmaError: ReferenceError: "Packages" is not defined.(//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js#6)
        at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
        at org.wso2.carbon.mashup.javascript.messagereceiver.JavaScriptEngine.call(JavaScriptEngine.java:176)
        at org.wso2.carbon.mashup.javascript.messagereceiver.JavaScriptEngine.call(JavaScriptEngine.java:208)
        at org.wso2.carbon.mashup.javascript.messagereceiver.JavaScriptReceiver.invokeBusinessLogic(JavaScriptReceiver.java:185)
        at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
        at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:110)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
        at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
        at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
        at org.wso2.carbon.core.transports.CarbonServlet.doPost(CarbonServlet.java:231)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at org.eclipse.equinox.http.helper.FilterServletAdaptor$FilterChainImpl.doFilter(FilterServletAdaptor.java:56)
        at org.wso2.carbon.mashup.jsservices.custom.ui.CustomUIServletFilter.doFilter(CustomUIServletFilter.java:233)
        at org.eclipse.equinox.http.helper.FilterServletAdaptor.service(FilterServletAdaptor.java:37)
        at org.eclipse.equinox.http.servlet.internal.ServletRegistration.handleRequest(ServletRegistration.java:90)
        at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:111)
        at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:67)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at org.wso2.carbon.tomcat.ext.servlet.DelegationServlet.service(DelegationServlet.java:68)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.wso2.carbon.tomcat.ext.filter.CharacterSetFilter.doFilter(CharacterSetFilter.java:61)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
        at org.wso2.carbon.tomcat.ext.valves.CompositeValve.invoke(CompositeValve.java:172)
        at org.wso2.carbon.tomcat.ext.valves.CarbonStuckThreadDetectionValve.invoke(CarbonStuckThreadDetectionValve.java:156)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
        at org.wso2.carbon.tomcat.ext.valves.CarbonContextCreatorValve.invoke(CarbonContextCreatorValve.java:52)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1653)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
Caused by: org.jaggeryjs.scriptengine.exceptions.ScriptException: org.jaggeryjs.scriptengine.exceptions.ScriptException: org.mozilla.javascript.EcmaError: ReferenceError: "Packages" is not defined. (//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js#6)
        at org.jaggeryjs.scriptengine.engine.RhinoEngine.execFunc(RhinoEngine.java:383)
        at org.jaggeryjs.scriptengine.engine.RhinoEngine.call(RhinoEngine.java:251)
        at org.wso2.carbon.mashup.javascript.messagereceiver.JavaScriptEngine.call(JavaScriptEngine.java:169)
        ... 40 more
Caused by: org.jaggeryjs.scriptengine.exceptions.ScriptException: org.mozilla.javascript.EcmaError: ReferenceError: "Packages" is not defined. (//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js#6)
        at org.jaggeryjs.scriptengine.engine.RhinoEngine.execFunc(RhinoEngine.java:401)
        at org.jaggeryjs.scriptengine.engine.RhinoEngine.execFunc(RhinoEngine.java:380)
        ... 42 more
Caused by: org.mozilla.javascript.EcmaError: ReferenceError: "Packages" is not defined. (//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js#6)
        at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3557)
        at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3535)
        at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3620)
        at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1652)
        at org.jaggeryjs.rhino.c0._c1(//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js:6)
        at org.jaggeryjs.rhino.c0.call(//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js)
        at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:401)
        at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3003)
        at org.jaggeryjs.rhino.c0.call(//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js)
        at org.jaggeryjs.scriptengine.engine.RhinoEngine.execFunc(RhinoEngine.java:398)
        ... 43 more

How do I fix this so that I can continue using Java libraries from my JavaScript Mashup services?

like image 215
GamerJosh Avatar asked Feb 12 '13 20:02

GamerJosh


1 Answers

The code that allowed this feature to work has been disabled.

I spent some time looking through the carbon SVN repository and discovered that the message-receiver mashup component was modified in such a way that prevents JavaScript Mashup services from being created with an ImporterTopLevel context. This is directly visible in org.wso2.carbon.mashup.javascript.messagereceiver.JavaScriptEngine, where previous versions extend ImporterTopLevel but newer versions do not. For future reference, this change was committed against revision 129254.

I've been able to merge the ImporterTopLevel code from 3.2.2 into the 4.0.3 version of messagereceiver to work around the problem.

like image 135
GamerJosh Avatar answered Sep 22 '22 14:09

GamerJosh