当前位置: 首页>>代码示例>>Java>>正文


Java MultipartFormDataInput类代码示例

本文整理汇总了Java中org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput的典型用法代码示例。如果您正苦于以下问题:Java MultipartFormDataInput类的具体用法?Java MultipartFormDataInput怎么用?Java MultipartFormDataInput使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MultipartFormDataInput类属于org.jboss.resteasy.plugins.providers.multipart包,在下文中一共展示了MultipartFormDataInput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBinaryArtifact

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入依赖的package包/类
@Nonnull
private InputStream getBinaryArtifact(MultipartFormDataInput input) {
    if (input == null || input.getParts() == null || input.getParts().isEmpty()) {
        throw new IllegalArgumentException("Multipart request is empty");
    }

    try {
        InputStream result;
        if (input.getParts().size() == 1) {
            InputPart filePart = input.getParts().iterator().next();
            result = filePart.getBody(InputStream.class, null);
        } else {
            result = input.getFormDataPart("file", InputStream.class, null);
        }

        if (result == null) {
            throw new IllegalArgumentException("Can't find a valid 'file' part in the multipart request");
        }

        return result;
    } catch (IOException e) {
        throw new IllegalArgumentException("Error while reading multipart request", e);
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:25,代码来源:ExtensionHandler.java

示例2: testSecurityAnalysisCsv

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入依赖的package包/类
@Test
public void testSecurityAnalysisCsv() {
    MultipartFormDataInput dataInput = mock(MultipartFormDataInput.class);
    Map<String, List<InputPart>> formValues = new HashMap<>();
    formValues.put("format", Collections.singletonList(new InputPartImpl("CSV", MediaType.TEXT_PLAIN_TYPE)));
    formValues.put("limit-types", Collections.singletonList(new InputPartImpl("CURRENT", MediaType.TEXT_PLAIN_TYPE)));
    MultivaluedMap<String, String> headers = new MultivaluedMapImpl<>();
    headers.putSingle("Content-Disposition", "filename=" + "case-file.xiidm");

    formValues.put("case-file",
            Collections.singletonList(new InputPartImpl(
                    new ByteArrayInputStream("Network".getBytes()),
                    MediaType.APPLICATION_OCTET_STREAM_TYPE, headers)));

    MultivaluedMap<String, String> headers2 = new MultivaluedMapImpl<>();
    headers2.putSingle("Content-Disposition", "filename=" + "contingencies-file.csv");
    formValues.put("contingencies-file",
            Collections.singletonList(new InputPartImpl(
                    new ByteArrayInputStream("contingencies".getBytes()),
                    MediaType.APPLICATION_OCTET_STREAM_TYPE, headers2)));

    when(dataInput.getFormDataMap()).thenReturn(formValues);
    Response res = service.analyze(dataInput);
    Assert.assertEquals(200, res.getStatus());
}
 
开发者ID:itesla,项目名称:ipst,代码行数:26,代码来源:SecurityWsTest.java

示例3: testWrongFormat

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入依赖的package包/类
@Test
public void testWrongFormat() {
    MultipartFormDataInput dataInput = mock(MultipartFormDataInput.class);
    Map<String, List<InputPart>> formValues = new HashMap<>();
    formValues.put("format", Collections.singletonList(new InputPartImpl("ERR", MediaType.TEXT_PLAIN_TYPE)));
    formValues.put("limit-types", Collections.singletonList(new InputPartImpl("CURRENT", MediaType.TEXT_PLAIN_TYPE)));
    MultivaluedMap<String, String> headers = new MultivaluedMapImpl<>();
    headers.putSingle("Content-Disposition", "filename=" + "case-file.xiidm.gz");

    formValues.put("case-file",
            Collections.singletonList(new InputPartImpl(
                    new ByteArrayInputStream("Network".getBytes()),
                    MediaType.APPLICATION_OCTET_STREAM_TYPE, headers)));

    MultivaluedMap<String, String> headers2 = new MultivaluedMapImpl<>();
    headers2.putSingle("Content-Disposition", "filename=" + "contingencies-file.csv");
    formValues.put("contingencies-file",
            Collections.singletonList(new InputPartImpl(
                    new ByteArrayInputStream("contingencies".getBytes()),
                    MediaType.APPLICATION_OCTET_STREAM_TYPE, headers2)));

    when(dataInput.getFormDataMap()).thenReturn(formValues);
    Response res = service.analyze(dataInput);
    Assert.assertEquals(400, res.getStatus());

}
 
开发者ID:itesla,项目名称:ipst,代码行数:27,代码来源:SecurityWsTest.java

示例4: testMissingFormat

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入依赖的package包/类
@Test
public void testMissingFormat() {
    MultipartFormDataInput dataInput = mock(MultipartFormDataInput.class);
    Map<String, List<InputPart>> formValues = new HashMap<>();
    formValues.put("limit-types", Collections.singletonList(new InputPartImpl("HIGH_VOLTAGE,CURRENT", MediaType.TEXT_PLAIN_TYPE)));
    MultivaluedMap<String, String> headers = new MultivaluedMapImpl<>();
    headers.putSingle("Content-Disposition", "filename=" + "case-file.xiidm.gz");

    formValues.put("case-file",
            Collections.singletonList(new InputPartImpl(
                    new ByteArrayInputStream("Network".getBytes()),
                    MediaType.APPLICATION_OCTET_STREAM_TYPE, headers)));

    MultivaluedMap<String, String> headers2 = new MultivaluedMapImpl<>();
    headers2.putSingle("Content-Disposition", "filename=" + "contingencies-file.csv");
    formValues.put("contingencies-file",
            Collections.singletonList(new InputPartImpl(
                    new ByteArrayInputStream("contingencies".getBytes()),
                    MediaType.APPLICATION_OCTET_STREAM_TYPE, headers2)));

    when(dataInput.getFormDataMap()).thenReturn(formValues);
    Response res = service.analyze(dataInput);
    Assert.assertEquals(400, res.getStatus());

}
 
开发者ID:itesla,项目名称:ipst,代码行数:26,代码来源:SecurityWsTest.java

示例5: testMissingCaseFile

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入依赖的package包/类
@Test
public void testMissingCaseFile() {
    MultipartFormDataInput dataInput = mock(MultipartFormDataInput.class);
    Map<String, List<InputPart>> formValues = new HashMap<>();
    formValues.put("format", Collections.singletonList(new InputPartImpl("JSON", MediaType.TEXT_PLAIN_TYPE)));
    formValues.put("limit-types", Collections.singletonList(new InputPartImpl("CURRENT", MediaType.TEXT_PLAIN_TYPE)));

    MultivaluedMap<String, String> headers2 = new MultivaluedMapImpl<>();
    headers2.putSingle("Content-Disposition", "filename=" + "contingencies-file.csv");
    formValues.put("contingencies-file",
            Collections.singletonList(new InputPartImpl(
                    new ByteArrayInputStream("contingencies".getBytes()),
                    MediaType.APPLICATION_OCTET_STREAM_TYPE, headers2)));

    when(dataInput.getFormDataMap()).thenReturn(formValues);
    Response res = service.analyze(dataInput);
    Assert.assertEquals(400, res.getStatus());

}
 
开发者ID:itesla,项目名称:ipst,代码行数:20,代码来源:SecurityWsTest.java

示例6: createClass

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入依赖的package包/类
@Override
public String createClass(@HeaderParam("sessionid") String sessionId, MultipartFormDataInput input)
        throws NotConnectedRestException, IOException {

    String userName = getUserName(sessionId);
    File classesDir = new File(getFileStorageSupport().getWorkflowsDir(userName), "classes");

    if (!classesDir.exists()) {
        logger.info("Creating dir " + classesDir.getAbsolutePath());
        classesDir.mkdirs();
    }

    String fileName = "";

    Map<String, List<InputPart>> uploadForm = input.getFormDataMap();
    String name = uploadForm.keySet().iterator().next();
    List<InputPart> inputParts = uploadForm.get(name);

    for (InputPart inputPart : inputParts) {

        try {
            //convert the uploaded file to inputstream
            InputStream inputStream = inputPart.getBody(InputStream.class, null);
            byte[] bytes = IOUtils.toByteArray(inputStream);

            //constructs upload file path
            fileName = classesDir.getAbsolutePath() + "/" + name;

            FileUtils.writeByteArrayToFile(new File(fileName), bytes);
        } catch (IOException e) {
            logger.warn("Could not read input part", e);
            throw e;
        }

    }

    return fileName;
}
 
开发者ID:ow2-proactive,项目名称:scheduling,代码行数:39,代码来源:StudioRest.java

示例7: executePost

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入依赖的package包/类
public InputStream executePost(String vdbName, int version, String procedureName, MultipartFormDataInput parameters,
        String charSet, boolean passthroughAuth, boolean usingReturn) throws SQLException {
    //the generated code sends a empty string rather than null.
    if (charSet != null && charSet.trim().isEmpty()) {
        charSet = null;
    }
    Connection conn = getConnection(vdbName, version, passthroughAuth);
    try {
        LinkedHashMap<String, Object> updatedParameters = convertParameters(conn, vdbName, procedureName, parameters);
        return executeProc(conn, procedureName, updatedParameters, charSet, usingReturn);
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
            }
        }
    }
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:20,代码来源:TeiidRSProvider.java

示例8: upload

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入依赖的package包/类
@ApiOperation(value = "upload a file")
@POST
@Path("/upload")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void upload(
    final MultipartFormDataInput input,
    @Suspended final AsyncResponse asyncResponse) throws IOException {

    final JsonObject json = new JsonObject();
    final Map<String, List<InputPart>> uploadForm = input.getFormDataMap();
    final List<InputPart> inputParts = uploadForm.get("uploadedFile");

    for (final InputPart inputPart : inputParts) {

        final MultivaluedMap<String, String> header = inputPart.getHeaders();
        final String fileName = getFileName(header);

        //fromJson the uploaded file to inputstream
        final InputStream inputStream = inputPart.getBody(InputStream.class, null);
        int c = 0;
        while (inputStream.read() != -1) {
            ++c;
        }

        json.add(fileName, new JsonPrimitive(c));
    }
    asyncResponse.resume(json);
}
 
开发者ID:trajano,项目名称:app-ms,代码行数:30,代码来源:HelloResource.java

示例9: storeFile

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入依赖的package包/类
private void storeFile(String location, MultipartFormDataInput dataInput) {
    // Store the artifact into the filestore
    try (InputStream file = getBinaryArtifact(dataInput)) {
        fileStore.write(location, file);
    } catch (IOException ex) {
        throw SyndesisServerException.launderThrowable("Unable to store the file into the filestore", ex);
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:9,代码来源:ExtensionHandler.java

示例10: setUp

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入依赖的package包/类
@Before
public void setUp() {
    SecurityAnalysisResult result = new SecurityAnalysisResult(
            new LimitViolationsResult(true, Collections.emptyList()), Collections.emptyList());
    service = Mockito.mock(SecurityAnalysisServiceImpl.class);
    when(service.analyze(any(Network.class), any(FilePart.class), any(LimitViolationFilter.class))).thenReturn(result);
    when(service.analyze(any(MultipartFormDataInput.class))).thenCallRealMethod();
}
 
开发者ID:itesla,项目名称:ipst,代码行数:9,代码来源:SecurityWsTest.java

示例11: testSecurityAnalysisJson

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入依赖的package包/类
@Test
public void testSecurityAnalysisJson() {
    MultipartFormDataInput dataInput = mock(MultipartFormDataInput.class);
    Map<String, List<InputPart>> formValues = new HashMap<>();
    formValues.put("format", Collections.singletonList(new InputPartImpl("JSON", MediaType.TEXT_PLAIN_TYPE)));
    formValues.put("limit-types", Collections.singletonList(new InputPartImpl("CURRENT", MediaType.TEXT_PLAIN_TYPE)));

    MultivaluedMap<String, String> headers = new MultivaluedMapImpl<>();
    headers.putSingle("Content-Disposition", "filename=" + "case-file.xiidm");

    formValues.put("case-file",
            Collections.singletonList(new InputPartImpl(
                    new ByteArrayInputStream("Network".getBytes()),
                    MediaType.APPLICATION_OCTET_STREAM_TYPE, headers)));

    MultivaluedMap<String, String> headers2 = new MultivaluedMapImpl<>();
    headers2.putSingle("Content-Disposition", "filename=" + "contingencies-file.csv");
    formValues.put("contingencies-file",
            Collections.singletonList(new InputPartImpl(
                    new ByteArrayInputStream("contingencies".getBytes()),
                    MediaType.APPLICATION_OCTET_STREAM_TYPE, headers2)));

    when(dataInput.getFormDataMap()).thenReturn(formValues);
    Response res = service.analyze(dataInput);
    Assert.assertEquals(200, res.getStatus());

}
 
开发者ID:itesla,项目名称:ipst,代码行数:28,代码来源:SecurityWsTest.java

示例12: testWrongLimits

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入依赖的package包/类
@Test
public void testWrongLimits() {
    MultipartFormDataInput dataInput = mock(MultipartFormDataInput.class);
    Map<String, List<InputPart>> formValues = new HashMap<>();
    formValues.put("format", Collections.singletonList(new InputPartImpl("JSON", MediaType.TEXT_PLAIN_TYPE)));
    formValues.put("limit-types", Collections.singletonList(new InputPartImpl("ERRR", MediaType.TEXT_PLAIN_TYPE)));

    MultivaluedMap<String, String> headers = new MultivaluedMapImpl<>();
    headers.putSingle("Content-Disposition", "filename=" + "case-file.xiidm.gz");

    formValues.put("case-file",
            Collections.singletonList(new InputPartImpl(
                    new ByteArrayInputStream("Network".getBytes()),
                    MediaType.APPLICATION_OCTET_STREAM_TYPE, headers)));

    MultivaluedMap<String, String> headers2 = new MultivaluedMapImpl<>();
    headers2.putSingle("Content-Disposition", "filename=" + "contingencies-file.csv");
    formValues.put("contingencies-file",
            Collections.singletonList(new InputPartImpl(
                    new ByteArrayInputStream("contingencies".getBytes()),
                    MediaType.APPLICATION_OCTET_STREAM_TYPE, headers2)));

    when(dataInput.getFormDataMap()).thenReturn(formValues);
    Response res = service.analyze(dataInput);
    Assert.assertEquals(400, res.getStatus());

}
 
开发者ID:itesla,项目名称:ipst,代码行数:28,代码来源:SecurityWsTest.java

示例13: uploadFile

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入依赖的package包/类
@POST
@Path(PATH_UPLOAD)
@Consumes(MULTIPART_FORM_DATA)
@RequiresJwt
public Response uploadFile(MultipartFormDataInput multipart) {
    try {
        byte[] data = multipart.getFormDataPart(PARAM_DATA, byte[].class, null);
        String bucketName = multipart.getFormDataPart(PARAM_BUCKET_NAME, String.class, null);
        String key = multipart.getFormDataPart(PARAM_KEY, String.class, null);
        String cannedACL = multipart.getFormDataPart(PARAM_CANNED_ACL, String.class, null);
        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentLength((long) data.length);
        this.storageService.uploadFile(S3Request.builder()
                .bucketName(bucketName)
                .key(key)
                .data(IOUtils.buffer(new ByteArrayInputStream(data)))
                .metadata(metadata)
                .cannedACL(CannedAccessControlList.valueOf(cannedACL))
                .build());
        return Response.ok("File uploaded successfully!!").build();
    } catch (Exception ex) {
        throw JaxRSException.builder()
                .message(ex.getMessage())
                .cause(ex)
                .status(STATUS_SERVER_ERROR)
                .logException(true)
                .build();
    }
}
 
开发者ID:AdeptJ,项目名称:adeptj-modules,代码行数:30,代码来源:UploadResource.java

示例14: upload

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入依赖的package包/类
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@SuppressWarnings("PMD.EmptyCatchBlock")
public Extension upload(MultipartFormDataInput dataInput, @QueryParam("updatedId") String updatedId) {

    String id = KeyGenerator.createKey();
    String fileLocation = "/extensions/" + id;

    try {
        storeFile(fileLocation, dataInput);

        Extension embeddedExtension = extractExtension(fileLocation);

        if (updatedId != null) {
            Extension replacedExtension = getDataManager().fetch(Extension.class, updatedId);
            if (!replacedExtension.getExtensionId().equals(embeddedExtension.getExtensionId())) {
                throw new IllegalArgumentException("The uploaded extensionId (" + embeddedExtension.getExtensionId() +
                    ") does not match the existing extensionId (" + replacedExtension.getExtensionId() + ")");
            }
        }

        Extension extension = new Extension.Builder()
            .createFrom(embeddedExtension)
            .id(id)
            .status(Extension.Status.Draft)
            .build();

        return getDataManager().create(extension);
    } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception ex) {
        try {
            delete(id);
        } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception dex) {
            // ignore
        }
        throw SyndesisServerException.launderThrowable(ex);
    }
}
 
开发者ID:syndesisio,项目名称:syndesis-rest,代码行数:39,代码来源:ExtensionHandler.java

示例15: validate

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入依赖的package包/类
@Override
public JobValidationData validate(PathSegment pathSegment, MultipartFormDataInput multipart) {
    File tmpFile = null;
    try {
        Map<String, List<InputPart>> formDataMap = multipart.getFormDataMap();
        String name = formDataMap.keySet().iterator().next();
        InputPart part1 = formDataMap.get(name).get(0);
        InputStream is = part1.getBody(new GenericType<InputStream>() {

        });

        tmpFile = File.createTempFile("valid-job", "d");
        IOUtils.copy(is, new FileOutputStream(tmpFile));

        Map<String, String> jobVariables = workflowVariablesTransformer.getWorkflowVariablesFromPathSegment(pathSegment);

        return jobValidator.validateJobDescriptor(tmpFile, jobVariables);
    } catch (IOException e) {
        JobValidationData validation = new JobValidationData();
        validation.setErrorMessage("Cannot read from the job validation request.");
        validation.setStackTrace(getStackTrace(e));
        return validation;
    } finally {
        if (tmpFile != null) {
            tmpFile.delete();
        }
    }
}
 
开发者ID:ow2-proactive,项目名称:scheduling,代码行数:29,代码来源:SchedulerStateRest.java


注:本文中的org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。