【简述】

查询三天的天气信息(天气概况、日期、温度),测试jaxws是否支持自定义pojo发布服务。

【开发过程】

服务端:

1.自定义pojo(天气概况、日期、温度)

2.开发SEI接口及实现类

3.发布服务

客户端:(采用service类标准方法调用webService)

1.根据wsdl说明书生成客户端调用代码。

2.将生成代码拷贝到工程中,编写客户端类。

【服务端工程截图】

【WeatherModel.java】

  1. package com.Higgin.ws.pojo;
  2. import java.util.Date;
  3.  
  4. public class WeatherModel {
  5.  
  6. //天气概况
  7. private String detail;
  8.  
  9. //日期
  10. private Date date;
  11.  
  12. //最高温度
  13. private int temperature_max;
  14.  
  15. //最低温度
  16. private int temperature_min;
  17. //忽略get/set方法...........
  18. }

【WeatherInterface.java】

  1. package com.Higgin.ws.service;
  2.  
  3. import java.util.List;
  4. import com.Higgin.ws.pojo.WeatherModel;
  5.  
  6. public interface WeatherInterface {
  7. public List<WeatherModel> queryWeatheer(String cityName);
  8. }

【WeatherInterfaceImpl.java】

  1. package com.Higgin.ws.service;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Calendar;
  5. import java.util.Date;
  6. import java.util.List;
  7.  
  8. import javax.jws.WebService;
  9.  
  10. import com.Higgin.ws.pojo.WeatherModel;
  11.  
  12. @WebService
  13. public class WeatherInterfaceImpl implements WeatherInterface{
  14.  
  15. @Override
  16. public List<WeatherModel> queryWeatheer(String cityName) {
  17.  
  18. //构造三天天气
  19. List<WeatherModel> list =new ArrayList<WeatherModel>();
  20. Calendar calendar=Calendar.getInstance();
  21. int day=calendar.get(Calendar.DATE);
  22.  
  23. WeatherModel weatherModel_1=new WeatherModel();
  24. weatherModel_1.setDetail("晴天");
  25. weatherModel_1.setDate(new Date());
  26. weatherModel_1.setTemperature_max(10);
  27. weatherModel_1.setTemperature_min(-10);
  28.  
  29. WeatherModel weatherModel_2=new WeatherModel();
  30. weatherModel_2.setDetail("阴天");
  31. calendar.set(Calendar.DATE, day+1);
  32. weatherModel_2.setDate(calendar.getTime());
  33. weatherModel_2.setTemperature_max(6);
  34. weatherModel_2.setTemperature_min(-2);
  35.  
  36. WeatherModel weatherModel_3=new WeatherModel();
  37. weatherModel_3.setDetail("晴天");
  38. calendar.set(Calendar.DATE, day+2);
  39. weatherModel_3.setDate(calendar.getTime());
  40. weatherModel_3.setTemperature_max(30);
  41. weatherModel_3.setTemperature_min(3);
  42.  
  43. list.add(weatherModel_1);
  44. list.add(weatherModel_2);
  45. list.add(weatherModel_3);
  46. return list;
  47. }
  48.  
  49. }

【WeatherServer.java】

  1. package com.Higgin.ws.service;
  2.  
  3. import javax.xml.ws.Endpoint;
  4.  
  5. public class WeatherServer {
  6. public static void main(String[] args) {
  7. Endpoint.publish("http://127.0.0.1:12345/weather", new WeatherInterfaceImpl());
  8. }
  9. }

【客户端工程截图】

已经使用Wsimport生成了相应的客户端代码

【WeatherClient.java】

  1. package com.higgin.ws.client;
  2.  
  3. import java.net.MalformedURLException;
  4. import java.net.URL;
  5. import java.text.SimpleDateFormat;
  6. import java.util.Date;
  7. import java.util.List;
  8.  
  9. import javax.xml.namespace.QName;
  10. import javax.xml.ws.Service;
  11.  
  12. import com.higgin.ws.service.WeatherInterfaceImpl;
  13. import com.higgin.ws.service.WeatherModel;
  14.  
  15. public class WeatherClient {
  16.  
  17. public static void main(String[] args) throws MalformedURLException {
  18. //使用说明书
  19. URL wsdlDocumentLocation =new URL("http://127.0.0.1:12345/weather?wsdl");
  20.  
  21. QName serviceName=new QName("http://service.ws.Higgin.com/", "WeatherInterfaceImplService");
  22.  
  23. //创建服务视图
  24. Service service=Service.create(wsdlDocumentLocation,serviceName);
  25.  
  26. //创建portType对象
  27. WeatherInterfaceImpl weatherInterfaceImpl=service.getPort(WeatherInterfaceImpl.class);
  28.  
  29. //调用WeatherInterfaceImpl方法
  30. List<WeatherModel> list=weatherInterfaceImpl.queryWeatheer("杭州");
  31.  
  32. for(WeatherModel weatherModel:list){
  33. System.out.println(weatherModel.getDetail());
  34. Date date=weatherModel.getDate().toGregorianCalendar().getTime();
  35. System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(date));
  36. System.out.println(weatherModel.getTemperatureMax());
  37. System.out.println(weatherModel.getTemperatureMin());
  38. }
  39.  
  40. }
  41.  
  42. }

【运行结果】

10_Jaxws使用自定义pojo发布服务的更多相关文章

  1. 自定义及发布一个webservice服务

    自定义及发布一个webservice服务    - 声明 某个业务服务为webservice服务       通过@webservice 注解来声明    - 发布webservice服务       ...

  2. Dubbo2.7源码分析-如何发布服务

    Dubbo的服务发布逻辑是比较复杂的,我还是以Dubbo自带的示例讲解,这样更方便和容易理解. Provider配置如下: <?xml version="1.0" encod ...

  3. ArcGIS 将自定义工具发布到ArcGIS Server,作为Geoprocessing Service

    新建自定义工具过程可参考上一篇博客:http://www.cnblogs.com/oceanking/p/3933681.html 1.执行自定义工具.此步骤不可省略 打开ArcCatalog,双击自 ...

  4. ServiceStack.Redis订阅发布服务的调用(Z)

      1.Redis订阅发布介绍Redis订阅发布是一种消息通信模式:发布者(publisher)发送消息,订阅者(Subscriber)接受消息.类似于设计模式中的观察者模式.发布者和订阅者之间使用频 ...

  5. ArcGIS Server开发教程系列(2)配置ARCMAP和ARCCatalog发布服务

    1.       Arc catalog的配置 打开catalog,如图新增刚刚创建的server 1. Use GIS services: 用户身份连接 使用此种连接,可以浏览.使用站点内发布的所有 ...

  6. ServiceStack.Redis订阅发布服务的调用

    1.Redis订阅发布介绍 Redis订阅发布是一种消息通信模式:发布者(publisher)发送消息,订阅者(Subscriber)接受消息.类似于设计模式中的观察者模式. 发布者和订阅者之间使用频 ...

  7. ArcGIS发布服务时缓存切片设置

    [文件]>[共享]>[服务]>[覆盖原有服务]或[创建新服务] 设置好相关参数后,会弹出"服务编辑框": 进入"缓存" 1."绘制此 ...

  8. 使用expect脚本语言写一键发布服务(代码发布、所有服务重启)

    互联网服务有很多台服务,但是在上线的时候需要将这些服务版本都更新与个个都重启,下面的脚本语言,就是一键发布服务~ 1.在/home/weihu/deploy/ 目录下建下publish .publis ...

  9. PHPRPC jsp发布服务

    PHPRPC是面向服务的高性能远程过程调用协议.PHPRPC for java 是此协议的一种实现,详细请到官方看PHPRPC的介绍 ,以其它rpc协议的性能对比请:Java.PHPRPC.Hessi ...

随机推荐

  1. 关系数据库 范式(NF: Normal Form) 说明

    关系数据库 范式(NF: Normal Form) 说明 数据库电话insertdelete存储oracle   目录(?)[+]   一.范式概述(NF:NormalForm) 数据库的设计范式是数 ...

  2. Fixed theorems

    Banach Schauder Bourbaki-Kneser

  3. XMPP——Smack[6]离线消息和离线文件的实现

    终篇,三天所学所用,也就这些,如果需要大家要自己去查资料研究研究,功能其实可以很强大的 可惜界面做得不好,一大短处,从大一迄今没整好,主要是个人审美不行,哎 毕业季呀毕业季,明天摆摊卖书,再半月就可能 ...

  4. powershell.exe直接运行命令

    powershell.exe -Command "& { ('time={0},user={1}' -f (get-date),(whoami)) | Out-File " ...

  5. Android 编程下 java.lang.NoClassDefFoundError: cn.jpush.android.api.JPushInterface 报错

    使用了极光推送的 jar 包项目在从 SVN 中检出后,假设不又一次对 jar 包和 Bulid Path 进行配置就会抛出 java.lang.NoClassDefFoundError: cn.jp ...

  6. file_put_contents() failed to open stream: Permission denied 问题解决

    很长时间没有写PHP了,今天突然有个需求要写一个保存文件的功能. function downloadFile( $url , $savePath = '' ) {     $fileName = ge ...

  7. Andropid自己定义组件-坐标具体解释

    在做一个view背景特效的时候被坐标的各个获取方法搞晕了,几篇抄来抄去的博客也没弄非常清楚. 如今把整个总结一下. 事实上仅仅要把以下这张图看明确就没问题了. watermark/2/text/aHR ...

  8. Android 自定义View修炼-Android中常见的热门标签的流式布局的实现

    一.概述:在日常的app使用中,我们会在android 的app中看见 热门标签等自动换行的流式布局,今天,我们就来看看如何 自定义一个类似热门标签那样的流式布局吧(源码下载在下面最后给出哈) 类似的 ...

  9. JSP的三种类型的元素

    JSP有三种类型的元素:指令元素(directive element).行为元素(action element).和脚本元素(script element). 指令元素用于指定整个JSP页面的相关信息 ...

  10. 关于Eclipse的常用快捷键

    最近用到了一些以前开发中没有用到的Eclipse中的快捷键,现在总结如下: Ctrl+Shift+G 全局 工作区中的引用 使用的图解: 在所选定的类上,按下Ctrl+Shift+G在Search的T ...