List of usage examples for javax.activation DataHandler getInputStream
public InputStream getInputStream() throws IOException
From source file:org.wso2.carbon.admin.service.AdminServiceLocalEntryAdminService.java
public void addLocalEntry(String sessionCookie, DataHandler dh) throws LocalEntryAdminException, IOException, XMLStreamException { new AuthenticateStub().authenticateStub(sessionCookie, localEntryAdminServiceStub); XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(dh.getInputStream()); //create the builder StAXOMBuilder builder = new StAXOMBuilder(parser); OMElement localEntryElem = builder.getDocumentElement(); localEntryAdminServiceStub.addEntry(localEntryElem.toString()); }
From source file:org.wso2.carbon.admin.service.AdminServiceSequenceAdmin.java
public void addSequence(String sessionCookie, DataHandler dh) throws SequenceEditorException, IOException, XMLStreamException { new AuthenticateStub().authenticateStub(sessionCookie, sequenceAdminServiceStub); XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(dh.getInputStream()); //create the builder StAXOMBuilder builder = new StAXOMBuilder(parser); OMElement sequenceElem = builder.getDocumentElement(); sequenceAdminServiceStub.addSequence(sequenceElem); }
From source file:org.wso2.carbon.la.restapi.FileProcessingApi.java
@POST @Path("/upload") @Produces(MediaType.APPLICATION_JSON)/*w w w .j av a 2s .co m*/ @Consumes(MediaType.MULTIPART_FORM_DATA) public Response uploadLog(@Multipart("logStream") String logStream, @Multipart("description") String description, @Multipart("file") Attachment attachment) { DataHandler dataHandler = attachment.getDataHandler(); String fileName = null; try { InputStream stream = dataHandler.getInputStream(); MultivaluedMap<String, String> map = attachment.getHeaders(); fileName = getFileName(map); String tempFolderLocation = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "data" + File.separator + "analyzer-logs"; String logFileDir = logStream; if (logFileDir != "") { logFileDir = logFileDir.replace(',', '_'); } File tempDir = new File(tempFolderLocation + File.separator + logFileDir); if (!tempDir.exists()) { FileUtils.forceMkdir(tempDir); } OutputStream out = new FileOutputStream( new File(tempFolderLocation + File.separator + logFileDir + File.separator + fileName)); int read = 0; byte[] bytes = new byte[1024]; //TODO: refactor reading part while ((read = stream.read(bytes)) != -1) { out.write(bytes, 0, read); } stream.close(); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } Object[] logSourceInfo = { logStream, fileName }; return Response.ok(logSourceInfo).build(); }
From source file:de.kp.ames.web.function.product.ProductDQM.java
/** * Retrieve FileUtil representation of a * certain product//w w w .j a v a2 s . com * * @param item * @return * @throws Exception */ public FileUtil getFile(String item) throws Exception { /* * Determine registry object from unique identifier */ RegistryObjectImpl ro = getRegistryObjectById(item); if (ro == null) throw new Exception("[ProductDQM] RegistryObject with id <" + item + "> does not exist."); String objectType = ro.getObjectType().getKey().getId(); if (!objectType.startsWith(EXTRINSIC_OBJECT)) throw new Exception("[ProductDQM] Product is not an ExtrinsicObject"); /* * Extrinsic objects must be restricted to xml document; * this is asserted by evaluating the assciated mimetype */ ExtrinsicObjectImpl eo = (ExtrinsicObjectImpl) ro; String mimeType = eo.getMimeType(); if (!mimeType.equals(GlobalConstants.MT_XML)) throw new Exception("[ProductDQM] Product is no XML file."); /* * Determine repository item as byte array */ DataHandler handler = eo.getRepositoryItem(); if (handler == null) throw new Exception("[ProductDQM] Product has no data."); InputStream stream = handler.getInputStream(); byte[] bytes = FileUtil.getByteArrayFromInputStream(stream); return new FileUtil(bytes, mimeType); }
From source file:org.apache.axis2.datasource.jaxb.AbstractJAXBAttachmentUnmarshaller.java
/** * Read the bytes from the DataHandler// w w w .j a v a 2 s . c o m * * @param dh * @return byte[] * @throws IOException */ private byte[] convert(DataHandler dh) throws IOException { if (log.isDebugEnabled()) { log.debug("Reading byte[] from DataHandler " + dh); } InputStream is = dh.getInputStream(); if (log.isDebugEnabled()) { log.debug("DataHandler InputStream " + is); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] b = new byte[1024]; int num = is.read(b); if (log.isDebugEnabled()) { if (num <= 0) { log.debug("DataHandler InputStream contains no data. num=" + num); } } while (num > 0) { baos.write(b, 0, num); num = is.read(b); } return baos.toByteArray(); }
From source file:org.wso2.carbon.admin.service.AdminServiceTaskAdmin.java
public void addTask(String sessionCookie, DataHandler dh) throws TaskManagementException, IOException, XMLStreamException { new AuthenticateStub().authenticateStub(sessionCookie, taskAdminStub); XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(dh.getInputStream()); //create the builder StAXOMBuilder builder = new StAXOMBuilder(parser); OMElement scheduleTaskElem = builder.getDocumentElement(); taskAdminStub.addTaskDescription(scheduleTaskElem); }
From source file:ebay.dts.client.FileTransferActions.java
public void downloadFile2(String fileName, String jobId, String fileReferenceId) throws EbayConnectorException { String callName = "downloadFile"; try {//from ww w .j ava2 s.co m FileTransferServicePort port = call.setFTSMessageContext(callName); com.ebay.marketplace.services.DownloadFileRequest request = new com.ebay.marketplace.services.DownloadFileRequest(); request.setFileReferenceId(fileReferenceId); request.setTaskReferenceId(jobId); DownloadFileResponse response = port.downloadFile(request); if (response.getAck().equals(AckValue.SUCCESS)) { logger.debug(AckValue.SUCCESS.toString()); } else { logger.error(response.getErrorMessage().getError().get(0).getMessage()); throw new EbayConnectorException(response.getErrorMessage().getError().get(0).getMessage()); } FileAttachment attachment = response.getFileAttachment(); DataHandler dh = attachment.getData(); try { InputStream in = dh.getInputStream(); BufferedInputStream bis = new BufferedInputStream(new GZIPInputStream(in)); FileOutputStream fo = new FileOutputStream(new File(fileName)); // "C:/myDownLoadFile.gz" BufferedOutputStream bos = new BufferedOutputStream(fo); int bytes_read = 0; byte[] dataBuf = new byte[4096]; while ((bytes_read = bis.read(dataBuf)) != -1) { bos.write(dataBuf, 0, bytes_read); } bis.close(); bos.flush(); bos.close(); logger.info("File attachment has been saved successfully to " + fileName); } catch (IOException e) { logger.error("Exception caught while trying to save the attachement"); throw new EbayConnectorException("Exception caught while trying to save the attachement", e); } } catch (Exception e) { throw new EbayConnectorException("Exception caught while trying to save the attachement", e); } }
From source file:com.jaspersoft.jasperserver.ws.axis2.repository.FileResourceHandler.java
protected void updateResource(Resource resource, ResourceDescriptor descriptor, RepositoryServiceContext serviceContext) throws WSException { FileResource fileResource = (FileResource) resource; String wsType = descriptor.getWsType(); if (wsType.equals(ResourceDescriptor.TYPE_REFERENCE) || descriptor.getIsReference()) { // check if the reference uri is valid... String referenceUri = descriptor.getReferenceUri(); try {//from w w w .ja v a 2 s. c o m serviceContext.getRepository().getResource(null, referenceUri); } catch (Exception ex) { throw new WSException(WSException.GENERAL_ERROR2, serviceContext .getMessage("webservices.error.resourceNotFoundOrInvalid", new Object[] { referenceUri })); } fileResource.setReferenceURI(referenceUri); } else { String fileType = getFileType(wsType); if (fileType != null) { fileResource.setFileType(fileType); } if (descriptor.getHasData()) { try { // Save the temporary file.... AttachmentPart[] parts = serviceContext.getMessageAttachments(); if (parts.length >= 1) { DataHandler actualDH = parts[0].getDataHandler(); // Save the content in the file... fileResource.readData(actualDH.getInputStream()); } } catch (SOAPException e) { throw new WSException(e); } catch (IOException e) { throw new WSException(e); } } } }
From source file:org.wso2.carbon.registry.resource.services.utils.AddResourceUtil.java
public static void addResource(String path, String mediaType, String description, DataHandler content, String symlinkLocation, Registry registry, String[][] properties) throws Exception { try {//from w w w . java 2 s. co m boolean isNew = !(registry.resourceExists(path)); ResourceImpl resourceImpl = (ResourceImpl) (isNew ? registry.newResource() : registry.get(path)); if (resourceImpl.getProperty(RegistryConstants.REGISTRY_LINK) != null && (CommonConstants.WSDL_MEDIA_TYPE.equals(mediaType) || CommonConstants.SCHEMA_MEDIA_TYPE.equals(mediaType))) { resourceImpl = (ResourceImpl) registry.newResource(); } resourceImpl.setMediaType(mediaType); resourceImpl.setDescription(description); if (properties != null && properties.length > 0) { for (String[] p : properties) { resourceImpl.setProperty(p[0], p[1]); } } //allow to upload a file with empty content if (content == null) { String temp = ""; resourceImpl.setContentStream(new ByteArrayInputStream(RegistryUtils.encodeString(temp))); } else { resourceImpl.setContentStream(content.getInputStream()); } if (symlinkLocation != null && isNew) { if (!symlinkLocation.endsWith(RegistryConstants.PATH_SEPARATOR)) { symlinkLocation += RegistryConstants.PATH_SEPARATOR; } resourceImpl.setProperty(RegistryConstants.SYMLINK_PROPERTY_NAME, symlinkLocation); // The symbolic link location is expected to be set only for WSDLs, Schemas and // Policies. Therefore, if this has been set, a symbolic link will be created at the // given location. However, if the symbolic link already exists, that means that the // content is being updated. In such a situation, the symbolic link will first be // removed before attempting to do the put operation. This will fix the issue // mentioned in CARBON-7350. if (registry.resourceExists(path)) { Resource resource = registry.get(path); if (resource != null) { if (resource.getProperty("registry.link") != null) { registry.removeLink(path); } } } } resourceImpl.setProperty(CommonConstants.SOURCE_PROPERTY, CommonConstants.SOURCE_ADMIN_CONSOLE); registry.put(path, resourceImpl); resourceImpl.discard(); } catch (Exception e) { String msg = "Failed to add resource " + path + ". " + ((e.getCause() instanceof SQLException) ? "" : e.getMessage()); log.error(msg, e); throw new RegistryException(msg, e); } }
From source file:org.wso2.am.admin.clients.sequences.SequenceAdminServiceClient.java
/** * adding sequence//from w w w . j ava2s .c o m * * @param dh * @throws SequenceEditorException * @throws java.io.IOException * @throws javax.xml.stream.XMLStreamException */ public void addSequence(DataHandler dh) throws SequenceEditorException, IOException, XMLStreamException { XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(dh.getInputStream()); //create the builder StAXOMBuilder builder = new StAXOMBuilder(parser); OMElement sequenceElem = builder.getDocumentElement(); sequenceAdminServiceStub.addSequence(sequenceElem); }