Skip to content

Commit

Permalink
Replace server's JAX-RS application (don't touch other <servlet-name>s)
Browse files Browse the repository at this point in the history
New `Dispatcher::getProxyClass` method
  • Loading branch information
namedgraph committed Oct 1, 2023
1 parent c8bb105 commit 80a3a99
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 39 deletions.
3 changes: 2 additions & 1 deletion platform/web.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ xmlns:jee="https://jakarta.ee/xml/ns/jakartaee"

<xsl:param name="jee:servlet-name"/>

<xsl:template match="jee:servlet-name/text()">
<!-- replace server's JAX-RS application (don't touch other <servlet-name>s) -->
<xsl:template match="jee:servlet-name/text()[. = 'com.atomgraph.linkeddatahub.Application']">
<xsl:choose>
<xsl:when test="$jee:servlet-name">
<xsl:value-of select="$jee:servlet-name"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,39 @@ public Dispatcher(@Context UriInfo uriInfo, Optional<Dataset> dataset, com.atomg
}

/**
* Returns JAX-RS resource that will handle this request.
* Returns proxy class that takes precedence over the default JAX-RS path matching.
* The request is proxied in two cases:
* <ul>
* <li>externally (URI specified by the <code>?uri</code> query param)</li>
* <li>internally if it matches a <code>lapp:Dataset</code> specified in the system app config</li>
* </ul>
* Otherwise, fall back to SPARQL Graph Store backed by the app's service.
*
* @return resource
* @return optional class
*/
@Path("{path: .*}")
public Object getSubResource()
public Optional<Class> getProxyClass()
{
if (getUriInfo().getQueryParameters().containsKey(AC.uri.getLocalName()))
{
if (log.isDebugEnabled()) log.debug("No Application matched request URI <{}>, dispatching to ProxyResourceBase", getUriInfo().getQueryParameters().getFirst(AC.uri.getLocalName()));
return ProxyResourceBase.class;
return Optional.of(ProxyResourceBase.class);
}
if (getDataset().isPresent())
{
if (log.isDebugEnabled()) log.debug("Serving request URI <{}> from Dataset <{}>, dispatching to ProxyResourceBase", getUriInfo().getAbsolutePath(), getDataset().get());
return ProxyResourceBase.class;
return Optional.of(ProxyResourceBase.class);
}

return getResourceClass();

return Optional.empty();
}

/**
* Returns JAX-RS resource that will handle this request.
*
* @return resource
*/
@Path("{path: .*}")
public Class getSubResource()
{
return getProxyClass().orElse(getResourceClass());
}

// TO-DO: move @Path annotations onto respective classes?
Expand All @@ -101,9 +109,9 @@ public Object getSubResource()
* @return endpoint resource
*/
@Path("sparql")
public Object getSPARQLEndpoint()
public Class getSPARQLEndpoint()
{
return SPARQLEndpointImpl.class;
return getProxyClass().orElse(SPARQLEndpointImpl.class);
}

/**
Expand All @@ -112,9 +120,9 @@ public Object getSPARQLEndpoint()
* @return endpoint resource
*/
@Path("service")
public Object getGraphStore()
public Class getGraphStore()
{
return GraphStoreImpl.class;
return getProxyClass().orElse(GraphStoreImpl.class);
}

/**
Expand All @@ -123,9 +131,9 @@ public Object getGraphStore()
* @return endpoint resource
*/
@Path("ns")
public Object getNamespace()
public Class getNamespace()
{
return Namespace.class;
return getProxyClass().orElse(Namespace.class);
}

/**
Expand All @@ -134,9 +142,9 @@ public Object getNamespace()
* @return namespace resource
*/
@Path("ns/{slug}/")
public Object getSubOntology()
public Class getSubOntology()
{
return Namespace.class;
return getProxyClass().orElse(Namespace.class);
}

/**
Expand All @@ -145,9 +153,9 @@ public Object getSubOntology()
* @return endpoint resource
*/
@Path("sign up")
public Object getSignUp()
public Class getSignUp()
{
return SignUp.class;
return getProxyClass().orElse(SignUp.class);
}

/**
Expand All @@ -156,9 +164,9 @@ public Object getSignUp()
* @return endpoint resource
*/
@Path("request access")
public Object getRequestAccess()
public Class getRequestAccess()
{
return RequestAccess.class;
return getProxyClass().orElse(RequestAccess.class);
}

/**
Expand All @@ -168,9 +176,9 @@ public Object getRequestAccess()
* @see com.atomgraph.linkeddatahub.apps.model.Application#UPLOADS_PATH
*/
@Path("uploads/{sha1sum}")
public Object getFileItem()
public Class getFileItem()
{
return com.atomgraph.linkeddatahub.resource.upload.sha1.Item.class;
return getProxyClass().orElse(com.atomgraph.linkeddatahub.resource.upload.sha1.Item.class);
}

/**
Expand All @@ -179,9 +187,9 @@ public Object getFileItem()
* @return endpoint resource
*/
@Path("importer")
public Object getImportEndpoint()
public Class getImportEndpoint()
{
return Importer.class;
return getProxyClass().orElse(Importer.class);
}

/**
Expand All @@ -190,9 +198,9 @@ public Object getImportEndpoint()
* @return endpoint resource
*/
@Path("add")
public Object getAddEndpoint()
public Class getAddEndpoint()
{
return Add.class;
return getProxyClass().orElse(Add.class);
}

/**
Expand All @@ -201,9 +209,9 @@ public Object getAddEndpoint()
* @return endpoint resource
*/
@Path("transform")
public Object getTransformEndpoint()
public Class getTransformEndpoint()
{
return Transform.class;
return getProxyClass().orElse(Transform.class);
}

/**
Expand All @@ -212,9 +220,9 @@ public Object getTransformEndpoint()
* @return endpoint resource
*/
@Path("generate")
public Object getGenerateEndpoint()
public Class getGenerateEndpoint()
{
return Generate.class;
return getProxyClass().orElse(Generate.class);
}

/**
Expand All @@ -223,9 +231,9 @@ public Object getGenerateEndpoint()
* @return endpoint resource
*/
@Path("clear")
public Object getClearEndpoint()
public Class getClearEndpoint()
{
return Clear.class;
return getProxyClass().orElse(Clear.class);
}

/**
Expand All @@ -234,9 +242,9 @@ public Object getClearEndpoint()
* @return endpoint resource
*/
@Path("oauth2/authorize/google")
public Object getAuthorizeGoogle()
public Class getAuthorizeGoogle()
{
return com.atomgraph.linkeddatahub.resource.admin.oauth2.google.Authorize.class;
return getProxyClass().orElse(com.atomgraph.linkeddatahub.resource.admin.oauth2.google.Authorize.class);
}

/**
Expand All @@ -245,9 +253,9 @@ public Object getAuthorizeGoogle()
* @return endpoint resource
*/
@Path("oauth2/login")
public Object getOAuth2Login()
public Class getOAuth2Login()
{
return com.atomgraph.linkeddatahub.resource.admin.oauth2.Login.class;
return getProxyClass().orElse(com.atomgraph.linkeddatahub.resource.admin.oauth2.Login.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ public ContainerRequestContext getContainerRequestContext()
*
* @return URI info
*/
@Override
public UriInfo getUriInfo()
{
return uriInfo;
Expand Down

0 comments on commit 80a3a99

Please sign in to comment.