使用Java和Glassfish进行AFNetworking [英] AFNetworking with Java and Glassfish

查看:143
本文介绍了使用Java和Glassfish进行AFNetworking的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个长期问题,但我没有找到关于这种特定技术组合的任何具体教程或文章。

This could be a longshot question, but I haven't found any specific tutorials or articles on this particular combination of technologies.

我的意图是使用我自己的使用AFNetworking在iOS设备上的API(来自部署在GlassFish服务器上的Java Bean)。

My intentions are to use my own APIs (from Java Beans deployed on a GlassFish server) on the iOS device using AFNetworking.

问题是,我真的不了解服务器和服务器之间的链接方法。 iOS设备。 iOS代码如何获得对GlassFish webservices的访问权限(例如)?

The problem is, I don't really understand the linkage method between the server and the iOS device. How does the iOS code gain access to GlassFish webservices (for example)?

免责声明:我没有这个特定领域的经验(即WebServices及其安全性) ,所以对我的问题的任何新手调整都非常受欢迎。

推荐答案

你正在使用Java的事实和GlassFish真的无关 - 这两种技术都能够发布各种服务。相反,请查看您的Web服务正在使用的协议。所以你需要问:

The fact that you're using Java and GlassFish are really irrelevant - these two technologies are capable of publishing all kinds of services. Instead, look at the protocol that your web-services are using. So you need to ask:


  • 是传输HTTP吗? (最有可能)

  • 有效负载是XML还是JSON?

  • 对于XML,是否还有一个包装实际数据的附加信封?像肥皂要求的东西?

  • 网络服务是否受到保护?什么安全规范被遵守? OAuth的? (推荐用于手机)。

  • Is the transport HTTP? (Most probably)
  • Is the payload XML or JSON?
  • In the case of XML, is there an additional envelope wrapping the actual data? Something like a soap request?
  • Are the web-services being secured? What security spec is being adhered to? OAuth? (recommended for mobile).

顺便提一下,我建议您不要公开Java Bean本身 - 在域驱动的开发术语中这是您的核心模型。公开您的核心模型称为 泄漏您的胆量 - 如果您更改此设置,那么您服务的所有订阅者也需要更改。

By the way, I recommend that you don't expose the Java Beans themselves - in domain driven development terms this is your core model. Exposing your core model is known as spilling your guts - if you change this then all subscribers to your service will need to change too.

相反,您应该使用有效负载输入/输出 用例特定服务合同 。然后,您可以将其内容映射到核心模型。 (如果要映射很多,你可以使用像Dozer这样的框架来为你做这件事)。

Instead you should expose a use-case specific service contract with a payload in/out. You can then map the contents of this onto your core model. (If there's a lot to map, you could use a Framework like Dozer to do it for you).

如果您自己做出技术决策,那么您可以选择多种技术。我个人的选择是:

If you're making the technology decisions yourself there are loads of technologies you could choose from. My personal choice would be:

以下任一项:


  • Spring WebServices(XML)

  • Spring MVC(JSON)

安全附带:


  • Spring Security OAuth提供商 - (AFAIK,与Google提供商相比有点复杂,但很多关于与上述两者整合的教程)。

使用这些技术首次更新定位目标:


  • Java是一种语言(显然;))

  • GlassFish是企业应用服务器 - 这意味着它能够托管企业Java Bean,访问LDAP目录,提供安全性等。

  • 上面描述的GlassFish的功能,您可能根本不需要。您需要的只是servlet引擎 - 它提供了一种通过HTTP接口托管线程化Java代码的方法。

您需要选择数据的序列化方式。 JSON更受欢迎。 (尽管John Blanco出色的 RaptureXML 库使得使用XML非常容易)。

You'll need to choose how your data is going to be serialized. JSON is much more popular. (Although John Blanco's excellent RaptureXML library makes working with XML really easy).

因此,我建议您按照教程将一个Spring MVC应用程序部署到glassfish上。

Therefore, I recommend that you follow a tutorial to deploy a Spring MVC app onto glassfish.

这是一个关于如何获得Spring MVC的教程: http://www.mkyong.com/spring-mvc/spring-3-mvc-and-json-example/

Here's a tutorial on how to get Spring MVC: http://www.mkyong.com/spring-mvc/spring-3-mvc-and-json-example/

确保在没有安全性的情况下让它正常工作,然后再转到该部分 - 否则会更复杂

Make sure you get it working without security first, before moving on to that part - otherwise it'll be more complicated

这篇关于使用Java和Glassfish进行AFNetworking的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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