Jersey/Jackson Polymorphic Deserialization

Categories: Java; Tagged with: ; @ October 1st, 2013 20:56

Jersey can handle concrete data binding smoothly, however, for Polymorphic, it’s not very configurable.

e.g.:

IUser

DefaultUser, SGUser, CNUser

We need a web service, which accept POST request from Client side:

saveUser(IUser newUser)…

Nobody knows it’s a DefaultUser or SGUser, or CNUser, except Spring config XML.  and there’re some ways to use Jersey do the deserialization.:

http://programmerbruce.blogspot.sg/2011/05/deserialize-json-with-jackson-into.html

 

However, I prefer to use “Simple” Data Binding from Jackson to do the mapping manually:

“Simple here just means that range of value types is limited to core JDK types”

  Object root = mapper.readValue(src, Object.class);
  Map<?,?> rootAsMap = mapper.readValue(src, Map.class);
 

So in the saveUser() method, we can get the raw values and then initialize the instances with the help of Spring to make sure what we know and what we only need to know is ‘Interface’/Contract:

saveUser(Map<String, Object> json) {

(Cast) json.get(“key”);

}

Axis2: IWAB0489E Error when deploying Web service to Axis runtime

Categories: Java; Tagged with: ; @ February 27th, 2013 19:28

I try to get started with Axis2, but when I try to create Web Service in Eclipse, I got the following Error:

IWAB0489E Error when deploying Web service to Axis runtime

After googling, I got the solution:

Make sure the config of web service Server and Runtime is correct:

image

Flex中使用WebService

Categories: Flex; Tagged with: ; @ October 13th, 2008 10:26

1. 简介 Flex提供了一组访问普通Web应用的HTTP类库和组件,提供了完整的基于ASP.NET,Java.PHP服务端技术的指导实践方案.对于HTTPService服务的访问Flex提供了两类访问模式:

名称

说明

文本方式的访问

以纯文本形式进行数据访问.以纯文本形式发送请求,以纯文本形式返回和处理请求

基于XML方式的访问

以XML形式访问数据,以XML方式发送请求,处理请求.

Flex基于HTTPService访问方式不是基于标准的协议.完全是由服务端开发人员与客户端开发人员定义的通信方式.这虽然不能成为标准的服务接口,但可以大大提高特殊应用的数据传输效率.

Flex访问HTTPService可以使用类库和组件两种方式.由于HTTPService不是标准协议,因此在进行HTTPService访问的时候,需要自己定义数据交换格式.

· 使用HTTPService类库.Flex对于HTTPService的访问方式与传统的B/S结构很像,同样是通过POST和GET方法发送请求,但Flex发送请求和处理结果的方式是异步的

· Flex访问HTTPService标签: 在Flex总一般会使用标签的方式访问HTTPService,访问HTTPService的标签为<mx:HTTPService></mx:HTTPService>

2. 实现:

Flex访问WebService

由于WebService是基于XML和SOAP协议的,所以Flex访问WebService的类库和组件封装了对请求内容以及响应内容的处理,这样可以在不需要了解WebService细节的情况下,通过使用Flex对WebService进行调用.

· Flex访问WebSerivice的类库集中在mx.rpc.soap包下,多使用WebService类.该类的属性和方法都是围绕着WebService规范和定义展开的.

· Flex访问WebService标签: 虽然可以直接通过类库的方式直接访问WebService,但通常会使用<mx:WebService>

3. 举例  使用http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx?wsdl作为我们要使用的WebService源.
具体信息请参见webxml.com.cn

	
		
			
				
					sh000001
				
			
		
	
	
	
		
		
	

下面是AS代码:

		import mx.controls.Alert;
		import mx.rpc.events.FaultEvent;
		import mx.rpc.events.ResultEvent;
		
		/**
		 * 监听ws,以便作出响应;
		 * 运行getStockInfoByCode.send(),发出请求
		 */ 
		private function sendCount():void{
			ws.addEventListener(ResultEvent.RESULT,showResult);
			ws.addEventListener(FaultEvent.FAULT,faultResult);
			ws.getStockInfoByCode.send();
		}
		
		/**
		 * 收到数据后现显示数据
		 */ 
		private function showResult(rs:ResultEvent):void{
			var rsStr:String  = new String(rs.result);
			var resultArray:Array = rsStr.split(",");
			
			shangzheng.text = resultArray[3];
			trace("收到" + shangzheng.text);
		}
		
		/**
		 * 遇到错误则报错.
		 */ 
		private function faultResult(faultmessage:FaultEvent):void{
			var faultStr:String = new String(faultmessage.message);
			Alert.show(faultStr,"访问错误");
		}

效果:

image image



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.