0

I defined a service xml like this:

<service verb="targetExample">
    <in-parameters><parameter name="testInput"/></in-parameters>
    <out-parameters><parameter name="testOutput"/></out-parameters>
    <actions>
        <set field="testOutput" value="Input was: ${testInput}"/>
        <log level="info" message="targetExample testOutput: '${testOutput}'"/>
    </actions>
</service>

I was curious if there is a chance to call it without adding a transition to wrap it. I tried to respect the service naming ${path}.${verb}#${noun} but in vain, i cannot call it without defining the following transition.

<transition name="localExample">
    <service-call name="moqui.example.ExampleServices.targetExample" web-send-json-response="true"/>
    <default-response type="none"/>
</transition>

Also, I was also wondering if someone managed to implement a service in java instead of groovy (I read in the documentation that it is possible). What I ask for is a working example of test.java file in the following definition:

<service verb="targetJavaExample" type="java"
    location="component://example/src/orq/moqui/example/test.java">
    <in-parameters><parameter name="testInput"/></in-parameters>
    <out-parameters><parameter name="testOutput"/></out-parameters>
</service>

1 Answers1

1

Any service may also be called from within any <actions> tags defined in the screen xml. e.g. The beginning of sections, the beginning of forms (<row-actions>), embedded in various files, or put in a file of their own and run like a script etc.

And within a service, when defining the "actions" invoked by the service, you can always drop down to Groovy/Java any time by using <script>... </script>. - That is always the case within XML Actions. (Or <script><![CDATA[... ]]></script> if you have have characters that might be interpreted as XML markup.)

Hope that helps.

Ronan Keane
  • 189
  • 8
  • Note - https://stackoverflow.com/questions/687601/valid-java-code-that-is-not-valid-groovy-code – Ronan Keane Jul 17 '17 at 12:32
  • Thank you Ronan for your time. I wanted to call the services from outside the moqui ecosystem (we're considering to build an Angular UI and keep moqui on the server side only) using Postman for the beginning (or curl). – Rares-Codrin Jul 17 '17 at 13:56
  • Regarding the services implemented in java, i know that you can write them inline or by giving the location of the file. I just wanted a concrete example of service written in java and bound to moqui because i couldn't find one in the docs or Example apps. – Rares-Codrin Jul 17 '17 at 13:58
  • Does the Service REST API meet your needs? Look at rest.xml in webroot for examples. And ExampleApp.xml in the example application. You can use these to call your service from outside Moqui. Then, in your service specify the location of your script. e.g. `` See for example, pollEmailServer.groovy which is a script called from a service in this way. I've never tried to refer to a .java file in the 'location' attribute, so am unsure about that. So afraid that's about as far as I can try to help you here. – Ronan Keane Jul 17 '17 at 15:25