Accepts a signed feed document containing one or more signed entries and attachments for some or all of those entries.
(RequestContext request)
| 641 | * attachments for some or all of those entries. |
| 642 | */ |
| 643 | public ResponseContext postMedia(RequestContext request) { |
| 644 | try { |
| 645 | if (MimeTypeHelper.isMultipart(request.getContentType().toString())) { |
| 646 | byte[] requestData = Common.readFully(request.getInputStream()); |
| 647 | List<MultipartRelatedPost> posts = getMultipartRelatedData( |
| 648 | request, new ByteArrayInputStream(requestData)); |
| 649 | Feed incomingFeed = null; |
| 650 | if (posts != null) { |
| 651 | Map<String, Entry> contentIdToEntry = new HashMap<String, Entry>(); |
| 652 | Map<String, String> contentIdToType = new HashMap<String, String>(); |
| 653 | Map<String, InputStream> contentIdToData = new HashMap<String, InputStream>(); |
| 654 | for (MultipartRelatedPost post : posts) { |
| 655 | String type = post.getDataHeaders().get("content-type"); |
| 656 | String cid = post.getDataHeaders().get("content-id"); |
| 657 | if (cid != null) { |
| 658 | if (cid.startsWith("<cid:")) { |
| 659 | cid = cid.substring(5); |
| 660 | cid = cid.substring(0, cid.length() - 1); |
| 661 | } |
| 662 | // find content id in entry list |
| 663 | List<Entry> entries; |
| 664 | if (post.getSource().getRoot() instanceof Feed) { |
| 665 | incomingFeed = ((Feed) post.getSource() |
| 666 | .getRoot()); |
| 667 | entries = incomingFeed.getEntries(); |
| 668 | } else if (post.getSource().getRoot() instanceof Entry) { |
| 669 | log.warn("Single entries not supported: " |
| 670 | + post.getSource().getRoot()); |
| 671 | entries = new LinkedList<Entry>(); |
| 672 | entries.add((Entry) post.getSource().getRoot()); |
| 673 | return ProviderHelper |
| 674 | .badrequest(request, |
| 675 | "Single entries not currently supported."); |
| 676 | } else { |
| 677 | log.error("Unrecognized source: " |
| 678 | + post.getSource()); |
| 679 | return ProviderHelper.badrequest(request, |
| 680 | "Unrecognized source."); |
| 681 | } |
| 682 | for (Entry entry : entries) { |
| 683 | if (entry.getContentSrc() != null |
| 684 | && entry.getContentSrc().toString() |
| 685 | .endsWith(cid)) { |
| 686 | // getContentSrc resolves against baseurl |
| 687 | contentIdToEntry.put(cid, entry); |
| 688 | contentIdToType.put(cid, type); |
| 689 | contentIdToData.put(cid, post.getData()); |
| 690 | } |
| 691 | } |
| 692 | } |
| 693 | } |
| 694 | // if all content ids match an entry content element |
| 695 | if (contentIdToEntry.size() == posts.size()) { |
| 696 | ingestFeed(persistence, incomingFeed); |
| 697 | for (Map.Entry<String, Entry> i : contentIdToEntry |
| 698 | .entrySet()) { |
| 699 | String cid = i.getKey(); |
| 700 | Entry entry = i.getValue(); |
nothing calls this directly
no test coverage detected