<div dir="ltr">Hello,<div><br></div><div>we also used JAX-RS as Antonio mentioned.</div><div><br></div><div>You need to add a class to enable JAX-RS:</div><div><br></div><div>import javax.ws.rs.ApplicationPath;<br>import javax.ws.rs.core.Application;<br><br>@ApplicationPath("/api")<br>public class JaxRsActivator extends Application {<br> public JaxRsActivator() {}<br>}<br></div><div><br></div><div>And the classes for your endpoints:</div><div><br></div><div>import org.opencms.file.CmsObject;<br><br>import javax.ws.rs.GET;<br>import javax.ws.rs.Path;<br>import javax.ws.rs.Produces;<br>import javax.ws.rs.core.Context;<br>import javax.ws.rs.core.Response;<br>import javax.ws.rs.ext.Providers;<br>import java.util.List;<br>import java.util.stream.Collectors;<br><br>@Path("news")<br>public class NewsResource {<br><br> @Context<br> private HttpServletRequest request;<br><br> @GET<br> @Produces("application/json")<br> public Response getNews() {<br> CmsObject cms = getCmsObject();<br> <br> // e.g. use Solr to get relevant News documents<br> List<News> news...<br><br> return Response.ok().entity(news).build();<br> }<br><br> public CmsObject getCmsObject() {<br> CmsObject cmsObject;<br> try {<br> // try recover cms from session<br> cmsObject = OpenCms.getAuthorizationHandler().initCmsObject(request, "oOo", "xXx");<br> } catch (CmsAuthentificationException e) {<br> cmsObject = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest());<br> } catch (CmsException e) {<br> throw new InternalServerErrorException("Failed to initialize CmsObject", e);<br> }<br> return cmsObject;<br> }<br><br>}<br></div><div><br></div><div>With some Provider magic you could easily map exceptions to response codes or provide the CmsObject as context object.</div><div><br></div><div>King Regards,</div><div>Stephan</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Di., 25. Feb. 2020 um 14:22 Uhr schrieb <<a href="mailto:giovanni.daquino@intellisync.it">giovanni.daquino@intellisync.it</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="IT"><div class="gmail-m_-8362828557068443340WordSection1"><p class="MsoNormal">Hello everyone, <u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">I am wondering if anybody has successfully implemented a REST or really any kind of APIs in OpenCMS. I would like to extend OpenCMS to use it headlessly. I think you should add one or more modules and have the module expose some endpoints. Is this correct?<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Thank you,<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><span lang="EN-GB" style="color:rgb(0,160,153)">Giovanni Andrea D’Aquino<u></u><u></u></span></p><p class="MsoNormal"><b><span lang="EN-GB" style="font-size:10pt;color:rgb(0,160,153)">Software Engineer<u></u><u></u></span></b></p><p class="MsoNormal"><span lang="EN-GB"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:10pt;font-family:Helvetica,sans-serif;color:black"><img width="150" height="43" id="gmail-m_-8362828557068443340Immagine_x0020_1" src="cid:1708639be7e4cff311" alt="Descrizione: picturemessage_2w1anxdt.xg3 (1)"></span><span><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:13.5pt;font-family:Roboto"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:13.5pt;color:rgb(0,160,153)">INTELLISYNC Srl<br></span><span lang="EN-GB" style="font-size:10pt;color:rgb(0,160,153)">Via Sclafani, 40/B</span><span lang="EN-GB" style="font-size:10pt;color:rgb(0,160,153)"><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-GB" style="font-size:10pt;color:rgb(0,160,153)">Free Mind Foundry Innovation Hub<br>95024 Acireale (CT) Italy<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-GB" style="font-size:10pt;color:rgb(0,160,153)">Tel/Fax: (+39) 3475744346<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-GB" style="color:rgb(0,160,153)"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-GB"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt;color:rgb(0,160,153)">Join our communities and get updated<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt;color:rgb(0,160,153)"><u></u> <u></u></span></p><p class="MsoNormal"><a href="https://www.linkedin.com/company/intellisync" target="_blank"><span style="font-size:10pt;color:blue;text-decoration:none"><img border="0" width="23" height="23" id="gmail-m_-8362828557068443340Picture_x0020_2" src="cid:1708639be7e5b16b22" alt="linkedin_email"></span></a><span lang="EN-US"><u></u><u></u></span></p><p class="MsoNormal"><span lang="DE" style="color:rgb(25,66,116)"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:8pt;color:rgb(0,160,153)">This email and any files transmitted with it are confidential and may be privileged and are intended solely for the use of the individual or entity to whom they are addressed. <br>If you are not an addressee, any unauthorized direct or indirect dissemination, distribution, publication or copying of this message and any attachments is strictly prohibited. <br>If you have received this email in error please notify the sender immediately, and delete this email from your system</span><span lang="EN-US" style="color:rgb(0,160,153)"><u></u><u></u></span></p><p class="MsoNormal"><u></u> <u></u></p></div></div>_______________________________________________<br>
This mail is sent to you from the opencms-dev mailing list<br>
To change your list options, or to unsubscribe from the list, please visit<br>
<a href="http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev" rel="noreferrer" target="_blank">http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev</a><br>
<br>
<br>
<br>
</blockquote></div>