Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- **String encoding = Base64.getEncoder().encodeToString(("admin:admin").getBytes());
- String hawkbitURL = "http://10.x.x.x:8080"; //Replaced with proper IP in my machine
- String moduleId=53; //hardcoded for now but I can get this via Java REST API code
- String uploadArtifactURL = "/rest/v1/softwaremodules/"+moduleId+"/artifacts";
- String boundaryString = "-----------------------------6o2knFse3p53ty9dmcQvWAIx1zInP11uCfbm";
- String message = "This is a multipart post";
- File artifactFile = new File(artifactPath);
- // build multipart upload request
- HttpEntity data = MultipartEntityBuilder.create()
- .setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
- .addBinaryBody("upfile", artifactFile, ContentType.DEFAULT_BINARY, artifactFile.getName())
- .addTextBody("text",message,ContentType.DEFAULT_BINARY)
- .setBoundary(boundaryString)
- .build();
- // build http request and assign multipart upload data
- HttpUriRequest request = RequestBuilder
- .post(hawkbitURL+uploadArtifactURL)
- .setHeader("Authorization", "Basic " + encoding)
- .setEntity(data)
- .build();
- System.out.println("Executing request " + request.getRequestLine());
- // Create a custom response handler
- ResponseHandler<String> responseHandler = response -> {
- System.out.println(response.getStatusLine());
- int status = response.getStatusLine().getStatusCode();
- if (status >= 200 && status < 300) {
- HttpEntity entity = response.getEntity();
- return entity != null ? EntityUtils.toString(entity) : null;
- } else {
- throw new ClientProtocolException("Unexpected response status: " + status);
- }
- };
- String responseBody = httpClient.execute(request, responseHandler);
- System.out.println("----------------------------------------");
- System.out.println(responseBody);**
Add Comment
Please, Sign In to add comment