<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Headless API - Is there a WebServerServlet equivalent?</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=120698685" />
  <subtitle>Headless API - Is there a WebServerServlet equivalent?</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=120698685</id>
  <updated>2026-04-04T08:47:41Z</updated>
  <dc:date>2026-04-04T08:47:41Z</dc:date>
  <entry>
    <title>RE: RE: Headless API - Is there a WebServerServlet equivalent?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120700252" />
    <author>
      <name>Christopher Dawson</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120700252</id>
    <updated>2021-03-29T16:48:48Z</updated>
    <published>2021-03-29T15:02:41Z</published>
    <summary type="html">&lt;p&gt;Thanks for the feedback Javier. Appreciate the timely response.&lt;/p&gt;</summary>
    <dc:creator>Christopher Dawson</dc:creator>
    <dc:date>2021-03-29T15:02:41Z</dc:date>
  </entry>
  <entry>
    <title>RE: RE: Headless API - Is there a WebServerServlet equivalent?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120697101" />
    <author>
      <name>Javier Gamarra</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120697101</id>
    <updated>2021-03-27T14:59:36Z</updated>
    <published>2021-03-27T14:59:36Z</published>
    <summary type="html">&lt;p&gt;Binary responses are supported but we have some flaws in the
  implementation (https://issues.liferay.com/browse/LPS-110447). The
  best way of defining them would be like the Batch API is doing: &lt;a href="https://github.com/liferay/liferay-portal/blob/7748a8326979c11a3563eed2da15ad4fd0ef915b/modules/apps/headless/headless-batch-engine/headless-batch-engine-impl/rest-openapi.yaml#L186"&gt;https://github.com/liferay/liferay-portal/blob/7748a8326979c11a3563eed2da15ad4fd0ef915b/modules/apps/headless/headless-batch-engine/headless-batch-engine-impl/rest-openapi.yaml#L186&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;That let's you return a Response object that can be anything: a DTO
  or in this case an output stream:&lt;/p&gt;
&lt;p&gt;
  &lt;a href="https://github.com/liferay/liferay-portal/blob/83e8e3c52b30cc8af9ba554700c7e4617bf3d771/modules/apps/headless/headless-batch-engine/headless-batch-engine-impl/src/main/java/com/liferay/headless/batch/engine/internal/resource/v1_0/ExportTaskResourceImpl.java#L80"&gt;https://github.com/liferay/liferay-portal/blob/83e8e3c52b30cc8af9ba554700c7e4617bf3d771/modules/apps/headless/headless-batch-engine/headless-batch-engine-impl/src/main/java/com/liferay/headless/batch/engine/internal/resource/v1_0/ExportTaskResourceImpl.java#L80&lt;/a&gt;&lt;/p&gt;</summary>
    <dc:creator>Javier Gamarra</dc:creator>
    <dc:date>2021-03-27T14:59:36Z</dc:date>
  </entry>
  <entry>
    <title>RE: Headless API - Is there a WebServerServlet equivalent?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120697044" />
    <author>
      <name>Javier Gamarra</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120697044</id>
    <updated>2021-03-27T14:53:06Z</updated>
    <published>2021-03-27T14:53:06Z</published>
    <summary type="html">&lt;p&gt;Mmm... it's a good question, most use cases getting images from the
  APIs are for retrieving meta information of *public* images. I guess
  that your use case is that you want to render private images and you
  want them to stay that way. So you can not embed them directly in an
  &amp;lt;img tag...&lt;/p&gt;
&lt;p&gt;So we can...&lt;/p&gt;
&lt;p&gt;-&amp;gt; Embed them. I would not recomment embedding images in a GET
  collection request because you can end with a large request (&amp;gt;1MB)
  that timeouts/get's dropped and chaos occurs. If you are getting
  images in a small number of requests (0-10) and those images are small
  (like &amp;gt;200kb) I don't see the problem, the browser would have to do
  an extra request either way of that similar size. You lose some things
  like caching the image automatically and some optimizations but I
  think it's Ok.&lt;/p&gt;
&lt;p&gt;-&amp;gt; Use the contentUrl. That was the planned path. But it that
  image is private we have to pass the token in the request. There is a
  limitation with basic auth right now that will be removed in the
  future but OAuth2/tokens is fine.&lt;/p&gt;
&lt;p&gt;-&amp;gt; Use adapted Images that are usually public and work with Basic
  Auth. The path
  http://localhost:8080&lt;em&gt;/o/adaptive-media/image/12345/Preview-1000x0/AnImage-123.png?t=1538761582000 &lt;/em&gt;should
  work for those...&lt;/p&gt;
&lt;p&gt;-&amp;gt; Create an API that returns the image.&lt;/p&gt;</summary>
    <dc:creator>Javier Gamarra</dc:creator>
    <dc:date>2021-03-27T14:53:06Z</dc:date>
  </entry>
  <entry>
    <title>RE: Headless API - Is there a WebServerServlet equivalent?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120698735" />
    <author>
      <name>Christopher Dawson</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120698735</id>
    <updated>2021-03-26T22:14:28Z</updated>
    <published>2021-03-26T22:13:30Z</published>
    <summary type="html">&lt;p&gt;As a follow up to this. I attempted to add my own API endpoint to
  return a file stream - however this does not appear to be supported
  within the 7.3.5 ga6 version of REST Builder: &lt;/p&gt;
&lt;pre&gt;&lt;code class="language-java"&gt;# rest-opeenapi.yaml

...
...
  &amp;quot;/app/image/{documentId}&amp;quot;:
    parameters:
      - in: path
        name: documentId
        schema:
          format: int64
          type: integer
        required: true
        description: id of the document
    get:
      summary: Get ImageFileStream for documentId
      responses:
        '200':
          description: OK
          content:
            application/octet-stream:
              schema: '#/components/schemas/ImageFileStream'
        '403':
          description: Forbidden
        '404':
          description: Not Found
        '500':
          description: Internal Server Error
      description: 'Based on a documentId, return a binary file stream for the asset'
      tags: [ImageFileStream]

...
...
components:
  schemas:
    ImageFileStream:
      type: string
      description: File stream for an image
      title: Image file stream
      format: binary
      readOnly: true


Resulting exception thrown by RESTBuilder: 

Exception in thread &amp;quot;main&amp;quot; java.lang.RuntimeException: Error generating REST API
Error in file &amp;quot;rest-openapi.yaml&amp;quot;: null
	at com.liferay.portal.tools.rest.builder.RESTBuilder.main(RESTBuilder.java:126)

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is mentioned as supported within OpenAPI v3.0 - refer to the
    section &lt;strong&gt;Response That Returns a File&lt;/strong&gt; in &lt;a
    href="https://swagger.io/docs/specification/describing-responses/ "&gt;the
    OpenAPI spec&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;While the spec indicates that one can just indicate a binary response
  - I have to incorporate a tag/resource in the RESTBuilder yaml -
  otherwise no Resource gets built. &lt;/p&gt;
&lt;p&gt;Again - any information on the above would be most helpful.&lt;/p&gt;</summary>
    <dc:creator>Christopher Dawson</dc:creator>
    <dc:date>2021-03-26T22:13:30Z</dc:date>
  </entry>
  <entry>
    <title>Headless API - Is there a WebServerServlet equivalent?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120698684" />
    <author>
      <name>Christopher Dawson</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120698684</id>
    <updated>2021-03-26T19:50:59Z</updated>
    <published>2021-03-26T19:45:48Z</published>
    <summary type="html">&lt;p&gt;Greetings:&lt;/p&gt;
&lt;p&gt;Hoping to get an answer regarding how to access file content from the
  document library via the headless api?&lt;/p&gt;
&lt;p&gt;We are running an independent SPA that is connecting to LR via the
  headless api with OAuth2/JWT. Since LR at this point is effectively
  stateless, I am wondering what the recommended approach is for
  delivering content from the document library?&lt;/p&gt;
&lt;p&gt;I am attempting to return links to images as part of my JSON payload
  and had started off by including an image preview url. I was clearly
  thinking old-school - leveraging the &lt;em&gt;WebServerServlet&lt;/em&gt; behind
  the /documents web.xml definition - because now there is no session
  information coming from the SPA -&amp;gt; API so every image request is
  getting redirected to the sign in page.&lt;/p&gt;
&lt;p&gt;I watched the DevCon presentation by Javier G. (thx for that!) and
  the topic was touched on briefly in terms of whether or not to embed
  content directly via nested fields. But I did not hear a definitive
  answer for larger files (or any files for that matter).&lt;/p&gt;
&lt;p&gt;I have browsed through the LR /o/headless-delivery/v1.0 endpoints -
  and did see an &lt;em&gt;Image&lt;/em&gt; schema entity. However I can find no
  relationship between that and any of the resources available from that
  endpoint. The &lt;em&gt;Document&lt;/em&gt; schema includes a contentUrl - but
  again that is going through the &lt;em&gt;WebServerServlet&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Options that occur to me:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Adapted Images. I do notice that as part of the document payload
    from a call
    to &lt;em&gt;/o/headless-delivery/v1.0/sites/{siteId}/documents&lt;/em&gt; that
    I am getting back an object containing adaptedImages e.g.  &lt;em&gt;/o/adaptive-media/image/12345/Preview-1000x0/AnImage-123.png?t=1538761582000&lt;/em&gt;
    &lt;br /&gt;However I am unable to retrieve these - nor does the
    path appear to match any of the available Rest APIs via API Explorer&lt;/li&gt;
  &lt;li&gt;Provide my own signed URL to S3 outside of the document library to
    allow timed access?&lt;/li&gt;
  &lt;li&gt;Incorporate some authentication token in every image request?&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Thanks in advance for any information you can provide on the matter.&lt;/p&gt;
&lt;p&gt;Sincerely,&lt;/p&gt;
&lt;p&gt;Chris D.&lt;/p&gt;</summary>
    <dc:creator>Christopher Dawson</dc:creator>
    <dc:date>2021-03-26T19:45:48Z</dc:date>
  </entry>
</feed>
