Class SeoMixin
/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:
Defaults & behavior:
- Robots policy — deny-all by default.
GET /robots.txtreturns"User-agent: *\nDisallow: /\n"unless the builder specifies a different policy viarobotsAllow(...)orrobotsDisallow(...). 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.xmlreturns an empty<urlset>when no entries are configured. Add entries viasitemapEntry(String)orsitemapEntry(String,ZonedDateTime,String,Double). - Content types.
/robots.txtreturnstext/plain; charset=UTF-8;/sitemap.xmlreturnsapplication/xml; charset=UTF-8. - Both endpoints are excluded from generated Swagger / OpenAPI specs via
@OpSwagger(ignore=true).
See Also:
- Since:
- 10.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder forSeoMixininstances.static final classSingle sitemap entry (immutable).Nested classes/interfaces inherited from class org.apache.juneau.rest.server.servlet.RestMixin
RestMixin.DefaultBuilder<R extends RestMixin> -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionSeoMixin()No-arg constructor used when a host registers the mixin without builder configuration.protectedSeoMixin(SeoMixin.Builder builder) Builder constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic SeoMixin.Buildercreate()Creates a new builder.voidgetRobotsTxt(RestResponse res) [GET /robots.txt] — emit the configured robots policy astext/plain.voidgetSitemap(RestResponse res) [GET /sitemap.xml] — emit the configured sitemap asapplication/xml.Methods inherited from class org.apache.juneau.rest.server.servlet.RestMixin
builder, getHostContext, getRestBuilder, setContext
-
Field Details
-
DEFAULT_ROBOTS
Default robots policy: deny everything.- See Also:
-
-
Constructor Details
-
SeoMixin
public SeoMixin()No-arg constructor used when a host registers the mixin without builder configuration. -
SeoMixin
Builder constructor.Stashes the programmatic
RestBuilder(the builder itself, carrying any@Rest-level overrides such aspath) viasuper(builder)so those values take precedence over this mixin's own@Restannotation.- Parameters:
builder- The builder. Must not benull .
-
-
Method Details
-
create
Creates a new builder.- Returns:
- A new builder.
-
getRobotsTxt
[GET /robots.txt] — emit the configured robots policy astext/plain.- Parameters:
res- The current REST response.- Throws:
IOException- If an I/O error occurs while writing the response.
-
getSitemap
[GET /sitemap.xml] — emit the configured sitemap asapplication/xml.- Parameters:
res- The current REST response.- Throws:
IOException- If an I/O error occurs while writing the response.
-