@Test public void testCreateResourceWithMissingAttachment() throws IOException { final List<Attachment> attachmentList = new ArrayList<>(); CreateResourceParam createResourceParam = new CreateResourceParam(); createResourceParam.setJvm("sampleJvm"); final Response response = cut.createResource("httpd.conf", createResourceParam, attachmentList); assertEquals("AEM78", ((ApplicationResponse) response.getEntity()).getMsgCode()); }
@Override public Response createResource(final String deployFilename, final CreateResourceParam createResourceParam, final List<Attachment> attachments) { final CreateResourceResponseWrapper createResourceResponseWrapper; final boolean isExternalProperty = createResourceParam.getGroup() == null && createResourceParam.getJvm() == null && createResourceParam.getWebApp() == null && createResourceParam.getWebServer() == null; if (attachments == null || !isExternalProperty && attachments.size() == 0 ) { LOGGER.error("Expected non-empty attachments. Returning without creating Resource."); return ResponseBuilder.notOk(Response.Status.INTERNAL_SERVER_ERROR, new FaultCodeException(FaultType.RESOURCE_NO_ATTACHMENT_EXCEPTION, "There is no attachment when try to create resource.")); } else { LOGGER.debug("attachments.size() " + attachments.size()); for (final Attachment attachment : attachments) { LOGGER.debug("attachment.getDataHandler().getName(): " + attachment.getDataHandler().getName() + " attachment.getHeader(\"Content-Type\"): " + attachment.getHeader("Content-Type")); } } try { final Map<String, Object> metaDataMap = new HashMap<>(); BufferedInputStream bufferedInputStream = null; String templateName = null; for (final Attachment attachment : attachments) { if (attachment.getDataHandler().getName() == null ){ LOGGER.debug("attachment.getDataHandler().getName() is null"); continue; } if (attachment.getHeader("Content-Type") == null) { metaDataMap.put(attachment.getDataHandler().getName(), IOUtils.toString(attachment.getDataHandler().getInputStream(), Charset.defaultCharset())); } else { templateName = attachment.getDataHandler().getName(); bufferedInputStream = new BufferedInputStream(attachment.getDataHandler().getInputStream()); } } metaDataMap.put("deployFileName", deployFilename); metaDataMap.put("templateName", templateName); metaDataMap.put("contentType", resourceService.getResourceMimeType(bufferedInputStream)); final Entity entity = new Entity(null, null, null, null, Boolean.parseBoolean((String) metaDataMap.get("assignToJvms"))); metaDataMap.remove("assignToJvms"); metaDataMap.put("entity", entity); final ResourceTemplateMetaData resourceTemplateMetaData = resourceService.getMetaData(new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(metaDataMap)); final ResourceIdentifier resourceIdentifier = new ResourceIdentifier.Builder().setResourceName(templateName) .setGroupName(createResourceParam.getGroup()) .setWebServerName(createResourceParam.getWebServer()) .setJvmName(createResourceParam.getJvm()) .setWebAppName(createResourceParam.getWebApp()).build(); createResourceResponseWrapper = resourceService.createResource(resourceIdentifier, resourceTemplateMetaData, bufferedInputStream); } catch (final IOException e) { LOGGER.error("Failed to create resource {}!", deployFilename, e); return ResponseBuilder.notOk(Response.Status.INTERNAL_SERVER_ERROR, new FaultCodeException(FaultType.IO_EXCEPTION, e.getMessage())); } return ResponseBuilder.ok(createResourceResponseWrapper); }
ResourceServiceRestImpl implements ResourceServiceRest { @Override public Response createResource(final String deployFilename, final CreateResourceParam createResourceParam, final List<Attachment> attachments) { final CreateResourceResponseWrapper createResourceResponseWrapper; final boolean isExternalProperty = createResourceParam.getGroup() == null && createResourceParam.getJvm() == null && createResourceParam.getWebApp() == null && createResourceParam.getWebServer() == null; if (attachments == null || !isExternalProperty && attachments.size() == 0 ) { LOGGER.error("Expected non-empty attachments. Returning without creating Resource."); return ResponseBuilder.notOk(Response.Status.INTERNAL_SERVER_ERROR, new FaultCodeException(FaultType.RESOURCE_NO_ATTACHMENT_EXCEPTION, "There is no attachment when try to create resource.")); } else { LOGGER.debug("attachments.size() " + attachments.size()); for (final Attachment attachment : attachments) { LOGGER.debug("attachment.getDataHandler().getName(): " + attachment.getDataHandler().getName() + " attachment.getHeader(\"Content-Type\"): " + attachment.getHeader("Content-Type")); } } try { final Map<String, Object> metaDataMap = new HashMap<>(); BufferedInputStream bufferedInputStream = null; String templateName = null; for (final Attachment attachment : attachments) { if (attachment.getDataHandler().getName() == null ){ LOGGER.debug("attachment.getDataHandler().getName() is null"); continue; } if (attachment.getHeader("Content-Type") == null) { metaDataMap.put(attachment.getDataHandler().getName(), IOUtils.toString(attachment.getDataHandler().getInputStream(), Charset.defaultCharset())); } else { templateName = attachment.getDataHandler().getName(); bufferedInputStream = new BufferedInputStream(attachment.getDataHandler().getInputStream()); } } metaDataMap.put("deployFileName", deployFilename); metaDataMap.put("templateName", templateName); metaDataMap.put("contentType", resourceService.getResourceMimeType(bufferedInputStream)); final Entity entity = new Entity(null, null, null, null, Boolean.parseBoolean((String) metaDataMap.get("assignToJvms"))); metaDataMap.remove("assignToJvms"); metaDataMap.put("entity", entity); final ResourceTemplateMetaData resourceTemplateMetaData = resourceService.getMetaData(new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(metaDataMap)); final ResourceIdentifier resourceIdentifier = new ResourceIdentifier.Builder().setResourceName(templateName) .setGroupName(createResourceParam.getGroup()) .setWebServerName(createResourceParam.getWebServer()) .setJvmName(createResourceParam.getJvm()) .setWebAppName(createResourceParam.getWebApp()).build(); createResourceResponseWrapper = resourceService.createResource(resourceIdentifier, resourceTemplateMetaData, bufferedInputStream); } catch (final IOException e) { LOGGER.error("Failed to create resource {}!", deployFilename, e); return ResponseBuilder.notOk(Response.Status.INTERNAL_SERVER_ERROR, new FaultCodeException(FaultType.IO_EXCEPTION, e.getMessage())); } return ResponseBuilder.ok(createResourceResponseWrapper); } }
ResourceServiceRestImpl implements ResourceServiceRest { @Override public Response createResource(final String deployFilename, final CreateResourceParam createResourceParam, final List<Attachment> attachments) { final CreateResourceResponseWrapper createResourceResponseWrapper; final boolean isExternalProperty = createResourceParam.getGroup() == null && createResourceParam.getJvm() == null && createResourceParam.getWebApp() == null && createResourceParam.getWebServer() == null; if (attachments == null || !isExternalProperty && attachments.size() == 0 ) { LOGGER.error("Expected non-empty attachments. Returning without creating Resource."); return ResponseBuilder.notOk(Response.Status.INTERNAL_SERVER_ERROR, new FaultCodeException(FaultType.RESOURCE_NO_ATTACHMENT_EXCEPTION, "There is no attachment when try to create resource.")); } else { LOGGER.debug("attachments.size() " + attachments.size()); for (final Attachment attachment : attachments) { LOGGER.debug("attachment.getDataHandler().getName(): " + attachment.getDataHandler().getName() + " attachment.getHeader(\"Content-Type\"): " + attachment.getHeader("Content-Type")); } } try { final Map<String, Object> metaDataMap = new HashMap<>(); BufferedInputStream bufferedInputStream = null; String templateName = null; for (final Attachment attachment : attachments) { if (attachment.getDataHandler().getName() == null ){ LOGGER.debug("attachment.getDataHandler().getName() is null"); continue; } if (attachment.getHeader("Content-Type") == null) { metaDataMap.put(attachment.getDataHandler().getName(), IOUtils.toString(attachment.getDataHandler().getInputStream(), Charset.defaultCharset())); } else { templateName = attachment.getDataHandler().getName(); bufferedInputStream = new BufferedInputStream(attachment.getDataHandler().getInputStream()); } } metaDataMap.put("deployFileName", deployFilename); metaDataMap.put("templateName", templateName); metaDataMap.put("contentType", resourceService.getResourceMimeType(bufferedInputStream)); final Entity entity = new Entity(null, null, null, null, Boolean.parseBoolean((String) metaDataMap.get("assignToJvms"))); metaDataMap.remove("assignToJvms"); metaDataMap.put("entity", entity); final ResourceTemplateMetaData resourceTemplateMetaData = resourceService.getMetaData(new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(metaDataMap)); final ResourceIdentifier resourceIdentifier = new ResourceIdentifier.Builder().setResourceName(templateName) .setGroupName(createResourceParam.getGroup()) .setWebServerName(createResourceParam.getWebServer()) .setJvmName(createResourceParam.getJvm()) .setWebAppName(createResourceParam.getWebApp()).build(); createResourceResponseWrapper = resourceService.createResource(resourceIdentifier, resourceTemplateMetaData, bufferedInputStream); } catch (final IOException e) { LOGGER.error("Failed to create resource {}!", deployFilename, e); return ResponseBuilder.notOk(Response.Status.INTERNAL_SERVER_ERROR, new FaultCodeException(FaultType.IO_EXCEPTION, e.getMessage())); } return ResponseBuilder.ok(createResourceResponseWrapper); } ResourceServiceRestImpl(final ResourceService resourceService); }
ResourceServiceRestImpl implements ResourceServiceRest { @Override public Response createResource(final String deployFilename, final CreateResourceParam createResourceParam, final List<Attachment> attachments) { final CreateResourceResponseWrapper createResourceResponseWrapper; final boolean isExternalProperty = createResourceParam.getGroup() == null && createResourceParam.getJvm() == null && createResourceParam.getWebApp() == null && createResourceParam.getWebServer() == null; if (attachments == null || !isExternalProperty && attachments.size() == 0 ) { LOGGER.error("Expected non-empty attachments. Returning without creating Resource."); return ResponseBuilder.notOk(Response.Status.INTERNAL_SERVER_ERROR, new FaultCodeException(FaultType.RESOURCE_NO_ATTACHMENT_EXCEPTION, "There is no attachment when try to create resource.")); } else { LOGGER.debug("attachments.size() " + attachments.size()); for (final Attachment attachment : attachments) { LOGGER.debug("attachment.getDataHandler().getName(): " + attachment.getDataHandler().getName() + " attachment.getHeader(\"Content-Type\"): " + attachment.getHeader("Content-Type")); } } try { final Map<String, Object> metaDataMap = new HashMap<>(); BufferedInputStream bufferedInputStream = null; String templateName = null; for (final Attachment attachment : attachments) { if (attachment.getDataHandler().getName() == null ){ LOGGER.debug("attachment.getDataHandler().getName() is null"); continue; } if (attachment.getHeader("Content-Type") == null) { metaDataMap.put(attachment.getDataHandler().getName(), IOUtils.toString(attachment.getDataHandler().getInputStream(), Charset.defaultCharset())); } else { templateName = attachment.getDataHandler().getName(); bufferedInputStream = new BufferedInputStream(attachment.getDataHandler().getInputStream()); } } metaDataMap.put("deployFileName", deployFilename); metaDataMap.put("templateName", templateName); metaDataMap.put("contentType", resourceService.getResourceMimeType(bufferedInputStream)); final Entity entity = new Entity(null, null, null, null, Boolean.parseBoolean((String) metaDataMap.get("assignToJvms"))); metaDataMap.remove("assignToJvms"); metaDataMap.put("entity", entity); final ResourceTemplateMetaData resourceTemplateMetaData = resourceService.getMetaData(new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(metaDataMap)); final ResourceIdentifier resourceIdentifier = new ResourceIdentifier.Builder().setResourceName(templateName) .setGroupName(createResourceParam.getGroup()) .setWebServerName(createResourceParam.getWebServer()) .setJvmName(createResourceParam.getJvm()) .setWebAppName(createResourceParam.getWebApp()).build(); createResourceResponseWrapper = resourceService.createResource(resourceIdentifier, resourceTemplateMetaData, bufferedInputStream); } catch (final IOException e) { LOGGER.error("Failed to create resource {}!", deployFilename, e); return ResponseBuilder.notOk(Response.Status.INTERNAL_SERVER_ERROR, new FaultCodeException(FaultType.IO_EXCEPTION, e.getMessage())); } return ResponseBuilder.ok(createResourceResponseWrapper); } ResourceServiceRestImpl(final ResourceService resourceService); Response createTemplate(final List<Attachment> attachments, final String targetName, final AuthenticatedUser user); @Override Response getResourceAttrData(); @Override Response getResourceTopology(); @Override Response getApplicationResourceNames(final String groupName, final String appName); @Override Response getAppTemplate(final String groupName, final String appName, final String templateName); @Override Response checkFileExists(final String groupName, final String jvmName, final String webappName, final String webserverName, final String fileName); @Override Response createResource(final String deployFilename, final CreateResourceParam createResourceParam,
                                   final List<Attachment> attachments); void setMessageContext(MessageContext messageContext); @Override Response uploadExternalProperties(AuthenticatedUser user); @Override // TODO: Re validation, maybe we can use CXF bean validation ? Response deleteResource(final String templateName, final ResourceHierarchyParam resourceHierarchyParam,
                                   final AuthenticatedUser aUser); @Override Response deleteResources(final String[] templateNameArray, ResourceHierarchyParam
            resourceHierarchyParam, AuthenticatedUser user); @Override Response getResourceContent(final String resourceName, final ResourceHierarchyParam param); @Override Response updateResourceContent(String resourceName, ResourceHierarchyParam
            resourceHierarchyParam, String templateContent); @Override Response updateResourceMetaData(String resourceName, ResourceHierarchyParam resourceHierarchyParam, String metaData); @Override Response previewResourceContent(final String resourceName, final ResourceHierarchyParam resourceHierarchyParam, String content); @Override Response getResourcesFileNames(ResourceHierarchyParam resourceHierarchyParam); @Override Response getExternalProperties(); @Override Response getExternalPropertiesView(); @Override Response getExternalPropertiesDownload(); @Override void afterPropertiesSet(); }
ResourceServiceRestImpl implements ResourceServiceRest { @Override public Response createResource(final String deployFilename, final CreateResourceParam createResourceParam, final List<Attachment> attachments) { final CreateResourceResponseWrapper createResourceResponseWrapper; final boolean isExternalProperty = createResourceParam.getGroup() == null && createResourceParam.getJvm() == null && createResourceParam.getWebApp() == null && createResourceParam.getWebServer() == null; if (attachments == null || !isExternalProperty && attachments.size() == 0 ) { LOGGER.error("Expected non-empty attachments. Returning without creating Resource."); return ResponseBuilder.notOk(Response.Status.INTERNAL_SERVER_ERROR, new FaultCodeException(FaultType.RESOURCE_NO_ATTACHMENT_EXCEPTION, "There is no attachment when try to create resource.")); } else { LOGGER.debug("attachments.size() " + attachments.size()); for (final Attachment attachment : attachments) { LOGGER.debug("attachment.getDataHandler().getName(): " + attachment.getDataHandler().getName() + " attachment.getHeader(\"Content-Type\"): " + attachment.getHeader("Content-Type")); } } try { final Map<String, Object> metaDataMap = new HashMap<>(); BufferedInputStream bufferedInputStream = null; String templateName = null; for (final Attachment attachment : attachments) { if (attachment.getDataHandler().getName() == null ){ LOGGER.debug("attachment.getDataHandler().getName() is null"); continue; } if (attachment.getHeader("Content-Type") == null) { metaDataMap.put(attachment.getDataHandler().getName(), IOUtils.toString(attachment.getDataHandler().getInputStream(), Charset.defaultCharset())); } else { templateName = attachment.getDataHandler().getName(); bufferedInputStream = new BufferedInputStream(attachment.getDataHandler().getInputStream()); } } metaDataMap.put("deployFileName", deployFilename); metaDataMap.put("templateName", templateName); metaDataMap.put("contentType", resourceService.getResourceMimeType(bufferedInputStream)); final Entity entity = new Entity(null, null, null, null, Boolean.parseBoolean((String) metaDataMap.get("assignToJvms"))); metaDataMap.remove("assignToJvms"); metaDataMap.put("entity", entity); final ResourceTemplateMetaData resourceTemplateMetaData = resourceService.getMetaData(new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(metaDataMap)); final ResourceIdentifier resourceIdentifier = new ResourceIdentifier.Builder().setResourceName(templateName) .setGroupName(createResourceParam.getGroup()) .setWebServerName(createResourceParam.getWebServer()) .setJvmName(createResourceParam.getJvm()) .setWebAppName(createResourceParam.getWebApp()).build(); createResourceResponseWrapper = resourceService.createResource(resourceIdentifier, resourceTemplateMetaData, bufferedInputStream); } catch (final IOException e) { LOGGER.error("Failed to create resource {}!", deployFilename, e); return ResponseBuilder.notOk(Response.Status.INTERNAL_SERVER_ERROR, new FaultCodeException(FaultType.IO_EXCEPTION, e.getMessage())); } return ResponseBuilder.ok(createResourceResponseWrapper); } ResourceServiceRestImpl(final ResourceService resourceService); Response createTemplate(final List<Attachment> attachments, final String targetName, final AuthenticatedUser user); @Override Response getResourceAttrData(); @Override Response getResourceTopology(); @Override Response getApplicationResourceNames(final String groupName, final String appName); @Override Response getAppTemplate(final String groupName, final String appName, final String templateName); @Override Response checkFileExists(final String groupName, final String jvmName, final String webappName, final String webserverName, final String fileName); @Override Response createResource(final String deployFilename, final CreateResourceParam createResourceParam,
                                   final List<Attachment> attachments); void setMessageContext(MessageContext messageContext); @Override Response uploadExternalProperties(AuthenticatedUser user); @Override // TODO: Re validation, maybe we can use CXF bean validation ? Response deleteResource(final String templateName, final ResourceHierarchyParam resourceHierarchyParam,
                                   final AuthenticatedUser aUser); @Override Response deleteResources(final String[] templateNameArray, ResourceHierarchyParam
            resourceHierarchyParam, AuthenticatedUser user); @Override Response getResourceContent(final String resourceName, final ResourceHierarchyParam param); @Override Response updateResourceContent(String resourceName, ResourceHierarchyParam
            resourceHierarchyParam, String templateContent); @Override Response updateResourceMetaData(String resourceName, ResourceHierarchyParam resourceHierarchyParam, String metaData); @Override Response previewResourceContent(final String resourceName, final ResourceHierarchyParam resourceHierarchyParam, String content); @Override Response getResourcesFileNames(ResourceHierarchyParam resourceHierarchyParam); @Override Response getExternalProperties(); @Override Response getExternalPropertiesView(); @Override Response getExternalPropertiesDownload(); @Override void afterPropertiesSet(); static final String UNEXPECTED_CONTENT_TYPE_ERROR_MSG; static final String TPL_FILE_EXTENSION; static final String EXT_PROPERTIES_RESOURCE_NAME; static final String EXT_PROPERTIES_RESOURCE_META_DATA; static final int CREATE_RESOURCE_ATTACHMENT_SIZE; }