【ZZ】JAVA+FLEX 使用WEB SERVICE的集成

FDS+JAVA开发... 本人在学习FDS的时候,遇到N多问题,网上很少能找到之类资料...找到了也不是很全,所以今天我想把这个过程和一些概念写在这里...希望更多人学习的时候不会饶更多弯... 废话说到这里...首先要明白什么叫做FDS,它干了件什么事儿,,,,FDS全名:Flex data service现在FDS就是LCDS...FDS就是他的前身... 首先需要安装有FDS,如果安装的是 阅读详情

我个人一直以为使用PYTHON和FLEX通过PYAMF通信是BS RIA的王道,不过在JAVA加强了对webservice的支持之后,在我对JAVA不那么偏执之后,我觉得是不是有必要也来看一下JAVA 和FLEX的集成,不管怎么样,这篇文章转给大家

Building a CRUD application using Java 6 Web Services and Flash Builder 4

 

October 12, 2009 5:29 PM

Java SE 6 has built-in support for web services thanks to JAX-WS 2.0 . Armed with nothing more than JDK 6, you can easily publish or consume a web service. This makes it really easy for a developer to prototype and quickly get started with web services. Using the data-centric features in Flash Builder 4, a web service can be easily introspected and accessed. In this article, I will build an end-to-end simple CRUD application in Java and Flex 4, where the Java methods are exposed as web service operations.

Java 6 Goodness

On the java side, all you need for this article is JDK 6 and optionally the mysql connector JAR if you want to run the final application.

To look at the complete Java code, download BookService.java and Book.java . The sample uses a simple mysql table called Books:

CREATE
 TABLE
 Books

(
BOOK_ID SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
BOOK_NAME VARCHAR (400) NOT NULL ,
BOOK_PRICE FLOAT NOT NULL ,
BOOK_AUTHOR VARCHAR (400) NOT NULL ,
PRIMARY KEY (BOOK_ID)
);

INSERT INTO Books ( BOOK_NAME, BOOK_PRICE, BOOK_AUTHOR )
VALUES ( 'Midnight''s Children' , 250, 'Salman Rushdie' )
INSERT INTO Books ( BOOK_NAME, BOOK_PRICE, BOOK_AUTHOR )
VALUES ( 'Shame' , 225, 'Salman Rushdie' );
INSERT INTO Books ( BOOK_NAME, BOOK_PRICE, BOOK_AUTHOR )
VALUES ( 'To Kill a Mocking Bird' , 250, 'Harper Lee' );
INSERT INTO Books ( BOOK_NAME, BOOK_PRICE, BOOK_AUTHOR )
VALUES ( 'The Colour of Magic' , 250, 'Terry Pratchett' );

To expose your Java class as a web service, simply:

1) Annotate your Java class with @WebService, @WebMethod.

package
 com.sampl
e
;

import com .sample .Boo k ;
import javax .jws .WebServic e ;
import javax .jws .WebMetho d ;
import javax .jws .soap .SOAPBindin g ;
import javax .xml .ws .Endpoin t ;

@WebService
@SOAPBinding(style = SOAPBinding .Style .RPC)
public class BookService
{

@WebMethod
public int addBook(Book book )
{
/* insert book into db */
in t resultCode = 0;
Connectio n connection = null;
/* code omitted for brevity */

2) Use the Endpoint class in main()

   public
 static
 voi
d
 main
(String
[] args
)
{
// create and publish an endpoint
BookServic e bookservice = new BookService ();
Endpoin t endpoint = Endpoint.publish("http://localhost:8080/books" , bookservice);
}

3) Create a directory called generated and run apt (Annotation Processing Tool):

apt -cp .;mysql.jar -d generated com/sample/BookService.java

4) Run your class:

java -cp generated;mysql.jar com.sample.BookService

That's it, you have a web server running on localhost:8080 and you can access the WSDL by navigating to http://localhost:8080/books?wsdl

Flash Builder 4 Magic

Accessing the WSDL in Flash Builder 4 to build a Flex application is a snap.

1) Get Adobe Flash Builder 4 Beta 2 from Adobe Labs if you haven't already.

2) Create a new Flex Project, type in a project name and hit Finish.

3) In the bottom part of Flash Builder, choose the Data/Services tab and click on "Connect to Data/Service".

New Project Wizard

4) Pick Web Service, hit Next.

Connect to Data Service Wizard

5) Paste the WSDL URL http://localhost:8080/books?wsdl as the "WSDL URI" and hit Finish.

Connect to Data Service Wizard

6) Flash Builder 4 will introspect the WSDL and show you a list of operations you can select. Hit Finish.

Wiring it to a Flex UI

1) Start off by replacing your main MXML file with the following code:

<?xml
 version
="1.0"
 encoding
="utf-8"
?>
<s :Application xmlns :fx ="http://ns.adobe.com/mxml/2009"
xmlns :s ="library://ns.adobe.com/flex/spark"
xmlns :mx ="library://ns.adobe.com/flex/halo"
minWidth ="1024" minHeight ="768" >
<s :Panel title ="Books" x ="61" y ="78" width ="124" height ="387" >
<s :List id ="list" x ="0" y ="10" width ="100%" height ="100%"
borderVisible ="false" ></s :List >
</s :Panel >
<s :Panel title ="Book Info" x ="193" y ="78" width ="379" height ="387" >
<mx :Form x ="0" y ="10" width ="377" height ="300" >
</mx :Form >
<s :HGroup x ="66" y ="309"
height ="46"
verticalAlign ="middle"
contentBackgroundColor ="#938F8F" >
<s :Button label ="Add" id ="button" />
<s :Button label ="Update" id ="button2" />
<s :Button label ="Delete" id ="button3" />
<s :Button label ="Get" id ="button4" />
</s :HGroup >
</s :Panel >
</s :Application >

You should now have a UI that looks this in design view:

Flash Builder 4

2) Switch to design view. Select the list in the "Books" panel. Right click the list and choose "Bind to Data".

Flash Builder 4

3) Choose "New service call" and select the operation as getBooks() . Choose "Bind to field" as name.

Flash Builder 4

4) Now select the form in the "Book Info" panel, right click it and choose "Bind to Data." Choose "Data type" in the "Generate form for" drop down. Hit Next.

Connect to Data Service Wizard

You can choose the ordering of values in the wizard.

Connect to Data Service Wizard

The generated form by default is bound to a value object with name "book."

5) Right click the list in the "Books" panel and choose "Generate Change Handler." The view will shift to source code and type in the following code into the change event handler:

/* 
point book to the selected item 
*/

book = list.selectedItem as Book ;

This is done so that every time the selected changes in the list, the form on the right is updated. If you run the application now, it should get the list of books from the server.

6) To make sure the first item in the list is selected every time the list is retrieved from the server, add a "result" event handler to the CallResponder that fetches the data in your main MXML file.

<s
:CallResponder
 id
="getBooksResult"
 result
="list.selectedIndex=0"
/>

CRUD

Getting the Add/Update/Delete/Get buttons to work is painless:

1) Select the Add button in design view.

2) Right click, choose "Generate Service Call" and choose the addBook operation.

3) The IDE automatically switches to source view so that you can type in the parameter to the addBook operation. Simply type in book

protected
 functio
n
 button_clickHandler
(event:MouseEvent
):void

{
addBookResult.token = books.addBook(book);
}
CRUD App with Java 6 Web Services and Flash Builder 4

4) Repeat steps 1 - 3 for the update and delete buttons. The delete button uses an integer parameter, book.bookid instead of book .

5) Right click the "Get" button and choose "Generate Click Handler." In the event handler, call the list's creation complete method.

protected
 functio
n
 button4_clickHandler
(event:MouseEvent
):void

{
list_creationCompleteHandler(null);
}

6) Optionally you could call list_creationCompleteHandler(null) after add, update and delete so that the list on the left is refreshed.

That's it, you have a CRUD app working! You can download the complete MXML file here.

CRUD App with Java 6 Web Services and Flash Builder 4

Conclusion

Web services are an easy medium to tap into for both Java and Flex developers. JDK 6 and Flash Builder comes with out-of-the-box support for it and you can quickly have an end-to-end application ready in no time.

SMR实战指南:从GWAS数据到eQTL分析的完整流程 本文提供了基于汇总数据的孟德尔随机化(SMR)实战指南,详细解析了如何从GWAS汇总数据出发,整合eQTL数据,完成从数据准备、BESD格式转换到最终SMR与HEIDI分析的完整流程。文章重点阐述了核心操作步骤、常见避坑技巧与结果解读,旨在帮助遗传学研究者高效掌握这一分析基因表达与复杂性状潜在因果关系的强大工具。 阅读详情

相关推荐

智能车学习日记【二】————十字和斜入十字

智能车学习日记【二】————十字和斜入十字 文章目录 智能车学习日记【二】————十字和斜入十字 前言 一、普通十字补线 二、斜入十字 1.判断是否为斜入十字和斜入十字类型 2.找斜入十字拐点 总结 前言 经过了一个多月的学习,小白的我终于也是能较稳定调出了2.8m以上的四轮车,过程中也遇到了很多困难,其中就有十字补线和斜入十字补线。尤其是斜入十字也是困扰了我快一周,现在和大家分享一下我处理斜入十字的方法(我的方法其实还有很多漏洞需要改进,仅供大家参考理解一下,欢迎各位在评论区指点出可

bsefef的博客 2740

java asmx_java调用webservice服务(web服务)(即new Service()报错解决办法)

java调用webservice服务(web服务)(即new Service()报错解决办法)2018-11-23(2011-04-16 16:05:30)标签:newservice()webserviceit分类:Java专区public static String getFlag(String bh,String pwd) throws Exception{String url ="h...

weixin_42144707的博客 916

【全网最新】使用 1panel面板 部署若依系统( springboot 和 vue)项目

打开前端项目的vue.config.js文件,检查devServer下的proxy代理部分,然后将下面这个端口修改为你要在打包后访问的端口,即使用nginx代理前的接口。这个端口默认是80端口,这里把其修改为不会冲突的8010端口,后台接口的地址配置为9080,不过感觉这里设置的8010和9080可能没有用,因为部署前端静态页面是,也配置了一次网页的外部接口和api的接口,后期有空了再验证。打开右侧的Maven,点击:生存期->package,然后点击运行,等待打包成功,包在如图所示的文件夹中。

老薛的专栏 1756

java flex web_java web开发 flex做前台(下)

第三步tomcat的配置现在遇到一个问题就是,我们需要将web项目发布出去,但是我们有希望可以通过eclipse来编写代码。为此有两种方法可以选择,可以讲eclipse的workspace选择在tomcat的webapps文件夹下,这样做有一些问题会比较麻烦,对于后续程序的更改问题。为此我们选择第二种,你的eclipse的workspace根据自己的情况而选择。假如是D:\eclipse\...

weixin_39886238的博客 165

手把手教你用Isaac Sim 8打造逼真光影效果:参数设置与场景应用

本文详细介绍了如何使用Isaac Sim 8打造逼真光影效果,涵盖基础参数设置、高级材质交互、专业级灯光造型技法以及复杂场景的灯光布局策略。通过实战案例和参数调优技巧,帮助用户提升虚拟场景的视觉表现,适用于数字孪生、虚拟仿真和影视特效等领域。

weixin_30836759的博客 80

智能车赛道识别:八邻域算法的实战解析与优化

本文深入解析了智能车赛道识别中八邻域算法的核心原理与实战优化。作为兼顾性能与稳定性的经典方案,该算法通过模拟探险家环顾八方的策略,能精准追踪弯道与直道边界。文章详细拆解了代码逻辑,并提供了边界平滑、异常处理及应对十字路口、环岛等复杂场景的关键优化策略,助力开发者提升智能车视觉系统的鲁棒性与实时性。

weixin_29228781的博客 261

BlazeDS For Flex第一步

下载BlazeDS.war 解压后文件目录如下: Lib下保存jar包: Flex中保存配置文件: Web.xml为配置文件: <servlet> <servlet-name>MessageBrokerServlet</servlet-name> <disp...

142

Prompt进阶2:LangGPT(构建高性能Prompt策略和技巧)--最佳实践指南

Prompt进阶2:LangGPT(构建高性能Prompt策略和技巧)--最佳实践指南

丨汀、的博客 2650

java 调用 flex_flex 和java 一起开发.实验远程调用.

首先下载最新的 BlazeDShttp://opensource.adobe.com/blazeds/最新BlazeDS下载地址.http://opensource.adobe.com/wiki/display/blazeds/Release+Builds下面就开始使用flex 创建一个 带java 的web 工程了.创建工程下载的是一个 war 文件..不用解压缩. 这个在创建工程的时候用到. ...

weixin_32865039的博客 192

【法如faro】三维激光软件Scene2023数据处理(自动配准并转换坐标)流程

法如faro Scene2023数据处理(自动配准并转换坐标)的主要流程为:新建项目、导入数据、处理、自动注册、坐标系转换、模型导出立和面模型导出等。

智慧空间实验室 2383

【WRF数据准备】气象驱动数据-ERA5再分析数据(Copernicus)

【WRF数据准备】气象驱动数据-ERA5再分析数据

WW、forever的博客 5529

关于Flex与Web Service的异常处理

作者: 王盛武 FLEX可以接受WSDL类型数据. 但我考虑了一个问题,如果程序遇到异常情况,能正确处理吗? 经过若干的编码测试, 还是不能拿到异常信息. 我找了个测试WEB SERVICE的工具, 输入WSDL地址, 异常信息的确获得到了。自己也写了个JAVA程序调用WSDL,异常也拿到了. 现在的问题是: 异常的确是返回的WSDL里,只是拿不出来. ...

iteye_10233的博客 187

我的GIT练习ONE

Git 是一个分布式版本控制及源代码管理工具;Git 可以为你的项目保存若干快照,以此来对整个项目进行版本管理每一次的练习,都是对自身知识的巩固,以及对自身知识的一个测试。

是个非常热爱生活、乐观、奋斗、努力的逗比青年 8869

Flex快速入门系列之二:FlashBuilder创建项目以及远程JAVA对象访问(包括spring)篇

前提:一个blazeds-turnkey,是adobe官方提供的访问远程java对象的工具,相关基本概念可参考:http://baike.baidu.com/view/1921230.html,官方文档去http://help.adobe.com/en_US/LiveCycleDataServicesES/3.1/Developing/index.html查看,因为对于最新的blazeds,ado

zhuixunzhe的专栏 2834

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

FLEX和spring、hibernate的集成

flex的后台使用spring+hibernate,spring+hibernate的集成方法和j2ee的项目中方法相同。主要是flex和spring的集成编写SpringFactory.java类:java 代码 package com.fire.spring;       import org.springframework.context.Ap

Eleven's Blog 2874

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

flex java 开发环境搭建_Flex+JAVA+BlazeDS开发环境配置(Java工程和Flex工程独立)

Flex+JAVA+BlazeDS开发环境配置(Java工程和Flex工程独立)2019年12月07日阅读数:7这篇文章主要向大家介绍Flex+JAVA+BlazeDS开发环境配置(Java工程和Flex工程独立),主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。[url]http://blog.youkuaiyun.com/assin/article/details/4277403[/u...

weixin_39640024的博客 272

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

对ADOBE FLEX的十大误解

导读:   对ADOBE FLEX的十大误解  用户不需要安装任何东西就可以运行FLEX应用程序  FLASH播放器其实还是需要的,不过最新的FLASH9的安装覆盖率已经达到了94% FLEX2,3在FP9环境下运行,FLEX应用程序工作在FP API(象矢量图形处理,网络)等,FLEX框架只是使用API构建了可重复使用的组件,象DATE PICKER之类的  对于桌面应用,ADO

The Way To Great 2090

认识Flex Data Services(FDS)

一 FDS相关概念    FDS全称Flex Data Services(现在Adobe将其改名为LiveCycle Data Services),是运行在服务器端的      java程序.它能够运行在大部分的java应用服务器上,包括JRun, JBoss, WebLogic, WebSphere, Oracle     10g, and Tomcat等.使用FDS,能够帮助你创建实时的,数据

没有天赋的IT人 1359

java Web与Flex通过HTTP service 通信 并解析Map 数据。

上篇通过Flex remoting 通信,进入调用方法后,发现并没有获取到Spring 注入的bean对象。bean 为 null so...修改为 HTTPService 的方式。 废话不多说, 1.Flex 通过 HTTPService 请求服务器 代码如下 public function getFlexDupont(companyA:String,companyB:St...

a9809的博客 162

Flex调用java webservice

<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="l...

weixin_34008805的博客 149

Flex与Spring进行整合的方式

今天想做整合,将Flex整合到SSH框架中来,由于之前已经将Flex与Java的通信调通,本以为这并不是一件复杂的事。没想到还是搞了两个小时。 我的想法是:Flex调用某个Java文件中的方法,然后我想在我的java方法中,调用Service层的业务逻辑方法。 在编写过程中,发现第一步没有问题,可以成功调用到Java文件中的方法,但第二步就出现问题了,因为Java文件中的Service对象始终

漂泊小柒的专栏 3273
上一篇: learn from tutorials of source code
下一篇: flash decompiler使用手记
zinking3
博客等级 码龄20年 262粉丝 215原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值