利用axis调用webservice

代码:

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import sun.misc.BASE64Decoder;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import java.io.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class callPostUrl {

    private final static DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static void main(String[] args){
        String htbh = "2009预1027288";
        String zjhm = "33012319570907332X";
        getPdf(htbh,zjhm);
    }

    /**
     * 调用接口获取pdf
     * @param htbh
     * @param zjhm
     * @return
     */
    public static byte[] getPdf(String htbh, String zjhm) {
        try {
            Service service = new Service();//
            String endpoint = "http://172.16.100.145:8091/Gxcx/services/Zjzww_Query";
            String method = "getHtwbPdf";
            QName opName = new QName("http://Service.mltx.dataPort.hz365.com", method);
            Call call = (Call) service.createCall();
            call.setOperationName(opName);
            call.setTargetEndpointAddress(endpoint);
            call.addParameter("htbh", XMLType.XSD_STRING, ParameterMode.IN);
            call.addParameter("zjhm", XMLType.XSD_STRING, ParameterMode.IN);
            call.setReturnType(XMLType.XSD_STRING);
//            call.setEncodingStyle("GBK");
            System.out.println("====开始网签合同转pdf接口调用,时间是:(" + DATE_FORMAT.format(new Date()) + ")====");
            Object invoke = call.invoke(new Object[]{htbh,zjhm});
            System.out.println("====网签合同转pdf接口调用结束,时间是:(" + DATE_FORMAT.format(new Date()) + ")====");
            if("201".equals(invoke.toString())){
                return null;
            }
            BASE64Decoder decoder = new BASE64Decoder();
            byte[] bytes = decoder.decodeBuffer(invoke.toString());//解密
            createPdf(bytes,htbh);
            return bytes;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 打印pdf
     * @param bytes
     * @param htbh
     */
    public static void createPdf(byte[] bytes,String htbh){
        BufferedOutputStream bos = null;
        FileOutputStream fos = null;
        File file = null;
        try {
            File dir = new File("G:\\Download");
            if(!dir.exists()){
                dir.mkdirs();
            }
            file = new File("G:\\Download\\"+htbh+".pdf");
            fos = new FileOutputStream(file);
            bos = new BufferedOutputStream(fos);
            bos.write(bytes);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(bos!=null){
                try {
                    bos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }

}

执行结果:
在这里插入图片描述
使用axis调用webservice需要的jar包
axis.jar
jaxrpc.jar
commons-discovery-0.2.jar
commons-logging-1.1.1.jar
wsdl4j-1.6.2.jar

下载链接:https://pan.baidu.com/s/1qkLPga_5ewSzdDpZHey9ZQ
可以在maven上下载:
在这里插入图片描述
在这里插入图片描述
选择要下载的对于的版本
在这里插入图片描述
点jar进行jar包下载,或者选择复制<dependenecy>进行maven管理jar包
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值