Example usage for java.net URISyntaxException printStackTrace

List of usage examples for java.net URISyntaxException printStackTrace

Introduction

In this page you can find the example usage for java.net URISyntaxException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.app.server.SARDeployer.java

/**
 * This method extracts the SAR archive and configures for the SAR and starts the services
 * @param file/*from   w  w w .  ja v  a  2s .  c  om*/
 * @param warDirectoryPath
 * @throws IOException
 */
public void extractSarDeploy(ClassLoader cL, Object... args) throws IOException {
    CopyOnWriteArrayList classPath = null;
    File file = null;
    String fileName = "";
    String fileWithPath = "";
    if (args[0] instanceof File) {
        classPath = new CopyOnWriteArrayList();
        file = (File) args[0];
        fileWithPath = file.getAbsolutePath();
        ZipFile zip = new ZipFile(file);
        ZipEntry ze = null;
        fileName = file.getName();
        fileName = fileName.substring(0, fileName.indexOf('.'));
        fileName += "sar";
        String fileDirectory;
        Enumeration<? extends ZipEntry> entries = zip.entries();
        int numBytes;
        while (entries.hasMoreElements()) {
            ze = entries.nextElement();
            // //log.info("Unzipping " + ze.getName());
            String filePath = serverConfig.getDeploydirectory() + "/" + fileName + "/" + ze.getName();
            if (!ze.isDirectory()) {
                fileDirectory = filePath.substring(0, filePath.lastIndexOf('/'));
            } else {
                fileDirectory = filePath;
            }
            // //log.info(fileDirectory);
            createDirectory(fileDirectory);
            if (!ze.isDirectory()) {
                FileOutputStream fout = new FileOutputStream(filePath);
                byte[] inputbyt = new byte[8192];
                InputStream istream = zip.getInputStream(ze);
                while ((numBytes = istream.read(inputbyt, 0, inputbyt.length)) >= 0) {
                    fout.write(inputbyt, 0, numBytes);
                }
                fout.close();
                istream.close();
                if (ze.getName().endsWith(".jar")) {
                    classPath.add(filePath);
                }
            }
        }
        zip.close();
    } else if (args[0] instanceof FileObject) {
        FileObject fileObj = (FileObject) args[0];
        fileName = fileObj.getName().getBaseName();
        try {
            fileWithPath = fileObj.getURL().toURI().toString();
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        fileName = fileName.substring(0, fileName.indexOf('.'));
        fileName += "sar";
        classPath = unpack(fileObj, new File(serverConfig.getDeploydirectory() + "/" + fileName + "/"),
                (StandardFileSystemManager) args[1]);
    }
    URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader();
    URL[] urls = loader.getURLs();
    WebClassLoader sarClassLoader;
    if (cL != null) {
        sarClassLoader = new WebClassLoader(urls, cL);
    } else {
        sarClassLoader = new WebClassLoader(urls);
    }
    for (int index = 0; index < classPath.size(); index++) {
        // log.info("file:"+classPath.get(index));
        sarClassLoader.addURL(new URL("file:" + classPath.get(index)));
    }
    sarClassLoader.addURL(new URL("file:" + serverConfig.getDeploydirectory() + "/" + fileName + "/"));
    //log.info(sarClassLoader.geturlS());
    sarsMap.put(fileWithPath, sarClassLoader);
    try {
        Sar sar = (Sar) sardigester.parse(new InputSource(new FileInputStream(
                serverConfig.getDeploydirectory() + "/" + fileName + "/META-INF/" + "mbean-service.xml")));
        CopyOnWriteArrayList mbeans = sar.getMbean();
        //log.info(mbeanServer);
        ObjectName objName, classLoaderObjectName = new ObjectName("com.app.server:classLoader=" + fileName);
        if (!mbeanServer.isRegistered(classLoaderObjectName)) {
            mbeanServer.registerMBean(sarClassLoader, classLoaderObjectName);
        } else {
            mbeanServer.unregisterMBean(classLoaderObjectName);
            mbeanServer.registerMBean(sarClassLoader, classLoaderObjectName);
            ;
        }
        for (int index = 0; index < mbeans.size(); index++) {
            Mbean mbean = (Mbean) mbeans.get(index);
            //log.info(mbean.getObjectname());
            //log.info(mbean.getCls());
            objName = new ObjectName(mbean.getObjectname());
            Class service = sarClassLoader.loadClass(mbean.getCls());
            if (mbeanServer.isRegistered(objName)) {
                //mbs.invoke(objName, "stopService", null, null);
                //mbs.invoke(objName, "destroy", null, null);
                mbeanServer.unregisterMBean(objName);
            }
            mbeanServer.createMBean(service.getName(), objName, classLoaderObjectName);
            //mbs.registerMBean(obj, objName);
            CopyOnWriteArrayList attrlist = mbean.getMbeanAttribute();
            if (attrlist != null) {
                for (int count = 0; count < attrlist.size(); count++) {
                    MBeanAttribute attr = (MBeanAttribute) attrlist.get(count);
                    Attribute mbeanattribute = new Attribute(attr.getName(), attr.getValue());
                    mbeanServer.setAttribute(objName, mbeanattribute);
                }
            }
            Attribute mbeanattribute = new Attribute("ObjectName", objName);
            mbeanServer.setAttribute(objName, mbeanattribute);
            if (((String) mbeanServer.getAttribute(objName, "Deployer")).equals("true")) {
                mbeanServer.invoke(objName, "init", new Object[] { deployerList },
                        new String[] { Vector.class.getName() });

            }
            mbeanServer.invoke(objName, "init", new Object[] { serviceList, serverConfig, mbeanServer },
                    new String[] { Vector.class.getName(), ServerConfig.class.getName(),
                            MBeanServer.class.getName() });
            mbeanServer.invoke(objName, "start", null, null);
            serviceListObjName.put(fileWithPath, objName);
        }
    } catch (Exception e) {
        log.error("Could not able to deploy sar archive " + fileWithPath, e);
        // TODO Auto-generated catch block
        //e.printStackTrace();
    }
}

From source file:eu.planets_project.tb.impl.data.util.DataHandlerImpl.java

public URI storeDigitalObject(DigitalObject dob, Experiment exp) {
    URI defaultDomUri = this.dataReg.getDefaultDigitalObjectManagerId();
    this.log.info("Attempting to store in data registry: " + defaultDomUri);
    UserBean currentUser = (UserBean) JSFUtil.getManagedObject("UserBean");
    String userid = ".";
    if (currentUser != null && currentUser.getUserid() != null) {
        userid = currentUser.getUserid();
    }//from   ww  w  .  ja v  a  2 s  .c  o  m

    // Store new DO in the user space, with path based on experiment details.
    URI baseUri = null;
    try {
        if (exp == null) {
            baseUri = new URI(defaultDomUri.toString() + "/testbed/users/" + userid + "/digitalobjects/");
        } else {
            baseUri = new URI(
                    defaultDomUri.toString() + "/testbed/experiments/experiment-" + exp.getEntityID() + "/");
        }
    } catch (URISyntaxException e) {
        e.printStackTrace();
        return null;
    }
    log.info("Attempting to store in: " + baseUri);

    // Pick a name for the object.
    String name = dob.getTitle();
    if (name == null || "".equals(name)) {
        UUID randomSequence = UUID.randomUUID();
        name = exp.getExperimentSetup().getBasicProperties().getExperimentName() + "-" + randomSequence
                + ".digitalObject";
    }

    // look at the location and pick a unique name.
    URI dobUri;
    try {
        dobUri = new URI(baseUri.getScheme(), baseUri.getUserInfo(), baseUri.getHost(), baseUri.getPort(),
                baseUri.getPath() + name, null, null);
    } catch (URISyntaxException e1) {
        e1.printStackTrace();
        return null;
    }
    log.info("Calling Data Registry List for " + baseUri);
    List<URI> storedDobs = dataReg.list(baseUri);
    if (storedDobs != null) {
        int unum = 1;
        while (storedDobs.contains(dobUri)) {
            try {
                dobUri = new URI(baseUri.getScheme(), baseUri.getUserInfo(), baseUri.getHost(),
                        baseUri.getPort(), baseUri.getPath() + unum + "-" + name, null, null);
            } catch (URISyntaxException e) {
                e.printStackTrace();
                return null;
            }
            unum++;
        }
    }

    log.info("Attempting to store at: " + dobUri);

    try {
        dobUri = this.storeDigitalObject(dobUri, dob);
    } catch (DigitalObjectNotStoredException e) {
        log.error("Store failed! " + e);
        e.printStackTrace();
        return null;
    }

    log.info("Was store at: " + dobUri);

    return dobUri;
}

From source file:org.apache.solr.update.InvenioKeepRecidUpdated.java

private void runProcessing(SolrCore core, String handlerUrl, int[] recids, SolrQueryRequest req)
        throws MalformedURLException, IOException, InterruptedException {

    URI u = null;/*from  w  w w  . ja  v a 2 s  .  co  m*/
    SolrRequestHandler handler = null;
    try {
        u = new URI(handlerUrl);
        String p = u.getPath();
        if (u.getHost() == null || u.getHost() == "") {
            if (core.getRequestHandler(p) != null) {
                handler = core.getRequestHandler(p);
            } else if (!p.startsWith("/") && core.getRequestHandler("/" + p) != null) {
                handler = core.getRequestHandler("/" + p);
            }

            if (handler != null) {
                Map<String, List<String>> handlerParams = WebUtils.parseQuery(u.getQuery());
                HashMap<String, String[]> hParams = new HashMap<String, String[]>();
                for (String val : handlerParams.keySet()) {
                    String[] nV = new String[handlerParams.get(val).size()];
                    int i = 0;
                    for (String v : handlerParams.get(val)) {
                        nV[i] = v;
                        i++;
                    }
                    hParams.put(val, nV);
                }

                runProcessingInternally(handler, recids, req, hParams);
                return;
            }
        }
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    runProcessingUpload(handlerUrl, recids, req);
}

From source file:org.openecomp.sdc.asdctool.impl.DataMigration.java

private boolean initEsClient() {
    String configHome = System.getProperty("config.home");
    URL url = null;/*from   w  ww  .j a  v a  2  s.com*/
    Settings settings = null;
    try {
        if (SystemUtils.IS_OS_WINDOWS) {
            url = new URL("file:///" + configHome + "/elasticsearch.yml");
        } else {
            url = new URL("file:" + configHome + "/elasticsearch.yml");
        }
        log.debug("URL {}", url);
        settings = Settings.settingsBuilder().loadFromPath(Paths.get(url.toURI())).build();
    } catch (MalformedURLException | URISyntaxException e1) {
        log.error("Failed to create URL in order to load elasticsearch yml", e1);
        return true;
    }

    this.elasticSearchClient = new ElasticSearchClient();
    this.elasticSearchClient.setClusterName(settings.get("cluster.name"));
    this.elasticSearchClient.setLocal(settings.get("elasticSearch.local"));
    this.elasticSearchClient.setTransportClient(settings.get("elasticSearch.transportclient"));
    try {
        elasticSearchClient.initialize();
    } catch (URISyntaxException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:com.pearson.dashboard.util.Util.java

private static void retrieveDefects(Map<String, List<Defect>> allDefects, RallyRestApi restApi,
        String projectId, String typeCategory, String releaseNum, String cutoffDate, String comparisonOperator,
        Configuration configuration, String operatingSystem) throws IOException, ParseException {
    List<Defect> defects;/* w w  w. j  a  va2 s .c om*/
    QueryFilter queryFilter;
    QueryRequest defectRequest;
    QueryResponse projectDefects;
    JsonArray defectsArray;
    defects = new ArrayList<Defect>();

    QueryFilter releaseQueryFilter = null;
    if (null != releaseNum) {
        String releases[] = releaseNum.split(",");
        releaseQueryFilter = new QueryFilter("Release.Name", "=", releases[0]);
        for (int r = 1; r < releases.length; r++) {
            releaseQueryFilter = releaseQueryFilter.or(new QueryFilter("Release.Name", "=", releases[r]));
        }
    }
    if (null != releaseQueryFilter) {
        queryFilter = new QueryFilter("State", "=", typeCategory).and(releaseQueryFilter);
    } else {
        queryFilter = new QueryFilter("State", "=", typeCategory);
    }
    if (null != cutoffDate) {
        queryFilter = queryFilter.and(new QueryFilter("CreationDate", comparisonOperator, cutoffDate));
    }
    defectRequest = new QueryRequest("defects");
    defectRequest.setQueryFilter(queryFilter);
    defectRequest.setFetch(new Fetch("State", "Release", "Name", "FormattedID", "Platform", "Priority",
            "Components", "LastUpdateDate", "SubmittedBy", "Owner", "Project", "ClosedDate"));
    defectRequest.setProject("/project/" + projectId);
    defectRequest.setScopedDown(true);
    defectRequest.setScopedDown(true);
    defectRequest.setLimit(2000);
    defectRequest.setOrder("FormattedID desc");
    boolean dataNotReceived = true;
    while (dataNotReceived) {
        try {
            projectDefects = restApi.query(defectRequest);
            dataNotReceived = false;
            defectsArray = projectDefects.getResults();
            for (int i = 0; i < defectsArray.size(); i++) {
                JsonElement elements = defectsArray.get(i);
                JsonObject object = elements.getAsJsonObject();
                //if(!object.get("Release").isJsonNull()) 
                {
                    Defect defect = new Defect();
                    defect.setDefectId(object.get("FormattedID").getAsString());

                    if (null != object.get("_ref")) {
                        String defectRef = object.get("_ref").getAsString();
                        if (null != defectRef) {
                            String url = configuration.getRallyURL() + "#/" + projectId + "ud/detail/defect"
                                    + defectRef.substring(defectRef.lastIndexOf("/"));
                            defect.setDefectUrl(url);
                        }
                    }

                    String strFormat1 = object.get("LastUpdateDate").getAsString().substring(0, 10);
                    DateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");
                    Date date = (Date) formatter1.parse(strFormat1);
                    DateFormat formatter2 = new SimpleDateFormat("MMM dd YY");
                    defect.setLastUpdateDate(formatter2.format(date));

                    defect.setLastUpdateDateOriginal(
                            object.get("LastUpdateDate").getAsString().substring(0, 10));

                    if (null != object.get("Priority") && !object.get("Priority").toString().isEmpty()
                            && !object.get("Priority").getAsString().startsWith("No")) {
                        defect.setPriority("P" + object.get("Priority").getAsString().charAt(0));
                    } else {
                        defect.setPriority("TBD");
                    }
                    defect.setState(object.get("State").getAsString());
                    JsonObject project = object.get("Project").getAsJsonObject();
                    defect.setProject(project.get("_refObjectName").getAsString());
                    defect.setDefectDesc(object.get("Name").getAsString());
                    String platform = "iOS";
                    if (null != object.get("c_Platform")) {
                        if (object.get("c_Platform").getAsString().contains("iOS")
                                && object.get("c_Platform").getAsString().contains("Win")) {
                            platform = "iOS";
                        } else if (object.get("c_Platform").getAsString().startsWith("iOS")) {
                            platform = "iOS";
                        } else if (object.get("c_Platform").getAsString().startsWith("Win")) {
                            platform = "Windows";
                        }
                    }
                    defect.setPlatform(platform);
                    defect.setComponents(object.get("c_Components").getAsString());
                    if (platform.equalsIgnoreCase(operatingSystem) || operatingSystem.equalsIgnoreCase("All")) {
                        defects.add(defect);
                    }
                }
            }
            List<Defect> olderDefects = allDefects.get(typeCategory);
            if (null == olderDefects) {
                olderDefects = new ArrayList<Defect>();
            }
            olderDefects.addAll(defects);
            Collections.sort(olderDefects);
            allDefects.put(typeCategory, olderDefects);
        } catch (HttpHostConnectException connectException) {
            if (null != restApi) {
                restApi.close();
            }
            try {
                restApi = loginRally(configuration);
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.fratello.longevity.smooth.AppGUI.java

private void openWebPage(String urlName) {
    try {//ww  w  .  ja v  a2 s.  co  m
        URL u = new URL(urlName);
        Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
        if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE))
            desktop.browse(u.toURI());
    } catch (IOException e) {
        e.printStackTrace();
    } catch (URISyntaxException e2) {
        e2.printStackTrace();
    }
}

From source file:com.yahoo.semsearch.fastlinking.io.ExtractWikipediaAnchorText.java

/**
 * Extracts CF for each found anchor.//from w  ww  .j  av  a2s  .com
 *
 * @param inputPath
 * @param mapPath
 * @param outputPath
 * @throws IOException
 */
private void task3(String inputPath, String mapPath, String outputPath) throws IOException {
    LOG.info("Extracting anchor text (phase 3)...");
    LOG.info(" - input:   " + inputPath);
    LOG.info(" - output:  " + outputPath);
    LOG.info(" - mapping: " + mapPath);

    JobConf conf = new JobConf(getConf(), ExtractWikipediaAnchorText.class);
    conf.setJobName(
            String.format("ExtractWikipediaAnchorText:phase3[input: %s, output: %s]", inputPath, outputPath));

    conf.setNumReduceTasks(1);
    String location = "map.dat";

    try {
        DistributedCache.addCacheFile(new URI(mapPath + "/part-00000/data" + "#" + location), conf);
        //DistributedCache.addCacheFile(new URI(mapPath + "/singleentitymap.data" + "#" + location), conf);
        DistributedCache.createSymlink(conf);
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    FileInputFormat.addInputPath(conf, new Path(inputPath));
    FileOutputFormat.setOutputPath(conf, new Path(outputPath));

    conf.setInputFormat(SequenceFileInputFormat.class);
    conf.setOutputFormat(MapFileOutputFormat.class);
    // conf.setOutputFormat(TextOutputFormat.class);

    conf.setMapOutputKeyClass(Text.class);
    conf.setMapOutputValueClass(IntWritable.class);

    conf.setOutputKeyClass(Text.class);
    conf.setOutputValueClass(IntWritable.class);

    conf.setMapperClass(MyMapper3.class);
    conf.setCombinerClass(MyReducer3.class);
    conf.setReducerClass(MyReducer3.class);

    JobClient.runJob(conf);
}

From source file:com.pearson.dashboard.util.Util.java

public static void retrieveTestCases(DashboardForm dashboardForm, Configuration configuration,
        String cutoffDate) throws IOException, URISyntaxException {
    RallyRestApi restApi = loginRally(configuration);
    List<TestCase> testCases = new ArrayList<TestCase>();
    QueryFilter queryFilter = new QueryFilter("CreationDate", ">=", cutoffDate)
            .and(new QueryFilter("Type", "=", "Regression"));
    QueryRequest defectRequest = new QueryRequest("testcases");
    defectRequest.setQueryFilter(queryFilter);
    defectRequest.setFetch(//from ww  w. ja v  a 2s  .  com
            new Fetch("FormattedID", "LastVerdict", "Name", "Description", "LastRun", "LastBuild", "Priority"));
    defectRequest.setProject("/project/" + dashboardForm.getProjectId());
    defectRequest.setScopedDown(true);
    defectRequest.setLimit(10000);
    defectRequest.setOrder("FormattedID desc");
    boolean dataNotReceived = true;
    while (dataNotReceived) {
        try {
            QueryResponse projectDefects = restApi.query(defectRequest);
            JsonArray defectsArray = projectDefects.getResults();
            dataNotReceived = false;

            for (int i = 0; i < defectsArray.size(); i++) {
                TestCase testCase = new TestCase();
                JsonElement elements = defectsArray.get(i);
                JsonObject object = elements.getAsJsonObject();
                testCase.setTestCaseId(object.get("FormattedID").getAsString());
                testCase.setLastVerdict(
                        object.get("LastVerdict") == null || object.get("LastVerdict").isJsonNull() ? ""
                                : object.get("LastVerdict").getAsString());
                testCase.setName(object.get("Name") == null || object.get("Name").isJsonNull() ? ""
                        : object.get("Name").getAsString());
                testCase.setDescription(
                        object.get("Description") == null || object.get("Description").isJsonNull() ? ""
                                : object.get("Description").getAsString());
                testCase.setLastRun(object.get("LastRun") == null || object.get("LastRun").isJsonNull() ? ""
                        : object.get("LastRun").getAsString());
                testCase.setLastBuild(
                        object.get("LastBuild") == null || object.get("LastBuild").isJsonNull() ? ""
                                : object.get("LastBuild").getAsString());
                testCase.setPriority(object.get("Priority") == null || object.get("Priority").isJsonNull() ? ""
                        : object.get("Priority").getAsString());
                testCases.add(testCase);
            }
            dashboardForm.setTestCases(testCases);
            restApi.close();

            List<Priority> priorities = new ArrayList<Priority>();
            Priority priority0 = new Priority();
            priority0.setPriorityName("Pass");
            Priority priority1 = new Priority();
            priority1.setPriorityName("Blocked");
            Priority priority2 = new Priority();
            priority2.setPriorityName("Error");
            Priority priority3 = new Priority();
            priority3.setPriorityName("Fail");
            Priority priority4 = new Priority();
            priority4.setPriorityName("Inconclusive");
            Priority priority5 = new Priority();
            priority5.setPriorityName("NotAttempted");
            if (null != testCases) {
                for (TestCase testCase : testCases) {
                    if (testCase.getLastVerdict().equalsIgnoreCase("Pass")) {
                        priority0.setPriorityCount(priority0.getPriorityCount() + 1);
                    }
                    if (testCase.getLastVerdict().equalsIgnoreCase("Blocked")) {
                        priority1.setPriorityCount(priority1.getPriorityCount() + 1);
                    }
                    if (testCase.getLastVerdict().equalsIgnoreCase("Error")) {
                        priority2.setPriorityCount(priority2.getPriorityCount() + 1);
                    }
                    if (testCase.getLastVerdict().equalsIgnoreCase("Fail")) {
                        priority3.setPriorityCount(priority3.getPriorityCount() + 1);
                    }
                    if (testCase.getLastVerdict().equalsIgnoreCase("Inconclusive")) {
                        priority4.setPriorityCount(priority4.getPriorityCount() + 1);
                    }
                    if (testCase.getLastVerdict().equalsIgnoreCase("")) {
                        priority5.setPriorityCount(priority5.getPriorityCount() + 1);
                    }
                }
            }
            List<Integer> arrayList = new ArrayList<Integer>();
            arrayList.add(priority0.getPriorityCount());
            arrayList.add(priority1.getPriorityCount());
            arrayList.add(priority2.getPriorityCount());
            arrayList.add(priority3.getPriorityCount());
            arrayList.add(priority4.getPriorityCount());
            arrayList.add(priority5.getPriorityCount());
            Integer maximumCount = Collections.max(arrayList);
            if (maximumCount <= 0) {
                priority0.setPxSize("0");
                priority1.setPxSize("0");
                priority2.setPxSize("0");
                priority3.setPxSize("0");
                priority4.setPxSize("0");
                priority5.setPxSize("0");
            } else {
                priority0.setPxSize(Math.round((100 * priority0.getPriorityCount()) / maximumCount) + "");
                priority1.setPxSize(Math.round((100 * priority1.getPriorityCount()) / maximumCount) + "");
                priority2.setPxSize(Math.round((100 * priority2.getPriorityCount()) / maximumCount) + "");
                priority3.setPxSize(Math.round((100 * priority3.getPriorityCount()) / maximumCount) + "");
                priority4.setPxSize(Math.round((100 * priority4.getPriorityCount()) / maximumCount) + "");
                priority5.setPxSize(Math.round((100 * priority5.getPriorityCount()) / maximumCount) + "");
            }
            priorities.add(priority0);
            priorities.add(priority1);
            priorities.add(priority2);
            priorities.add(priority3);
            priorities.add(priority4);
            priorities.add(priority5);

            dashboardForm.setTestCasesCount(testCases.size());
            dashboardForm.setTestCasesPriorities(priorities);
        } catch (HttpHostConnectException connectException) {
            if (restApi != null) {
                restApi.close();
            }
            try {
                restApi = loginRally(configuration);
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.jaspersoft.studio.utils.jasper.JasperReportsConfiguration.java

protected DefaultRepositoryService getLocalRepositoryService() {
    if (localRepositoryService == null) {
        localRepositoryService = new DefaultRepositoryService(this) {
            @Override//from   w  ww .  ja  v  a  2 s  .  co m
            public InputStream getInputStream(String uri) {
                try {
                    URL url = JRResourcesUtil.createURL(uri, urlHandlerFactory);
                    if (url != null) {
                        if (url.getProtocol().toLowerCase().equals("http")
                                || url.getProtocol().toLowerCase().equals("https")) {
                            try {
                                URI uuri = url.toURI();
                                Executor exec = Executor.newInstance();
                                HttpUtils.setupProxy(exec, uuri);

                                Request req = Request.Get("http://somehost/");
                                HttpUtils.setupProxy(exec, uuri, req);
                                return exec.execute(req).returnContent().asStream();
                            } catch (URISyntaxException e) {
                                e.printStackTrace();
                            } catch (ClientProtocolException e) {
                                new JRException(JRLoader.EXCEPTION_MESSAGE_KEY_INPUT_STREAM_FROM_URL_OPEN_ERROR,
                                        new Object[] { url }, e);
                            } catch (IOException e) {
                                new JRException(JRLoader.EXCEPTION_MESSAGE_KEY_INPUT_STREAM_FROM_URL_OPEN_ERROR,
                                        new Object[] { url }, e);
                            }

                        }
                        return JRLoader.getInputStream(url);
                    }

                    File file = JRResourcesUtil.resolveFile(uri, fileResolver);
                    if (file != null) {
                        return JRLoader.getInputStream(file);
                    }

                    url = JRResourcesUtil.findClassLoaderResource(uri, classLoader);
                    if (url != null) {
                        return JRLoader.getInputStream(url);
                    }
                } catch (JRException e) {
                    throw new JRRuntimeException(e);
                }

                return null;
            }
        };
    }
    return localRepositoryService;
}

From source file:com.yahoo.semsearch.fastlinking.io.ExtractWikipediaAnchorText.java

/**
 *
 * Maps from (srcID, (targetID, anchor) to (targetID, (anchor, count)).
 *
 * @param inputPath//from  w w  w .j  a va 2s.c o  m
 * @param outputPath
 * @throws IOException
 */
private void task2(String inputPath, String outputPath, String redirPath) throws IOException {
    LOG.info("Extracting anchor text (phase 2)...");
    LOG.info(" - input: " + inputPath);
    LOG.info(" - output: " + outputPath);
    Random r = new Random();
    //String tmpOutput = "tmp-" + this.getClass().getCanonicalName() + "-" + r.nextInt(10000);
    //LOG.info( "intermediate folder for merge " + tmpOutput );

    JobConf conf = new JobConf(getConf(), ExtractWikipediaAnchorText.class);
    conf.setJobName(
            String.format("ExtractWikipediaAnchorText:phase2[input: %s, output: %s]", inputPath, outputPath));

    // Gathers everything together for convenience; feasible for Wikipedia.
    conf.setNumReduceTasks(1);

    try {
        DistributedCache.addCacheFile(new URI(redirPath + "/part-00000" + "#" + "redirs.dat"), conf);
        DistributedCache.createSymlink(conf);
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    FileInputFormat.addInputPath(conf, new Path(inputPath));
    FileOutputFormat.setOutputPath(conf, new Path(outputPath));
    //FileOutputFormat.setOutputPath(conf, new Path(tmpOutput));

    conf.setInputFormat(SequenceFileInputFormat.class);
    conf.setOutputFormat(MapFileOutputFormat.class);
    // conf.setOutputFormat(TextOutputFormat.class);

    conf.setMapOutputKeyClass(Text.class);
    conf.setMapOutputValueClass(Text.class);

    conf.setOutputKeyClass(Text.class);
    conf.setOutputValueClass(HMapSIW.class);

    conf.setMapperClass(MyMapper2.class);
    conf.setReducerClass(MyReducer2.class);

    // Delete the output directory if it exists already.
    FileSystem.get(conf).delete(new Path(outputPath), true);

    JobClient.runJob(conf);
    // Clean up intermediate data.
    FileSystem.get(conf).delete(new Path(inputPath), true);

    /*
    //merge
    String finalO = outputPath+"/part-00000/data";
    FileSystem.get(conf).mkdirs( new Path( outputPath + "part-00000") );
    getMergeInHdfs( tmpOutput, finalO, conf );
    FileSystem.get(conf).delete(new Path(tmpOutput), true);
    */
}