Serving static files via CLAP protocol

2010-11-09 Thread gopheralex
Good people of Restlet-Land,

I'm using Restlet 2.0.3 JSE, including its built-in web server, in a small
standalone Java application. Having got a few resources working, my next
task is to serve a directory of static files from within a JAR file. As I
understand, I need to use the CLAP protocol for this, but my efforts in
getting it working have been unsuccessful. Explanation follows the code:

// Main.java:

public static void main(String[] args) throws Exception {
Component component = new Component();
component.getServers().add(Protocol.HTTP, 8080);
component.getDefaultHost().attach("/myapp",
new MyApplication());
component.start();
}

// MyApplication.java:

public synchronized Restlet createInboundRoot() {
this.authenticator = createAuthenticator();

Router router = new Router(this.getContext());
router.attach("/test", TestResource.class);

authenticator.setNext(router);

// initialize the static file server
final Component component = new Component();
component.getClients().add(Protocol.CLAP);
component.getContext().getParameters().add("timeToLive", "0");
final Directory dir = new Directory(
getContext(),
"clap://system/web/restlet_docs/schema/");
dir.setDeeplyAccessible(true);
dir.setListingAllowed(false);
dir.setNegotiatingContent(false);
router.attach("/schema", dir);

ErrorFilter ef = new ErrorFilter(this.getContext());
ef.setNext(authenticator);
return ef;
}

Upon app launch, Restlet logs the following:

Nov 9, 2010 7:04:46 PM org.restlet.engine.Engine createHelper
WARNING: No available server connector supports the required protocols:
'CLAP' . Please add the JAR of a matching connector to your classpath.
Nov 9, 2010 7:04:46 PM org.restlet.engine.http.connector.HttpServerHelper
start
INFO: Starting the internal HTTP server on port 8080

A subsequent request to http://localhost:8080/myapp/schema/ results in a 404
as well as the following log output:

Nov 9, 2010 7:10:05 PM org.restlet.engine.component.ClientRouter getNext
WARNING: The protocol used by this request is not declared in the list of
client connectors. (CLAP)
Nov 9, 2010 7:10:05 PM org.restlet.engine.component.ClientRouter getNext
WARNING: The protocol used by this request is not declared in the list of
client connectors. (CLAP)
Nov 9, 2010 7:10:05 PM org.restlet.engine.local.DirectoryServerResource
getVariants
INFO: Getting variants for : clap://system/web/restlet_docs/schema/
Nov 9, 2010 7:10:05 PM org.restlet.engine.local.DirectoryServerResource
doInit
INFO: Converted target URI: clap://system/web/restlet_docs/schema/
Nov 9, 2010 7:10:05 PM org.restlet.engine.log.LogFilter afterHandle
INFO: 2010-11-09 19:10:05 0:0:0:0:0:0:0:1%0 - - 8080 GET /myapp/schema/ -
404

I have the following JARs in my classpath:
org.restlet.jar
org.restlet.ext.json.jar
org.restlet.ext.xml.jar
org.restlet.ext.velocity.jar

Am I missing something?

Regards,
Alex

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

InputStream In not closing properly in InputRepresentation Class

2010-11-09 Thread Somu
Hello Jerome , Thierry, 

I'm was using the Restlet to serve the pdf retrievals and while I was
testing  I found that InputRepresentation.release() method is not closing
the inputstream properly if there is any socket exception or IO exception. I
tested with Restlet 1.1.10 and Restlet 2.0.2 version. but problem is existed
in both versions.

And I made the changes to source code(Restlet 1.1.0) to address this
problem. there are two ways to resolve this issue.

1) Changing the InputRepresentation release() method implementation, Instead
of creating the local 'result' variable inside the getStream() method
declare it as class level variable and use 'result' variable in release()
method to close the stream.
or
2) Wrapping the try-catch exception block for write method in in
ByteUtils(Line 970) and closing  the inputstream inside the catch block if
there is any IO Exception.

I'm attaching the changed source files and my test file which I used to
produce this bug. by the way to produce this bug in my test code I used
‘socket time out’ value to be small(1000 mills).

let me know If I'm wrong...

Attached files are(These files are from Restlet 1.1.10) as I mentioned same
issue is existed in 2.0 version code also.

http://restlet-discuss.1400322.n2.nabble.com/file/n5722563/ByteUtils.bmp
ByteUtils.bmp 
http://restlet-discuss.1400322.n2.nabble.com/file/n5722563/InputRepresentation.java
InputRepresentation.java 
http://restlet-discuss.1400322.n2.nabble.com/file/n5722563/InputRepresentationTest.java
InputRepresentationTest.java 
http://restlet-discuss.1400322.n2.nabble.com/file/n5722563/ByteUtils.java
ByteUtils.java 

Thanks, 
Somu

Here is the exception stack trace
java.io.IOException: Broken pipe
at
simple.http.MonitoredOutputStream.destroy(MonitoredOutputStream.java:159)
at 
simple.http.MonitoredOutputStream.write(MonitoredOutputStream.java:111)
at simple.http.ResponseStream.write(ResponseStream.java:141)
at org.restlet.util.ByteUtils.write(ByteUtils.java:975)
at
org.restlet.resource.InputRepresentation.write(InputRepresentation.java:119)
at
com.noelios.restlet.http.HttpServerCall.writeResponseBody(HttpServerCall.java:492)
at
com.noelios.restlet.http.HttpServerCall.sendResponse(HttpServerCall.java:428)
at
com.noelios.restlet.http.HttpServerConverter.commit(HttpServerConverter.java:392)
at
com.noelios.restlet.http.HttpServerHelper.handle(HttpServerHelper.java:148)
at
com.noelios.restlet.ext.simple.SimpleProtocolHandler.handle(SimpleProtocolHandler.java:75)
at simple.http.Dispatcher.run(Dispatcher.java:83)
at simple.util.process.Daemon.execute(Daemon.java:121)
at simple.util.process.Daemon.run(Daemon.java:106)
2010/11/09 15:42:35:375 EST [DEBUG] DefaultClientConnection

-- 
View this message in context: 
http://restlet-discuss.1400322.n2.nabble.com/InputStream-In-not-closing-properly-in-InputRepresentation-Class-tp5722563p5722563.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


XStream extention and NO_REFERENCES

2010-11-09 Thread webpost
I am using the XStream extension with ServerResource, and the generated XML 
contains references.  Is there a way to disable this?  It seems 
Xstream.setMode(XStream.NO_REFERENCES) should do it, but how do i get the 
XStream instance from within the @Get("xml") retrieve() method?

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


Re: Data loss between HTTP client and restlet server, errors writing to non-blocking channel

2010-11-09 Thread Carles Barrobés
I just tried using nginx as a reverse proxy. It doesn't seem to make any
difference, data is still being lost.

-- 
View this message in context: 
http://restlet-discuss.1400322.n2.nabble.com/Data-loss-between-HTTP-client-and-restlet-server-errors-writing-to-non-blocking-channel-tp5720451p5721844.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Re: Data loss between HTTP client and restlet server, errors writing to non-blocking channel

2010-11-09 Thread Tal Liron
I've been seeing this strange behavior in one of my hosts, which does 
have a weird setup. I "solved" it by putting Restlet (the server) behind 
an Apache reverse proxy. Somehow Apache streamlined the connections for 
me. I'm not saying this is the solution, but perhaps it can help you 
isolate where the problem is.


-Tal


On 11/09/2010 05:04 AM, Carles Barrobés wrote:

> I get these errors frequently in my restlet server log.
> I'm running restlet 2.0-RC04 as a standalone process.
> I consume the web services with Apache HTTP client 3.1.
>
> It seems to be related with serving "relatively" large pages (it seems to
> get more frequent).
>
> At the HTTP client side, sometimes the HTTP responses are missing data bytes
> (part of the response bytes are missing, sometimes part of the headers,
> other times part of the XHTML responses - it is not a data truncation, the
> bytes missing are bytes in-between the response) (see below).
>
> I haven't yet been able to establish a correlation between these errors,
> since these happen at a customer site and I have not been able to reproduce
> them in my development environment, even connecting to the customer's
> server.
>
> Any hints as to where to start?
>
>
> 
> Trace (server):
>
> INFO: 2010-10-2709:34:51192.168.1.4 pinsos  -   8182
> GET /v1/docs/   -   200 65129   -   40
> http://192.168.1.1:8182 Jakarta Commons-HttpClient/3.0.1-
> 27-oct-2010 9:34:51 org.restlet.engine.http.adapter.ServerAdapter commit
> GRAVE: An exception occured writing the response entity
> java.io.IOException: Unable to write to the non-blocking channel. Error
> sending response
>  at
> org.restlet.engine.io.NbChannelOutputStream.doWrite(NbChannelOutputStream.java:132)
>  at
> org.restlet.engine.io.NbChannelOutputStream.write(NbChannelOutputStream.java:153)
>  at org.restlet.engine.io.BioUtils.copy(BioUtils.java:80)
>  at
> org.restlet.representation.CharacterRepresentation.write(CharacterRepresentation.java:71)
>  at
> org.restlet.representation.CharacterRepresentation.write(CharacterRepresentation.java:77)
>  at
> org.restlet.engine.http.ServerCall.writeResponseBody(ServerCall.java:500)
>  at
> org.restlet.engine.http.ServerCall.sendResponse(ServerCall.java:439)
>  at
> org.restlet.engine.http.adapter.ServerAdapter.commit(ServerAdapter.java:198)
>  at
> org.restlet.engine.http.HttpServerHelper.handle(HttpServerHelper.java:151)
>  at
> org.restlet.ext.simple.internal.SimpleContainer.handle(SimpleContainer.java:77)
>  at
> org.simpleframework.http.core.Dispatcher.dispatch(Dispatcher.java:107)
>  at org.simpleframework.http.core.Dispatcher.run(Dispatcher.java:90)
>  at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>  at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>  at java.lang.Thread.run(Thread.java:619)
>
> --
> Client exception:
>
> Caused by: org.apache.commons.httpclient.ProtocolException: Unable to parse
> status code from status line: 'HTTP/1.141Uatoie
> Content-Type:tx/tl hre=T-
> Conncin epai
> WWW-uhniae ai el=Praim"'
>   at org.apache.commons.httpclient.StatusLine.(StatusLine.java:117)
>   at
> org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1853)
>   at
> org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1590)
>   at
> org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:995)
>   at
> org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397)
>   at
> org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
>   at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
>   at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
>   at
> es.isigma.portasigma.client.lib.WebServiceClient.execute(WebServiceClient.java:253)
>   at
> es.isigma.portasigma.client.lib.WebServiceClient.executeAndParse(WebServiceClient.java:238)
>   at
> es.isigma.portasigma.client.lib.WebServiceClient.uploadDocument(WebServiceClient.java:157)
>   at es.isigma.portasigma.client.Uploader.upload(Uploader.java:173)
>   ... 3 more

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


Data loss between HTTP client and restlet server, errors writing to non-blocking channel

2010-11-09 Thread Carles Barrobés
I get these errors frequently in my restlet server log.
I'm running restlet 2.0-RC04 as a standalone process.
I consume the web services with Apache HTTP client 3.1.

It seems to be related with serving "relatively" large pages (it seems to
get more frequent).

At the HTTP client side, sometimes the HTTP responses are missing data bytes
(part of the response bytes are missing, sometimes part of the headers,
other times part of the XHTML responses - it is not a data truncation, the
bytes missing are bytes in-between the response) (see below).

I haven't yet been able to establish a correlation between these errors,
since these happen at a customer site and I have not been able to reproduce
them in my development environment, even connecting to the customer's
server.

Any hints as to where to start?



Trace (server):

INFO: 2010-10-2709:34:51192.168.1.4 pinsos  -   8182   
GET /v1/docs/   -   200 65129   -   40 
http://192.168.1.1:8182 Jakarta Commons-HttpClient/3.0.1-
27-oct-2010 9:34:51 org.restlet.engine.http.adapter.ServerAdapter commit
GRAVE: An exception occured writing the response entity
java.io.IOException: Unable to write to the non-blocking channel. Error
sending response
at
org.restlet.engine.io.NbChannelOutputStream.doWrite(NbChannelOutputStream.java:132)
at
org.restlet.engine.io.NbChannelOutputStream.write(NbChannelOutputStream.java:153)
at org.restlet.engine.io.BioUtils.copy(BioUtils.java:80)
at
org.restlet.representation.CharacterRepresentation.write(CharacterRepresentation.java:71)
at
org.restlet.representation.CharacterRepresentation.write(CharacterRepresentation.java:77)
at
org.restlet.engine.http.ServerCall.writeResponseBody(ServerCall.java:500)
at
org.restlet.engine.http.ServerCall.sendResponse(ServerCall.java:439)
at
org.restlet.engine.http.adapter.ServerAdapter.commit(ServerAdapter.java:198)
at
org.restlet.engine.http.HttpServerHelper.handle(HttpServerHelper.java:151)
at
org.restlet.ext.simple.internal.SimpleContainer.handle(SimpleContainer.java:77)
at
org.simpleframework.http.core.Dispatcher.dispatch(Dispatcher.java:107)
at org.simpleframework.http.core.Dispatcher.run(Dispatcher.java:90)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)

--
Client exception:

Caused by: org.apache.commons.httpclient.ProtocolException: Unable to parse
status code from status line: 'HTTP/1.141Uatoie
Content-Type:tx/tl hre=T-
Conncin epai
WWW-uhniae ai el=Praim"'
at org.apache.commons.httpclient.StatusLine.(StatusLine.java:117)
at
org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1853)
at
org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1590)
at
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:995)
at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397)
at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
at
es.isigma.portasigma.client.lib.WebServiceClient.execute(WebServiceClient.java:253)
at
es.isigma.portasigma.client.lib.WebServiceClient.executeAndParse(WebServiceClient.java:238)
at
es.isigma.portasigma.client.lib.WebServiceClient.uploadDocument(WebServiceClient.java:157)
at es.isigma.portasigma.client.Uploader.upload(Uploader.java:173)
... 3 more
-- 
View this message in context: 
http://restlet-discuss.1400322.n2.nabble.com/Data-loss-between-HTTP-client-and-restlet-server-errors-writing-to-non-blocking-channel-tp5720451p5720451.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


RE: Hang when calling setStatus with CLIENT_ERROR_BAD_REQUEST

2010-11-09 Thread webpost
version: 2.0.3 (stable)

I am seeing this too, although not only on CLIENT_ERROR_BAD_REQUEST.

Did you get anywhere discovering what it might be ?

Regards

Fraser

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