99偷拍视频精品区一区二,口述久久久久久久久久久久,国产精品夫妇激情啪发布,成人永久免费网站在线观看,国产精品高清免费在线,青青草在线观看视频观看,久久久久久国产一区,天天婷婷久久18禁,日韩动漫av在线播放直播

SAAJ帶附件的soap消息如何理解

今天就跟大家聊聊有關(guān)SAAJ帶附件的soap消息如何理解,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

創(chuàng)新互聯(lián)建站作為成都網(wǎng)站建設(shè)公司,專注網(wǎng)站建設(shè)公司、網(wǎng)站設(shè)計,有關(guān)企業(yè)網(wǎng)站制作方案、改版、費用等問題,行業(yè)涉及成都發(fā)電機租賃等多個領(lǐng)域,已為上千家企業(yè)服務(wù),得到了客戶的尊重與認(rèn)可。

帶附件的soap消息api,其內(nèi)容很豐富,它是一個允許用soap消息而不是用jax-rpc來調(diào)用web service的API .它通過直接創(chuàng)建XML消息來完成web serivce的調(diào)用.SOAP API 簡化了創(chuàng)建XML的工作. 取自j2ee文檔的soap消息的結(jié)構(gòu)圖.
 沒有詳細(xì)介紹saaj的一些類的使用.好在它們都有很好的自解釋性.

package array;   import javax.xml.soap.*;  import java.net.*;  import java.io.*;  import java.util.*;  import java.text.SimpleDateFormat;  public class SaajClient {      public SaajClient() {      }       public static void main(String[] args) throws Exception {          SaajClient client = new SaajClient();          User[] user = new User[2];          user[0] = new User("張三", "027-88888888", new Date());          user[1] = new User("lisi", null, new Date());          saajTest(user);       }       private static void saajTest(User[] user) throws MalformedURLException,              IOException,              UnsupportedOperationException, SOAPException {          MessageFactory factory = MessageFactory.newInstance();//SAAJ的根工廠類          SOAPMessage message = factory.createMessage();          //SOAPMessage 對象需要一些元素,包括SOAPPart,SOAPEnvelope,SOAPHeader,SOAPBody對象          //SAAJ通過返回一個新的已經(jīng)包括這些元素的SOAPMessage對象來簡化操作          SOAPFactory s = SOAPFactory.newInstance();//通用工廠類,創(chuàng)建Name,SOAPElement對象           Name countUser = s.createName("countUser", "mh", "http://array");          //Name對象表示一個XML限定名稱          Name arrayOfUser_1 = s.createName("arrayOfUser_1");          Name xsi = s.createName("xmlns:xsi");          Name nullAttribute = s.createName("xsi:nil");           //下面的代碼創(chuàng)建soap對象          SOAPBody body = message.getSOAPBody();          SOAPBodyElement bodyChildElement = body.addBodyElement(countUser);          SOAPElement arrayOfUser = bodyChildElement.addChildElement(                  arrayOfUser_1);        //  arrayOfUser.addAttribute(xsi, "http://www.w3.org/2001/XMLSchema-instance");          arrayOfUser.addNamespaceDeclaration("xsi","http://www.w3.org/2001/XMLSchema-instance");          //定義arrayOfUser的 xmlns:xsi屬性  該名稱空間是XML模式實例命名空間,由XML模式規(guī)范定義,它定義了          //可以在XML文檔中使用的屬于該命名空間的一些特性.          for (int i = 0; i < user.length; i++) {              //需要注意順序,也就是和復(fù)雜類型的sequence元素的順序?qū)?yīng)              Name valueName = s.createName("value");              SOAPElement value = arrayOfUser.addChildElement(valueName);              Name birthday = s.createName("birthDay");              SOAPElement birthdayElement = value.addChildElement(birthday);               if (user[i].getBirthDay() == null) {                  birthdayElement.addAttribute(nullAttribute, "1");              } else {                  //日期類型必須進行格式化                  SimpleDateFormat format= new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");                  birthdayElement.addTextNode(format.format(user[i].getBirthDay()));              }              Name name = s.createName("name");              SOAPElement nameElement = value.addChildElement(name);              if (user[i].getName() == null) {                  //傳送空值                  nameElement.addAttribute(nullAttribute, "1");              } else {                  nameElement.addTextNode(user[i].getName());              }              Name phone = s.createName("phone");              SOAPElement phoneElement = value.addChildElement(phone);              if (user[i].getPhone() == null) {                  phoneElement.addAttribute(nullAttribute, "1");              } else {                  phoneElement.addTextNode(user[i].getPhone());              }           }           //發(fā)送soap消息          SOAPConnectionFactory f = SOAPConnectionFactory.newInstance();          SOAPConnection conn = f.createConnection();          URL url = new URL("http://localhost:8082/complexType-array/services/CountUser");          SOAPMessage response = conn.call(message, url);           SOAPBody soapBody = response.getSOAPBody();          Iterator it = soapBody.getChildElements();          while (it.hasNext()) {              SOAPBodyElement bodyElement = (SOAPBodyElement) it.next();              String returnValue = bodyElement.getValue();              System.out.println(bodyElement.getElementName().getLocalName() +                                 "      " + returnValue);          }            response.writeTo(System.out);      }  }

程序向服務(wù)器端傳送的數(shù)據(jù):

POST /complexType-array/services/CountUser HTTP/1.1  SOAPAction: ""  Content-Type: text/xml; charset=UTF-8  User-Agent: Java/1.5.0_03  Host: localhost:8082  Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2  Connection: keep-alive  Content-Length: 448   < env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>    < env:Header/>    < env:Body>       < mh:countUser xmlns:mh='http://array'>          < arrayOfUser_1 xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>             < value>                < birthDay>2006-11-08T22:36:13< /birthDay>                < name>張三< /name>                < phone>027-88888888< /phone>             < /value>             < value>                < birthDay>2006-11-08T22:36:13                 < name>lisi                 < phone xsi:nil='1'/>             < /value>          < /arrayOfUser_1>       < /mh:countUser>    < /env:Body>

從傳送的數(shù)據(jù)來看,就是一個符合soap規(guī)范的xml文檔.既然是xml文檔,也就是說可以用jdom api 來操作它
事實上就是這樣,在J2EE web service開發(fā)中,soap api 可以跟 jdom api混合使用。

看完上述內(nèi)容,你們對SAAJ帶附件的soap消息如何理解有進一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。

新聞名稱:SAAJ帶附件的soap消息如何理解
當(dāng)前網(wǎng)址:http://www.yijiale78.com/article26/pioojg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站品牌網(wǎng)站建設(shè)企業(yè)網(wǎng)站制作手機網(wǎng)站建設(shè)ChatGPTApp開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站