[Logo] Terracotta Discussion Forums
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
Trying to use Jersey Client to Process POST to ehCache Server running in Tomcat.  XML
Forum Index -> Ehcache
Author Message
jdekker

journeyman

Joined: 11/30/2012 16:20:21
Messages: 21
Offline

I am using JDK 1.6, Jersey, & Jersey Client, Tomcat 7, and ehCache Server 1.0.0 to post a JSON String (from a standalone command line Java program) to a web service running on my local tomcat container.

In my ehCache.xml file, I have the following cache defined:

Code:
  <!--
 Cache named ipad
 This cache has a maximum of 1000 elements in memory. There is no overflow to disk, so 1000
 is also the maximum cache size. Note that when a cache is eternal, timeToLive and
 timeToIdle are not used and do not need to be specified.
 -->
 <cache name="ipad"
        maxElementsInMemory="10000"
        eternal="true"
        overflowToDisk="false"
        memoryStoreEvictionPolicy="FIFO"
 />
 


Here's the standalone command line Java program:

Code:
 import com.sun.jersey.api.client.Client;
 import com.sun.jersey.api.client.ClientResponse;
 import com.sun.jersey.api.client.WebResource;
 
 public class PostClient {
 	
 	private static final String EH_CACHE_IPAD_URI = "http://localhost:8080/ehcache/rest/ipad/";
 
 	public static void main(String[] args) {
 		try {
 			// Post the JSON Object to ehCache
 			String jsonString = "{\"qty\":100,\"name\":\"iPad 4\"}";
 			
 			System.out.println("JSON String: " + jsonString);
 			Client jerseyClient = Client.create();
 			WebResource webResource = jerseyClient.resource(EH_CACHE_IPAD_URI);
 
 			ClientResponse response = webResource.type("application/json").post(ClientResponse.class, jsonString);
 
 			if (response.getStatus() != 201) {
 				throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
 			}
 			System.out.println("\nposted successfully to ehCache Server\n");
 
 			System.out.println("\nOutput from ehCache Server .... \n");
 			String output = response.getEntity(String.class);
 			System.out.println(output);
 
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
 	}
 }
 


This is the what I output I get when I run this program:

Code:
 JSON String: {"qty":100,"name":"iPad 4"}
 java.lang.RuntimeException: Failed : HTTP error code : 405
 	at com.myapp.client.PostClient.main(PostClient.java:26)
 


What am I doing wrong? Is there a configuration issue with ehCache that I do not know of?

This same problems occurs in Tomcat 6.

All I am trying to do is to populate my cache with some JSON and then obtain it.

Is this a hard thing to do in ehCache?

Thank you for taking the time to read this...

-James
klalithr

consul

Joined: 01/23/2011 10:58:07
Messages: 485
Offline

Seems like I answered a simillar post elsewhere.
Just use the OSS Terracotta Server and simply use any framework (axis, jaxb) to expose your cache as a service?
This would provide additional scale and HA options.

Karthik Lalithraj (Terracotta)
jdekker

journeyman

Joined: 11/30/2012 16:20:21
Messages: 21
Offline

You never answered the question... You didn't even bother commenting on my code. I would prefer you to stop suggesting other servers and not answer my question with those suggestions. If ehCache can not be populated with JSON coming in from a different web service than what is it good for?
 
Forum Index -> Ehcache
Go to:   
Powered by JForum 2.1.7 © JForum Team