Skip to content

Commit

Permalink
[NOT A PR] Showcase manipulating Lyo objects via an interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
berezovskyi committed Dec 10, 2023
1 parent 8712b8a commit b6c06c4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public Set<Object> getSingletons() {
// Start of user code Custom Resource Classes
RESOURCE_CLASSES.add(OslcCorsFilter.class);
RESOURCE_CLASSES.add(OslcCspFilter.class);
RESOURCE_CLASSES.add(ExtendedPropWriteInterceptor.class);
// End of user code

RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put(OslcConstants.PATH_ALLOWED_VALUES, AllowedValues.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package co.oslc.refimpl.cm.gen.servlet;

import co.oslc.refimpl.cm.gen.CMConstants;
import co.oslc.refimpl.cm.gen.auth.AuthenticationApplication;
import org.eclipse.lyo.oslc4j.core.model.ServiceProviderCatalog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.ext.Provider;
import javax.ws.rs.ext.WriterInterceptor;
import javax.ws.rs.ext.WriterInterceptorContext;
import javax.xml.namespace.QName;
import java.io.IOException;

@Provider
public class ExtendedPropWriteInterceptor implements WriterInterceptor {
private static final QName OAUTH_REALM_NAME = new QName("http://jazz.net/xmlns/prod/jazz/jfs/1.0/", "oauthRealmName");
private final Logger log = LoggerFactory.getLogger(ExtendedPropWriteInterceptor.class);

@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
log.info("Interceptor called");
final Object entity = context.getEntity();
if (entity instanceof ServiceProviderCatalog) {
final ServiceProviderCatalog catalog = (ServiceProviderCatalog) entity;
catalog.getExtendedProperties().put(OAUTH_REALM_NAME, AuthenticationApplication.OAUTH_REALM);
context.setEntity(catalog);
}
context.proceed();
}
}

0 comments on commit b6c06c4

Please sign in to comment.