基于SOAP的Web Services的开发

来源:互联网 发布:免费sd卡数据恢复软件 编辑:程序博客网 时间:2024/06/07 17:14

 打开blog,发现csdn在使用FCKeditor感觉很亲切。因为eHarbors用的也是FCK,前几天刚研究过。现在已经放到服务器上做最后的测试了,bug还是不断的出现。自己写的解析接收eBay SOAPMessage的程序也出现罢工的迹象。以前没有做过基于SOAP的Web Services的开发,对这方面了解不多。经过查资料程序虽然写了出来但是一抛异常就没底了,不知道如何解决。

消息发送测试程序:

/*
 * Copyright 2006 eHarbors.com.  All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * eHarbors.com ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms specified by eHarbors.com 
 */
package com.eharbors.notification;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.transform.stream.StreamSource;

import org.w3c.dom.Document;

/**
 * @author Joe
 *
 * Important:
 *
 * Create at 2006-7-21 14:58:35
 */
public class NFTest {

 /**
  * @param args
  * @throws SOAPException
  */
 public static void main(String[] args) throws Exception {
  // TODO Auto-generated method stub
  // First create the connection
  SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory
    .newInstance();
  SOAPConnection connection = soapConnFactory.createConnection();

  // Next, create the actual message
  MessageFactory messageFactory = MessageFactory.newInstance();
  SOAPMessage message = messageFactory.createMessage();

  // Create objects for the message parts
  SOAPPart soapPart = message.getSOAPPart();
  StreamSource preppedMsgSrc = new StreamSource(new FileInputStream(
    "E:/ebay/endofauc.xml"));
  soapPart.setContent(preppedMsgSrc);

   message.saveChanges();
  URL endpoint = new URL("http://172.18.31.184:8080/eHarbors/receiveNF");
  try {
   SOAPMessage response = null;
   connection.call(message, endpoint);
   if (response != null) {
    // 输出SOAP消息到控制台
    System.out.println("Receive SOAP message from localhost:");
    response.writeTo(System.out);
   } else {
    System.err.println("No response received from partner!");
   }
  } catch (SOAPException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } finally {
   connection.close();
  }

 }
}
消息接收者是一个Servlet.有时间再写。

 

 
原创粉丝点击