Skip to content

Commit ef5db9c

Browse files
committed
[NOT A PR] Showcase manipulating Lyo objects via an interceptor
1 parent a341170 commit ef5db9c

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/server-cm/src/main/java/co/oslc/refimpl/cm/gen/servlet/Application.java

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ public Set<Object> getSingletons() {
151151
// Start of user code Custom Resource Classes
152152
RESOURCE_CLASSES.add(OslcCorsFilter.class);
153153
RESOURCE_CLASSES.add(OslcCspFilter.class);
154+
RESOURCE_CLASSES.add(ExtendedPropWriteInterceptor.class);
154155
// End of user code
155156

156157
RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put(OslcConstants.PATH_ALLOWED_VALUES, AllowedValues.class);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package co.oslc.refimpl.cm.gen.servlet;
2+
3+
import co.oslc.refimpl.cm.gen.CMConstants;
4+
import co.oslc.refimpl.cm.gen.auth.AuthenticationApplication;
5+
import org.eclipse.lyo.oslc4j.core.model.ServiceProviderCatalog;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
import javax.ws.rs.WebApplicationException;
10+
import javax.ws.rs.ext.Provider;
11+
import javax.ws.rs.ext.WriterInterceptor;
12+
import javax.ws.rs.ext.WriterInterceptorContext;
13+
import javax.xml.namespace.QName;
14+
import java.io.IOException;
15+
16+
@Provider
17+
public class ExtendedPropWriteInterceptor implements WriterInterceptor {
18+
private static final QName OAUTH_REALM_NAME = new QName("http://jazz.net/xmlns/prod/jazz/jfs/1.0/", "oauthRealmName");
19+
private final Logger log = LoggerFactory.getLogger(ExtendedPropWriteInterceptor.class);
20+
21+
@Override
22+
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
23+
log.info("Interceptor called");
24+
final Object entity = context.getEntity();
25+
if (entity instanceof ServiceProviderCatalog) {
26+
final ServiceProviderCatalog catalog = (ServiceProviderCatalog) entity;
27+
catalog.getExtendedProperties().put(OAUTH_REALM_NAME, AuthenticationApplication.OAUTH_REALM);
28+
context.setEntity(catalog);
29+
}
30+
context.proceed();
31+
}
32+
}

0 commit comments

Comments
 (0)