You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by Daniel Sun <re...@hotmail.com> on 2016/12/11 08:02:23 UTC

About SimpleHTTPServer

Hi all,

      Does Groovy provide any function like Python's SimpleHTTPServer(e.g.
python -m SimpleHTTPServer 8000)?  If no similar module exits, I'd like to
implement one via Groovy 3(e.g. groovy -m SimpleHTTPServer 8000).

      FYI: https://docs.python.org/2/library/simplehttpserver.html

Cheers,
Daniel.Sun



--
View this message in context: http://groovy.329449.n5.nabble.com/About-SimpleHTTPServer-tp5737191.html
Sent from the Groovy Dev mailing list archive at Nabble.com.

Re: About SimpleHTTPServer

Posted by Daniel Sun <re...@hotmail.com>.
Hi Remi,

       Your reply is always so helpful :-)
       As far as I remember, Sun introduced the http server in Java6. It's
lucky for us that it's included in the OpenJDK too.

Cheers,
Daniel.Sun



--
View this message in context: http://groovy.329449.n5.nabble.com/About-SimpleHTTPServer-tp5737191p5737201.html
Sent from the Groovy Dev mailing list archive at Nabble.com.

Re: About SimpleHTTPServer

Posted by Remi Forax <fo...@univ-mlv.fr>.
FYIW, there is already an httpserver with the jdk
  http://hg.openjdk.java.net/jdk9/jdk9/jdk/file/tip/src/jdk.httpserver/share/classes/com/sun/net/httpserver/package-info.java

cheers,
Rémi

----- Mail original -----
> De: "Daniel Sun" <re...@hotmail.com>
> À: dev@groovy.incubator.apache.org
> Envoyé: Dimanche 11 Décembre 2016 09:02:23
> Objet: About SimpleHTTPServer

> Hi all,
> 
>      Does Groovy provide any function like Python's SimpleHTTPServer(e.g.
> python -m SimpleHTTPServer 8000)?  If no similar module exits, I'd like to
> implement one via Groovy 3(e.g. groovy -m SimpleHTTPServer 8000).
> 
>      FYI: https://docs.python.org/2/library/simplehttpserver.html
> 
> Cheers,
> Daniel.Sun
> 
> 
> 
> --
> View this message in context:
> http://groovy.329449.n5.nabble.com/About-SimpleHTTPServer-tp5737191.html
> Sent from the Groovy Dev mailing list archive at Nabble.com.

Re: About SimpleHTTPServer

Posted by Daniel Sun <re...@hotmail.com>.
Thanks for your suggestion, mrhaki :)
In order to avoid maintaining the httpserver, I'd like to use the built-in
httpserver of JDK.

Cheers,
Daniel.Sun



--
View this message in context: http://groovy.329449.n5.nabble.com/About-SimpleHTTPServer-tp5737191p5737213.html
Sent from the Groovy Dev mailing list archive at Nabble.com.

Re: About SimpleHTTPServer

Posted by Hubert Klein Ikkink <h....@gmail.com>.
Hi,

the following code snippet can be used as inspiration:

https://github.com/mrhaki/groovyrun-gradle-plugin/blob/master/src/main/groovy/com/mrhaki/gradle/groovyrun/SimpleHttpServer.groovy

It has no 3rd party dependencies and uses the Groovy socket support.

Kind regards, Hubert Klein Ikkink

> On 11 Dec 2016, at 11:33, Daniel Sun <re...@hotmail.com> wrote:
> 
> Hi Sébastien,
> 
>     The SimpleHTTPServer will be implemented with NO 3rd part library, so
> it will not impact existing production systems. In addition, it is
> recommended to be used to provide http service for convenience(such as
> testing WebRTC app). If we want to deploy our static web site, the
> SimpleHTTPServer is not recommended to be used in production :)
> 
> Cheers,
> Daniel.Sun
> 
> 
> 
> --
> View this message in context: http://groovy.329449.n5.nabble.com/About-SimpleHTTPServer-tp5737191p5737205.html
> Sent from the Groovy Dev mailing list archive at Nabble.com.


Re: About SimpleHTTPServer

Posted by Daniel Sun <re...@hotmail.com>.
Hi Sébastien,

> My concern is that an HTTP server built into groovy would come with its 
> potential risks – even it is not used directly. 

      To be frank, I can not figure out... Could you tell me some exact
potential risks? 

> Having to redeploy an 
> app where groovy is embedded because of an issue with such a 
> non-critical feature would be somewhat... frustrating. 

      As such a feature is not core for a programming language, it will not
be updated frequently ;)

Cheers,
Daniel.Sun



--
View this message in context: http://groovy.329449.n5.nabble.com/About-SimpleHTTPServer-tp5737191p5737223.html
Sent from the Groovy Dev mailing list archive at Nabble.com.

Re: About SimpleHTTPServer

Posted by Sébastien Le Callonnec <se...@weblogism.com>.
Hi Daniel,

On 2016-12-11 10:33:52, Daniel Sun wrote:
>      The SimpleHTTPServer will be implemented with NO 3rd part library, so
> it will not impact existing production systems. In addition, it is
> recommended to be used to provide http service for convenience(such as
> testing WebRTC app). If we want to deploy our static web site, the
> SimpleHTTPServer is not recommended to be used in production :)


I understand this is not for Production use. ;)

My concern is that an HTTP server built into groovy would come with its
potential risks \u2013 even it is not used directly.  Having to redeploy an
app where groovy is embedded because of an issue with such a
non-critical feature would be somewhat... frustrating.

As a groovy user, I want to make sure the pros and cons are carefully
considered before adding this to core.  My personal preference would be
to have this feature as part of an optional groovy library, but maybe
it's just me. :D


Regards,
S�bastien.

Re: About SimpleHTTPServer

Posted by Daniel Sun <re...@hotmail.com>.
That's great :)



--
View this message in context: http://groovy.329449.n5.nabble.com/About-SimpleHTTPServer-tp5737191p5737216.html
Sent from the Groovy Dev mailing list archive at Nabble.com.

Re: About SimpleHTTPServer

Posted by Remi Forax <fo...@univ-mlv.fr>.
There are com.sun classes and com.sun classes :) 

These ones are exported 
http://hg.openjdk.java.net/jdk9/jdk9/jdk/file/tip/src/jdk.httpserver/share/classes/module-info.java 
so ok to use. 

Said differently, they are not part of Java but part of the OpenJDK. 

Rémi 

> De: "Cédric Champeau" <ce...@gmail.com>
> À: dev@groovy.apache.org
> Cc: dev@groovy.incubator.apache.org
> Envoyé: Dimanche 11 Décembre 2016 17:20:08
> Objet: Re: About SimpleHTTPServer

> Is it just me or Remi is advising to use a com.sun class?

> Le 11 déc. 2016 17:18, "Daniel Sun" < realbluesun@hotmail.com > a écrit :

>> Hi Paul,

>> The built-in httpserver of JDK suggested by Remi seems better for us,
>> it is stable and does not require 3rd party library:

>> http://hg.openjdk.java.net/jdk9/jdk9/jdk/file/tip/src/jdk.httpserver/share/classes/com/sun/net/httpserver/package-info.java

>> As to hooking to the existing socket server, I think it feasible as
>> mrhaki showed the relevant sample code, but we have to maintain it... so I
>> would like to implement SimpleHTTPServer based on the built-in httpserver.

>> Cheers,
>> Daniel.Sun

>> --
>> View this message in context:
>> http://groovy.329449.n5.nabble.com/About-SimpleHTTPServer-tp5737191p5737211.html
>> Sent from the Groovy Dev mailing list archive at Nabble.com.

Re: About SimpleHTTPServer

Posted by Daniel Sun <re...@hotmail.com>.
Hi Cédric,

      It is also available in the openjdk, any potential problem with it?

http://hg.openjdk.java.net/jdk9/jdk9/jdk/file/tip/src/jdk.httpserver/share/classes/com/sun/net/httpserver/package-info.java

Cheers,
Daniel.Sun



--
View this message in context: http://groovy.329449.n5.nabble.com/About-SimpleHTTPServer-tp5737191p5737214.html
Sent from the Groovy Dev mailing list archive at Nabble.com.

Re: About SimpleHTTPServer

Posted by Cédric Champeau <ce...@gmail.com>.
Is it just me or Remi is advising to use a com.sun class?

Le 11 déc. 2016 17:18, "Daniel Sun" <re...@hotmail.com> a écrit :

> Hi Paul,
>
>       The built-in httpserver of JDK suggested by Remi seems better for us,
> it is stable and does not require 3rd party library:
>
> http://hg.openjdk.java.net/jdk9/jdk9/jdk/file/tip/src/
> jdk.httpserver/share/classes/com/sun/net/httpserver/package-info.java
>
>       As to hooking to the existing socket server, I think it feasible as
> mrhaki showed the relevant sample code, but we have to maintain it... so I
> would like to implement SimpleHTTPServer based on the built-in httpserver.
>
> Cheers,
> Daniel.Sun
>
>
>
> --
> View this message in context: http://groovy.329449.n5.nabble.com/About-
> SimpleHTTPServer-tp5737191p5737211.html
> Sent from the Groovy Dev mailing list archive at Nabble.com.
>

Re: About SimpleHTTPServer

Posted by Daniel Sun <re...@hotmail.com>.
Hi Paul,

      The built-in httpserver of JDK suggested by Remi seems better for us,
it is stable and does not require 3rd party library:
     
http://hg.openjdk.java.net/jdk9/jdk9/jdk/file/tip/src/jdk.httpserver/share/classes/com/sun/net/httpserver/package-info.java

      As to hooking to the existing socket server, I think it feasible as
mrhaki showed the relevant sample code, but we have to maintain it... so I
would like to implement SimpleHTTPServer based on the built-in httpserver.

Cheers,
Daniel.Sun



--
View this message in context: http://groovy.329449.n5.nabble.com/About-SimpleHTTPServer-tp5737191p5737211.html
Sent from the Groovy Dev mailing list archive at Nabble.com.

Re: About SimpleHTTPServer

Posted by Paul King <pa...@asert.com.au>.
I should have mentioned the above example is more about illustrating
groovlets rather than serving up static content but it isn't too hard
to switch between the two.

On Sun, Dec 11, 2016 at 9:59 PM, Paul King <pa...@asert.com.au> wrote:
> I don't know whether you would find listing 12.16 from ReGinA useful:
>
> It is based on Jetty rather than com.sun.net.httpserver.HttpServer but
> might provide some useful inspiration:
>
> https://github.com/Dierk/GroovyInAction/blob/master/listings/chap12/Listing_12_16_GroovletExample.groovy
>
> Also, I don't know whether you need a separate -m switch or whether
> you could hook into the existing "listen on port (-l port)"
> functionality but modify it to accept a class name.
>
> Cheers, Paul.
>
>
> On Sun, Dec 11, 2016 at 8:33 PM, Daniel Sun <re...@hotmail.com> wrote:
>> Hi Sébastien,
>>
>>      The SimpleHTTPServer will be implemented with NO 3rd part library, so
>> it will not impact existing production systems. In addition, it is
>> recommended to be used to provide http service for convenience(such as
>> testing WebRTC app). If we want to deploy our static web site, the
>> SimpleHTTPServer is not recommended to be used in production :)
>>
>> Cheers,
>> Daniel.Sun
>>
>>
>>
>> --
>> View this message in context: http://groovy.329449.n5.nabble.com/About-SimpleHTTPServer-tp5737191p5737205.html
>> Sent from the Groovy Dev mailing list archive at Nabble.com.

Re: About SimpleHTTPServer

Posted by Paul King <pa...@asert.com.au>.
I don't know whether you would find listing 12.16 from ReGinA useful:

It is based on Jetty rather than com.sun.net.httpserver.HttpServer but
might provide some useful inspiration:

https://github.com/Dierk/GroovyInAction/blob/master/listings/chap12/Listing_12_16_GroovletExample.groovy

Also, I don't know whether you need a separate -m switch or whether
you could hook into the existing "listen on port (-l port)"
functionality but modify it to accept a class name.

Cheers, Paul.


On Sun, Dec 11, 2016 at 8:33 PM, Daniel Sun <re...@hotmail.com> wrote:
> Hi Sébastien,
>
>      The SimpleHTTPServer will be implemented with NO 3rd part library, so
> it will not impact existing production systems. In addition, it is
> recommended to be used to provide http service for convenience(such as
> testing WebRTC app). If we want to deploy our static web site, the
> SimpleHTTPServer is not recommended to be used in production :)
>
> Cheers,
> Daniel.Sun
>
>
>
> --
> View this message in context: http://groovy.329449.n5.nabble.com/About-SimpleHTTPServer-tp5737191p5737205.html
> Sent from the Groovy Dev mailing list archive at Nabble.com.

Re: About SimpleHTTPServer

Posted by Daniel Sun <re...@hotmail.com>.
Hi Sébastien,

     The SimpleHTTPServer will be implemented with NO 3rd part library, so
it will not impact existing production systems. In addition, it is
recommended to be used to provide http service for convenience(such as
testing WebRTC app). If we want to deploy our static web site, the
SimpleHTTPServer is not recommended to be used in production :)

Cheers,
Daniel.Sun



--
View this message in context: http://groovy.329449.n5.nabble.com/About-SimpleHTTPServer-tp5737191p5737205.html
Sent from the Groovy Dev mailing list archive at Nabble.com.

Re: About SimpleHTTPServer

Posted by Sébastien Le Callonnec <se...@weblogism.com>.
Hi Daniel,


On 2016-12-11 08:02:23, Daniel Sun wrote:
> Hi all,
>
>       Does Groovy provide any function like Python's SimpleHTTPServer(e.g.
> python -m SimpleHTTPServer 8000)?  If no similar module exits, I'd like to
> implement one via Groovy 3(e.g. groovy -m SimpleHTTPServer 8000).

As a separate library, this would indeed be a nice feature to have \u2013 but
as a core Groovy feature, I am bit more wary that this would cause bloat
and bring in potential vulnerabilities that users don't necessarily want
to worry about in production apps.


Regards,
S�bastien.

Re: About SimpleHTTPServer

Posted by Daniel Sun <re...@hotmail.com>.
Yeah, I think so too, but I'm not sure whether Groovy already has some
similar function or not...

Cheers,
Daniel.Sun




--
View this message in context: http://groovy.329449.n5.nabble.com/About-SimpleHTTPServer-tp5737191p5737196.html
Sent from the Groovy Dev mailing list archive at Nabble.com.

Re: About SimpleHTTPServer

Posted by Balachandran Sivakumar <ba...@balachandran.org>.
Hi,

On Sun, Dec 11, 2016 at 01:02:23AM -0700, Daniel Sun wrote:
> Hi all,
> 
>       Does Groovy provide any function like Python's SimpleHTTPServer(e.g.
> python -m SimpleHTTPServer 8000)?  If no similar module exits, I'd like to
> implement one via Groovy 3(e.g. groovy -m SimpleHTTPServer 8000).
> 

    Yes, that would be an amazing feature to have. Thanks
    
-- 

Thank you,
Balachandran Sivakumar.

Re: About SimpleHTTPServer

Posted by Daniel Sun <re...@hotmail.com>.
Hi Jochen,

       Given we have a directory containing some web pages and want to
access these pages via http protocal(e.g. we want to test WebRTC app), we
have to run a httpserver to provide http service. In the past, we have to
use Python to achieve the requirement because its SimpleHTTPServer is very
easy to use, just run "python -m SimpleHTTPServer 8000" to serve files of
current directory. As you know, my favorite programming language is Groovy,
so I want to find or implement similar function in Groovy :) 
        If I implement it, I want to rely on NO 3rd part library(e.g.
netty). It's lucky that JDK provide a httpserver as Remi suggested. Groovy's 
SimpleHTTPServer can rely on it ;)

Cheers,
Daniel.Sun



--
View this message in context: http://groovy.329449.n5.nabble.com/About-SimpleHTTPServer-tp5737191p5737203.html
Sent from the Groovy Dev mailing list archive at Nabble.com.

Re: About SimpleHTTPServer

Posted by Jochen Theodorou <bl...@gmx.org>.
On 11.12.2016 09:02, Daniel Sun wrote:
> Hi all,
>
>        Does Groovy provide any function like Python's SimpleHTTPServer(e.g.
> python -m SimpleHTTPServer 8000)?  If no similar module exits, I'd like to
> implement one via Groovy 3(e.g. groovy -m SimpleHTTPServer 8000).
>
>        FYI: https://docs.python.org/2/library/simplehttpserver.html

something like:

> import org.apache.catalina.startup.Tomcat
> import groovy.servlet.GroovyServlet
>
> new Tomcat().with {
>     port = 8000
>     ctx = addContext("", new File(".").getAbsolutePath())
>     Tomcat.addServlet(ctx, "Groovy", new GroovyServlet())
>     ctx.addServletMappingDecoded("/*", "Groovy")
>     start()
>     server.await()
> }

would do the job I think... didnt test it and the servlet-api stuff 
could get in the way.

If all you want is Groovy listening on a port and evaluate the scripts 
you give it, that is something we have already. So the question to be 
answered would be... what do you intend to do with the http server?

bye Jochen