Search in sources :

Example 1 with FormData

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);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) FormData(feign.form.FormData) UploadException(org.jreleaser.model.uploader.spi.UploadException) IOException(java.io.IOException) Artifact(org.jreleaser.model.Artifact) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with FormData

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);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) FormData(feign.form.FormData) UploadException(org.jreleaser.model.uploader.spi.UploadException) IOException(java.io.IOException) Artifact(org.jreleaser.model.Artifact) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with FormData

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));
    }
}
Also used : CMISService(it.cnr.cool.cmis.service.CMISService) User(it.cnr.ict.domain.User) LoggerFactory(org.slf4j.LoggerFactory) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleDateFormat(java.text.SimpleDateFormat) OilService(it.cnr.ict.service.OilService) Value(org.springframework.beans.factory.annotation.Value) JSONObject(org.json.JSONObject) Calendar(java.util.Calendar) Service(org.springframework.stereotype.Service) State(it.cnr.ict.domain.State) UrlBuilder(org.apache.chemistry.opencmis.commons.impl.UrlBuilder) DateFormat(java.text.DateFormat) FeignException(feign.FeignException) CmisBindingsHelper(org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingsHelper) Response(org.apache.chemistry.opencmis.client.bindings.spi.http.Response) Logger(org.slf4j.Logger) IOException(java.io.IOException) StringUtil(it.cnr.cool.util.StringUtil) CMISUser(it.cnr.cool.security.service.impl.alfresco.CMISUser) HttpStatus(org.springframework.http.HttpStatus) Category(it.cnr.ict.domain.Category) HelpDeskNotConfiguredException(it.cnr.si.cool.jconon.exception.HelpDeskNotConfiguredException) FormData(feign.form.FormData) MultipartFile(org.springframework.web.multipart.MultipartFile) Optional(java.util.Optional) ExternalProblem(it.cnr.ict.domain.ExternalProblem) MailException(org.springframework.mail.MailException) UserService(it.cnr.cool.security.service.UserService) Collections(java.util.Collections) HelpdeskBean(it.cnr.si.cool.jconon.model.HelpdeskBean) I18nService(it.cnr.cool.service.I18nService) FormData(feign.form.FormData) ExternalProblem(it.cnr.ict.domain.ExternalProblem) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

FormData (feign.form.FormData)3 IOException (java.io.IOException)3 Path (java.nio.file.Path)2 LinkedHashMap (java.util.LinkedHashMap)2 Artifact (org.jreleaser.model.Artifact)2 UploadException (org.jreleaser.model.uploader.spi.UploadException)2 FeignException (feign.FeignException)1 CMISService (it.cnr.cool.cmis.service.CMISService)1 UserService (it.cnr.cool.security.service.UserService)1 CMISUser (it.cnr.cool.security.service.impl.alfresco.CMISUser)1 I18nService (it.cnr.cool.service.I18nService)1 StringUtil (it.cnr.cool.util.StringUtil)1 Category (it.cnr.ict.domain.Category)1 ExternalProblem (it.cnr.ict.domain.ExternalProblem)1 State (it.cnr.ict.domain.State)1 User (it.cnr.ict.domain.User)1 OilService (it.cnr.ict.service.OilService)1 HelpDeskNotConfiguredException (it.cnr.si.cool.jconon.exception.HelpDeskNotConfiguredException)1 HelpdeskBean (it.cnr.si.cool.jconon.model.HelpdeskBean)1 DateFormat (java.text.DateFormat)1