class MultiPartFileProcessor {

    public String processUploadedFile(final InputStream resource, final String contentType, final String fieldName, final String fileName) {
        String result;
        String resFileName = extractFileNameFromAbsolutePath(fileName);

        String classUploadResult = processUploadedClasses(resource, contentType, fieldName, resFileName);
        if (classUploadResult != null) {
            result = classUploadResult;
        } else {
            if ("stub-configuration".equals(fieldName) && JSON_CONTENT_TYPE.equals(contentType)) {
                try {
                    routingService.performModification(new NewStubDescriptorCommand(resource, stubConfigurationJsonBuilder, sequenceDescriptorHolder));
                    serviceMap.detectServices();
                } catch (ClassNotFoundException e) {
                    result = "Uploading " + fileName + " failed with ClassNotFoundException.";
                    throw new CannotUploadExternalResourceException(result, e);
                }
                result = "New stub configuration was uploaded to Wilma.";
            } else if ("stub-template".equals(fieldName)) {
                writeResourceToFile(resource, resFileName, stubResourcePathProvider.getTemplatesPathAsString());
                result = "External template '" + resFileName + "' was uploaded to Wilma.";
            } else {
                result = "Uploading " + fileName + " failed: wrong content type or tried to upload file from unauthorized form!";
                throw new CannotUploadExternalResourceException(result);
            }
        }
        return result;
    }

}