Example usage for java.net MalformedURLException getMessage

List of usage examples for java.net MalformedURLException getMessage

Introduction

In this page you can find the example usage for java.net MalformedURLException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:sft.LoginAndBookSFT.java

public void startBooking() throws URISyntaxException, MalformedURLException, ProtocolException, IOException {
    final BasicCookieStore cookieStore = new BasicCookieStore();
    final CloseableHttpClient httpclient = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
    try {/*from ww  w .ja va  2  s. com*/
        // get cookie
        final HttpGet httpget = new HttpGet("https://sft.ticketack.com");
        final CloseableHttpResponse response1 = httpclient.execute(httpget);
        try {
            final HttpEntity entity = response1.getEntity();

            System.out.println("Login form get: " + response1.getStatusLine());
            EntityUtils.consume(entity);

            System.out.println("Initial set of cookies:");
            final List<Cookie> _cookies = cookieStore.getCookies();
            if (_cookies.isEmpty()) {
                System.out.println("None");
            } else {
                for (int i = 0; i < _cookies.size(); i++) {
                    System.out.println("- " + _cookies.get(i).toString());
                }
            }
        } finally {
            response1.close();
        }

        // login
        final HttpUriRequest login = RequestBuilder.post()
                .setUri(new URI("https://sft.ticketack.com/ticket/view/"))
                .addParameter("ticket_number", username).addParameter("ticket_key", password).build();
        final CloseableHttpResponse response2 = httpclient.execute(login);
        try {
            final HttpEntity entity = response2.getEntity();

            System.out.println("Login form get: " + response2.getStatusLine());
            EntityUtils.consume(entity);

            System.out.println("Post logon cookies:");
            final List<Cookie> cookies = cookieStore.getCookies();
            if (cookies.isEmpty()) {
                System.out.println("None");
            } else {
                for (int i = 0; i < cookies.size(); i++) {
                    // System.out.println("- " + cookies.get(i).toString());
                }
            }
        } finally {
            response2.close();
        }
    } finally {
        httpclient.close();
    }

    final Cookie _cookie = cookieStore.getCookies().get(0);
    final String mightyCooke = "PHPSESSID=" + _cookie.getValue();

    for (final String _booking : bookings) {

        // get free seatings
        // json https://sft.ticketack.com/screening/infos_json/02c101f9-c62a-445e-ad72-19fb32db34c0
        final String _json = doGet(mightyCooke, _booking, "https://sft.ticketack.com/screening/infos_json/");

        final Gson gson = new Gson();
        final Example _allInfos = gson.fromJson(_json, Example.class);

        if (_allInfos.getCinemaHall().getMap() != null) {

            final String _mySeat = getMeAFreeSeat(_json);

            // book on seating
            // 02c101f9-c62a-445e-ad72-19fb32db34c0?format=json&overbook=false&seat=Parkett%20Rechts:1:16
            try {
                if (_mySeat != null)
                    doGet(mightyCooke,
                            _booking + "?format=json&overbook=true&seat=" + URLEncoder.encode(_mySeat, "UTF-8"),
                            "https://sft.ticketack.com/screening/book_on_ticket/");
            } catch (final MalformedURLException exception) {
                System.err.println("Error: " + exception.getMessage());
            } catch (final ProtocolException exception) {
                System.err.println("Error: " + exception.getMessage());
            } catch (final UnsupportedEncodingException exception) {
                System.err.println("Error: " + exception.getMessage());
            } catch (final IOException exception) {
                System.err.println("Error: " + exception.getMessage());
            }
            System.out.println("booking (seat) done for: " + _booking);

        } else {

            // book
            // https://sft.ticketack.com/screening/book_on_ticket/76c039cc-d1d5-40a1-9a5d-2b1cd4c47799
            // Cookie:PHPSESSID=s1a6a8casfhidfq68tqn2cb565
            doGet(mightyCooke, _booking, "https://sft.ticketack.com/screening/book_on_ticket/");
            System.out.println("booking done for: " + _booking);
        }

    }

    System.out.println("All done!");

}

From source file:ch.entwine.weblounge.bridge.oaipmh.WebloungeHarvester.java

/**
 * {@inheritDoc}//from   w  ww.  ja  va 2s.c  o m
 * 
 * @see ch.entwine.weblounge.common.scheduler.JobWorker#execute(java.lang.String,
 *      java.util.Dictionary)
 */
@SuppressWarnings("unchecked")
public void execute(String name, Dictionary<String, Serializable> ctx) throws JobException {

    Site site = (Site) ctx.get(Site.class.getName());

    // Get hold of the content repository
    WritableContentRepository contentRepository = null;
    if (site.getContentRepository().isReadOnly())
        throw new JobException(this, "Content repository of site '" + site + "' is read only");
    contentRepository = (WritableContentRepository) site.getContentRepository();

    // Read the configuration value for the repository url
    String repositoryUrl = (String) ctx.get(OPT_REPOSITORY_URL);
    if (StringUtils.isBlank(repositoryUrl))
        throw new JobException(this,
                "Configuration option '" + OPT_REPOSITORY_URL + "' is missing from the job configuration");

    // Make sure the url is well formed
    URL url = null;
    try {
        url = new URL(repositoryUrl);
    } catch (MalformedURLException e) {
        throw new JobException(this, "Repository url '" + repositoryUrl + "' is malformed: " + e.getMessage());
    }

    // Read the configuration value for the flavors
    String presentationTrackFlavor = (String) ctx.get(OPT_PRSENTATION_TRACK_FLAVORS);
    if (StringUtils.isBlank(presentationTrackFlavor))
        throw new JobException(this, "Configuration option '" + OPT_PRSENTATION_TRACK_FLAVORS
                + "' is missing from the job configuration");

    String presenterTrackFlavor = (String) ctx.get(OPT_PRESENTER_TRACK_FLAVORS);
    if (StringUtils.isBlank(presenterTrackFlavor))
        throw new JobException(this, "Configuration option '" + OPT_PRESENTER_TRACK_FLAVORS
                + "' is missing from the job configuration");

    String dcEpisodeFlavor = (String) ctx.get(OPT_EPISODE_DC_FLAVORS);
    if (StringUtils.isBlank(dcEpisodeFlavor))
        throw new JobException(this,
                "Configuration option '" + OPT_EPISODE_DC_FLAVORS + "' is missing from the job configuration");

    String dcSeriesFlavor = (String) ctx.get(OPT_SERIES_DC_FLAVORS);
    if (StringUtils.isBlank(dcSeriesFlavor))
        throw new JobException(this,
                "Configuration option '" + OPT_SERIES_DC_FLAVORS + "' is missing from the job configuration");

    String mimesTypes = (String) ctx.get(OPT_MIMETYPES);
    if (StringUtils.isBlank(mimesTypes))
        throw new JobException(this,
                "Configuration option '" + OPT_MIMETYPES + "' is missing from the job configuration");

    // Read the configuration value for the handler class
    String handlerClass = (String) ctx.get(OPT_HANDLER_CLASS);
    if (StringUtils.isBlank(handlerClass))
        throw new JobException(this,
                "Configuration option '" + OPT_HANDLER_CLASS + "' is missing from the job configuration");

    UserImpl harvesterUser = new UserImpl(name, site.getIdentifier(), "Harvester");

    RecordHandler handler;
    try {
        Class<? extends AbstractWebloungeRecordHandler> c = (Class<? extends AbstractWebloungeRecordHandler>) Thread
                .currentThread().getContextClassLoader().loadClass(handlerClass);
        Class<?> paramTypes[] = new Class[8];
        paramTypes[0] = Site.class;
        paramTypes[1] = WritableContentRepository.class;
        paramTypes[2] = User.class;
        paramTypes[3] = String.class;
        paramTypes[4] = String.class;
        paramTypes[5] = String.class;
        paramTypes[6] = String.class;
        paramTypes[7] = String.class;
        Constructor<? extends AbstractWebloungeRecordHandler> constructor = c.getConstructor(paramTypes);
        Object arglist[] = new Object[8];
        arglist[0] = site;
        arglist[1] = contentRepository;
        arglist[2] = harvesterUser;
        arglist[3] = presentationTrackFlavor;
        arglist[4] = presenterTrackFlavor;
        arglist[5] = dcEpisodeFlavor;
        arglist[6] = dcSeriesFlavor;
        arglist[7] = mimesTypes;
        handler = constructor.newInstance(arglist);
    } catch (Throwable t) {
        throw new IllegalStateException("Unable to instantiate class " + handlerClass + ": " + t.getMessage(),
                t);
    }

    SearchResult searchResult;
    SearchQuery q = new SearchQueryImpl(site);
    q.withTypes(MovieResource.TYPE);
    q.sortByPublishingDate(Order.Descending);
    q.withPublisher(harvesterUser);
    try {
        searchResult = contentRepository.find(q);
    } catch (ContentRepositoryException e) {
        logger.error("Error searching for resources with harvester publisher.");
        throw new RuntimeException(e);
    }

    Option<Date> harvestingDate = Option.<Date>none();
    if (searchResult.getHitCount() > 0) {
        MovieResourceSearchResultItemImpl resultItem = (MovieResourceSearchResultItemImpl) searchResult
                .getItems()[0];
        Date lastDate = resultItem.getMovieResource().getPublishFrom();
        // To not include the resources updated, 1 second is added to the last
        // update date
        lastDate.setTime(lastDate.getTime() + 1000);
        harvestingDate = some(lastDate);
    }

    try {
        harvest(repositoryUrl, harvestingDate, handler);
    } catch (Exception e) {
        logger.warn("An error occured while harvesting " + url + ". Skipping this repository for now...",
                e.getMessage());

    }
}

From source file:es.tekniker.framework.ktek.questionnaire.mng.server.EventServiceClient.java

private HttpURLConnection getEventServiceSEConnection(String method, String service, String contentType) {
    HttpURLConnection conn = null;
    URL url = null;/*www  .j  a  v a  2  s .c om*/

    String urlStr = protocol + "://" + service + method;
    log.debug(urlStr);

    try {
        url = new URL(urlStr);
        conn = (HttpURLConnection) url.openConnection();
        conn.setDoOutput(true);
        conn.setRequestMethod(methodPOST);
        conn.setRequestProperty(headerContentType, contentType);
        conn.setRequestProperty(headerAuthorization, headerAuthorizationOAuth + " " + headerToken);
        conn.setConnectTimeout(timeout);

        log.debug(headerContentType + " " + contentType);

        log.debug(headerAuthorizationOAuth + " " + headerToken);

    } catch (MalformedURLException e) {
        log.error("MalformedURLException " + e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        log.error("IOException " + e.getMessage());
        e.printStackTrace();
    }

    return conn;
}

From source file:net.orpiske.sdm.engine.GroovyEngine.java

public void run(final File file, String... phases) throws EngineException {
    long total = 0;

    GroovyObject groovyObject = getObject(file);

    Object url = groovyObject.getProperty("url");

    if (phases.length == 0) {
        return;// w  w w  .j  a v a  2 s.com
    }

    if (ArrayUtils.contains(phases, "fetch")) {
        total += runPhase(groovyObject, "fetch", url);
    }

    String artifactName = null;

    try {
        if (url != null && !url.toString().isEmpty()) {
            artifactName = URLUtils.getFilename(url.toString());
            artifactName = WorkdirUtils.getWorkDir() + File.separator + artifactName;
        }

    } catch (MalformedURLException e) {
        String urlString = url.toString();
        if (!ScmUrlUtils.isValid(urlString)) {
            throw new EngineException("The package URL is invalid: " + e.getMessage(), e);
        }

    } catch (URISyntaxException e) {
        throw new EngineException("The URL syntax is invalid: " + e.getMessage(), e);
    }

    if (ArrayUtils.contains(phases, "extract")) {
        total += runPhase(groovyObject, "extract", artifactName);
    }

    if (ArrayUtils.contains(phases, "build")) {
        total += runPhase(groovyObject, "build", (Object[]) null);
    }

    if (ArrayUtils.contains(phases, "verify")) {
        total += runPhase(groovyObject, "verify", (Object[]) null);
    }

    if (ArrayUtils.contains(phases, "prepare")) {
        total += runPhase(groovyObject, "prepare", (Object[]) null);
    }

    if (ArrayUtils.contains(phases, "install")) {
        total += runPhase(groovyObject, "install", (Object[]) null);
    }

    if (ArrayUtils.contains(phases, "finish")) {
        total += runPhase(groovyObject, "finish", (Object[]) null);
    }

    if (ArrayUtils.contains(phases, "cleanup")) {
        total += runPhase(groovyObject, "cleanup", (Object[]) null);
    }

    printPhaseHeader("install completed");
    logger.info("Installation completed in " + total + " ms");
}

From source file:com.sonymobile.tools.gerrit.gerritevents.workers.rest.AbstractRestCommandJob.java

@Override
public void run() {
    ReviewInput reviewInput = createReview();

    String reviewEndpoint = resolveEndpointURL();

    HttpPost httpPost = createHttpPostEntity(reviewInput, reviewEndpoint);

    if (httpPost == null) {
        return;/*from  ww w.j  av  a 2  s  . com*/
    }

    DefaultHttpClient httpclient = new DefaultHttpClient();
    httpclient.getCredentialsProvider().setCredentials(new AuthScope(null, -1), config.getHttpCredentials());
    if (config.getGerritProxy() != null && !config.getGerritProxy().isEmpty()) {
        try {
            URL url = new URL(config.getGerritProxy());
            HttpHost proxy = new HttpHost(url.getHost(), url.getPort(), url.getProtocol());
            httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        } catch (MalformedURLException e) {
            logger.error("Could not parse proxy URL, attempting without proxy.", e);
            if (altLogger != null) {
                altLogger.print("ERROR Could not parse proxy URL, attempting without proxy. " + e.getMessage());
            }
        }
    }
    try {
        HttpResponse httpResponse = httpclient.execute(httpPost);
        String response = IOUtils.toString(httpResponse.getEntity().getContent(), "UTF-8");

        if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            logger.error("Gerrit response: {}", httpResponse.getStatusLine().getReasonPhrase());
            if (altLogger != null) {
                altLogger.print("ERROR Gerrit response: " + httpResponse.getStatusLine().getReasonPhrase());
            }
        }
    } catch (Exception e) {
        logger.error("Failed to submit result to Gerrit", e);
        if (altLogger != null) {
            altLogger.print("ERROR Failed to submit result to Gerrit" + e.toString());
        }
    }
}

From source file:eu.scidipes.toolkits.pawebapp.web.validation.FormValidator.java

@Override
public void validate(final Object target, final Errors errors) {
    final Form form = (Form) target;

    rejectIfEmptyOrWhitespace(errors, "dataHolderType", DHT_REQ_ERR_CODE);
    rejectIfEmptyOrWhitespace(errors, "RILCPID", RILCPID_REQ_ERR_CODE);
    rejectIfEmptyOrWhitespace(errors, "itemFileName", ITEM_FILENAME_REQ_ERR_CODE);

    rejectIfEmptyOrWhitespace(errors, DATA_HOLDER_FIELD,
            form.getDataHolderType() == BYTESTREAM ? FILE_REQ_ERR_CODE : URI_REQ_ERR_CODE);

    if (!errors.hasFieldErrors(DATA_HOLDER_FIELD)) {

        final String dataHolder = errors.getFieldValue(DATA_HOLDER_FIELD).toString();
        boolean validURL = false;

        /* Check its a valid URI location (URL) */
        try {//  w  w  w  .  j  a  va  2  s .c  om
            new URL(dataHolder);
            validURL = true;

            /* URL is valid and type (URI) is correct so check length */
            if (form.getDataHolderType() == URI && dataHolder.length() > URL_MAX_LENGTH) {
                errors.rejectValue(DATA_HOLDER_FIELD, MAX_LENGTH_URI_ERR_CODE);
                LOG.debug("Rejected valid URL as length exceeds {}", Integer.valueOf(URL_MAX_LENGTH));
                return;
            }

        } catch (final MalformedURLException e) {
            /* Reject invalid URL if type is URI */
            if (form.getDataHolderType() == URI) {
                if (dataHolder.length() < URL_MAX_LENGTH) {
                    LOG.debug("Rejected invalid URL '{}' - reason: {}", dataHolder, e.getMessage());
                } else {
                    LOG.debug("Rejected invalid URL, length > {}", Integer.valueOf(URL_MAX_LENGTH));
                }
                errors.rejectValue(DATA_HOLDER_FIELD, INVALID_URI_ERR_CODE);
                return;
            }
        }

        if (form.getDataHolderType() == BYTESTREAM) {

            /* URL is valid but type is incorrect, probably due to previous value, so reject */
            if (validURL) {
                errors.rejectValue(DATA_HOLDER_FIELD, FILE_REQ_ERR_CODE);
                return;
            }

            /* Check the size does not exceed max (most likely caught before validation) */
            if (dataHolder != null && dataHolder.length() > maxUploadSize.longValue()) {
                errors.rejectValue(DATA_HOLDER_FIELD, MAX_UPLOAD_SIZE_ERR_CODE);
                return;
            }

        }
    }

}

From source file:AppearanceTest.java

public void init() {
    if (bgImage == null) {
        // the path to the image for an applet
        try {//from   ww  w.j  a v  a2  s  .c om
            bgImage = new java.net.URL(getCodeBase().toString() + "bg.jpg");
        } catch (java.net.MalformedURLException ex) {
            System.out.println(ex.getMessage());
            System.exit(1);
        }
    }

    if (texImage == null) {
        // the path to the image for an applet
        try {
            texImage = new java.net.URL(getCodeBase().toString() + "apimage.jpg");
        } catch (java.net.MalformedURLException ex) {
            System.out.println(ex.getMessage());
            System.exit(1);
        }
    }
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    Canvas3D c = new Canvas3D(config);
    add("Center", c);

    // Create a simple scene and attach it to the virtual universe
    BranchGroup scene = createSceneGraph();
    u = new SimpleUniverse(c);

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    u.getViewingPlatform().setNominalViewingTransform();

    u.addBranchGraph(scene);
}

From source file:org.apache.cxf.fediz.service.idp.beans.STSClientAction.java

public void setWsdlLocation(String wsdlLocation) {
    this.wsdlLocation = wsdlLocation;
    try {/*from w w  w. j a  v a 2s.c om*/
        URL url = new URL(wsdlLocation);
        isPortSet = url.getPort() > 0;
        if (!isPortSet) {
            LOG.info("Port is 0 for 'wsdlLocation'. Port evaluated when processing first request.");
        }
    } catch (MalformedURLException e) {
        LOG.error("Invalid Url '" + wsdlLocation + "': " + e.getMessage());
    }
}

From source file:com.twinsoft.convertigo.engine.util.RemoteAdmin.java

public RemoteAdmin(String serverBaseUrl, boolean bHttps, boolean bTrustAllCertificates)
        throws RemoteAdminException {
    this.serverBaseUrl = serverBaseUrl;
    this.bHttps = bHttps;
    this.bTrustAllCertificates = bTrustAllCertificates;
    this.httpClient = new HttpClient();

    try {//w  w  w.ja  va 2  s  .c  o m
        url = new URL("http" + (bHttps ? "s" : "") + "://" + serverBaseUrl);
        this.serverPort = url.getPort();
        this.host = url.getHost();

        if (serverPort == -1) {
            if (bHttps)
                serverPort = 443;
            else
                serverPort = 80;
        }
    } catch (MalformedURLException e) {
        throw new RemoteAdminException(
                "The Convertigo server is not valid: " + serverBaseUrl + "\n" + e.getMessage());
    }
}

From source file:com.wavemaker.runtime.service.WaveMakerService.java

private void proxyCheck(String remoteURL) throws WMRuntimeException {
    logger.debug("Checking: " + remoteURL);
    try {//from w w w  .ja v a 2 s  .c om
        String host = new URL(remoteURL).getHost();
        if (host != null && (hostSet.contains(new URL(remoteURL).getHost()))) {
            return;
        }
        String domain = hostToDomain(host);
        if (domain != null && (domainSet.contains(domain))) {
            return;
        }
        String referer = hostToDomain(
                new URL(RuntimeAccess.getInstance().getRequest().getHeader("referer")).getHost());
        if (referer != null && referer.equals(domain) && isStudio) {
            return;
        } else {
            throw new WMRuntimeException("Remote URL not allowed for Proxy call " + remoteURL);
        }
    } catch (MalformedURLException e) {
        logger.error("ERROR: " + e.getMessage() + remoteURL);
        throw new WMRuntimeException("Malformed URL " + remoteURL);
    }
}