【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.

5实践报告撰写 一 项目流程 明确标准 确定分析目标 寻找分析数据 清洗数据 描述性分析 诊断性分析 提出建议 撰写报告 二 确定分析目标 什么是你感兴趣的? 什么是你熟悉的? 什么是你擅长的? 1 电商零售行业 商品销量分析 价格分析 评价分析 ...... 2 自媒体行业 广告投放力度分析 广告投放回报分析 不同类型的产品分析 ...... 3 金融行业 股票价格分析 信贷业务违约分析 客户画像分析 ...... ... 阅读详情

相关推荐

零外围电路!用CH340X实现ESP32一键下载的完整教程

本文详细介绍了如何利用CH340X系列USB转串口芯片实现ESP32的一键自动下载功能,无需任何外围逻辑控制电路。通过解析CH340X的增强型DTR/RTS功能,提供核心电路设计、电压匹配方案,并指导在Arduino IDE和PlatformIO中进行软件配置,帮助开发者构建简洁、可靠且低成本的ESP32下载方案。

gpu4optimizer的博客 775

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

双三相电机控制避坑指南:为什么你的SVPWM谐波大?四矢量调制实战解析

本文深入解析双三相电机控制中SVPWM谐波大的问题,并提供四矢量调制实战方案。通过分析谐波来源、四矢量调制原理及工程实现步骤,显著降低电流THD至3-5%,提升系统效率2.3个百分点。特别适合需要优化电机控制的工程师参考。

weixin_30645617的博客 397

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

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

weixin_39886238的博客 165

Android14_MTK调试LCD屏功能

android14 MTK平台调试LCD屏

m0_37786046的博客 1472

细胞膜电学特性的分数阶微积分建模

分数阶微积分在细胞膜电学特性建模中的应用主要体现在对细胞膜的电容行为和神经元放电活动的更精确描述上。

冰河世纪20的博客 623

BlazeDS For Flex第一步

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

142

对比实验系列:Efficientdet环境配置及训练个人数据集

可以通过下方链接下载Efficientdet源码。

Yayisheng的博客 4585

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

AttributeError: module ‘numpy‘ has no attribute ‘int‘解决方案

本文主要介绍了AttributeError: module ‘numpy’ has no attribute 'int’解决方案,希望能对使用numpy的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案 2.1 方案一 2.2 方案二

weixin_43178406的博客 28万+

(11-3-03)多任务与元强化学习:综合实战:基于元强化学习的迷宫导航系统(3)

本文介绍了策略网络隐空间可视化的实现方法及其在强化学习中的应用。通过设计visualize_latent_space函数,使用t-SNE算法将高维隐空间特征降维至二维进行可视化,直观展示策略网络在不同任务中的特征分布。文章详细阐述了实现流程:状态收集、t-SNE降维和可视化绘图,并提供了完整的Python代码示例。实验结果表明,该方法能有效分析策略网络的学习过程与适应能力,为优化模型提供重要依据。同时,文章还介绍了主程序的完整流程,包括环境初始化、元智能体训练与评估、学习策略比较等环节,最后对实验结果进行可

码农三叔 1041

关于Flex与Web Service的异常处理

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

iteye_10233的博客 187

芯片原厂linux驱动开发的分享

大家好,我是XX,来自湖南XX学院,电子信息18级,也曾在创新基地控制组学习过两三年,毕业后就职于一家芯片原厂的解决方案部,担任驱动工程师的职位,算上实习期,我的工作时长已有两年。在此我想将这两年期间学习与积累到的一些经验输出出来,与大家一同分享。知识面有限,只能简单介绍一些驱动开发方向的一些经验,且由于经验尚浅,文中难免会有一些疏漏和错误之处,还请大家积极地批评指正。

嵌入式技术开发 849

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

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

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

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

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

对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、付费专栏及课程。

余额充值