我常用的系统之间的数据交互方式有:
1.HTTP 这个现在比较多,一般数据是JSON/XML格式
2.WEBSERVICE 传统互联网金融银行保险用的比较多,电商好像基本不用
3.socket 用的比较少了 老旧项目用的多
4.SFTP/FTP 现在因为安全问题一般都是使用SFTP
5.系统之间共用数据库可能会数据库直接授权。
6.有些服务集群可能会有共享磁盘,大家都有权限去读写。
7.MQ
8.集群有时候中间会过一道NGINX APACHE 之类的
下面放一个http例子:
package com.example.test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
public class TestHttps {
public static void main(String[] args) throws UnsupportedEncodingException {
String aString = "7898989";
String urlString = "http:******************* ";
executeHttpPostMethod(urlString,aString,"UTF-8");
}
public static String executeHttpPostMethod(String requestUrl,String request,String charsetName) {
String result = "";
HttpsURLConnection httpURLConnection = null;
ByteArrayOutputStream outputStream = null;
InputStream inputStream = null;
try {
URL url = new URL(requestUrl);
httpURLConnection = (HttpsURLConnection) url.openConnection();
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
httpURLConnection.setRequestProperty("Content-Type","text/plain");
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setInstanceFollowRedirects(true);
httpURLConnection.setConnectTimeout(60 * 1000);
httpURLConnection.connect();
httpURLConnection.getOutputStream().write(request.getBytes(charsetName));
httpURLConnection.getOutputStream().flush();
outputStream = new ByteArrayOutputStream();
inputStream = httpURLConnection.getInputStream();
int len = 0;
byte[] byteArray = new byte[1024 * 8];
while ((len = inputStream.read(byteArray)) != -1) {
outputStream.write(byteArray, 0, len);
}
outputStream.flush();
byte[] data = outputStream.toByteArray();
result = new String(data, charsetName);
} catch (MalformedURLException e) {
System.out.println("MalformedURLException 请求报文" + request+e);
} catch (ProtocolException e) {
System.out.println("ProtocolException 请求报文" + request+ e);
} catch (IOException e) {
System.out.println("IOException 请求报文" + request+e);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
System.out.println("error happened close inputStream 请求报文"+ request+ e);
}
}
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
System.out.println("error happened close outputStream 请求报文"+ request+ e);
}
}
httpURLConnection.disconnect();
}
System.out.println("响应报文" + result);
return result;
}
}