Bootstrapping a web server in Scala

后端 未结 8 1713
走了就别回头了
走了就别回头了 2021-02-01 10:32

The following is possible using Python:

$ apt-get install python
$ easy_install Flask
$ cat > hello.py
from flask import Flask
app = Flask(__name__)

@app.rou         


        
8条回答
  •  醉酒成梦
    2021-02-01 10:45

    This solution uses a JAX-WS Endpoint:

    import java.io._
    import javax.xml.ws._
    import javax.xml.ws.http._
    import javax.xml.transform._
    import javax.xml.transform.stream._
    
    @WebServiceProvider
    @ServiceMode(value=Service.Mode.PAYLOAD)
    class P extends Provider[Source] {
      def invoke(source: Source) = new StreamSource( new StringReader("

    Hello There!

    ")); } val address = "http://127.0.0.1:8080/" Endpoint.create(HTTPBinding.HTTP_BINDING, new P()).publish(address) println("Service running at "+address) println("Type [CTRL]+[C] to quit!") Thread.sleep(Long.MaxValue)

    You can copy it to a file WebServer.scala and run it simply by typing:

    scala WebServer.scala
    

提交回复
热议问题