ImageVerifierCode 换一换
格式:PPT , 页数:20 ,大小:340KB ,
资源ID:379700      下载积分:2000 积分
快捷下载
登录下载
邮箱/手机:
温馨提示:
如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝扫码支付 微信扫码支付   
注意:如需开发票,请勿充值!
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【http://www.mydoc123.com/d-379700.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Chapter 29- Introduction to Web Services and SOAP.ppt)为本站会员(cleanass300)主动上传,麦多课文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文库(发送邮件至master@mydoc123.com或直接QQ联系客服),我们立即给予删除!

Chapter 29- Introduction to Web Services and SOAP.ppt

1、Chapter 29: Introduction to Web Services and SOAP,Outline 29.1 Introduction 29.2 Simple Object Access Protocol (SOAP) 29.3 SOAP Weather Service,29.1 Introduction,SOAP Simple Object Access Protocol Promote interoperability Communication among different software systems. Provides XML communication in

2、many Web services Web Services Exposes public interfaces usable by Web applications,29.2 Simple Object Access Protocol (SOAP),SOAP HTTP-XML-based protocol Enables application to communicate over Internet Uses XML documents called messages SOAP message contains an envelope Describes messages content

3、and intended recipient Ability to make a Remote Procedure Call (RPC) Request to another machine to run a task,Fig. 29.1 Class SimpleService. Line 4 Lines 6-12,1 / Fig. 29.1: SimpleService.java 2 / Implementation for the requested method on the server 3 4 public class SimpleService 5 6 public String

4、getWelcome( String message ) throws Exception 7 8 String text = 9 “Welcome to SOAP!nHere is your message: “ + message; 10 11 return text; / response 12 13 ,29.2 Simple Object Access Protocol (SOAP) (cont.),Fig. 29.2 SOAP package administration tool.,29.2 Simple Object Access Protocol (SOAP) (cont.),

5、Fig. 29.3 Description of deployed service.,Fig. 29.4 Client making a SOAP request (part 1). Lines 10-11 Line 13 Line 17 Lines 27-28 Lines 31-33,1 / Fig. 29.4 : GetMessage.java 2 / Program that makes a SOAP RPC 3 4 / import Java packages 5 import java.io.*; 6 import .*; 7 import java.util.*; 8 9 / im

6、port third-party packages 10 import org.apache.soap.*; 11 import org.apache.soap.rpc.*; 12 13 public class GetMessage 14 15 / main method 16 public static void main( String args ) 17 String encodingStyleURI = Constants.NS_URI_SOAP_ENC; 18 String message; 19 20 if ( args.length != 0 ) 21 message = ar

7、gs 0 ; 22 else 23 message = “Thanks!“; 24 25 / attempt SOAP remote procedure call 26 try 27 URL url = new URL( 28 “http:/localhost:8080/soap/servlet/rpcrouter“ ); 29 30 / build call 31 Call remoteMethod = new Call(); 32 remoteMethod.setTargetObjectURI( 33 “urn:xml-simple-message“ ); 34,Fig. 29.4 Cli

8、ent making a SOAP request (part 2). Lines 40-44 Line 48 Lines 51-57 Lines 60-63,35 / set name of remote method to be invoked 36 remoteMethod.setMethodName( “getWelcome“ ); 37 remoteMethod.setEncodingStyleURI( encodingStyleURI ); 38 39 / set parameters for remote method 40 Vector parameters = new Vec

9、tor(); 41 42 parameters.addElement( new Parameter( “message“, 43 String.class, message, null ) ); 44 remoteMethod.setParams( parameters ); 45 Response response; 46 47 / invoke remote method 48 response = remoteMethod.invoke( url, “ ); 49 50 / get response 51 if ( response.generatedFault() ) 52 Fault

10、 fault = response.getFault(); 53 54 System.err.println( “CALL FAILED:nFault Code = “ 55 + fault.getFaultCode()+ “nFault String = “ 56 + fault.getFaultString() ); 57 58 59 else 60 Parameter result = response.getReturnValue(); 61 62 / display result of call 63 System.out.println( result.getValue() );

11、64 65 66,Fig. 29.4 Client making a SOAP request (part 3).,67 / catch malformed URL exception 68 catch ( MalformedURLException malformedURLException ) 69 malformedURLException.printStackTrace(); 70 System.exit( 1 ); 71 72 73 / catch SOAPException 74 catch ( SOAPException soapException ) 75 System.err

12、.println( “Error message: “ + 76 soapException.getMessage() ); 77 System.exit( 1 ); 78 79 80 ,java GetMessage Welcome to SOAP! Here is your message: Thanks!,java GetMessage “my message” Welcome to SOAP! Here is your message: my message,29.3 SOAP Weather Service,SOAP Weather Service Web service Modif

13、ication of RMI-based Weather Service (Chapter 13) Use SOAP RPC instead of Java RMI Send information from server to client,Fig. 29.5 SOAP implementation of class Weather-Service (part 1). Line 11,1 / Fig. 29.5: WeatherService.java 2 / WeatherService provides a method to retrieve weather 3 / informati

14、on from the National Weather Service. 4 package com.deitel.advjhtp1.soap.weather; 5 6 / Java core packages 7 import java.io.*; 8 import .URL; 9 import java.util.*; 10 11 public class WeatherService 12 13 private Vector weatherInformation; / WeatherBean objects 14 15 / get weather information from NW

15、S 16 private void updateWeatherConditions() 17 18 try 19 System.out.println( “Update weather information.“ ); 20 21 / National Weather Service Travelers Forecast page 22 URL url = new URL( 23 “http:/iwin.nws.noaa.gov/iwin/us/traveler.html“ ); 24 25 / set up text input stream to read Web page content

16、s 26 BufferedReader in = new BufferedReader( 27 new InputStreamReader( url.openStream() ) ); 28 29 / helps determine starting point of data on Web page 30 String separator = “TAV12“; 31 32 / locate separator string in Web page 33 while ( !in.readLine().startsWith( separator ) ) 34 ; / do nothing 35,

17、Fig. 29.5 SOAP implementation of class Weather-Service (part 2). Lines 66-71,36 / strings representing headers on Travelers Forecast 37 / Web page for daytime and nighttime weather 38 String dayHeader = 39 “CITY WEA HI/LO WEA HI/LO“; 40 String nightHeader = 41 “CITY WEA LO/HI WEA LO/HI“; 42 43 Strin

18、g inputLine = “; 44 45 / locate header that begins weather information 46 do 47 inputLine = in.readLine(); 48 while ( !inputLine.equals( dayHeader ) ,Fig. 29.5 SOAP implementation of class Weather-Service (part 3). Lines 95-100,70 weatherInformation.add( 71 inputLine.substring( 23, 29 ) ); 72 73 inp

19、utLine = in.readLine(); / get next citys data 74 75 76 in.close(); / close connection to NWS Web server 77 78 System.out.println( “Weather information updated.“ ); 79 80 81 / process failure to connect to National Weather Service 82 catch( .ConnectException connectException ) 83 connectException.pri

20、ntStackTrace(); 84 System.exit( 1 ); 85 86 87 / process other exceptions 88 catch( Exception exception ) 89 exception.printStackTrace(); 90 System.exit( 1 ); 91 92 93 94 / implementation for WeatherService interface method 95 public Vector getWeatherInformation() 96 97 updateWeatherConditions(); 98

21、99 return weatherInformation; 100 101 ,Fig. 29.6 SOAP implementation of class Weather-ServiceClient (part 1). Lines 31-32,1 / Fig. 29.6: WeatherServiceClient.java 2 / WeatherServiceClient accesses the WeatherService remote 3 / object via SOAP to retrieve weather information. 4 package com.deitel.adv

22、jhtp1.soap.weather; 5 6 / Java core packages 7 import java.util.*; 8 import .*; 9 10 / Java extension packages 11 import javax.swing.*; 12 13 / third-party packages 14 import org.apache.soap.*; 15 import org.apache.soap.rpc.*; 16 17 / Deitel packages 18 import com.deitel.advjhtp1.rmi.weather.*; 19 2

23、0 public class WeatherServiceClient extends JFrame 21 22 / WeatherServiceClient constructor 23 public WeatherServiceClient( String server ) 24 25 super( “SOAP WeatherService Client“ ); 26 27 / connect to server and get weather information 28 try 29 30 / URL of remote SOAP object 31 URL url = new URL

24、( “http:/“ + server + “:8080/soap/“ 32 + “servlet/rpcrouter“ ); 33,Fig. 29.6 SOAP implementation of class Weather-ServiceClient (part 2). Lines 35-37 Line 46 Lines 49-55 Lines 58-65,34 / build SOAP RPC call 35 Call remoteMethod = new Call(); 36 remoteMethod.setTargetObjectURI( 37 “urn:xml-weather-se

25、rvice“ ); 38 39 / set name of remote method to be invoked 40 remoteMethod.setMethodName( 41 “getWeatherInformation“ ); 42 remoteMethod.setEncodingStyleURI( 43 Constants.NS_URI_SOAP_ENC ); 44 45 / invoke remote method 46 Response response = remoteMethod.invoke( url, “ ); 47 48 / get response 49 if (

26、response.generatedFault() ) 50 Fault fault = response.getFault(); 51 52 System.err.println( “CALL FAILED:nFault Code = “ 53 + fault.getFaultCode() + “nFault String = “ 54 + fault.getFaultString() ); 55 56 57 else 58 Parameter result = response.getReturnValue(); 59 60 Vector weatherStrings = ( Vector

27、 ) 61 result.getValue(); 62 63 / get weather information from result object 64 List weatherInformation = createBeans( 65 weatherStrings ); 66,Fig. 29.6 SOAP implementation of class Weather-ServiceClient (part 3). Line 95,67 / create WeatherListModel for weather information 68 ListModel weatherListMo

28、del = 69 new WeatherListModel( weatherInformation ); 70 71 / create JList, set its CellRenderer and add to 72 / layout 73 JList weatherJList = new JList( weatherListModel ); 74 weatherJList.setCellRenderer( new 75 WeatherCellRenderer() ); 76 getContentPane().add( new 77 JScrollPane( weatherJList ) )

29、; 78 79 80 / end try 81 82 / handle bad URL 83 catch ( MalformedURLException malformedURLException ) 84 malformedURLException.printStackTrace(); 85 86 87 / handle SOAP exception 88 catch ( SOAPException soapException ) 89 soapException.printStackTrace(); 90 91 92 / end WeatherServiceClient construct

30、or 93 94 / create List of WeatherBeans from Vector of Strings 95 public List createBeans( Vector weatherStrings ) 96 97 List list = new ArrayList();,Fig. 29.6 SOAP implementation of class Weather-ServiceClient (part 4).,98 for ( int i = 0; ( weatherStrings.size() - 1 ) i; 99 i += 3 ) 100 list.add( n

31、ew WeatherBean( 101 ( String ) weatherStrings.elementAt( i ), 102 ( String ) weatherStrings.elementAt( i + 1 ), 103 ( String ) weatherStrings.elementAt( i + 2 ) ) ); 104 105 106 return list; 107 108 109 / execute WeatherServiceClient 110 public static void main( String args ) 111 112 WeatherServiceC

32、lient client = null; 113 114 / if no server IP address or host name specified, 115 / use “localhost“; otherwise use specified host 116 if ( args.length = 0 ) 117 client = new WeatherServiceClient( “localhost“ ); 118 else 119 client = new WeatherServiceClient( args 0 ); 120 121 / configure and displa

33、y application window 122 client.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); 123 client.pack(); 124 client.setResizable( false ); 125 client.setVisible( true ); 126 127 ,29.3 SOAP Weather Service (cont.),Fig. 29.7 Apache SOAP Admin page.,29.3 SOAP Weather Service (cont.),Fig. 29.8 Apache SOAP Service Deployment Descriptor Template.,29.3 SOAP Weather Service (cont.),Fig. 29.9 SOAP WeatherService Client.,

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1