代码:
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包