Commit b52d9e76 authored by ckx's avatar ckx

项目上传

parent 0cb4a8b5
package com.yundong.third.ht.api.database;
import com.yundong.base.context.Context;
import com.yundong.base.result.Result;
/**
* @author sy
*/
public interface ProjectUpload {
Result<StringBuilder> upload(Context context, String appId, String version, String data) throws IllegalAccessException;
}
package com.yundong.third.ht.api.database.impl;
import com.yundong.base.context.Context;
import com.yundong.base.result.Result;
import com.yundong.gateway.register.annotation.YdcGateway;
import com.yundong.third.ht.api.database.ProjectUpload;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
/**
* @author 沈
* @date 2024年03月01日 9:24
*/
@Slf4j
@org.springframework.stereotype.Service
@Service(version = "${dubbo.provider.version}", group = "${dubbo.provider.group}")
public class ProjectUploadImpl implements ProjectUpload {
@Override
@YdcGateway(name = "project-upload", url = "biz/third/ht/database/projectUploadImpl.json")
public Result<StringBuilder> upload(Context context, String appId, String version, String data) throws IllegalAccessException {
String url1 = "http://10.136.208.159/esbmule/services/receive/DAM_FROM_PM_XM";
try {
// 创建URL对象
URL url = new URL(url1);
// 打开连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// 设置请求方法为POST
connection.setRequestMethod("POST");
// 设置请求头
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("usercode", "jyz");
connection.setRequestProperty("password", "jyz851155");
// 启用输出,并设置请求体
connection.setDoOutput(true);
String requestBody = data;
try (OutputStream os = connection.getOutputStream()) {
byte[] input = requestBody.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
// 发起请求并获取响应
int responseCode = connection.getResponseCode();
System.out.println("Response Code: " + responseCode);
// 读取响应信息
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// 打印响应内容
System.out.println("Response Body: " + response.toString());
// 关闭连接
connection.disconnect();
return Result.success(response);
} catch (Exception e) {
e.printStackTrace();
}
return Result.fail("同步失败");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment