RESTLET Point

Programming/JAVA,JSP 2013. 4. 21. 17:22 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
import java.io.IOException;
import java.net.URLDecoder;
 
import org.restlet.Application;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.Restlet;
import org.restlet.Server;
import org.restlet.data.MediaType;
import org.restlet.data.Protocol;
import org.restlet.ext.xml.DomRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.ServerResource;
import org.restlet.routing.Router;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
 
public class RESTRouteService extends Application {
    public static void main(String[] args) throws Exception {
        // Create the HTTP server and listen on port 8182
        Server server = new Server(Protocol.HTTP, 8182);
        server.setNext(new RESTRouteService());
        server.start();
    }
 
    public Restlet restlet1 = new Restlet() {
        public void handle(Request request, Response response) {
           String message = "This is a information for students";
           response.setEntity(message, MediaType.TEXT_PLAIN);
        }
    };
 
    public Restlet restlet2 = new Restlet() {
        public void handle(Request request, Response response) {
           String message = "_ 1/students/1_ 2/students/2";
           response.setEntity(message, MediaType.TEXT_XML);
        }
    };
    public Restlet restlet3 = new Restlet() {
        public void handle(Request request, Response response) {
           String message = "_  1Jun-Ha Jung
Seoul
_
"; response.setEntity(message, MediaType.TEXT_XML); } }; Restlet order = new Restlet(getContext()) { @Override public void handle(Request request, Response response) { // Print the user name of the requested orders String p1 = (String)request.getAttributes().get("p1"); String p2 = (String)request.getAttributes().get("p2"); String sum = "" + (new Integer(p1) + new Integer(p2)); String message = "p1 \"" + p1 + "\" p2 \"" + p2 + "\" sum \"" + sum + "\"" ; response.setEntity(message, MediaType.TEXT_PLAIN); } }; @Override public Restlet createInboundRoot() { Router router = new Router(); router.attach("http://localhost:8182/info", restlet1); router.attach("http://localhost:8182/students", restlet2); router.attach("http://localhost:8182/students/1", restlet3); router.attach("http://localhost:8182/Point/{p1}/{p2}", order); return router; } }
org.reslet.ext.xml 추가

'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA 코드 그럴듯 하게 보이게 하기?!  (1) 2013.04.27
restlet download restlet-jse-2.1.2  (0) 2013.04.27
RESTlet HelloWorld  (0) 2013.04.21
JAVA 로 Word 문서 만들기  (0) 2013.03.29
JAVA 선택정렬  (0) 2013.03.03