-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NOT A PR] Showcase manipulating Lyo objects via an interceptor
- Loading branch information
1 parent
8fc8ee4
commit d034150
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/server-cm/src/main/java/co/oslc/refimpl/cm/gen/servlet/ExtendedPropWriteInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |