Google App Engine 上的 RESTful Web 服务 [英] RESTful Webservices on Google App Engine

查看:20
本文介绍了Google App Engine 上的 RESTful Web 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先我要说的是,我在 Google App Engine 方面的经验并不丰富.

First of all I need to say that I'm not so experienced in Google App Engine.

我知道我们有可能在 GAE 上部署 RESTful Web 服务 (JERSEY)

我也知道 RESTLET 有一个专门用于 GAE 的版本.

And also I know that RESTLET has a version specifically for GAE.

我想听取那些使用过这两种方法的人的建议,哪种方法更好.

I want to take advice from those who have worked with both approaches that which one is better.

例如,为 JERSEY 配置 GAE 应用程序是否太困难或难以解决?或者例如使用 RESTLET 有什么缺点吗?还是太厚了(RESTLET)?

For example is configuring the GAE application for JERSEY too difficult or struggling??? Or for example has using RESTLET any disadvantages? Or is it too thick (RESTLET)?

谢谢

推荐答案

我一年前开始使用 Jersey 和 Google App Engine 开发一个应用程序.我的经验很棒,但我从未使用过 Restlet ..

I started one year ago to develop an app with Jersey and Google App Engine. Great experience from my side, but I have never worked with Restlet ..

我在这里尝试总结一下我在 GAE 集成中发现的主要困难:

I try here to summarize the main difficulties I found in GAE integration:

  • 球衣版本:1.6 作品
  • 我建议你使用 Jackson(1.7.1 版)来表示 json

web.xml 片段:

web.xml fragment:

<servlet>
<servlet-name>jersey</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>***package-with-your-classes***;org.codehaus.jackson.jaxrs</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

配置器:

@Provider
public class JAXBContextResolver implements ContextResolver<JAXBContext> {
private AnnoxAnnotationReader annotationReader;
private JAXBContext context;
private Class<?>[] classTypes = new Class[] { .. all your classes .. };

public JAXBContextResolver() {
annotationReader = new AnnoxAnnotationReader();
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(JAXBRIContext.ANNOTATION_READER, annotationReader);      
try {
    this.context = JAXBContext.newInstance(classTypes, properties);
} catch (JAXBException e) {
    ..  
}
public JAXBContext getContext(Class<?> objectType) {
    return context;
}

.. 如您所见,我使用 Annox 来避免在我的模型类中添加注释!

.. as you can see I use Annox to avoid annotations inside my model classes!

希望对您有所帮助!米歇尔·奥尔西

Hope it helps! Michele Orsi

这篇关于Google App Engine 上的 RESTful Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆