| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="utf-8"> |
| <meta name="viewport" content="width=device-width,initial-scale=1"> |
| <title>Hints and Tips :: Apache Isis</title> |
| <link rel="canonical" href="https://isis.apache.org/vro/2.0.0-M3/hints-and-tips.html"> |
| <meta name="generator" content="Antora 2.2.0"> |
| <link rel="stylesheet" href="../../_/css/site.css"> |
| <link rel="stylesheet" href="../../_/css/site-custom.css"> |
| <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,700,700i|Raleway:300,400,500,700,800|Montserrat:300,400,700" rel="stylesheet"> |
| <link rel="home" href="https://isis.apache.org" title="Apache Isis"> |
| <link rel="next" href="cors/about.html" title="CORS"> |
| <link rel="prev" href="security.html" title="Security"> |
| </head> |
| <body class="article"> |
| <header class="header"> |
| <nav class="navbar"> |
| <div class="navbar-brand"> |
| <a class="navbar-item" href="https://isis.apache.org"> |
| <span class="icon"> |
| <img src="../../_/img/isis-logo-48x48.png"></img> |
| </span> |
| <span>Apache Isis</span> |
| </a> |
| <button class="navbar-burger" data-target="topbar-nav"> |
| <span></span> |
| <span></span> |
| <span></span> |
| </button> |
| </div> |
| <div id="topbar-nav" class="navbar-menu"> |
| <a class="navbar-end"> |
| <div class="navbar-item has-dropdown is-hoverable"> |
| <a class="navbar-link" href="#">Quick Start</a> |
| <div class="navbar-dropdown"> |
| <span class="navbar-item navbar-heading">Starter Apps</span> |
| <a class="navbar-item" href="../../docs/latest/starters/helloworld.html">Hello World</a> |
| <a class="navbar-item" href="../../docs/latest/starters/simpleapp.html">Simple App</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Demos & Tutorials</span> |
| <a class="navbar-item" href="../../docs/latest/demo/about.html">Demo App</a> |
| <a class="navbar-item" href="https://danhaywood.gitlab.io/isis-petclinic-tutorial-docs/petclinic/1.16.2/intro.html">Petclinic (tutorial)</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Resources</span> |
| <a class="navbar-item" href="../../docs/latest/resources/cheatsheet.html">Cheatsheet</a> |
| <a class="navbar-item" href="../../docs/latest/resources/icons.html">Icons</a> |
| </div> |
| </div> |
| <div class="navbar-item has-dropdown is-hoverable"> |
| <a class="navbar-link" href="#">Guides</a> |
| <div class="navbar-dropdown"> |
| <span class="navbar-item navbar-heading">Development</span> |
| <a class="navbar-item" href="../../setupguide/latest/about.html">Setup Guide</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Core</span> |
| <a class="navbar-item" href="../../userguide/latest/about.html">User Guide</a> |
| <a class="navbar-item" href="../../refguide/latest/about.html">Reference Guide</a> |
| <a class="navbar-item" href="../../testing/latest/about.html">Testing Guide</a> |
| </div> |
| </div> |
| <div class="navbar-item has-dropdown is-hoverable"> |
| <a class="navbar-link" href="#">Libraries</a> |
| <div class="navbar-dropdown"> |
| <span class="navbar-item navbar-heading">For Use in Apps</span> |
| <a class="navbar-item" href="../../subdomains/latest/about.html">Subdomain Libraries</a> |
| <a class="navbar-item" href="../../valuetypes/latest/about.html">Value Types</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Integrate between Apps</span> |
| <a class="navbar-item" href="../../mappings/latest/about.html">Bounded Context Mapping Libraries</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Other</span> |
| <a class="navbar-item" href="../../incubator/latest/about.html">Incubator</a> |
| <a class="navbar-item" href="../../legacy/latest/about.html">Legacy</a> |
| </div> |
| </div> |
| <div class="navbar-item has-dropdown is-hoverable"> |
| <a class="navbar-link" href="#">Components</a> |
| <div class="navbar-dropdown"> |
| <span class="navbar-item navbar-heading">Viewers</span> |
| <a class="navbar-item" href="../../vw/latest/about.html">Wicket UI</a> |
| <a class="navbar-item" href="../../vro/latest/about.html">Restful Objects (REST)</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Security</span> |
| <a class="navbar-item" href="../../security/latest/about.html">Security Guide</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Persistence</span> |
| <a class="navbar-item" href="../../pjdo/latest/about.html">DataNucleus (JDO)</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Extensions</span> |
| <a class="navbar-item" href="../../extensions/latest/about.html">Extensions Catalog</a> |
| </div> |
| </div> |
| <div class="navbar-item has-dropdown is-hoverable"> |
| <a class="navbar-link" href="#">Support</a> |
| <div class="navbar-dropdown"> |
| <span class="navbar-item navbar-heading">Contact</span> |
| <a class="navbar-item" href="../../docs/latest/support/slack-channel.html">Slack</a> |
| <a class="navbar-item" href="../../docs/latest/support/mailing-list.html">Mailing Lists</a> |
| <a class="navbar-item" href="https://issues.apache.org/jira/browse/ISIS">JIRA</a> |
| <a class="navbar-item" href="https://stackoverflow.com/questions/tagged/isis">Stack Overflow</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Releases</span> |
| <a class="navbar-item" href="../../docs/latest/downloads/how-to.html">Downloads</a> |
| <a class="navbar-item" href="../../relnotes/latest/about.html">Release Notes</a> |
| <a class="navbar-item" href="../../docs/latest/archive/1-x.html">Archive (1.x)</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Framework</span> |
| <a class="navbar-item" href="../../conguide/latest/about.html">Contributors' Guide</a> |
| <a class="navbar-item" href="../../comguide/latest/about.html">Committers' Guide</a> |
| <a class="navbar-item" href="../../core/latest/about.html">Core Design</a> |
| </div> |
| </div> |
| <div class="navbar-item has-dropdown is-hoverable"> |
| <a class="navbar-link" href="#">ASF</a> |
| <div class="navbar-dropdown"> |
| <a class="navbar-item" href="http://www.apache.org/">Apache Homepage</a> |
| <a class="navbar-item" href="https://www.apache.org/events/current-event">Events</a> |
| <a class="navbar-item" href="https://www.apache.org/licenses/">Licenses</a> |
| <a class="navbar-item" href="https://www.apache.org/security/">Security</a> |
| <a class="navbar-item" href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a> |
| <a class="navbar-item" href="https://www.apache.org/foundation/thanks.html">Thanks</a> |
| <hr class="navbar-divider"/> |
| <a class="navbar-item" href="https://whimsy.apache.org/board/minutes/Isis.html">PMC board minutes</a> |
| </div> |
| </div> |
| <a class="navbar-item" href="../../docs/latest/about.html"> |
| <span class="icon"> |
| <img src="../../_/img/home.png"></img> |
| </span> |
| </a> |
| </div> |
| </div> |
| </nav> |
| </header> |
| <div class="body "> |
| <div class="nav-container" data-component="vro" data-version="2.0.0-M3"> |
| <aside class="nav"> |
| <div class="panels"> |
| <div class="nav-panel-pagination"> |
| <a class="page-previous" rel="prev" href="security.html" title="Security"><span></span></a> |
| <a class="page-next" rel="next" |
| href="cors/about.html" title="CORS"><span></span></a> |
| <!-- |
| page.parent doesn't seem to be set... |
| <a class="page-parent disabled" rel="prev" href="" title="Security"><span></span></a> |
| --> |
| </div> |
| <div class="nav-panel-menu is-active" data-panel="menu"> |
| <nav class="nav-menu"> |
| <h3 class="title"><a href="about.html">Restful Objects Viewer</a></h3> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="0"> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="ro-spec.html">RO Spec</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="architecture.html">Architecture</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="layout-resources.html">Layout Resources</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="health-check.html">Health Check</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="simplified-representations.html">Simplified Representations</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="configuration-properties.html">Configuration Properties</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="security.html">Security</a> |
| </li> |
| <li class="nav-item is-current-page" data-depth="1"> |
| <a class="nav-link" href="hints-and-tips.html">Hints-n-Tips</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <button class="nav-item-toggle"></button> |
| <span class="nav-text">Extensions</span> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="2"> |
| <a class="nav-link" href="cors/about.html">CORS</a> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </nav> |
| </div> |
| <div class="nav-panel-explore" data-panel="explore"> |
| <div class="context"> |
| <span class="title">Restful Objects Viewer</span> |
| <span class="version">2.0.0-M3</span> |
| </div> |
| <ul class="components"> |
| <li class="component"> |
| <span class="title"> </span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../docs/2.0.0-M3/about.html">2.0.0-M3</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">BC Mappings Catalog</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../mappings/2.0.0-M3/about.html">2.0.0-M3</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Committers' Guide</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../comguide/2.0.0-M3/about.html">2.0.0-M3</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Contributors' Guide</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../conguide/2.0.0-M3/about.html">2.0.0-M3</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Design Docs</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../core/2.0.0-M3/about.html">2.0.0-M3</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Extensions Catalog</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../extensions/2.0.0-M3/about.html">2.0.0-M3</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Incubator Catalog</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../incubator/2.0.0-M3/about.html">2.0.0-M3</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">JDO/DataNucleus</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../pjdo/2.0.0-M3/about.html">2.0.0-M3</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Legacy Catalog</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../legacy/2.0.0-M3/about.html">2.0.0-M3</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Reference Guide</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../refguide/2.0.0-M3/about.html">2.0.0-M3</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Release Notes</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../relnotes/2.0.0-M3/about.html">2.0.0-M3</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component is-current"> |
| <span class="title">Restful Objects Viewer</span> |
| <ul class="versions"> |
| <li class="version is-current is-latest"> |
| <a href="about.html">2.0.0-M3</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Security Guide</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../security/2.0.0-M3/about.html">2.0.0-M3</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Setup Guide</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../setupguide/2.0.0-M3/about.html">2.0.0-M3</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Subdomains Catalog</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../subdomains/2.0.0-M3/about.html">2.0.0-M3</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Testing Guide</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../testing/2.0.0-M3/about.html">2.0.0-M3</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">User Guide</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../userguide/2.0.0-M3/about.html">2.0.0-M3</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Value Types Catalog</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../valuetypes/2.0.0-M3/about.html">2.0.0-M3</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Wicket Viewer</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../vw/2.0.0-M3/about.html">2.0.0-M3</a> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| </div> |
| </aside> |
| </div> |
| <main role="main"> |
| <div class="toolbar" role="navigation"> |
| <button class="nav-toggle"></button> |
| <a href="../../docs/2.0.0-M3/about.html" class="home-link"></a> |
| <nav class="breadcrumbs" aria-label="breadcrumbs"> |
| <ul> |
| <li><a href="about.html">Restful Objects Viewer</a></li> |
| <li><a href="hints-and-tips.html">Hints-n-Tips</a></li> |
| </ul> |
| </nav> |
| <div class="edit-this-page"><a href="https://github.com/apache/isis/edit/2.0.0-M3/viewers/restfulobjects/adoc/modules/ROOT/pages/hints-and-tips.adoc">Edit</a></div> |
| </div> |
| <article class="doc"> |
| <a name="section-top"></a> |
| <h1 class="page">Hints and Tips</h1> |
| <div id="preamble"> |
| <div class="sectionbody"> |
| <div class="admonitionblock warning"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-warning" title="Warning"></i> |
| </td> |
| <td class="content"> |
| TODO: this content has not yet been reviewed/updated for v2.0 |
| </td> |
| </tr> |
| </table> |
| </div> |
| <div class="paragraph"> |
| <p>This chapter provides some solutions for problems we’ve encountered ourselves or have been raised on the Apache Isis mailing lists.</p> |
| </div> |
| <div class="paragraph"> |
| <p>Since the Restful Objects viewer is designed for computer programs to interact with (rather than human beings), it can be a little difficult to explore and generally "grok" how it works.</p> |
| </div> |
| <div class="paragraph"> |
| <p>This section provides a few hints-and-tips to help you on your way.</p> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="using-chrome-devtools"><a class="anchor" href="#using-chrome-devtools"></a>Using Chrome Dev Tools</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>This <a href="https://www.youtube.com/watch?v=_-TOvVYWCHc">screencast</a> shows how to explore the Restful API using Chrome plugins/extensions, and how we use them to write end-2-end (TCK) tests for the Restful Objects viewer.</p> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="angular-tips"><a class="anchor" href="#angular-tips"></a>Angular Tips</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>The hypermedia API exposed by Apache Isis' Restful Objects viewer is intended be support both bespoke custom-written viewers as well as generic viewers. Indeed, we expect most clients consuming the API will be bespoke, not generic.</p> |
| </div> |
| <div class="paragraph"> |
| <p>This page captures one or two tips on using Angular to write such a bespoke client.</p> |
| </div> |
| <div class="sect2"> |
| <h3 id="invoking-a-get-link-eg-invoking-a-query-action"><a class="anchor" href="#invoking-a-get-link-eg-invoking-a-query-action"></a>Invoking a GET link (eg invoking a query action)</h3> |
| <div class="paragraph"> |
| <p>Suppose you have a <code>CustomerService</code> providing a <code>findCustomer</code> action:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public class CustomerService { |
| public String id() { return "customers"; } |
| @Action(semantics=SemanticsOf.SAFE) |
| public Customer findCustomer( |
| @ParameterLayout(named="customerName") |
| final String customerName) { |
| ... |
| } |
| }</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>Restful Objects will expose this as action with the following link that looks something like:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-javascript hljs" data-lang="javascript">{ |
| "rel" : "urn:org.restfulobjects:rels/invoke", |
| "href" : "http://localhost:8080/restful/services/customers/actions/findCustomer/invoke", |
| "method" : "GET", |
| "type" : "application/json;profile=\"urn:org.restfulobjects:repr-types/action-result\"", |
| "arguments" : { |
| "customerName" : { |
| "value" : null |
| } |
| } |
| }</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>You can then invoke this using Angular' <code>$resource</code> service as follows.</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-javascript hljs" data-lang="javascript">var findCustomer = $resource("http://localhost:8080/restful/services/customers/actions/findCustomer/invoke?:queryString"); |
| var findCustomerArgs = { |
| "customerName": { |
| "value": "Fred" |
| } |
| }; |
| findCustomer.get({queryString: JSON.stringify(findCustomerArgs)}, function(data) { /* ... */ } )</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>Here the <code>:queryString</code> placeholder in the initial <code>$resource</code> constructor is expanded with a stringified version of the JSON object representing the args. Note how the <code>findCustomerArgs</code> is the same as the <code>"arguments"</code> attribute in the original link (with a value provided instead of <code>null</code>).</p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="invoking-a-put-or-post-link"><a class="anchor" href="#invoking-a-put-or-post-link"></a>Invoking a PUT or POST link</h3> |
| <div class="paragraph"> |
| <p>If the method is a PUT or a POST, then no <code>:queryString</code> placeholder is required in the URL, and the args are instead part of the body.</p> |
| </div> |
| <div class="paragraph"> |
| <p>Use <code>$resource.put(…​)</code> or <code>$resource.post(…​)</code> instead.</p> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="pretty-printing"><a class="anchor" href="#pretty-printing"></a>Pretty printing</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>The JSON representations generated by the Restful Objects viewer are in compact form if the <a href="../../refguide/2.0.0-M3/config/about.html#deployment-types" class="page">deployment type</a> is SERVER (ie production), but will automatically be "pretty printed" (in other words indented) if the deployment type is PROTOTYPE.</p> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="restful-image-property"><a class="anchor" href="#restful-image-property"></a>How parse images in RO viewer?</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>From this <a href="http://markmail.org/message/4kcu7sml4ufdsah3">thread</a> on the Apache Isis users mailing list:</p> |
| </div> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p><em>I am trying to display an image in a JavaScript client app, the image comes from |
| an Isis RO web service as a string, but it won’t show. |
| Is there something I should do to change the message?</em></p> |
| </li> |
| </ul> |
| </div> |
| <div class="paragraph"> |
| <p>The RO viewer returns the image as a string, in the form:</p> |
| </div> |
| <div class="literalblock"> |
| <div class="content"> |
| <pre>"Tacos.jpg:image/jpeg:/9j//4AAQSkZJRgABAQEAlgCWAAD/ ...."</pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>This is in the form:</p> |
| </div> |
| <div class="literalblock"> |
| <div class="content"> |
| <pre>(filename):(mime type):(binary data in base64)</pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>This is basically the <a href="#refguide:applib-cm:classes/value-types.adoc#Blob" class="page unresolved"><code>Blob</code></a> value type, in string form.</p> |
| </div> |
| <div class="paragraph"> |
| <p>To use, split the parts then format the mime type and base64 data correctly before using as source in an <code><img></code> tag.</p> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="view-model-as-parameter"><a class="anchor" href="#view-model-as-parameter"></a>View Model as Parameter</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>As discussed <a href="https://lists.apache.org/thread.html/cbd18320bbf6e5c5e767283f9e675cf56e7f4692c109e1e79dbaa90a@%3Cusers.isis.apache.org%3E">on the mailing list</a>.</p> |
| </div> |
| <div class="sect2"> |
| <h3 id="query"><a class="anchor" href="#query"></a>Query</h3> |
| <div class="paragraph"> |
| <p>I must provide a REST service accepting more complex view model as input |
| parameter.</p> |
| </div> |
| <div class="paragraph"> |
| <p>My view model parameter would look like</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">@DomainObject( |
| nature = Nature.VIEW_MODEL, |
| objectType = "OfferTemplateFilter" |
| ) |
| @XmlRootElement(name = "OfferTemplateFilter") |
| @XmlAccessorType(XmlAccessType.FIELD) |
| @Getter @Setter |
| public class OfferTemplateFilter { |
| public List<String> selectedDeviceManufacturer = new ArrayList<>(); |
| public List<String> selectedDeviceSizes = new ArrayList<>(); |
| }</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>My REST domain service would be someting like</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">@DomainService( |
| nature = NatureOfService.VIEW_REST_ONLY, |
| objectType = "OfferRestService" |
| ) |
| public class OfferRestService { |
| |
| @Action(semantics = SemanticsOf.IDEMPOTENT) |
| public OfferTemplateSelectorForCustomer |
| offerSelectorForCustomer( |
| final String subscriberNumber, |
| final OfferTemplateFilter filter) { |
| return offerSelectorRepository.create(subscriberNumber, filter); |
| } |
| ... |
| }</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>I’m wondering how this could be achieved without custom rest service. |
| Ideally the service consumer would post a kind of JSON structure where my |
| view model OfferTemplateFilter would be created?</p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="possible-answer"><a class="anchor" href="#possible-answer"></a>Possible Answer…​</h3> |
| <div class="paragraph"> |
| <p>Rather than try to "upload" the <code>OfferTemplateFilter</code> view model as a parameter, instead treat it as a resource.</p> |
| </div> |
| <div class="paragraph"> |
| <p>That is:</p> |
| </div> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p>have a new service to create an instance of the filter, and then</p> |
| </li> |
| <li> |
| <p>update this filter (adding/removing from its two collections).</p> |
| </li> |
| <li> |
| <p>When done, pass a reference to the filter to the original REST service, as a regular reference.</p> |
| </li> |
| </ul> |
| </div> |
| <div class="paragraph"> |
| <p>Obviously the URL passed in the last step will be rather long and messy, but that’s not a problem per-se.</p> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="troubleshooting"><a class="anchor" href="#troubleshooting"></a>Troubleshooting</h2> |
| <div class="sectionbody"> |
| <div class="sect2"> |
| <h3 id="exception"><a class="anchor" href="#exception"></a>Exception</h3> |
| <div class="paragraph"> |
| <p>When invoking a REST service and getting a response with an embeded stacktrace like:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-json hljs" data-lang="json">{ |
| "httpStatusCode": 500, |
| "message": "com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions |
| Klasse enthält zwei Eigenschaften mit demselben Namen \"name\" |
| this problem is related to the following location: |
| at public java.lang.String ife.dep.ServiceName.getName() |
| at ife.dep.ServiceName |
| at public ife.dep.ServiceName ife.dep.ProvidedService.getServiceName() |
| at ife.dep.ProvidedService |
| at public java.util.SortedSet ife.dep.Release.getCapabilities() |
| at ife.dep.Release |
| at public ife.dep.Release ife.cfg.Configuration.getRelease() |
| at ife.cfg.Configuration |
| at public ife.cfg.Configuration ife.cfg.ConfigEntry.getConfiguration() |
| at ife.cfg.ConfigEntry |
| at public java.util.SortedSet ife.cfg.Endpoint.getCfgEntries() |
| at ife.cfg.Endpoint |
| this problem is related to the following location: |
| at public java.lang.String ife.dep.ServiceName.name |
| at ife.dep.ServiceName |
| at public ife.dep.ServiceName ife.dep.ProvidedService.getServiceName() |
| at ife.dep.ProvidedService |
| at public java.util.SortedSet ife.dep.Release.getCapabilities() |
| at ife.dep.Release |
| at public ife.dep.Release ife.cfg.Configuration.getRelease() |
| at ife.cfg.Configuration |
| at public ife.cfg.Configuration ife.cfg.ConfigEntry.getConfiguration() |
| at ife.cfg.ConfigEntry |
| at public java.util.SortedSet ife.cfg.Endpoint.getCfgEntries() |
| at ife.cfg.Endpoint |
| ", |
| [...] |
| }</code></pre> |
| </div> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="solution"><a class="anchor" href="#solution"></a>Solution</h3> |
| <div class="paragraph"> |
| <p>Add <code>@XmlAccessorType(XmlAccessType.FIELD)</code> to your domain entity:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">@javax.jdo.annotations.PersistenceCapable(identityType = IdentityType.DATASTORE) |
| @javax.jdo.annotations.DatastoreIdentity(strategy = javax.jdo.annotations.IdGeneratorStrategy.NATIVE, column = "id") |
| @javax.jdo.annotations.Version(strategy = VersionStrategy.VERSION_NUMBER, column = "version") |
| @DomainObject(objectType = "ServiceName", bounded = true) |
| @DomainObjectLayout(cssClassFa = "tag", describedAs = "") |
| @XmlAccessorType(XmlAccessType.FIELD) |
| @SuppressWarnings("javadoc") |
| public class ServiceName implements Capability, Comparable<ServiceName> { |
| |
| public String title() { |
| return getName(); |
| } |
| |
| public int compareTo(ServiceName o) { |
| return name.compareTo(o.name); |
| } |
| |
| @Override |
| public String toString() { |
| return title(); |
| } |
| |
| @MemberOrder(sequence = "1") |
| @javax.jdo.annotations.Column(allowsNull = "false") |
| @Getter @Setter |
| public String name; |
| |
| public boolean isSynchronous() { |
| return !isAsynchonous(); |
| } |
| |
| public boolean isAsynchonous() { |
| return name.startsWith(Constants.ESB_JMS_PREFIX); |
| } |
| }</code></pre> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| </article> |
| <aside class="article-aside toc" role="navigation"> |
| <p class="toc-title">On this page</p> |
| <div id="article-toc"></div> |
| </aside> |
| </main> |
| </div> |
| <footer class="footer"> |
| <div class="content"> |
| <div class="copyright"> |
| <p> |
| Copyright © 2010~2020 The Apache Software Foundation, licensed under the Apache License, v2.0. |
| <br/> |
| Apache, the Apache feather logo, Apache Isis, and the Apache Isis project logo are all trademarks of The Apache Software Foundation. |
| </p> |
| </div> |
| <div class="revision"> |
| <p>Revision: SNAPSHOT</p> |
| </div> |
| </div> |
| </footer> |
| <script src="../../_/js/site.js"></script> |
| <script async src="../../_/js/vendor/highlight.js"></script> |
| <script src="../../_/js/vendor/jquery-3.4.1.min.js"></script> |
| <script src="../../_/js/vendor/jquery-ui-1.12.1.custom.widget-only.min.js"></script> |
| <script src="../../_/js/vendor/jquery.tocify.min.js"></script> |
| |
| <script> |
| $(function() { |
| $("#article-toc").tocify( { |
| showEffect: "slideDown", |
| hashGenerator: "pretty", |
| hideEffect: "slideUp", |
| selectors: "h2, h3", |
| scrollTo: 120, |
| smoothScroll: true, |
| theme: "jqueryui", |
| highlightOnScroll: true |
| } ); |
| }); |
| </script> |
| </body> |
| </html> |