eclipse-archived / golo-lang

Golo - a lightweight dynamic language for the JVM.
http://golo-lang.org/
Eclipse Public License 2.0
478 stars 91 forks source link

this simple program does not work #513

Closed NIJAVA closed 6 years ago

NIJAVA commented 6 years ago
module teste.WebServer

import java.lang
import java.net.InetSocketAddress
import com.sun.net.httpserver.HttpServer

function main = |args| {

  let server = HttpServer.create(InetSocketAddress("localhost", 8081), 0)
    let handler1 = |exchange| {
    let response = "bem vindo"
    exchange: getResponseHeaders(): set("Content-Type", "text/plain")
        println(response: length())
    exchange: sendResponseHeaders(200, response: length())
    exchange: getResponseBody(): write(response: getBytes())
    exchange: close()
  }
  server: createContext("/", handler1)
    let handler2 = |exchange| {
     let response = "tchau"
    exchange: getResponseHeaders(): set("Content-Type", "text/plain")
    exchange: sendResponseHeaders(200, response: length())
    exchange: getResponseBody(): write(response: getBytes())
    exchange: close()
    server: stop(5)
  }
  server: createContext("/shut", handler2)

  server: start()
  println("> http://localhost:8081/")
}
NIJAVA commented 6 years ago

the same program in groovy works fine

yloiseau commented 6 years ago

Could you at least provide some information on failure, like a stack trace, expected result vs. observed behavior and so on...

NIJAVA commented 6 years ago

9 Exception in thread "Thread-2" java.lang.NoSuchMethodError: class sun.net.httpserver.HttpExchangeImpl::sendResponseHeade rs at org.eclipse.golo.runtime.MethodInvocationSupport.fallback(MethodInvocationSupport.java:271) at teste.WebServer.__$$_sugar_closure_0(httpgolo.golo:14) at java.lang.invoke.MethodHandleProxies$1.invoke(MethodHandleProxies.java:187) at com.sun.proxy.$Proxy5.handle(Unknown Source) at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79) at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83) at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:82) at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:675) at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79) at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:647) at sun.net.httpserver.ServerImpl$DefaultExecutor.execute(ServerImpl.java:158) at sun.net.httpserver.ServerImpl$Dispatcher.handle(ServerImpl.java:431) at sun.net.httpserver.ServerImpl$Dispatcher.run(ServerImpl.java:396) at java.lang.Thread.run(Thread.java:748)

artpej commented 6 years ago

just change that:

exchange: sendResponseHeaders(200, response: length())

by this:

exchange: sendResponseHeaders(intValue(200), response: length())

in Golo unboxing is explicit : http://golo-lang.org/documentation/next/#_number_type_conversions

NIJAVA commented 6 years ago

hei Artpej, your hint do not work too: same error reported.

artpej commented 6 years ago

Add longValue() on response: length() too .

Sorry for not be more precise but it is not easy to type with a phone :wink:

NIJAVA commented 6 years ago

ok, thanks Artpeg, now it worked, but then golo does not integrate wel with java, groovy does not need such explicit conversions.

NIJAVA commented 6 years ago

intValue(200) was not necessary, only longValue() needed.

NIJAVA commented 6 years ago

golo samples has a file http-server.golo that do not have those conversions.

yloiseau commented 6 years ago

It's not an unboxing error, but an implicit upcast one. The method expects a long but an int (thus an Integer) is given. The code in the samples used to work, but it's indeed no more the case since the big method resolution refactoring.

NIJAVA commented 6 years ago

The module http-server in samples don't work too, the necessity of explicit method parammeters conversions means golo does not seamless integrate with java code as groovy does.

yloiseau commented 6 years ago

No, it means that we have a regression...

NIJAVA commented 6 years ago

Then it needs a re-evolution, golo is a beautiful engineered little language.