Example usage for javax.activation DataHandler getName

List of usage examples for javax.activation DataHandler getName

Introduction

In this page you can find the example usage for javax.activation DataHandler getName.

Prototype

public String getName() 

Source Link

Document

Return the name of the data object.

Usage

From source file:org.wso2.am.admin.clients.registry.ResourceAdminServiceClient.java

public void addSchema(String description, DataHandler dh)
        throws ResourceAdminServiceExceptionException, RemoteException {
    String fileName;/* w  ww . j a v a 2 s.  co  m*/
    fileName = dh.getName().substring(dh.getName().lastIndexOf('/') + 1);
    resourceAdminServiceStub.addResource("/" + fileName, MEDIA_TYPE_SCHEMA, description, dh, null, null);
}

From source file:org.wso2.am.admin.clients.registry.ResourceAdminServiceClient.java

public void addPolicy(String description, DataHandler dh)
        throws ResourceAdminServiceExceptionException, RemoteException {
    String fileName;//from w  w  w  .  ja  v  a  2  s.  c o  m
    fileName = dh.getName().substring(dh.getName().lastIndexOf('/') + 1);
    resourceAdminServiceStub.addResource("/" + fileName, MEDIA_TYPE_POLICY, description, dh, null, null);
}

From source file:org.wso2.am.admin.clients.registry.ResourceAdminServiceClient.java

public void uploadArtifact(String description, DataHandler dh)
        throws ResourceAdminServiceExceptionException, RemoteException {
    String fileName;/*w ww.  j  av  a2  s .c o m*/
    fileName = dh.getName().substring(dh.getName().lastIndexOf('/') + 1);
    resourceAdminServiceStub.addResource("/" + fileName, MEDIA_TYPE_GOVERNANCE_ARCHIVE, description, dh, null,
            null);
}

From source file:org.wso2.am.admin.clients.registry.ResourceAdminServiceClient.java

public void addWSDL(String description, DataHandler dh)
        throws ResourceAdminServiceExceptionException, RemoteException {

    String fileName;//from www . j a va2 s .  com
    fileName = dh.getName().substring(dh.getName().lastIndexOf('/') + 1);
    log.debug(fileName);
    resourceAdminServiceStub.addResource("/" + fileName, MEDIA_TYPE_WSDL, description, dh, null, null);
}

From source file:org.wso2.am.admin.clients.registry.ResourceAdminServiceClient.java

public void addWADL(String description, DataHandler dh)
        throws ResourceAdminServiceExceptionException, RemoteException {

    String fileName;//from  w w w . j  a va  2  s.c o m
    fileName = dh.getName().substring(dh.getName().lastIndexOf('/') + 1);
    log.debug(fileName);
    resourceAdminServiceStub.addResource("/" + fileName, MEDIA_TYPE_WADL, description, dh, null, null);
}

From source file:org.paxle.core.doc.impl.BasicDocumentFactoryTest.java

public void testStoreMarshalledCommand() throws IOException, ParseException {
    // Create the ZIP file
    final File outFile = File.createTempFile("command", ".zip");
    outFile.deleteOnExit();//from   ww w .  ja va2s.c  o  m
    ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(outFile));

    // creating a test command
    final ICommand cmd = this.createTestCommand();

    // marshal command
    final ZipEntry commandEntry = new ZipEntry("command.xml");
    commandEntry.setComment("command.xml");
    zipOut.putNextEntry(commandEntry);

    final TeeOutputStream out = new TeeOutputStream(System.out, zipOut);
    final Map<String, DataHandler> attachments = this.docFactory.marshal(cmd, out);
    zipOut.closeEntry();

    // write attachments
    if (attachments != null) {
        for (Entry<String, DataHandler> attachment : attachments.entrySet()) {
            final String cid = attachment.getKey();
            final DataHandler data = attachment.getValue();

            final ZipEntry zipEntry = new ZipEntry(cid);
            zipEntry.setComment(data.getName());
            zipOut.putNextEntry(zipEntry);

            IOUtils.copy(data.getInputStream(), zipOut);
            zipOut.closeEntry();
        }
    }
    zipOut.close();
    System.out.println("Command written into file: " + outFile.toString());

    // print content
    final ZipFile zf = new ZipFile(outFile);
    for (Enumeration<? extends ZipEntry> entries = zf.entries(); entries.hasMoreElements();) {
        ZipEntry entry = entries.nextElement();
        System.out.println(entry.getName() + ": " + entry.getComment());
    }
    zf.close();
}

From source file:de.extra.client.plugins.responseprocessplugin.filesystem.FileSystemResultPackageDataResponseProcessPlugin.java

/**
 * @param responseId/*  w ww . jav  a  2  s  . c o  m*/
 * @param responseBody
 * @return fileName
 */
private String saveBodyToFilesystem(final String incomingFileName, final String responseId,
        final DataHandler packageBodyDataHandler) {
    try {

        final String dateiName = buildFilename(incomingFileName, responseId);

        final File responseFile = new File(eingangOrdner, dateiName);

        final FileOutputStream fileOutputStream = new FileOutputStream(responseFile);
        final String dataHandlerName = packageBodyDataHandler.getName();
        logger.info("Receiving File : " + dataHandlerName);

        IOUtils.copy(packageBodyDataHandler.getInputStream(), fileOutputStream);

        IOUtils.closeQuietly(fileOutputStream);

        logger.info("Input file is stored under " + responseFile.getAbsolutePath());
        logger.info("ChecksumCRC32 " + FileUtils.checksumCRC32(responseFile));
        logger.info("Filesize: " + FileUtils.sizeOf(responseFile));

        transportObserver.responseDataForwarded(responseFile.getAbsolutePath(), responseFile.length());

        logger.info("Response gespeichert in File: '" + dateiName + "'");

        return dateiName;
    } catch (final IOException ioException) {
        throw new ExtraResponseProcessPluginRuntimeException(ExceptionCode.UNEXPECTED_INTERNAL_EXCEPTION,
                "Fehler beim schreiben der Antwort", ioException);
    }
}

From source file:org.apache.camel.component.jetty.MultiPartFormTest.java

protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            // START SNIPPET: e1
            // Set the jetty temp directory which store the file for multi part form
            // camel-jetty will clean up the file after it handled the request.
            // The option works rightly from Camel 2.4.0
            getContext().getProperties().put("CamelJettyTempDir", "target");

            from("jetty://http://localhost:{{port}}/test").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    Message in = exchange.getIn();
                    assertEquals("Get a wrong attachement size", 1, in.getAttachments().size());
                    // The file name is attachment id
                    DataHandler data = in.getAttachment("NOTICE.txt");

                    assertNotNull("Should get the DataHandle NOTICE.txt", data);
                    // This assert is wrong, but the correct content-type (application/octet-stream)
                    // will not be returned until Jetty makes it available - currently the content-type
                    // returned is just the default for FileDataHandler (for the implentation being used)
                    //assertEquals("Get a wrong content type", "text/plain", data.getContentType());
                    assertEquals("Got the wrong name", "NOTICE.txt", data.getName());

                    assertTrue("We should get the data from the DataHandle",
                            data.getDataSource().getInputStream().available() > 0);

                    // The other form date can be get from the message header
                    exchange.getOut().setBody(in.getHeader("comment"));
                }/*from w  w  w  . jav  a 2  s.  c o m*/

            });
            // END SNIPPET: e1
        }
    };
}

From source file:org.apache.camel.component.jetty.MultiPartFormWithCustomFilterTest.java

protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            // START SNIPPET: e1
            // Set the jetty temp directory which store the file for multi part form
            // camel-jetty will clean up the file after it handled the request.
            // The option works rightly from Camel 2.4.0
            getContext().getProperties().put("CamelJettyTempDir", "target");

            from("jetty://http://localhost:{{port}}/test?multipartFilterRef=myMultipartFilter")
                    .process(new Processor() {
                        public void process(Exchange exchange) throws Exception {
                            Message in = exchange.getIn();
                            assertEquals("Get a wrong attachement size", 1, in.getAttachments().size());
                            // The file name is attachment id
                            DataHandler data = in.getAttachment("NOTICE.txt");

                            assertNotNull("Should get the DataHandle NOTICE.txt", data);
                            // This assert is wrong, but the correct content-type (application/octet-stream)
                            // will not be returned until Jetty makes it available - currently the content-type
                            // returned is just the default for FileDataHandler (for the implentation being used)
                            //assertEquals("Get a wrong content type", "text/plain", data.getContentType());
                            assertEquals("Got the wrong name", "NOTICE.txt", data.getName());

                            assertTrue("We should get the data from the DataHandle",
                                    data.getDataSource().getInputStream().available() > 0);

                            // The other form date can be get from the message header
                            exchange.getOut().setBody(in.getHeader("comment"));
                        }//from w ww  .j  a v a 2 s . c  o m
                    });
            // END SNIPPET: e1

            // Test to ensure that setting a multipartFilterRef overrides the enableMultipartFilter=false parameter
            from("jetty://http://localhost:{{port}}/test2?multipartFilterRef=myMultipartFilter&enableMultipartFilter=false")
                    .process(new Processor() {
                        public void process(Exchange exchange) throws Exception {
                            Message in = exchange.getIn();
                            assertEquals("Get a wrong attachement size", 1, in.getAttachments().size());
                            DataHandler data = in.getAttachment("NOTICE.txt");

                            assertNotNull("Should get the DataHandle NOTICE.txt", data);
                            // The other form date can be get from the message header
                            exchange.getOut().setBody(in.getHeader("comment"));
                        }
                    });
        }
    };
}

From source file:org.wso2.appserver.integration.common.clients.JARServiceUploaderClient.java

public void uploadJARServiceFile(String serviceGroup, List<DataHandler> dhJarList, DataHandler dhWsdl)
        throws JarUploadExceptionException, RemoteException, DuplicateServiceGroupExceptionException,
        DuplicateServiceExceptionException {

    Resource resourceData;/*from ww w.j a v a2 s.  c o  m*/
    Resource resourceDataWsdl;
    UploadArtifactsResponse uploadArtifactsResponse;

    Resource[] resourceDataArray = new Resource[dhJarList.size()];

    assert dhJarList.size() != 0;
    for (int i = 0; dhJarList.size() > i; i++) {
        resourceData = new Resource();
        resourceData.setFileName(
                dhJarList.get(i).getName().substring(dhJarList.get(i).getName().lastIndexOf('/') + 1));
        resourceData.setDataHandler(dhJarList.get(i));
        resourceDataArray[i] = resourceData;
    }

    if (dhWsdl != null) {
        resourceDataWsdl = new Resource();
        resourceDataWsdl.setFileName(dhWsdl.getName().substring(dhWsdl.getName().lastIndexOf('/') + 1));
        resourceDataWsdl.setDataHandler(dhWsdl);
    } else {
        resourceDataWsdl = null;
    }

    uploadArtifactsResponse = jarServiceCreatorAdminStub.upload(serviceGroup, resourceDataWsdl,
            resourceDataArray);

    Service[] service = uploadArtifactsResponse.getServices();
    for (Service temp : service) {
        temp.setUseOriginalWsdl(false);
        temp.setDeploymentScope("request");
    }

    jarServiceCreatorAdminStub.createAndDeployService(uploadArtifactsResponse.getResourcesDirPath(), "",
            serviceGroup, service);
    log.info("Artifact uploaded");

}