package perftest.server

import com.sun.net.httpserver.HttpServer
import com.sun.net.httpserver.{HttpHandler, HttpExchange}
import java.net.InetSocketAddress

import ccf.transport.Response
import ccf.transport.json.JsonFormatter

import java.net.URL

class HttpRequestHandler extends HttpHandler {
  def handle(exchange: HttpExchange) { 
    try {
      val response = Response(Map[String, String](), Some((0 to 1023).map(x => 0).mkString("")))
      val body = JsonFormatter.formatResponse(response)
      exchange.sendResponseHeaders(200, body.length)
      exchange.getResponseBody.write(body.getBytes)
    } finally {
      exchange.getResponseBody.close
    }
  }
}

object Server {
  def run(url: URL)= { 
    val server = HttpServer.create(new InetSocketAddress(url.getHost, url.getPort), 0)
    server.createContext("/perftest", new HttpRequestHandler)
    server.start
  }
}

package perftest.server

import com.sun.net.httpserver.HttpServer
import com.sun.net.httpserver.{HttpHandler, HttpExchange}
import java.net.InetSocketAddress

import ccf.transport.Response
import ccf.transport.json.JsonFormatter

import java.net.URL

class HttpRequestHandler extends HttpHandler {
  def handle(exchange: HttpExchange) { 
    try {
      val response = Response(Map[String, String](), Some((0 to 1023).map(x => 0).mkString("")))
      val body = JsonFormatter.formatResponse(response)
      exchange.sendResponseHeaders(200, body.length)
      exchange.getResponseBody.write(body.getBytes)
    } finally {
      exchange.getResponseBody.close
    }
  }
}

object Server {
  def run(url: URL)= { 
    val server = HttpServer.create(new InetSocketAddress(url.getHost, url.getPort), 0)
    server.createContext(url.getPath, new HttpRequestHandler)
    server.start
  }
}

Use the path of the specified URL when creating a HTTP context
perftest: Use the path of the specified URL when creating a HTTP context

Signed-off-by: Karim Osman <94396faf6cc817be76165477038b3cfa832e89a4@reaktor.fi>
Acked-by: Harri Salokorpi <eefb23b8deb8c30dca252cd0ae751b67337dc69f@reaktor.fi>
