Re: Odd issue with VirtualHost.setServerAddress

2007-08-17 Thread Jerome Louvel
Hi Alex,

The serverAddress property indeed does comparisons based on the
numerical IP address. There are some convenience static methods on
VirtualHost:
 - getLocalHostAddress()
 - getIpAddress(String domain)

This should get clarified in the Javadocs too.

Best regards,
Jerome


2007/8/17, Alex Milowski [EMAIL PROTECTED]:
 On 8/16/07, Alex Milowski [EMAIL PROTECTED] wrote:
  Currently you can set a server's bind address by name (e.g. localhost)
  but when you set the server address on a VirtualHost instance, the
  wrong thing happens (e.g. nothing works).
 
  I think the problem is that the server's address is in numeric form
  internally.  For example, in the case of localhost, you are comparing
  localhost to 127.0.0.1--which is always going to fail.

 I've been able to fix this by doing:

try {
   InetAddress addr = 
 InetAddress.getByName(iface.getAddress());
   String saddr = addr.toString();
   saddr = saddr.substring(saddr.indexOf('/')+1);
   getLogger().info(Restricting +host.getName()+ to
 address +saddr);
   vhost.setServerAddress(saddr);
} catch (UnknownHostException ex) {
   getLogger().severe(Cannot resolve host name
 +iface.getAddress());
}

 Should I have to pass in the resolved address ?

 --Alex Milowski



Re: How to use servlet connector?

2007-08-17 Thread Alex
Hi,


I've moved a Restlet.Application and a Restlet.Resource to tomcat. I run into
the following problems.


in servlet-mapping of web.xml, if I use /* or /dir/* , like below:

servlet-mapping
servlet-nameServerServlet/servlet-name
url-pattern/*/url-pattern or url-pattern/dir/*/url-pattern
/servlet-mapping

I can get into the Resource by entering URLs like these:

http://localhost:8081/MyFirstOc4j/dir/abc/afile/
http://localhost:8081/MyFirstOc4j/dir/something

where, however, in the Router.attach() statement, I can only specify an emtpy
String:

router.attach(, IAPRestFileResource.class);


If I use URL pattern like these

router.attach(/dir, IAPRestFileResource.class);
router.attach(/dir/{dir}, IAPRestFileResource.class);

I cannot get into the Resource, though I can clearly see, from the log, that the
URL has been assigned to request.resourceRef /MyFirstOc4j/dir/abc/afile/):

Aug 17, 2007 7:46:03 PM com.noelios.restlet.LogFilter afterHandle
INFO: 2007-08-1719:46:03127.0.0.1   -   127.0.0.1   
8081GET
/MyFirstOc4j/dir/abc/afile/ -   404 331 -   1142413 
http://localhost:8081
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; OOCL; SV1; .NET CLR 1.1.4322;
InfoPath.1; .NET CLR 2.0.50727) -


1) Why cannot I specify the URL pattern?  How would I avoid in reinventing the
wheel to get those parameters from the link by parsing the URL from
request.resourceRef by myself?


2) even more serious, When there is escape character in the URL, e.g.,

http://localhost:8081/MyFirstOc4j/dir/c%3a%5ctemp/afile/

I cannot even get into Application.  Why and is there a standard method to cater
for escaped characters?


Yours,
Alex


Re: Odd issue with VirtualHost.setServerAddress

2007-08-17 Thread Alex Milowski
On 8/17/07, Jerome Louvel [EMAIL PROTECTED] wrote:
 Hi Alex,

 The serverAddress property indeed does comparisons based on the
 numerical IP address. There are some convenience static methods on
 VirtualHost:
  - getLocalHostAddress()
  - getIpAddress(String domain)

 This should get clarified in the Javadocs too.

This seems a bit inconsistent that you can use hostname when adding a server:

   getServers().add(Protocol.HTTPS,localhost,8080);

but you have to use a numeric ip addresses with setServerAddress on VirtualHost:

   vhost.setServerAddress(127.0.0.1);

InetAddress will do the right thing and handle both domain names and numeric
ip addresses and so this would be easy to implement as either.  Internally,
we could resolve any domain names to a specific numeric ip address and use
that for matching.

--Alex Milowski


get and send Cookie not working....

2007-08-17 Thread Regis Leray
I dont understand, i try to send a cookie to my client browser (firefox, IE6
) but it doesn't seems to work.

so it is pretty simple i have a filter and a router


(*filter*1) --- router - [handler1]
   |
   |-- [handler2]




So here my filter


MyFilter extends Filter {

//= IN DEBUGMODE I SAW ANY COOKIES in the request object, but in my
firefox browser or IE
// i have many cookies which came from my personal usage
public void beforeHandle(Request request, Response response) {
Cookie cookie = null;

if ((cookie = hasCookie(request)) != null) {
String hash = cookie.getValue();
 .
}
}

public void doHandle(Request request, Response response) {
super.doHandle(request, response);
}


//= I put in the response object the cookie, so by defautl it shoud
send the cookie to my browser
public void afterHandle(Request request, Response response) {

if (hasCookie(request) == null) {
CookieSetting cookie = new CookieSetting(COOKIE_VERSION,
COOKIE_HASH, session.getHash(), COOKIE_PATH,
request.getHostRef().getIdentifier());

cookie.setMaxAge(0);
cookie.setSecure(false);
response.getCookieSettings().add(cookie);
}
}


private Cookie hasCookie(Request request) {

ListCookie cookies = request.getCookies(); //always NULL

for (Cookie cookie : cookies) {

if (cookie.getPath().equals(COOKIE_PATH)
 cookie.getVersion() == COOKIE_VERSION.intValue()
 cookie.getDomain().equals(request.getHostRef
().getIdentifier())
 cookie.getName().equals(COOKIE_HASH)
 cookie.getValue().length()  1) {
return cookie;
}

}

return null;

}

}


Could you tell me what's wrong with my code ?
My goal it is to send a cookie to my client if it doesn't exist...

About my environment all of this it is run in a tomcat container, and i use
the restlet version 1.0.4.

thanks for your reply.




-- 
Regis LERAY


Re: get and send Cookie not working....

2007-08-17 Thread Alex Milowski
On 8/17/07, Regis Leray [EMAIL PROTECTED] wrote:
 private Cookie hasCookie(Request request) {

 ListCookie cookies = request.getCookies(); //always NULL

The getCookies() call should not return a null value.

snip/


 About my environment all of this it is run in a tomcat container, and i use
 the restlet version 1.0.4.

There could be an environment issue.  Have you tried running your application
outside of Tomcat using the Simple or Jetty connectors?

Have you checked the return headers using the LiveHttpHeaders [1] or
my Poster [2]
extension for Firefox to see if the Set-Cookie header is there?

[1] https://addons.mozilla.org/en-US/firefox/addon/3829
[2] https://addons.mozilla.org/en-US/firefox/addon/2691

--Alex Milowski


xml representation

2007-08-17 Thread Peter Sole
It's been couple of days since I have started reading about restlet api. I am 
implementing a service where my restlet/resource gets normal HTTP POST and 
after some processing I am suppose to return xml message back. I was looking 
at restlet api and xmlWriter class etc. I also read that restlet has extensive 
support to xml. A co-worker told me about a http://simple.sourceforge.net/ 
which allows serilization/deserialization of xml into java objects. Since I am 
new to both I was wondering which approch is better? whether restlet's api is 
enough to do the same of I have to use some third party xml api's?

Thanks for help,