折腾了一把JAX-WS, SOA & Java EE 5(part 2 of 3)

/**
   * saves service response to file
   * 
   * @param response
   * @throws Exception
   */
  private void saveFile(SOAPMessage msg, String filename) throws Exception {
    
    if( msg != null ) {
      
      if(StringUtils.isEmpty(wsresponsefile)) {
        wsresponsefile = "testResponse.xml";
      }
      
      System.out.println("Saving service response: " + filename);
      
      FileOutputStream fos = null;
      
      try {
        fos = new FileOutputStream(filename);
        msg.writeTo(fos);
      }
      catch(Exception e) {
        e.printStackTrace();
      }
      finally {
        IOUtils.close(fos);
      }
    }
  }
  
  private SOAPMessage createSOAPMsgFromFile(String filename) throws Exception {
    
    if ( ! StringUtils.isEmpty(filename) ) {
      
      System.out.println("Loading request payload: " + filename);
      
      FileInputStream fis = null;
      
      try {
        fis = new FileInputStream(filename);
        return MessageFactory.newInstance().createMessage(null, fis);
      } 
      catch (Exception e) {
        e.printStackTrace();
      } 
      finally {
        IOUtils.close(fis);
      }
    }
    
    return null;
  }

  public static void main(String[] a) throws Exception {
    new SoapClient().testWebService();
  }
}
{code}


SOAP request --------------

{code}
<?xml version="1.0" encoding="UTF-8"?>

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
                    xmlns:fn="http://www.w3.org/2005/xpath-functions" 
                    xmlns:xs="http://www.w3.org/2001/XMLSchema">                            
  <SOAP-ENV:Header/>
      <SOAP-ENV:Body>
        <sc:getPersonRequest xmlns:sc="http://www.t50.com/portable" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            xsi:schemaLocation="http://www.t50.com/portable GetPerson.xsd ">
          <person>
            <firstName>john</firstName>
            <lastName>wang</lastName>
            <age>86</age>
          </person>
        </sc:getPersonRequest>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
{code}


SOAP response --------------

{code}
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
    <ns2:getPersonResponse xmlns:ns2="http://www.t50.com/portable">
        <person>
            <firstName>john</firstName>
            <lastName>wang</lastName>
            <age>30001</age>
        </person>
    </ns2:getPersonResponse>
</S:Body>
</S:Envelope>
{code}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值