List of usage examples for org.springframework.oxm UnmarshallingFailureException getMessage
@Override
@Nullable
public String getMessage()
From source file:com.ephesoft.dcma.webservice.util.WebServiceHelper.java
/** * performs table extraction on the HOCR file provided ,accepts input xml with HOCR page and document type classification along * with HOCR pages on whuich extraction is to be performed * //from ww w .j av a 2 s .c om * @param req * @param resp * @return * @throws ValidationException * @throws InternalServerException */ public Batch.Documents processtableExtractionHOCR(final HttpServletRequest req, final HttpServletResponse resp) throws ValidationException, InternalServerException { LOGGER.info("Start processing web service for table extraction...."); String respStr = WebServiceUtil.EMPTY_STRING; String xmlFileName = WebServiceUtil.EMPTY_STRING; String workingDir = WebServiceUtil.EMPTY_STRING; Batch.Documents documents = null; InputStream instream = null; int responseCode = 0; if (req instanceof DefaultMultipartHttpServletRequest) { final String webServiceFolderPath = bsService.getWebServicesFolderPath(); try { workingDir = WebServiceUtil.createWebServiceWorkingDir(webServiceFolderPath); final DefaultMultipartHttpServletRequest multiPartRequest = (DefaultMultipartHttpServletRequest) req; final MultiValueMap<String, MultipartFile> fileMap = multiPartRequest.getMultiFileMap(); boolean isFileHOCR = false; boolean isFilePlainXML = false; if (fileMap.size() >= WebServiceConstants.MINIMUM_FILE_COUNT_FOR_TABLE_EXTRACTION) { for (final String inputFileName : fileMap.keySet()) { try { isFileHOCR = inputFileName.trim().endsWith(WebServiceConstants.HOCR_EXTENSION); isFilePlainXML = inputFileName.toLowerCase() .endsWith(FileType.XML.getExtensionWithDot()); if (!(isFileHOCR || isFilePlainXML)) { respStr = WebServiceConstants.INVALID_FILES_TABLE_EXTRACTION; responseCode = WebServiceConstants.INVALID_PARAMETERS_CODE; createAndThrowValidationException(null, responseCode, respStr); } if (!isFileHOCR) { xmlFileName = inputFileName; } final MultipartFile multiPartFile = multiPartRequest.getFile(inputFileName); instream = multiPartFile.getInputStream(); WebServiceUtil.copyFile(workingDir, inputFileName, instream); } catch (FileNotFoundException fileNotFoundException) { respStr = WebServiceConstants.ERROR; responseCode = WebServiceConstants.INTERNAL_SERVER_ERROR_CODE; } } LOGGER.info("XML file name is" + xmlFileName); final File xmlFile = new File( EphesoftStringUtil.concatenate(workingDir, File.separator, xmlFileName)); final FileInputStream inputStream = new FileInputStream(xmlFile); final Source source = XMLUtil.createSourceFromStream(inputStream); String response = WebServiceUtil.EMPTY_STRING; ExtractTableParam extractTableParams = (ExtractTableParam) batchSchemaDao.getJAXB2Template() .getJaxb2Marshaller().unmarshal(source); List<com.ephesoft.dcma.batch.schema.ExtractTableParam.Documents.Document> docList = extractTableParams .getDocuments().getDocument(); final String batchClassIdentifier = extractTableParams.getBatchClassId(); Map<DocumentType, List<HocrPages>> documentHOCRMap = new HashMap<DocumentType, List<HocrPages>>(); if (EphesoftStringUtil.isNullOrEmpty(batchClassIdentifier)) { responseCode = WebServiceConstants.INVALID_PARAMETERS_CODE; respStr = WebServiceConstants.UNDEFINED_BATCH_IDENTIFIER; createAndThrowValidationException(null, responseCode, respStr); } final BatchClass batchClass = bcService.getBatchClassByIdentifier(batchClassIdentifier); if (null == batchClass) { response = WebServiceUtil.BATCH_NOT_EXISTS; } if (EphesoftStringUtil.isNullOrEmpty(response)) { String tableExtractionSwitch = WebServiceConstants.EMPTY_STRING; try { tableExtractionSwitch = batchClassPPService.getPropertyValue(batchClassIdentifier, WebServiceConstants.TABLE_EXTRACTION_PLUGIN, TableExtractionProperties.TABLE_EXTRACTION_SWITCH); } catch (NullPointerException nullPointerException) { responseCode = WebServiceConstants.INVALID_PARAMETERS_CODE; respStr = EphesoftStringUtil.concatenate( WebServiceConstants.UNDEFINED_TABLE_EXTRACTION_SWITCH, batchClassIdentifier); createAndThrowConfigurationException(responseCode, respStr); } if (WebServiceUtil.OFF_STRING.equals(tableExtractionSwitch)) { respStr = EphesoftStringUtil.concatenate( WebServiceConstants.TABLE_EXTRACCTION_SWITCH_OFF_MESSAGE, batchClassIdentifier); responseCode = WebServiceConstants.TABLE_EXTRACTION_SWITCH_OFF_CODE; createAndThrowConfigurationException(responseCode, respStr); } final List<DocumentType> docTypeList = batchClass.getDocumentTypes(); List<String> docTypesName = obtainDocumentNameList(docTypeList); documentHOCRMap = generateDocumentMapHOCR(docList, workingDir, docTypesName, batchClassIdentifier); if (documentHOCRMap.isEmpty()) { respStr = WebServiceConstants.INVALID_MAPPING_DOCUMENT_HOCR_PAGES; responseCode = WebServiceConstants.INVALID_PARAMETERS_CODE; createAndThrowValidationException(null, responseCode, respStr); } final int gapBetweenColumnWords = tableFinderService.getGapBetweenColumnWords(); documents = tableExtraction.processDocPageForTableExtractionWebService( gapBetweenColumnWords, documentHOCRMap, docTypeList, docTypesName); } else { respStr = response; responseCode = WebServiceConstants.INVALID_PARAMETERS_CODE; createAndThrowValidationException(null, responseCode, respStr); } } else { respStr = WebServiceConstants.TABLE_EXTRACTION_MINIMUM_PARAMETERS_REQUIRED_ERROR_MESSAGE; responseCode = WebServiceConstants.INVALID_PARAMETERS_CODE; createAndThrowValidationException(null, responseCode, respStr); } } catch (ClassCastException classCastException) { LOGGER.error(EphesoftStringUtil.concatenate("Not an Object of extract table Params", classCastException.getMessage())); respStr = WebServiceConstants.INVALID_ARGUMENTS_IN_XML_INPUT_MESSAGE; responseCode = WebServiceConstants.INVALID_ARGUMENTS_IN_XML_INPUT_CODE; } catch (DCMABusinessException dcmaBusinessException) { LOGGER.error(EphesoftStringUtil.concatenate("Invalid HOCR xml file uploaded", dcmaBusinessException.getMessage())); respStr = WebServiceConstants.INVALID_HOCR_FILE_UPLOAD_MESSAGE; responseCode = WebServiceConstants.INVALID_HOCR_FILE_UPLOADED_CODE; } catch (org.springframework.oxm.UnmarshallingFailureException unmarshallingFailureException) { LOGGER.error(EphesoftStringUtil.concatenate("Not an Object of extract table Params", unmarshallingFailureException.getMessage())); respStr = WebServiceConstants.INVALID_ARGUMENTS_IN_XML_INPUT_MESSAGE; responseCode = WebServiceConstants.INVALID_ARGUMENTS_IN_XML_INPUT_CODE; } catch (Exception exception) { LOGGER.error(EphesoftStringUtil.concatenate("Error generated is ", exception.getMessage())); if (EphesoftStringUtil.isNullOrEmpty(respStr)) { respStr = WebServiceConstants.INVALID_MULTIPART_REQUEST; responseCode = WebServiceConstants.INTERNAL_SERVER_ERROR_CODE; } } finally { if (!workingDir.isEmpty()) { FileUtils.deleteDirectoryAndContentsRecursive(new File(workingDir).getParentFile()); } } } else { if (EphesoftStringUtil.isNullOrEmpty(respStr)) { respStr = WebServiceConstants.INVALID_MULTIPART_REQUEST; responseCode = WebServiceConstants.INTERNAL_SERVER_ERROR_CODE; } } validateResponse(responseCode, respStr); return documents; }