Package org.wso2.carbon.utils

Examples of org.wso2.carbon.utils.ArchiveManipulator


        */
       public void undeployArtifacts(CarbonApplication carbonApp, AxisConfiguration axisConfig) {

           List<Artifact.Dependency> artifacts =
                   carbonApp.getAppConfig().getApplicationArtifact().getDependencies();
           ArchiveManipulator archiveManipulator = new ArchiveManipulator();

           String repo = axisConfig.getRepository().getPath();
           String artifactPath, destPath;
           for (Artifact.Dependency dep : artifacts) {
               Artifact artifact = dep.getArtifact();
               if (artifact == null) {
                   continue;
               }
               if (BRSAppDeployer.BRS_TYPE.equals(artifact.getType())) {
                   destPath = repo + File.separator + BRSAppDeployer.BRS_DIR;
               } else {
                   continue;
               }

               List<CappFile> files = artifact.getFiles();
               if (files.size() != 1) {
                   log.error(
                           "A BRS must have a single file. But " + files.size() + " files found.");
                   continue;
               }
               String fileName = artifact.getFiles().get(0).getName();
               artifactPath = artifact.getExtractedPath() + File.separator + fileName;
               File artifactInRepo;
               try {
                   String[] filesInZip = archiveManipulator.check(artifactPath);
                   File jsFile = null;
                   for (String file : filesInZip) {
                       String artifactRepoPath = destPath + File.separator + file;
                       if (file.indexOf("/") == -1) {
                           String extension = file.substring(file.indexOf(".") + 1);
View Full Code Here


        }

        try {

            File file = new File(axisServiceGroupURL.getPath());
            ArchiveManipulator am = new ArchiveManipulator();
            if (file.isDirectory()) {
                FileManipulator.copyDir(file, f);
            } else if (file.isFile() && axisServiceGroupURL.getPath().endsWith(".class")) {
                FileManipulator.copyFileToDir(file, f);
            } else {
                am.extract(axisServiceGroupURL.getPath(), f.getAbsolutePath());
            }

            File servicesF =
                    new File(f.getAbsolutePath() + File.separator + "META-INF", "services.xml");

            String servicesXmlPath = servicesF.getAbsolutePath();
            // delete the existing services.xml file
            if (servicesF.exists() && !servicesF.delete()) {
                log.warn("Could not delete the existing services.xml at : " +
                        servicesF.getAbsolutePath());
            }
            // create the new serices.xml file using the created xml infoset
            File newServicesXml = new File(servicesXmlPath);
            OMElement axisServiceGroupXMLInfoset = createServiceGroupXMLInfoset(axisServiceGroup);
            OutputStream os = new FileOutputStream(newServicesXml);
            axisServiceGroupXMLInfoset.serializeAndConsume(os);

            File[] oldWsdls = f.listFiles(new FileFilter() {
                public boolean accept(File fw) {
                    return fw.getName().endsWith(".wsdl");
                }
            });

            if (oldWsdls != null) {
                for (int i = 0; i < oldWsdls.length; i++) {
                    File oldWsdl = oldWsdls[i];
                    if (oldWsdl.exists() && !oldWsdl.delete()) {
                        log.warn("Could not delete " + oldWsdl.getAbsolutePath());
                    }
                }
            }
            //Creating wsdls
            for (Iterator iterator = axisServiceGroup.getServices(); iterator.hasNext();) {
                AxisService axisService = (AxisService) iterator.next();

                boolean isRpcMessageReceiver = false;
                for (Iterator ops = axisService.getOperations(); ops.hasNext();) {
                    MessageReceiver receiver =
                            ((AxisOperation) ops.next()).getMessageReceiver();
                    isRpcMessageReceiver =
                            receiver instanceof RPCMessageReceiver || receiver instanceof RPCInOnlyMessageReceiver;
                }
                // If an RpcMessageReceiver is used, it does not make sense to store the WSDL in the AAR
                if (!isRpcMessageReceiver) {
                    File wsdlF = new File(f.getAbsolutePath() + File.separator + "META-INF",
                                          formatServiceName(axisService.getName()) + ".wsdl");
                    OutputStream wbOut = new FileOutputStream(wsdlF);
                    axisService.printWSDL(wbOut, NetworkUtils.getLocalHostname());
                }
            }
            File fout = new File(workdir + File.separator + "dump_aar_output" + File.separator
                                 + uuid);
            if(!fout.exists() && !fout.mkdirs()){
                log.warn("Could not create " + fout.getAbsolutePath());
            }
            String outAARFilename = fout.getAbsolutePath() + File.separator +
                                    formatServiceName(serviceGroupName) + ".aar";

            am.archiveDir(outAARFilename, f.getPath());

            // TODO : This is a hack. storing file resources in the super tenant config context
            // this is because, currently File download servlet is only registered under super
            // tenat. all other places like wsdl2code work using the super tenant CC
            ConfigurationContext superTenantConfigContext = MessageContext
View Full Code Here

        String filePath = filePathFromArchiveId.substring(0, endIndex);
        String archiveFileName = filePathFromArchiveId.substring(endIndex);
        archiveFileName = archiveFileName.substring(1, archiveFileName
                .lastIndexOf("."));

        ArchiveManipulator archiveManipulator = new ArchiveManipulator();

        // ----------------- Unzip the file ------------------------------------
        String unzippeDir = filePath + File.separator + "springTemp";
        File unzipped = new File(unzippeDir);
        unzipped.mkdirs();

        try {
            archiveManipulator.extract(filePathFromArchiveId, unzippeDir);
        } catch (IOException e) {
            String msg = bundle.getString("spring.cannot.extract.archive");
            handleException(msg, e);
        }

        // TODO copy the spring xml
        String springContextRelLocation = "spring/context.xml";
        try {
            File springContextRelDir = new File(unzippeDir + File.separator
                    + "spring");
            springContextRelDir.mkdirs();
            File absFile = new File(springContextRelDir, "context.xml");
            if (!absFile.exists()) {
                absFile.createNewFile();
            }
            File file = new File(filePathForSpringContext);
            FileInputStream in = new FileInputStream(file);
            FileOutputStream out = new FileOutputStream(absFile);
            // Transfer bytes from in to out
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.close();

        } catch (FileNotFoundException e) {
            throw AxisFault.makeFault(e);
        } catch (IOException e) {
            throw AxisFault.makeFault(e);
        }

        // ---- Generate the services.xml and place it in META-INF -----
        File file = new File(unzippeDir + File.separator + "META-INF"
                + File.separator + "services.xml");
        file.mkdirs();

        try {
            File absoluteFile = file.getAbsoluteFile();

            if (absoluteFile.exists()) {
                absoluteFile.delete();
            }

            absoluteFile.createNewFile();

            OutputStream os = new FileOutputStream(file);
            OMElement servicesXML = createServicesXMLFromSpringBeans(
                    beanClasses, springContextRelLocation);
            servicesXML.build();
            servicesXML.serialize(os);
        } catch (Exception e) {
            String msg = bundle.getString("spring.cannot.write.services.xml");
            handleException(msg, e);
        }

        // ----------------- Create the AAR ------------------------------------
        // These are the files to include in the ZIP file
        String outAARFilename = filePath + File.separator + archiveFileName
                + ".aar";

        try {
            archiveManipulator.archiveDir(outAARFilename, unzipped.getPath());
        } catch (IOException e) {
            String msg = bundle.getString("springcannot.create.new.aar.archive");
            handleException(msg, e);
        }
View Full Code Here

        JSServiceUploadClient serviceUploaderClient =
                new JSServiceUploadClient(configurationContext, serverURL, cookie);
        MashupServiceAdminClient client =
                new MashupServiceAdminClient(cookie, serverURL, configurationContext);
        List<JSServiceUploadData> jsServiceDataList = new ArrayList<JSServiceUploadData>();
        ArchiveManipulator archiveManipulator = new ArchiveManipulator();
        String[] serviceNames = new String[tempDataList.size()];
        ArrayList<File> tempFiles = new ArrayList<File>();
        try {
            for (int i = 0; i < tempDataList.size(); i++) {
                FileItemData fileData = tempDataList.get(i);
                String fileName = getFileName(fileData.getFileItem().getName());
                checkServiceFileExtensionValidity(fileName, ALLOWED_FILE_EXTENSIONS);
                JSServiceUploadData tempData = new JSServiceUploadData();
                tempData.setFileName(fileName);
                tempData.setDataHandler(fileData.getDataHandler());

                if (fileName.endsWith(".zip")) {
                    //validating the content of the zip file.
                    File zipFile = ((DeferredFileOutputStream) fileData.getFileItem().
                            getOutputStream()).getFile();
                    fileData.getFileItem().write(zipFile);
                    tempFiles.add(zipFile);
                    String[] files = archiveManipulator.check(zipFile.getAbsolutePath());
                    boolean jsFile = false;
                    boolean resourceFolder = false;
                    //validates the structure of zip file. i.e. zip file shoud contains only one
                    //.js file in the root folder and no other file types, but directories.
                    for (String file : files) {
View Full Code Here

                Transformer transformer =
                        TransformerFactory.newInstance().newTransformer(xslSource);
                transformer.transform(xmlSource, result);
            }

            new ArchiveManipulator().archiveDir(destArchive, new File(codegenOutputDir).getPath());
            FileManipulator.deleteDir(new File(codegenOutputDir));
            Map fileResourcesMap =
                    (Map) configContext.getProperty(WSO2Constants.FILE_RESOURCE_MAP);

            if (fileResourcesMap == null) {
View Full Code Here

     */
    private List<Service> getClasses(String filePath) throws AxisFault {
        List<Service> services = new ArrayList<Service>();
        if (filePath != null) {
            try {
                String[] entries = new ArchiveManipulator().check(filePath);
                for (int i = 0; i < entries.length; i++) {
                    String entry = entries[i];
                    if (entry.endsWith(".class")) {
                        entry = entry.replace('/', '.').substring(0,
                                                                  entry.lastIndexOf(".class"));
View Full Code Here

        String tempDir = getTempDir();
        new File(tempDir).mkdirs();
        String outAARFilename = tempDir + File.separator + serviceGroupName + ".aar";

        try {
            ArchiveManipulator archiveManipulator = new ArchiveManipulator();
            archiveManipulator.archiveDir(outAARFilename, directoryPath);
        } catch (IOException e) {
            String msg = "Cannot create new AAR archive";
            log.error(msg, e);
            throw new AxisFault(msg, e);
        }
View Full Code Here

                    log.error(error);
                    throw new AxisFault(error);
                }
            }

            ArchiveManipulator archiveManipulator = new ArchiveManipulator();
            try {
                archiveManipulator.extractFromStream(uploadData.getDataHandler().getInputStream(),
                        jaggeryAppsPath + File.separator + fName);
            } catch (IOException e) {
                log.error("Could not unzip the Jaggery App Archive", e);
                throw new AxisFault(e.getMessage(), e);
            }
View Full Code Here

        }

        public void run() {
            try {
                MessageContext msgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
                Event<MessageContext> event = new Event(msgCtx);
                subscriptions = subscriptionManager.getMatchingSubscriptions(event);
            } catch (EventException e) {
                handleException("Matching subscriptions fetching error", e);
            }
View Full Code Here

     * @throws EventException event
     */
    private void processGetStatusRequest(MessageContext mc,
                                         ResponseMessageBuilder messageBuilder)
            throws AxisFault, EventException {
        Subscription subscription =
                SubscriptionMessageBuilder.createGetStatusMessage(mc);
        if (log.isDebugEnabled()) {
            log.debug("GetStatus request recived for SynapseSubscription ID : " +
                    subscription.getId());
        }
        subscription = subscriptionManager.getSubscription(subscription.getId());
        if (subscription != null) {
            if (log.isDebugEnabled()) {
                log.debug("Sending GetStatus responce for SynapseSubscription ID : " +
                        subscription.getId());
            }
            //send the responce
            SOAPEnvelope soapEnvelope = messageBuilder.genGetStatusResponse(subscription);
            dispatchResponse(soapEnvelope, EventingConstants.WSE_GET_STATUS_RESPONSE,
                    mc, false);
View Full Code Here

TOP

Related Classes of org.wso2.carbon.utils.ArchiveManipulator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.