This discussion is archived
9 Replies Latest reply: Jun 1, 2012 6:51 AM by 810618 RSS

com.sun.net.httpserver

939719 Newbie
Currently Being Moderated
I am new to server side programming and Java Frameworks.

Is 'com.sun.net.httpserver' enough to create a primitive server with the session support ?
  • 1. Re: com.sun.net.httpserver
    gimbal2 Guru
    Currently Being Moderated
    Don't use com.sun classes, pretend they don't exist. When you use those you have a good chance that your code won't work on other versions of Java as Oracle is free to change them, move them, remove them, whatever. Only use classes that are actually part of the API, or are not part of the JDK.

    If you want a basic Java webserver I would look into Netty which is something you can bundle with your application in stead of having to install it standalone.
  • 2. Re: com.sun.net.httpserver
    EJP Guru
    Currently Being Moderated
    With respect that's not what it says in the Javadoc. The comment you are referring to is about the sun.* classes. The com.sun.httpserver.* classes are documented, and supported indefinitely as far as I can see.
  • 3. Re: com.sun.net.httpserver
    gimbal2 Guru
    Currently Being Moderated
    Doh! I think I've made that mistake a few times now :(

    http://docs.oracle.com/javase/6/docs/jre/api/net/httpserver/spec/overview-summary.html

    Thanks for the boot to the bum, may I have another?
  • 4. Re: com.sun.net.httpserver
    939719 Newbie
    Currently Being Moderated
    Yeah, I know already about the Java providers documenting the private API, which sounds weird to me.

    But since it's my first very tutorial thing, I'd like to use the highest-level API possible at this point. So I'm just curious of what that server is capable of, does it contain all the functionality required to build a minimum web server ?

    (In response to 'gimbal2')

    Edited by: user3650728 on 26.05.2012 13:59
  • 5. Re: com.sun.net.httpserver
    jtahlborn Expert
    Currently Being Moderated
    user3650728 wrote:
    But since it's my first very tutorial thing, I'd like to use the highest-level API possible at this point. So I'm just curious of what that server is capable of, does it contain all the functionality required to build a minimum web server ?
    you haven't indicated what your specifications are for a "minimum web server". we use it internally for some low traffic services. are you expecting to serve your company webservice off of it? it's more than sufficient for internal testing and prototyping. that said, jetty and tomcat tend to be pretty trivial to setup these days...
  • 6. Re: com.sun.net.httpserver
    810618 Newbie
    Currently Being Moderated
    >
    ....
    But since it's my first very tutorial thing, I'd like to use the highest-level API possible at this point. So I'm just curious of what that server is capable of, does it contain all the functionality required to build a minimum web server ?
    It plays an important role for us as an embedded server for a REST-based monitor and control system. In our system, it runs on 256 PC-104 computers (little 5" square PC circuit cards running Linux), each attached to large circuit boards that make the overall machine.

    The class provides the basic HTTP protocol services. It does the communication, you implement the 'handle' method that is supplied with an 'HttpExchange' that encapsulates the HTTP request. The 'handle' method is similar to the Java Servlet 'doGet' and 'doPost' methods.

    I switched from Embedded Tomcat to this because it is built into the Java language and 'embeds' nicely into your code as opposed to having to run in a web-apps area that is controlled by Tomcat. We have about 520 web servers, based on this, running in our system for the past 4 or 5 years.

    There are examples 'out there' that you can cut and paste to have a server up and running with just a few lines of code. I suggest you try that to play with the API to see if it does what you need.

    Kevin
  • 7. Re: com.sun.net.httpserver
    939719 Newbie
    Currently Being Moderated
    Currently I just want to have a session functionality, that's it. :)
    No, no website, just an abstract tutorial, that's it.

    Did not see any examples using these API..

    Edited by: user3650728 on 1.06.2012 13:30
  • 8. Re: com.sun.net.httpserver
    939719 Newbie
    Currently Being Moderated
    "There are examples 'out there' that you can cut and paste to have a server up and running with just a few lines of code. I suggest you try that to play with the API to see if it does what you need."

    out where ? :)
  • 9. Re: com.sun.net.httpserver
    810618 Newbie
    Currently Being Moderated
    user3650728 wrote:

    out where ? :)
    In googleland.

    http://www.java2s.com/Tutorial/Java/0320__Network/LightweightHTTPServer.htm

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points