RE: Error form HttpConverter

2009-04-29 Thread webpost
We where able to finally narrow down the  issue  to firewall rules that can 
causing some part of the code to fail.

However the last question, should we remove the following code?

esponseHeaders.add(​Cache-Control, no-cache);
responseHeaders.add(Pragma, no-cache);
responseHeaders.add(Expires, 0);

THanks for you help.

rgds,
vinoo

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=1973713


Re: Error form HttpConverter

2009-04-29 Thread Thierry Boileau
Hello Vinoo,

at least, you must remove responseHeaders.add(Expires, 0);  
because it's forbidden and replace it by a call to 
Representation#setExpirationDate() as pointed by Jerome.
Having said that, I think you can remove the code, or let it and set the 
expiration date with the current date.

best regards,
Thierry Boileau

I have also a few very minor remarks on your code:
- you can replace org.restlet.http.headers by 
HttpConstants.ATTRIBUTE_HEADERS (if 1.1 rc2 allows it)
- I'm not sure it's good pratice to have one Resource class that handle 
/products and /products/{assetId}
 We where able to finally narrow down the  issue  to firewall rules that can 
 causing some part of the code to fail.

 However the last question, should we remove the following code?

 responseHeaders.add(​Cache-Control, no-cache);
 responseHeaders.add(Pragma, no-cache);
 responseHeaders.add(Expires, 0);

 THanks for you help.

 rgds,
 vinoo

 --
 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=1973713



--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=1977293


RE: Error form HttpConverter

2009-04-27 Thread vinoo
Hi Jerome,

I have attached 3 files that I thought may be relevant for you to identify our 
issue. Also trimmed the code to level that you can easily understand.

Guess the ERRORs are related to the following code.
responseHeaders.add(Cache-Control, no-cache); 

responseHeaders.add(Pragma, no-cache);

responseHeaders.add(Expires, 0);

Should we get rid of the above code?

Note: For some historical reason we are on Restlet 1.1-RC2 level.

We where wondering why we see these exception gets thrown only when we request 
the service via the external IP(load balancer). ie Not if we directly access 
the service using the http://server:8087 address.

Thank you.

rgds,
vinoopackage com..catalog.internal.restlet;

import org.restlet.Application;
import org.restlet.Context;
import org.restlet.Restlet;
import org.restlet.Router;

public class CatalogApplication extends Application {

	public RegistryApplication(Context parentContext) {
		super(parentContext);
	}

	/**
	* Creates a root Restlet that will receive all incoming calls.
	*/
	@Override
	public synchronized Restlet createRoot() {
	// Create a router Restlet that defines routes.
		Router router = new Router(getContext());

		// Defines a route for Products
		router.attach(/products, CatalogResource.class);

		// Defines a route for a particular Product
		router.attach(/products/{assetId}, CatalogResource.class);
		
		return router;
	}
}
package com..registry.internal.restlet;

import java.io.BufferedReader;
...

/**
 * Resource which has only one representation.
 * 
 */
public class CatalogResource extends Resource {
	
	private ListProduct products = new ArrayListProduct();
..
	public CatalogResource(Context context, Request request, Response response) {
		super(context, request, response);

		this.errors.clear();
		this.Products.clear();

		Form responseHeaders = (Form) getResponse().getAttributes().get(org.restlet.http.headers);  
		if (responseHeaders == null) {  
			responseHeaders = new Form();  
			getResponse().getAttributes().put(org.restlet.http.headers, responseHeaders);  
		}  
		responseHeaders.add(Cache-Control, no-cache); 
		responseHeaders.add(Pragma, no-cache);
		responseHeaders.add(Expires, 0);

//code to get the value
// Get the assetId attribute value taken from the URI template /products/{assetId}.
		String assetId = (String) getRequest().getAttributes().get(assetId);  
if ((assetId != null)  (assetId.length()  0)) {
		getProductByAssetId(new Integer(assetId));
}

		if (sResponseFormat == null || sResponseFormat.length() == 0) {
			getVariants().add(new Variant(MediaType.APPLICATION_JSON));
		} else if (sResponseFormat.equals(TEXT_HTML)) {
			getVariants().add(new Variant(MediaType.TEXT_HTML));
			this.pathToComposerTemplate = getPathToComposerTemplate(request);
		} else if (sResponseFormat.equals(TEXT_XML)) {
			getVariants().add(new Variant(MediaType.TEXT_XML));
		} else if (sResponseFormat.equals(APPLICATION_XML)) {
			getVariants().add(new Variant(MediaType.APPLICATION_XML));
		}
	}

	/**
	 * Returns a listing of all Products found.
	 */
	public Representation represent(Variant variant) {
	   Representation representation = null;
	   String json = null;

   // XML Representation
   if (MediaType.TEXT_XML.equals(variant.getMediaType()) ||
		   MediaType.APPLICATION_XML.equals(variant.getMediaType())) {
representation = getDomRepresentation();
   }
   // JSON Representation
   else if (MediaType.APPLICATION_JSON.equals(variant.getMediaType())) {
Gson gson = new GsonBuilder().serializeNulls().create();
 
//added the call back
if ( this.callback )
 json = this.callbackFname + ( + gson.toJson(this.rs) + );;
else
	 json = gson.toJson(this.rs);
representation = new StringRepresentation(json, MediaType.APPLICATION_JSON);
   }
   // HTML Representation
   else {
	StringBuffer sb =  getComposerTemplate();
	Product Product = this.Products.get(0);
		HashtableString, String ht = new HashtableString, String();

representation = new StringRepresentation(sb.toString(), MediaType.TEXT_HTML );		
   }
   
   return representation;
	}

	/**
	 * Retrieves the concrete Products from repository with given assetId
	 * 
	 * @param assetId
	 */
	public void getProductsByAssetId(Integer assetId) {
{
 //Code to get the Products by assetId
 this.products.add(product);  
  
}
}
?xml version=1.0 encoding=UTF-8?
web-app version=2.5 
	xmlns=http://java.sun.com/xml/ns/javaee; 
	xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance; 
	xsi:schemaLocation=http://java.sun.com/xml/ns/javaee 
	

RE: Error form HttpConverter

2009-04-25 Thread Jerome Louvel
Hi Vinoo,

I'm not sure, I would need to look a some reproducible code. It might be due
to the way to defined your Restlet VirtualHost instances.

Also, used Representation#setExpirationDate() instead of manually setting
the Expires HTTP header. That will save you a warning message.
 
Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com


-Message d'origine-
De : vinoo [mailto:vinoo.jos...@gmail.com] 
Envoyé : vendredi 24 avril 2009 22:55
À : discuss@restlet.tigris.org
Objet : Error form HttpConverter

My team is running into a very strange issues with our REST services. We are
in a hosted environment.
We have our application deployed to a JBoss server running on port 8087. 

We have a service as follows
http://xxx.xxx.xx.xx:8087/productcatalog/catalog/products/507?response_forma
t=TEXT_HTML
And it successfully returns a HTML document of the product details.

We also have firewall port forwarding rules that maps a public IP, say
ZZZ.ZZ.ZZ.ZZZ which is mapped to the interal IP as follows
xxx.xxx.xx.xx:8087. 

Now if I try to access the same REST url that I used above
http://ZZZ.ZZ.ZZ.ZZZ/productcatalog/catalog/products/507?response_format=TEX
T_HTML

It FAILS !!

In the server.log, I see the following error, ERROR 2009-04-24 10:21:39,947
STDERR -- Apr 24, 2009 10:21:39 AM com.noelios.restlet.LogFilter afterHandle
INFO: 2009-04-2410:21:39aaa.aaa.aaa.aaa-xxx.xxx.xx.xx80
GET

productcatalog/catalog/mashups/507response_format=TEXT_HTML2000
-828

http://registry.serena.comMozilla/5.0 (Windows; U; Windows NT 5.1;
en-US; rv:1.9.0.9) Gecko/2009040821 

Firefox/3.0.9 (.NET CLR 3.5.30729)-
: ERROR 2009-04-24 10:21:39,947 STDERR -- Apr 24, 2009 10:21:39 AM 

com.noelios.restlet.http.HttpServerConverter commit
WARNING: A response with an unavailable entity was returned. Ignoring the
entity for resource 

http://ZZZ.ZZ.ZZ.ZZZ/productcatalog/catalog/products/507?response_format=TE
XT_HTML.
: ERROR 2009-04-24 10:21:39,947 STDERR -- Apr 24, 2009 10:21:39 AM
com.noelios.restlet.http.HttpConverter 

addAdditionalHeaders
INFO: Addition of the standard header Cache-Control is discouraged. Future
versions of the Restlet API will 

directly support it.
: ERROR 2009-04-24 10:21:39,947 STDERR -- Apr 24, 2009 10:21:39 AM
com.noelios.restlet.http.HttpConverter 

addAdditionalHeaders
INFO: Addition of the standard header Pragma is discouraged. Future
versions of the Restlet API will 

directly support it.
: ERROR 2009-04-24 10:21:39,947 STDERR -- Apr 24, 2009 10:21:39 AM
com.noelios.restlet.http.HttpConverter 

addAdditionalHeaders
WARNING: Addition of the standard header Expires is not allowed. Please
use the Restlet API instead.


Relevant Code snippet

public Representation represent(Variant variant) { {
   StringBuffer sb =  getComposerTemplate();
   //Builds the HTML
   representation = new StringRepresentation(sb.toString(),
MediaType.TEXT_HTML );

   return representation;
}

Any help will be really appreciate and this is happening in a pre-production
environment.

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=18975
54

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=1909830