use of feign.form.FormData in project jreleaser by jreleaser.
the class HttpArtifactUploader method upload.
@Override
public void upload(String name) throws UploadException {
List<Artifact> artifacts = collectArtifacts();
if (artifacts.isEmpty()) {
context.getLogger().info(RB.$("artifacts.no.match"));
}
String username = uploader.getResolvedUsername();
String password = uploader.getResolvedPassword();
for (Artifact artifact : artifacts) {
Path path = artifact.getEffectivePath(context);
context.getLogger().info(" - {}", path.getFileName());
if (!context.isDryrun()) {
try {
FormData data = ClientUtils.toFormData(path);
Map<String, String> headers = new LinkedHashMap<>();
switch(uploader.resolveAuthorization()) {
case NONE:
break;
case BASIC:
String auth = username + ":" + password;
byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes());
auth = new String(encodedAuth);
headers.put("Authorization", "Basic " + auth);
break;
case BEARER:
headers.put("Authorization", "Bearer " + password);
break;
}
resolveHeaders(artifact, headers);
if (uploader.getMethod() == HttpUploader.Method.POST) {
ClientUtils.postFile(context.getLogger(), uploader.getResolvedUploadUrl(context, artifact), uploader.getConnectTimeout(), uploader.getReadTimeout(), data, headers);
} else {
ClientUtils.putFile(context.getLogger(), uploader.getResolvedUploadUrl(context, artifact), uploader.getConnectTimeout(), uploader.getReadTimeout(), data, headers);
}
} catch (IOException e) {
context.getLogger().trace(e);
throw new UploadException(RB.$("ERROR_unexpected_upload", context.getBasedir().relativize(path)), e);
}
}
}
}
use of feign.form.FormData in project jreleaser by jreleaser.
the class ArtifactoryArtifactUploader method upload.
@Override
public void upload(String name) throws UploadException {
List<Artifact> artifacts = collectArtifacts();
if (artifacts.isEmpty()) {
context.getLogger().info(RB.$("artifacts.no.match"));
}
String username = uploader.getResolvedUsername();
String password = uploader.getResolvedPassword();
for (Artifact artifact : artifacts) {
Path path = artifact.getEffectivePath(context);
context.getLogger().info(" - {}", path.getFileName());
if (!context.isDryrun()) {
try {
FormData data = ClientUtils.toFormData(path);
Map<String, String> headers = new LinkedHashMap<>();
switch(uploader.resolveAuthorization()) {
case BASIC:
String auth = username + ":" + password;
byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes());
auth = new String(encodedAuth);
headers.put("Authorization", "Basic " + auth);
break;
case BEARER:
headers.put("Authorization", "Bearer " + password);
break;
}
headers.put("X-Checksum-Deploy", "false");
headers.put("X-Checksum-Sha1", ChecksumUtils.checksum(Algorithm.SHA_1, data.getData()));
headers.put("X-Checksum-Sha256", ChecksumUtils.checksum(Algorithm.SHA_256, data.getData()));
headers.put("X-Checksum", ChecksumUtils.checksum(Algorithm.MD5, data.getData()));
ClientUtils.putFile(context.getLogger(), uploader.getResolvedUploadUrl(context, artifact), uploader.getConnectTimeout(), uploader.getReadTimeout(), data, headers);
} catch (IOException e) {
context.getLogger().trace(e);
throw new UploadException(RB.$("ERROR_unexpected_upload", context.getBasedir().relativize(path)), e);
}
}
}
}
use of feign.form.FormData in project cool-jconon by consiglionazionaledellericerche.
the class HelpdeskService method sendMessage.
protected void sendMessage(HelpdeskBean hdBean, MultipartFile allegato, CMISUser user) throws MailException, IOException {
StringBuilder subject = new StringBuilder();
subject.append(hdBean.getCall() + " - " + hdBean.getSubject());
// aggiunge il footer al messaggio
StringBuilder testo = new StringBuilder();
testo.append(hdBean.getMessage());
testo.append("\n\n");
testo.append("Utente: ");
testo.append(hdBean.getFirstName());
testo.append(" ");
testo.append(hdBean.getLastName());
if (Optional.ofNullable(hdBean.getMatricola()).isPresent()) {
testo.append(" Matricola: ");
testo.append(hdBean.getMatricola());
}
testo.append(" Email: ");
testo.append(hdBean.getEmail());
if (Optional.ofNullable(hdBean.getPhoneNumber()).isPresent()) {
testo.append(" Tel: ");
testo.append(hdBean.getPhoneNumber());
}
testo.append(" Data: ");
DateFormat formatter = new SimpleDateFormat("dd.MM.yyyy (HH:mm:ss)");
testo.append(formatter.format(Calendar.getInstance().getTime()));
testo.append(" IP: ");
testo.append(hdBean.getIp());
ExternalProblem externalProblem = new ExternalProblem();
externalProblem.setFirstName(hdBean.getFirstName());
externalProblem.setFamilyName(hdBean.getLastName());
externalProblem.setEmail(hdBean.getEmail());
externalProblem.setConfirmRequested(Optional.ofNullable(user).filter(cmisUser -> cmisUser.isGuest()).map(s -> "y").orElse("n"));
externalProblem.setTitolo(subject.toString());
externalProblem.setDescrizione(testo.toString());
externalProblem.setStato(State.APERTA);
externalProblem.setCategoria(Integer.valueOf(hdBean.getCategory()));
final Optional<Long> idSegnalazione = oilService.map(oil -> oil.newProblem(externalProblem));
if (allegato != null && !allegato.isEmpty() && idSegnalazione.isPresent()) {
FormData formData = new FormData(allegato.getContentType(), allegato.getOriginalFilename(), allegato.getBytes());
oilService.ifPresent(oil -> oil.addAttachments(idSegnalazione.get(), formData));
}
}
Aggregations