DPML argument passing

Poster Content
nk4um User
Posts: 90
March 24, 2016 13:04

Hi Tony,

I changed the configuration as you suggested, but the argument method should be 'from-string' which is counter intuitive. This is what I did:

<endpoint>
  <id>lm:loginSubmit</id>
  <grammar> res:/
    <groupname="action">
      <regex>loginSubmit|logout</regex>
    </group>
  </grammar>
  <request>
    <identifier>active:dpml</identifier>
    <argumentname="action">arg:action</argument>
    <argumentname="operator">
      <literaltype="xml">
        <sequence>
          <requestassignment="logResult">
            <identifier>active:java</identifier>
            <argumentname="class">my.LoginAccessor </argument>
            <argumentname="action"> arg:action </argument>
          </request>
          <requestassignment="response">
            <identifier>active:postLoginLogout </identifier>
            <argumentname="validation">this:logResult </argument>
          </request>
        </sequence>
      </literal>
    </argument>
  </request>
</endpoint>

This is the mapped endpoint, I tried some combinations of argument methods; the correct result is the String "{}"

<endpoint>
  <id>lm:postLoginLogout</id>
  <grammar>
    <active>
      <identifier>active:postLoginLogout</identifier>
      <argumentname="validation" />
    </active>
  </grammar>
  <request>
    <identifier>active:java</identifier>
    <argumentname="class">other.PostLoginLogoutAccessor </argument>
    <!-- 1 ============= -->
    <!-- getArgumentValue(): pbv:70ca3ba9 -->
    <!-- source(): {} -->
    <!-- <argument name="validation">arg:validation -->
    <!-- </argument> -->
    <!-- 2 ============= -->
    <!-- getArgumentValue(): pbv:validation -->
    <!-- source(): pbv:70ca3ba9 -->
    <!-- <argument name="validation" method="as-string">arg:validation -->
    <!-- </argument> -->
    <!-- 3 ============= -->
    <!-- correct -->
    <!-- getArgumentValue(): {} -->
    <!-- source(): exception -->
    <argumentname="validation" method="from-string">arg:validation </argument>
    <!-- 4 ============= -->
    <!-- getArgumentValue(): pbv:validation -->
    <!-- source(): {} -->
    <!-- <argument name="validation" method="value"> -->
    <!-- arg:validation -->
    <!-- </argument> -->
    <!-- 5 ============= -->
    <!-- getArgumentValue(): pbv:70ca3ba9 -->
    <!-- source(): {} -->
    <!-- <argument name="validation">[[arg:validation]] -->
    <!-- </argument> -->
    <!-- 6 ============= -->
    <!-- getArgumentValue(): pbv:validation -->
    <!-- source(): pbv:70ca3ba9 -->
    <!-- <argument name="validation" method="as-string">[[arg:validation]] -->
    <!-- </argument> -->
    <!-- 7 ============= -->
    <!-- correct -->
    <!-- getArgumentValue(): {} -->
    <!-- source(): exception -->
    <argumentname="validation" method="from-string">[[arg:validation]] </argument>
    <!-- 8 ============= -->
    <!-- getArgumentValue(): pbv:validation -->
    <!-- source(): {} -->
    <!-- <argument name="validation" method="value">[[arg:validation]] -->
    <!-- </argument> -->
  </request>
</endpoint>

The arguments 3 and 7 give the desired result. I wouldn't have expected this from reading the docs:

from-string 	This method is the inverse of as-string and as such it is useful
 for converting an incoming pass-by-value argument into a pass-by-reference argument.
The argument is treated as an identifier reference and SOURCEd as a string. 
This string is then passed-by-reference on the constructed requests identifier.

Are the docs correct?

But at last it works, thanks!

Stefan

Like · Post Reply
nk4um Moderator
Posts: 595
March 24, 2016 11:36

Hi Stefan, unfortunately DPML doesn't support quite the same set of method attributes on the request arguments as declarative request. What you want to achieve isn't possible directly however you can achieve it by wrapping the endpoint in question in a mapper overlay. This will allow you to change the validation argument from pass by value to a direct string on the identifier.

something like this should work:

<mapper>
  <config>
    <endpoint>
      <grammar>
        <active>
          <identifier>active:wrappedLogin</identifier>
          <argumentname="validation" />
        </active>
      </grammar>
      <request>
        <identifier>active:java</identifier>
        <argumentname="class">my.LoginAccessor</argument>
        <argumentname="validation" method="as-string">arg:validation</argument>
      </request>
    </endpoint>
  </config>
</mapper>

See http://docs.netkernel.org/book/view/book:guide:standardmodule/doc:logicalreference:module:standard:logical:declarative:request:syntax for more information.

Like · Post Reply
nk4um User
Posts: 90
March 24, 2016 10:38DPML argument passing

Hello,

this is my first contact with DPML, so please be kind. I'm trying to chain two endpoints in module.xml to do some extra stuff depeneding on the outcome of the first endpoint and without having to change the code of the endpoints.

That's the declaration:

<endpoint>
  <id>lm:loginSubmit</id>
  <grammar>res:/
    <groupname="action">
      <regex>loginSubmit|logout</regex>
    </group>
  </grammar>
  <request>
    <identifier>active:dpml</identifier>
    <argumentname="action">arg:action</argument>
    <argumentname="operator">
      <literaltype="xml">
        <sequence>
          <requestassignment="logResult">
            <identifier>active:java</identifier>
            <argumentname="class">my.LoginAccessor </argument>
            <argumentname="action"> arg:action </argument>
          </request>
          <requestassignment="response">
            <identifier>active:java</identifier>
            <argumentname="class">other.PostLoginLogoutAccessor </argument>
            <argumentname="validation" method="eager">this:logResult </argument>
          </request>
        </sequence>
      </literal>
    </argument>
  </request>
</endpoint>

Unfortunately the second endpoint is not under my control and it gets the arguments value like this:

String validation = aContext.getThisRequest().getArgumentValue("validation");

But the result is the identifier of the argument like "pbv:70ca3b21" and not the value. I expected it to work like the argument passing for arg:action to the active:dpml request which value can be retrieved in the first request (assignment="logResult) with getArgumentValue("action"). But it looks like DPML handles this differently.

I tried different ways like this, but with no result:

<argumentname="validation" method="eager">
  <request>
    <identifier>this:logResult </identifier>
    <representation>java.lang.String</representation>
    <verb>SOURCE</verb>
  </request>
</argument>

How can I change the argument in the DPML script to make the second endpoint work?

Thanks a lot, Stefan

Like · Post Reply