Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    accessing servletRequest in an OperationBinding script block

    Hi,

    I have been trying out some other features and trying to get access to the HttpServletRequest in a script block in my server-side DS definition. I am using Isomorphic
    (v10.1p_2016-02-28/Pro Deployment (I also tested 2015-12-10 and couldn't get that to work either)

    Code:
    <operationBinding operationType="fetch" operationId="fetchEncoding">
        <script language="javascript">
        var response = servletRequest.getHeader("Accept-Encoding");
        response;
        </script>
    </operationBinding>
    When I make the request for the following I get the following error in my server logs (Jetty):

    Code:
    === 2016-02-29 14:00:42,990 [9-22] WARN  RequestContext - dsRequest.execute() failed: 
    javax.script.ScriptException: ReferenceError: "servletRequest" is not defined in nashorn:mozilla_compat.js at line number 67
        at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:467)
        at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:451)
        at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:403)
        at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:399)
        at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
    I also tried writing my script in groovy and using a different AppServer (WebSphere) and got the following stack trace:
    Code:
    [29/02/16 14:11:54:079 GMT] 00000273 SystemOut     O === 2016-02-29 14:11:54,079 [ : 1] WARN  RequestContext - dsRequest.execute() failed: 
    groovy.lang.MissingPropertyException: No such property: servletRequest for class: Script1
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
        at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
        at Script1.run(Script1.groovy:10)
    According to the documentation for OperationBinding.script: " Scriptlets also have access to a set of contextual variables related to the Servlets API, as follows:
    • servletRequest: the current ServletRequest"

    Can you suggest what I might be doing wrong?


    Thanks!

    #2
    Is the request coming in thrown our included IDACall Servlet or through some other mechanism?

    Do you have any trouble accessing other context variables (such as DSRequest or RequestConext) or is the problem just the ServletRequest?

    Comment


      #3
      I am using IDACall - nothing special about the setup.

      I am able to access dsRequest and servletContext so it seems only servletRequest is unavailable.

      Comment


        #4
        Just an update:

        I tried with
        Code:
        dsRequest.getHttpServletRequest().getHeader("Accept-Encoding");
        and things work fine. Perhaps just a documentation update is required here to make clear that the servletRequest can be accessed via dsRequest.

        Comment


          #5
          This was actually a bug and it is fixed in latest nightly build. The servletRequest variable now is available as the docs state.

          Comment


            #6
            Originally posted by Isomorphic View Post
            This was actually a bug and it is fixed in latest nightly build. The servletRequest variable now is available as the docs state.
            Thanks!

            Comment

            Working...
            X