org.apache.cxf.jaxrs.ext.multipart.Attachment.getContentDisposition()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中org.apache.cxf.jaxrs.ext.multipart.Attachment.getContentDisposition()方法的一些代码示例,展示了Attachment.getContentDisposition()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Attachment.getContentDisposition()方法的具体详情如下:
包路径:org.apache.cxf.jaxrs.ext.multipart.Attachment
类名称:Attachment
方法名:getContentDisposition

Attachment.getContentDisposition介绍

暂无

代码示例

代码示例来源:origin: apache/cxf

public static boolean matchAttachmentId(Attachment at, String value) {
  if (value.isEmpty()) {
    return true;
  }
  if (at.getContentId().equals(value)) {
    return true;
  }
  ContentDisposition cd = at.getContentDisposition();
  return cd != null && value.equals(cd.getParameter("name"));
}

代码示例来源:origin: apache/cxf

public Attachment getAttachment(String contentId) {
  for (Attachment a : atts) {
    if (contentId.equalsIgnoreCase(a.getContentId())) {
      return a;
    }
    ContentDisposition cd = a.getContentDisposition();
    if (cd != null && contentId.equals(cd.getParameter("name"))) {
      return a;
    }
  }
  return null;
}

代码示例来源:origin: org.apache.cxf/cxf-bundle-jaxrs

public static boolean matchAttachmentId(Attachment at, String value) {
  if (value.isEmpty()) {
    return true;
  }
  if (at.getContentId().equals(value)) {
    return true;
  }
  ContentDisposition cd = at.getContentDisposition();
  if (cd != null && value.equals(cd.getParameter("name"))) {
    return true;
  }
  return false;
}

代码示例来源:origin: org.apache.cxf/cxf-bundle-jaxrs

public Attachment getAttachment(String contentId) {
  for (Attachment a : atts) {
    if (contentId.equalsIgnoreCase(a.getContentId())) {
      return a;
    }
    ContentDisposition cd = a.getContentDisposition();
    if (cd != null && contentId.equals(cd.getParameter("name"))) {
      return a;
    }
  }
  return null;
}

代码示例来源:origin: apache/cxf

private static Map<String, Attachment> fromListToMap(List<Attachment> atts,
                           boolean preferContentDisposition) {
  Map<String, Attachment> map = new LinkedHashMap<>();
  for (Attachment a : atts) {
    String contentId = null;
    if (preferContentDisposition) {
      ContentDisposition cd = a.getContentDisposition();
      if (cd != null) {
        contentId = cd.getParameter("name");
      }
    }
    if (contentId == null) {
      contentId = a.getContentId();
    }
    map.put(contentId, a);
  }
  return map;
}

代码示例来源:origin: org.apache.cxf/cxf-bundle-jaxrs

private static Map<String, Attachment> fromListToMap(List<Attachment> atts,
                           boolean preferContentDisposition) {
  Map<String, Attachment> map = new LinkedHashMap<String, Attachment>();
  for (Attachment a : atts) {
    String contentId = null;
    if (preferContentDisposition) {
      ContentDisposition cd = a.getContentDisposition();
      if (cd != null) {
        contentId = cd.getParameter("name");
      }
    } 
    if (contentId == null) {
      contentId = a.getContentId();
    }
    map.put(contentId, a);    
  }
  return map;
}

代码示例来源:origin: apache/cxf

@Path("/books/file/semicolon")
@Consumes("multipart/form-data")
@Produces("text/plain")
@POST
public String addBookFileNameSemicolon(@Multipart("a") Attachment att) {
  return att.getObject(String.class)
    + ", filename:" + att.getContentDisposition().getParameter("filename");
}

代码示例来源:origin: apache/archiva

String fileName = file.getContentDisposition().getParameter( "filename" );

代码示例来源:origin: org.apache.archiva/archiva-web-common

String fileName = file.getContentDisposition().getParameter( "filename" );

代码示例来源:origin: Talend/tesb-rt-se

ub.path("logo").path(appName.toLowerCase());
ContentDisposition cd = att.getContentDisposition();
if (cd != null && cd.getParameter("filename") != null) {
  ub.path(cd.getParameter("filename"));

代码示例来源:origin: apache/cxf

checkNumberOfParts(m, atts.size());
for (Attachment a : atts) {
  ContentDisposition cd = a.getContentDisposition();
  if (cd != null && !MULTIPART_FORM_DATA_TYPE.equalsIgnoreCase(cd.getType())) {
    continue;

代码示例来源:origin: Talend/tesb-rt-se

ub.path("logo").path(appName.toLowerCase());
ContentDisposition cd = att.getContentDisposition();
if (cd != null && cd.getParameter("filename") != null) {
  ub.path(cd.getParameter("filename"));

代码示例来源:origin: org.apache.cxf/cxf-bundle-jaxrs

checkNumberOfParts(m, atts.size());
for (Attachment a : atts) {
  ContentDisposition cd = a.getContentDisposition();
  if (cd != null && !MULTIPART_FORM_DATA_TYPE.equalsIgnoreCase(cd.getType())) {
    continue;

代码示例来源:origin: apache/cxf

@Test
public void testUploadImageFromForm2() throws Exception {
  File file =
    new File(getClass().getResource("/org/apache/cxf/systest/jaxrs/resources/java.jpg")
              .toURI().getPath());
  String address = "http://localhost:" + PORT + "/bookstore/books/formimage2";
  WebClient client = WebClient.create(address);
  client.type("multipart/form-data").accept("multipart/form-data");
  WebClient.getConfig(client).getRequestContext().put("support.type.as.multipart",
                            "true");
  MultipartBody body2 = client.post(file, MultipartBody.class);
  InputStream is2 = body2.getRootAttachment().getDataHandler().getInputStream();
  byte[] image1 = IOUtils.readBytesFromStream(
    getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"));
  byte[] image2 = IOUtils.readBytesFromStream(is2);
  assertTrue(Arrays.equals(image1, image2));
  ContentDisposition cd2 = body2.getRootAttachment().getContentDisposition();
  assertEquals("form-data;name=file;filename=java.jpg", cd2.toString());
  assertEquals("java.jpg", cd2.getParameter("filename"));
}

代码示例来源:origin: apache/cxf

@Test
public void testUploadImageFromForm() throws Exception {
  InputStream is1 =
    getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg");
  String address = "http://localhost:" + PORT + "/bookstore/books/formimage";
  WebClient client = WebClient.create(address);
  HTTPConduit conduit = WebClient.getConfig(client).getHttpConduit();
  conduit.getClient().setReceiveTimeout(1000000);
  conduit.getClient().setConnectionTimeout(1000000);
  client.type("multipart/form-data").accept("multipart/form-data");
  ContentDisposition cd = new ContentDisposition("attachment;filename=java.jpg");
  MultivaluedMap<String, String> headers = new MetadataMap<>();
  headers.putSingle("Content-ID", "image");
  headers.putSingle("Content-Disposition", cd.toString());
  headers.putSingle("Content-Location", "http://host/bar");
  headers.putSingle("custom-header", "custom");
  Attachment att = new Attachment(is1, headers);
  MultipartBody body = new MultipartBody(att);
  MultipartBody body2 = client.post(body, MultipartBody.class);
  InputStream is2 = body2.getRootAttachment().getDataHandler().getInputStream();
  byte[] image1 = IOUtils.readBytesFromStream(
    getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"));
  byte[] image2 = IOUtils.readBytesFromStream(is2);
  assertTrue(Arrays.equals(image1, image2));
  ContentDisposition cd2 = body2.getRootAttachment().getContentDisposition();
  assertEquals("attachment;filename=java.jpg", cd2.toString());
  assertEquals("java.jpg", cd2.getParameter("filename"));
  assertEquals("http://host/location", body2.getRootAttachment().getHeader("Content-Location"));
}

相关文章