RE: Bugfix for possible Nullpointer in Template.java

2008-07-18 Thread Jerome Louvel

Hi Ralf,

Thanks for the detailed report. The fix is now in SVN trunk!

Best regards,
Jerome


-Message d'origine-
De : Ralf Bommersbach [mailto:[EMAIL PROTECTED] 
Envoyé : jeudi 17 juillet 2008 17:52
À : discuss@restlet.tigris.org
Objet : Bugfix for possible Nullpointer in Template.java

Okay I think I found a little bug in the Template.java (in the 1.1snapshot):

It occurrs when the UserAgentTunnel in the Application is set enabled 
(setUserAgentTunnel(true) and your application gets a request where the 
user-agent is omitted.
The Template then tries to parse the user-agent string and gets a 
Nullpointer.

Here is the relevant part of the stackTrace:
java.lang.NullPointerException
at java.util.regex.Matcher.getTextLength(Unknown Source)
at java.util.regex.Matcher.reset(Unknown Source)
at java.util.regex.Matcher.init(Unknown Source)
at java.util.regex.Pattern.matcher(Unknown Source)
at org.restlet.util.Template.parse(Template.java:756)
at
org.restlet.data.ClientInfo.getAgentAttributes(ClientInfo.java:336)
at 
com.noelios.restlet.application.TunnelFilter.processUserAgent(TunnelFilter.j
ava:316)
at 
com.noelios.restlet.application.TunnelFilter.beforeHandle(TunnelFilter.java:
74)


and here a code snippet of the relevant part of Template.java at line 
752 (with the fix):
public int parse(String formattedString, MapString, Object variables) {
 int result = -1;
// fix
if (formattedString == null)
return result;
...}


Apparently Google Maps does this (i.e. no user-agent), as I pasted an 
URL which points to an KML-Representation of a Resource in the Google 
Maps Query Box and got the Nullpointer. (I can also see in the Server 
log that there is no user-agent)
When I disable the UserAgentTunnel it works (google maps neatly displays 
the kml then)

Okay thats it I think.

Greetings
Ralf Bommersbach

P.S. The fixed file is attached






Re: response MediaType with parameter

2008-07-18 Thread Thierry Boileau

Hello Zsolt,

thanks for your report, since this is a bug (following section 3.7 of 
the HTTP RFC).

It will be fixed soon.

best regards,
Thierry Boileau



Hello

I'd like to response an atom entry with content-type header:
'application/atom+xml; type=entry'.

I have an AtomRepresentation class (extends OutputRepresentation),
which contains the following constructor:

public AtomEntryRepresentation() {
   super(MediaType.APPLICATION_ATOM_XML);
   getMediaType().getParameters().add(type, entry);
   System.out.println(getMediaType().toString());  //
this prints  the type parameter correctly
}


When I response this representation to the client, the content-type
header contains only the type without the 'type' parameter.

# curl -v  http://localhost:8182/czinkos/resource/




 HTTP/1.1 200 The request has succeeded
 Content-Type: application/atom+xml
 Date: Thu, 17 Jul 2008 15:05:47 GMT
 Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
 Server: Noelios-Restlet-Engine/1.1.m4
 Connection: close
 Transfer-Encoding: chunked

atom:feed xmlns:atom=http://www.w3.org/2005/Atom;
 atom:id/
 atom:titleRoot collection for user czinkos/atom:title
 atom:updated2008-07-17T14:58:44,812Z/atom:updated
 atom:published2008-07-17T14:58:44,812Z/atom:published
* Closing connection #0
/atom:feed



What am I doing wrong?

Thank you


Zsolt

  


Re: response MediaType with parameter

2008-07-18 Thread Thierry Boileau

Hi Zsolt,

thanks for having reported this issue.

best regards,
Thierry Boileau


Hello

It works, thanks a lot.

Just a note for the record. The code I wrote is incorrect, since it
adds a 'type' parameter to MediaType.APPLICATION_ATOM_XML on every
instance creation (since it is static).

Following works correctly:

public AtomEntryRepresentation() {
  super(new MediaType(application/atom+xml));
  getMediaType().getParameters().add(type, entry);
}


Thanks again.

Zsolt




On Fri, Jul 18, 2008 at 11:11 AM, Thierry Boileau [EMAIL PROTECTED] wrote:
  

Hi Zsolt,

I've updated the svn repository. Could try it?

best regards,
Thierry Boileau




Hello

I'd like to response an atom entry with content-type header:
'application/atom+xml; type=entry'.

I have an AtomRepresentation class (extends OutputRepresentation),
which contains the following constructor:

public AtomEntryRepresentation() {
  super(MediaType.APPLICATION_ATOM_XML);
  getMediaType().getParameters().add(type, entry);
  System.out.println(getMediaType().toString());  //
this prints  the type parameter correctly
}


When I response this representation to the client, the content-type
header contains only the type without the 'type' parameter.

# curl -v  http://localhost:8182/czinkos/resource/




 HTTP/1.1 200 The request has succeeded
 Content-Type: application/atom+xml
 Date: Thu, 17 Jul 2008 15:05:47 GMT
 Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
 Server: Noelios-Restlet-Engine/1.1.m4
 Connection: close
 Transfer-Encoding: chunked

atom:feed xmlns:atom=http://www.w3.org/2005/Atom;
 atom:id/
 atom:titleRoot collection for user czinkos/atom:title
 atom:updated2008-07-17T14:58:44,812Z/atom:updated
 atom:published2008-07-17T14:58:44,812Z/atom:published
* Closing connection #0
/atom:feed



What am I doing wrong?

Thank you


Zsolt


  


  


Re: SSL + Virtual Hosts and Issue #489?

2008-07-18 Thread Alex Milowski
On Wed, Jul 16, 2008 at 2:32 AM, Jerome Louvel [EMAIL PROTECTED] wrote:

 Hi Alex,

 I have added a paragraph on Confidentiality in the Securing applications
 page covering this topic:
 http://wiki.restlet.org/docs_1.1/g1/13-restlet/29-restlet/99-restlet/46-rest
 let.html

 At some point, it might makes sense to split up this page into several ones.

Thanks.

I think it would be good to have some ssl-specific information make its
way into the connector documentation as an example.

That is, there is a simple example here:

   
http://wiki.restlet.org/docs_1.1/g1/13-restlet/27-restlet/37-restlet/38-restlet.html

Maybe we could have about ssl configuration there as well.  Of course, the
parameters are specific to the server helper...

--Alex Milowski


Re: SSL + Virtual Hosts and Issue #489?

2008-07-18 Thread Bruno Harbulot



Alex Milowski wrote:

On Wed, Jul 16, 2008 at 2:32 AM, Jerome Louvel [EMAIL PROTECTED] wrote:

Hi Alex,

I have added a paragraph on Confidentiality in the Securing applications
page covering this topic:
http://wiki.restlet.org/docs_1.1/g1/13-restlet/29-restlet/99-restlet/46-rest
let.html

At some point, it might makes sense to split up this page into several ones.


Thanks.

I think it would be good to have some ssl-specific information make its
way into the connector documentation as an example.

That is, there is a simple example here:

   
http://wiki.restlet.org/docs_1.1/g1/13-restlet/27-restlet/37-restlet/38-restlet.html

Maybe we could have about ssl configuration there as well.  Of course, the
parameters are specific to the server helper...


Actually, using the SslContextFactory, the parameters can now be 
consistent across the Grizzly, Jetty and Simple HTTPS connectors. We're 
currently debating how it should be configured (see issue 489, feel free 
to join in): parameters vs. instances.


I reckon that, for the DefaultSslContextFactory, parameters would 
definitely make more sense. The current behaviour is to be able to pass 
to its init() method a series of parameters that will more or less 
follow the previous style of parameters. (It doesn't set any trust 
manager, which instead use the values set in the javax.net.ssl.* system 
properties as default).


The DefaultSslContextFactory wouldn't help choosing an alias. I guess it 
would be feasible to have a fixed alias (in a similar way as I've done 
it in jSSLutils with FixedServerAliasKeyManager -- see one of the 
previous messages in this thread), but that wouldn't really help for 
your initial problem, unless you use a different context per connector.



If you want to be able to use a single SSLContext between your two 
sockets, you're going to need a KeyManager that is able to pick the 
right alias depending on which socket is used.
In jSSLutils, the FixedServerAliasKeyManager I've implemented picks one 
by always returning the same value (the one with which it's been 
constructed). What we'd need for would be a way to configure such a 
KeyManager so that it would look like this:


  class SocketSelectorKeyManager implements X509KeyManager {
 private final SomeInformation someInformation;
 public SocketSelectorKeyManager(SomeInformation someInformation) {
this.someInformation = someInformation;
 }
 public String chooseServerAlias(String keyType, Principal[] 
issuers, Socket socket) {
String alias = makeSomeDecisionBasedOn(someInformation, 
socket.getLocalSocketAddress()); // (or other arguments)

return alias;
 }
 ...
   }

What SomeInformation and makeSomeDecisionBasedOn should be like 
could depend on many factors. I could try to implement one of these in 
jSSLutils, but I'm not sure how you'd like to be able to configure such 
a KeyManager. Any preferences?



Regarding the documentation, I'm planning to document the 
jSSLutils-specific settings on the jSSLutils website when I get the time 
to do so (probably next week). I'll try to document the 
DefaultSslContextFactory in the Restlet doc too (although I'm not sure I 
have access to the wiki).



Best wishes,

Bruno.



Re: Variant and MediaType...

2008-07-18 Thread Stephan Koops

Hi Kit,

For the chart you should create a Resource class and add the variant 
with JSON to to the variants of this resource (see 
http://www.restlet.org/documentation/1.1/firstSteps#part01).


The selection for the image examples you show is pretty simple: You 
create a Resource class for the images, and set the attribute 
extensionTunnel of the TunnelService of your application to true. The 
extensions are mapped to mime types in the MetadataService of the 
application.


best regards
  Stephan

Kit Plummer schrieb:

I'm having a problem getting the Variant-getRepresentation scheme to work.
How does the Variant get determined? Or, really how does the MediaType get
determined for a request?

What I really want to do is return a JSON list for /chart/ and a GIF for
/chart/1234.gif or a PNG for /chart/1234.png.  Any ideas?  Something simple,
that I'm just missing?

TIA,
Kit
  


Re: questions about response.getEntity()

2008-07-18 Thread Helen Chen
I tried response.getEntity().getText()   then I get correct  data out.

maybe just response.getEntity() is not enough.

Helen

 Helen Chen 07/17/08 2:03 PM 
Hello there,

I have a issue when writing the client code. Basically I'm trying to get the
response from a url and then print out the response entity. But I found that if
I do 2 GET  requests one after another, the content of the response will be
stick together.  And I'm using JDK net connector.

The following are part of my client code:

this is a method to do the GET request:
  public static void get(Client client, Reference reference)throws
IOException 
  {
  if(log.isLoggable(Level.WARNING))
  {
  log.log(Level.INFO,);
  log.log(Level.INFO,response for the uri :  +
reference.toString() );
  }

  Response response = client.get(reference);
  if (response.getStatus().isSuccess()) {
 if(log.isLoggable(Level.WARNING))  
log.log(Level.INFO,request success);
 if (response.isEntityAvailable()) {
if(log.isLoggable(Level.WARNING))   
log.log(Level.INFO,entity available);
response.getEntity().write(System.out);
 }
  }
   }


then I have main method to call the get method:
public static void main(String[] args) throws IOException
{
Client client1 = new Client(Protocol.HTTP);
Client client2 = new Client(Protocol.HTTP);

Reference itemURI1 = new
Reference(http://myhost/articles/abc.json;);
Reference itemURI2 = new
Reference(http://myhost/articles/abc.xml;);

 //  I tried to use one client for testing, didn't work,
then I tried to separate each get call with different client, same result
get(client1, itemURI1);
get(client2, itemURI2);
}


the following are the output:
 [java] INFO: 
 [java] INFO: response for the uri : http://myhost/articles/abc.json 
 [java] INFO: request success
 [java] INFO: entity available
 [java] INFO: 
 [java] INFO: response for the uri : http://myhost/articles/abc.xml 
 [java] INFO: request success
 [java] INFO: entity available
 [java] {code:abc}?xml version=1.0
encoding=UTF-8?articlecodeabc/accode/article

the output {code:abc} should be for the first request, and the rest ?xml
version=1.0 encoding=UTF-8?articlecodeabc/accode/article should be
for the second request. You can see the data got sticked together. I actually
tried the apache http connector and I got the same result. Which kind of tells
me that just use response.getEntity() may not be enough to dump data out.

Can anyone tell me the trick how to make it work correctly?

Thanks, Helen


Re: questions about response.getEntity()

2008-07-18 Thread Helen Chen
Hi Stephan,

Thanks for pointing out. I changed the code to write to System.err and it works
as expected.  Thanks a lot.

Helen


 Stephan Koops [EMAIL PROTECTED] 07/18/08 4:08 PM 
Hi Helen,

the reason may be, that the INFOs are logged via System.err, but the 
entity via System.out.
In Java you could not be sure, that if you first write into System.out 
and then into System.err, that the data for System.out reaches your 
console before the data of System.err. So this is only a problem of the 
console
You could add a Thread.sleep(1000) between the calls of your get method 
(ignore the InterruptedException). Than you should see the data in right 
sequence

best regards
   Stephan

Helen Chen schrieb:
 I tried response.getEntity().getText()   then I get correct  data out.

 maybe just response.getEntity() is not enough.

 Helen

   
 Helen Chen 07/17/08 2:03 PM 
 
 Hello there,

 I have a issue when writing the client code. Basically I'm trying to get the
 response from a url and then print out the response entity. But I found that
if
 I do 2 GET  requests one after another, the content of the response will be
 stick together.  And I'm using JDK net connector.

 The following are part of my client code:

 this is a method to do the GET request:
   public static void get(Client client, Reference reference)   
throws
 IOException 
   {
   if(log.isLoggable(Level.WARNING))
   {
   log.log(Level.INFO,);
   log.log(Level.INFO,response for the uri :  +
 reference.toString() );
   }

   Response response = client.get(reference);
   if (response.getStatus().isSuccess()) {
  if(log.isLoggable(Level.WARNING))  
 log.log(Level.INFO,request success);
  if (response.isEntityAvailable()) {
 if(log.isLoggable(Level.WARNING))   
 log.log(Level.INFO,entity available);
 response.getEntity().write(System.out);
  }
   }
}


 then I have main method to call the get method:
 public static void main(String[] args) throws IOException
 {
 Client client1 = new Client(Protocol.HTTP);
 Client client2 = new Client(Protocol.HTTP);

 Reference itemURI1 = new
 Reference(http://myhost/articles/abc.json;);
 Reference itemURI2 = new
 Reference(http://myhost/articles/abc.xml;);

  //  I tried to use one client for testing, didn't work,
 then I tried to separate each get call with different client, same result
 get(client1, itemURI1);
 get(client2, itemURI2);
 }


 the following are the output:
  [java] INFO: 
  [java] INFO: response for the uri : http://myhost/articles/abc.json 
  [java] INFO: request success
  [java] INFO: entity available
  [java] INFO: 
  [java] INFO: response for the uri : http://myhost/articles/abc.xml 
  [java] INFO: request success
  [java] INFO: entity available
  [java] {code:abc}?xml version=1.0
 encoding=UTF-8?articlecodeabc/accode/article

 the output {code:abc} should be for the first request, and the rest
?xml
 version=1.0 encoding=UTF-8?articlecodeabc/accode/article should
be
 for the second request. You can see the data got sticked together. I
actually
 tried the apache http connector and I got the same result. Which kind of
tells
 me that just use response.getEntity() may not be enough to dump data out.

 Can anyone tell me the trick how to make it work correctly?

 Thanks, Helen