java.lang.Object
org.apache.juneau.rest.server.servlet.RestMixin
org.apache.juneau.rest.server.convention.SeoMixin

public class SeoMixin extends RestMixin
Mixin that serves SEO-conventional endpoints /robots.txt and /sitemap.xml.

Sibling of FaviconMixin (/favicon.ico), VersionMixin (/version), and WellKnownMixin (/.well-known/*). All four classes live in the org.apache.juneau.rest.server.convention convention-endpoints mixin pack.

Compose into a host resource via @Rest(mixins=SeoMixin.class); the /robots.txt and /sitemap.xml URLs become available alongside the host's own endpoints with no further wiring.

Hardcoded mount paths:

Unlike the sibling api-docs and ops mixins (see SwaggerMixin, VersionMixin, etc.), the two mount paths here are not SVL-configurable. /robots.txt is fixed by the Robots Exclusion Protocol (RFC 9309) which prescribes that crawlers fetch the policy from /robots.txt at the site root; /sitemap.xml is fixed by the sitemaps.org protocol (and consumed by search engines configured to look for the file at that exact path). A runtime mount-path override here would have no practical effect.

Mixin-only deployment:

This resource is designed for composition via @Rest(mixins=...). The two mount paths (/robots.txt, /sitemap.xml) are pinned at the op level by @RestGet(path=...) on the handler methods; a class-level @Rest(paths=...) declaration would be silently ignored under the mixin pattern (see @Rest(paths) Javadoc).

Composition example:

@Rest(path="/api", mixins=SeoMixin.class) public class ApiResource extends RestServlet { } // Override defaults via a @Bean factory: @Bean SeoMixin seo() { return SeoMixin.create() .robotsAllow("*", "/") .sitemapEntry("/api/items") .build(); }

Defaults & behavior:
  • Robots policy — deny-all by default. GET /robots.txt returns "User-agent: *\nDisallow: /\n" unless the builder specifies a different policy via robotsAllow(...) or robotsDisallow(...). The deny-all default is intentional — mounting the mixin without thinking should not auto-opt the service into search-engine indexing.
  • Sitemap empty by default. GET /sitemap.xml returns an empty <urlset> when no entries are configured. Add entries via sitemapEntry(String) or sitemapEntry(String,ZonedDateTime,String,Double).
  • Content types. /robots.txt returns text/plain; charset=UTF-8; /sitemap.xml returns application/xml; charset=UTF-8.
  • Both endpoints are excluded from generated Swagger / OpenAPI specs via @OpSwagger(ignore=true).
See Also:
Since:
10.0.0
  • Field Details

  • Constructor Details

    • SeoMixin

      public SeoMixin()
      No-arg constructor used when a host registers the mixin without builder configuration.
    • SeoMixin

      protected SeoMixin(SeoMixin.Builder builder)
      Builder constructor.

      Stashes the programmatic RestBuilder(the builder itself, carrying any @Rest-level overrides such as path) via super(builder) so those values take precedence over this mixin's own @Rest annotation.

      Parameters:
      builder - The builder. Must not be null.
  • Method Details

    • create

      public static SeoMixin.Builder create()
      Creates a new builder.
      Returns:
      A new builder.
    • getRobotsTxt

      public void getRobotsTxt(RestResponse res) throws IOException
      [GET /robots.txt] — emit the configured robots policy as text/plain.
      Parameters:
      res - The current REST response.
      Throws:
      IOException - If an I/O error occurs while writing the response.
    • getSitemap

      public void getSitemap(RestResponse res) throws IOException
      [GET /sitemap.xml] — emit the configured sitemap as application/xml.
      Parameters:
      res - The current REST response.
      Throws:
      IOException - If an I/O error occurs while writing the response.