Search in sources :

Example 1 with Attachment

use of com.consol.citrus.samples.todolist.model.Attachment in project citrus-samples by christophd.

the class TodoWebServiceEndpoint method addTodoEntry.

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "addTodoEntryRequest")
@ResponsePayload
public AddTodoEntryResponse addTodoEntry(@RequestPayload AddTodoEntryRequest request, MessageContext messageContext) {
    TodoEntry entry = new TodoEntry(request.getTitle(), request.getDescription());
    Iterator<org.springframework.ws.mime.Attachment> it = ((SoapMessage) messageContext.getRequest()).getAttachments();
    if (it.hasNext()) {
        org.springframework.ws.mime.Attachment attachment = it.next();
        Attachment todoAttachment = new Attachment();
        String contentId = attachment.getContentId();
        if (contentId.startsWith("<") && contentId.endsWith(">")) {
            contentId = contentId.substring(1, contentId.length() - 1);
        }
        todoAttachment.setCid(contentId);
        todoAttachment.setContentType(attachment.getContentType());
        try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            FileCopyUtils.copy(attachment.getInputStream(), out);
            todoAttachment.setData(Base64.getEncoder().encodeToString(out.toByteArray()));
        } catch (IOException e) {
            throw new RuntimeException("Failed to read attachment", e);
        }
        entry.setAttachment(todoAttachment);
    }
    todoListService.addEntry(entry);
    AddTodoEntryResponse response = new AddTodoEntryResponse();
    response.setSuccess(true);
    return response;
}
Also used : Attachment(com.consol.citrus.samples.todolist.model.Attachment) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SoapMessage(org.springframework.ws.soap.SoapMessage) TodoEntry(com.consol.citrus.samples.todolist.model.TodoEntry)

Example 2 with Attachment

use of com.consol.citrus.samples.todolist.model.Attachment in project citrus-samples by christophd.

the class TodoWebServiceEndpoint method getTodoList.

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getTodoListRequest")
@ResponsePayload
public GetTodoListResponse getTodoList(@RequestPayload GetTodoListRequest request) {
    List<TodoEntry> todoEntryList = todoListService.getAllEntries();
    GetTodoListResponse response = new GetTodoListResponse();
    response.setList(new GetTodoListResponse.List());
    for (TodoEntry todoEntry : todoEntryList) {
        GetTodoListResponse.List.TodoEntry entry = new GetTodoListResponse.List.TodoEntry();
        entry.setId(todoEntry.getId().toString());
        entry.setTitle(todoEntry.getTitle());
        entry.setDescription(todoEntry.getDescription());
        if (todoEntry.getAttachment() != null) {
            GetTodoListResponse.List.TodoEntry.Attachment attachment = new GetTodoListResponse.List.TodoEntry.Attachment();
            attachment.setCid(todoEntry.getAttachment().getCid());
            attachment.setContentType(todoEntry.getAttachment().getContentType());
            attachment.setData(todoEntry.getAttachment().getData());
            entry.setAttachment(attachment);
        }
        response.getList().getTodoEntry().add(entry);
    }
    return response;
}
Also used : Attachment(com.consol.citrus.samples.todolist.model.Attachment) TodoEntry(com.consol.citrus.samples.todolist.model.TodoEntry)

Aggregations

Attachment (com.consol.citrus.samples.todolist.model.Attachment)2 TodoEntry (com.consol.citrus.samples.todolist.model.TodoEntry)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 SoapMessage (org.springframework.ws.soap.SoapMessage)1