码迷,mamicode.com
首页 > 其他好文 > 详细

<!-- 车理赔调用收付 接口 -->

时间:2016-08-29 19:37:40      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:

 <!--  车理赔调用收付 接口 -->

package com.isoftstone.core.service.impl;

import com.isoftstone.core.service.intf.ServiceOfStringPara;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.nio.charset.Charset;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;

public class FinTransferImpl
  implements ServiceOfStringPara
{
  private String serviceUrl = "http://10.15.22.14:8004/finarp/services/finClmService";

  private static Logger log = Logger.getLogger(FinTransferImpl.class.getName());

  public String invoke(String sRequest)
  {
    HttpClient httpclient = HttpClients.createDefault();
    HttpPost httppost = new HttpPost(this.serviceUrl);

    StringEntity content = new StringEntity(sRequest, Charset.forName("UTF-8"));
    content.setContentType("application/soap+xml; charset=UTF-8");
    content.setContentEncoding("UTF-8");
    httppost.setEntity(content);

    HttpResponse response = null;
    String returnXml = null;
    String sentity = null;
    try {
      response = httpclient.execute(httppost);
      HttpEntity resEntity = response.getEntity();
      if (resEntity != null) {
        sentity = EntityUtils.toString(resEntity, "UTF-8");
        returnXml = sentity;
      }
    } catch (ClientProtocolException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      log.info("发送收付系统的请求报文:\n" + sRequest);
      log.info("收付系统返回的响应报文:\n" + sentity);
    }
    return returnXml;
  }

  public String getServiceUrl()
  {
    return this.serviceUrl;
  }

  public void setServiceUrl(String serviceUrl)
  {
    this.serviceUrl = serviceUrl;
  }

  public static void main(String[] args) throws Exception
  {
    File file = new File("C:\\Users\\King\\Desktop\\connectANSI.xml");
    System.out.println(file.exists());

    String temp2 = null;
    StringBuilder sb2 = new StringBuilder();
    InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "GBK");
    BufferedReader br = new BufferedReader(isr);
    temp2 = br.readLine();

    while (temp2 != null) {
      sb2.append(temp2);
      temp2 = br.readLine();
    }
    String sss = sb2.toString();

    new FinTransferImpl().invoke(sss);
  }
}

 

<!-- 车理赔调用收付 接口 -->

标签:

原文地址:http://www.cnblogs.com/bobo1713930654/p/5819053.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!