zoukankan      html  css  js  c++  java
  • gae json web 服务

    在网上找到一篇GAE上建JSON WEB服务的文章

    Json REST Java Service for Google App Engine Example

    1. Download Eclipse and the Google Plugin for Eclipse ( I use Eclipse IDE for Java EE Developers Helios 3.6)

    http://code.google.com/eclipse/docs/download.html

    2. Down Restlet  (I use 2.0.5 stable zip file)

    http://www.restlet.org/downloads/stable

    3. Create a Web Application Project

     

     

     

     

    Like this.

     


    4. Copy these files to /war/WEB-INF/lib

    org.json.jar (in D:\DevTools\restlet-gae-2.0.5\lib\org.json_2.0)
    org.restlet.ext.json.jar (in D:\DevTools\restlet-gae-2.0.5\lib)
    org.restlet.ext.servlet.jar (in D:\DevTools\restlet-gae-2.0.5\lib)
    org.restlet.jar (in D:\DevTools\restlet-gae-2.0.5\lib)

    Look like this,

     

     


    5. Add JARS… to Libaries

     





    Like this,




    6. Change MyFirstRestServerServlet.java

    package com.example.myfirstrestserver;

     

    import org.restlet.Application;

    import org.restlet.Restlet;

    import org.restlet.routing.Router;

     

    public class MyFirstRestServerServlet extends Application{

     

    /**

     * Creates a root Restlet that will receive all incoming calls.

     */

    @Override

    public synchronized Restlet createRoot() {

    // Create a router Restlet that routes each call to a new Resource

    Router router = new Router(getContext());

     

    router.attachDefault(TestJsonResource.class);

    return router;

    }

    }


    Like this,

     





    7. Make a new java class called TestJsonResource,

     

     

     

    package com.example.myfirstrestserver;

     

    import java.io.IOException;

    import org.json.JSONException;

    import org.json.JSONObject;

    import org.restlet.ext.json.JsonRepresentation;

    import org.restlet.resource.Get;

    import org.restlet.resource.ServerResource;

     

    public class TestJsonResource extends ServerResource {

     

    @Get("json")

    public String handleGet() {

    try {

    JSONObject json = new JSONObject();

    json.put("name", "value");

     

    JsonRepresentation jsonRep = new JsonRepresentation(json);

     

    return jsonRep.getText();

    } catch (JSONException e) {

    e.printStackTrace();

    } catch (IOException e)

    {

    e.printStackTrace();

    }

    return null;

    }

    }


    Like this,

     





    8. Change web.xml file,

    xml version="1.0" encoding="utf-8"?>

    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xmlns="http://java.sun.com/xml/ns/javaee"

    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

     

     

    <context-param>

    <param-name>org.restlet.applicationparam-name>

    <param-value>com.example.myfirstrestserver.MyFirstRestServerServletparam-value>

    context-param>

     

     

    <servlet>

    <servlet-name>MyFirstRestServerservlet-name>

    <servlet-class>org.restlet.ext.servlet.ServerServletservlet-class>

    servlet>

     

    <servlet-mapping>

    <servlet-name>MyFirstRestServerservlet-name>

    <url-pattern>/*url-pattern>

    servlet-mapping>

    <welcome-file-list>

    <welcome-file>index.htmlwelcome-file>

    welcome-file-list>

    web-app>



    9. Run.

     

  • 相关阅读:
    Unity3D性能优化--- 收集整理的一堆
    Unity5.3官方VR教程重磅登场-系列7 优化VR体验
    VR沉浸体验的要求
    Unity5中叹为观止的实时GI效果
    浅谈控制反转与依赖注入[转]
    unity 使用unityaction 需要注意的问题[转]
    c# orm框架 sqlsugar
    unity Instantiate设置父级物体bug
    宝塔面板 使用mongodb注意事项
    unity中gameObject.SetActive()方法的注意事项。
  • 原文地址:https://www.cnblogs.com/redmondfan/p/3107408.html
Copyright © 2011-2022 走看看