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
@Path("info/{tweeter}") | |
@POST | |
@Consumes("application/x-www-form-urlencoded") | |
public Response postInfo(@FormParam("tweeter_id") String id, @FormParam("tweeter_email") String email){ | |
//use the injected values from HTML form attributes tweeter_id and tweeter_email | |
} |
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
@Path({id}/tweet) | |
@POST | |
@Consumes("application/json") | |
public Response postTweet(Tweet aTweet){ | |
//Tweet is a custom domain object | |
} | |
@Provider | |
@Consumes("application/json") | |
public TweetReader implements MessageBodyReader<Tweet>{ |
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
@Provider | |
public class HeaderModifierFilter implements ContainerResponseFilter{ | |
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException{ | |
//logic here - add custom heasers to the response | |
} | |
} |
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
@Provider | |
public CustomWriterInterceptor implements WriterInterceptor{ | |
@Override | |
public void aroundWriteFrom(WriterInterceptorContext wic){ | |
//use the methods from the WriterInterceptorContext | |
wic.proceed(); | |
//invoke the proceed method to get things moving! | |
} | |
} |
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
@Path({user_id}/tweet/{tweet_id}) | |
@GET | |
@Produces("application/json") | |
public Tweet getTweet(@PathParam("user_id") String userid, @PathParam("tweet_id") String tweeter){ | |
//use the userid and tweetid to fetch the Tweet (domain object) and return it - this will trigger the MessageBodyWriter implementation | |
} | |
@Provider | |
@Produces("application/json") | |
public TweetWriter implements MessageBodyWriter<Tweet>{ |
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
public class EmbeddedEJBExample{ | |
//inject an EJB available on the classpath | |
@EJB | |
MyLocalEJB local; | |
//use JNDI to talk to remotely deployed EJBs (via RMI) | |
EJBContainer container = EJBContainer.createEJBContainer(); | |
Context context = container.getContext(); | |
ARemoteEJB remote = (ARemoteEJB) context.lookup(<provide JNDI name here >) | |
} |
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
// is this robust enough ? | |
@WebService | |
public class POJO_WS{ | |
@WebMethod | |
public String getDate(){ | |
System.out.println("hashCode -- "+ this.hashCode()); | |
return new Date().toString(); | |
} | |
} |
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
//not perfect - but better than just @WebService | |
//will recieve free services from the EJB container, courtsey @Stateless ! | |
@Stateless | |
@WebService | |
public class POJO_EJB_and_SOAP { | |
public String fetchDate(){ | |
System.out.println("hashCode -- "+ this.hashCode()); | |
return new Date().toString(); | |
} |
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
public class JCacheUsage{ | |
public static void main(String[] args){ | |
//bootstrap the JCache Provider | |
CachingProvider jcacheProvider = Caching.getCachingProvider(); | |
CacheManager jcacheManager = jcacheProvider.getCacheManager(); | |
//configure cache | |
MutableConfiguration<String, Integer> jcacheConfig = new MutableConfiguration<>(); | |
jcacheConfig.setTypes(String.class, MyPreciousObject.class); | |
//create cache | |
Cache<String, MyPreciousObject> cache = jcacheManager.createCache("PreciousObjectCache", jcacheConfig); |
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
//set JMV level system property | |
-Djavax.cache.spi.cachingprovider=org.ehcache.jcache.JCacheCachingProvider | |
//code level config | |
System.setProperty("javax.cache.spi.cachingprovider","org.ehcache.jcache.JCacheCachingProvider"); | |
//you want to choose from multiple JCache providers at runtime | |
CachingProvider ehcacheJCacheProvider = Caching.getCachingProvider("org.ehcache.jcache.JCacheCachingProvider"); | |
//which JCache providers do I have on the classpath? |