/** * <p>Constructs a URL instance based on the specified URL string, taking into account the fact that the * specified URL string may represent an <tt>"about:..."</tt> URL, a <tt>"javascript:..."</tt> URL, or * a <tt>data:...</tt> URL.</p> * * <p>The caller should be sure that URL strings passed to this method will parse correctly as URLs, as * this method never expects to have to handle {@link MalformedURLException}s.</p> * * @param url the URL string to convert into a URL instance * @return the constructed URL instance */ public static URL toUrlSafe(final String url) { try { return toUrlUnsafe(url); } catch (final MalformedURLException e) { // Should never happen. throw new RuntimeException(e); } }
/** * <p>Constructs a URL instance based on the specified URL string, taking into account the fact that the * specified URL string may represent an <tt>"about:..."</tt> URL, a <tt>"javascript:..."</tt> URL, or * a <tt>data:...</tt> URL.</p> * * <p>The caller should be sure that URL strings passed to this method will parse correctly as URLs, as * this method never expects to have to handle {@link MalformedURLException}s.</p> * * @param url the URL string to convert into a URL instance * @return the constructed URL instance */ public static URL toUrlSafe(final String url) { try { return toUrlUnsafe(url); } catch (final MalformedURLException e) { // Should never happen. throw new RuntimeException(e); } }
/** * <p>Constructs a URL instance based on the specified URL string, taking into account the fact that the * specified URL string may represent an <tt>"about:..."</tt> URL, a <tt>"javascript:..."</tt> URL, or * a <tt>data:...</tt> URL.</p> * * <p>The caller should be sure that URL strings passed to this method will parse correctly as URLs, as * this method never expects to have to handle {@link MalformedURLException}s.</p> * * @param url the URL string to convert into a URL instance * @return the constructed URL instance */ public static URL toUrlSafe(final String url) { try { return toUrlUnsafe(url); } catch (final MalformedURLException e) { // Should never happen. throw new RuntimeException(e); } }
/** * <p>Constructs a URL instance based on the specified URL string, taking into account the fact that the * specified URL string may represent an <tt>"about:..."</tt> URL, a <tt>"javascript:..."</tt> URL, or * a <tt>data:...</tt> URL.</p> * * <p>The caller should be sure that URL strings passed to this method will parse correctly as URLs, as * this method never expects to have to handle {@link MalformedURLException}s.</p> * * @param url the URL string to convert into a URL instance * @return the constructed URL instance */ public static URL toUrlSafe(final String url) { try { return toUrlUnsafe(url); } catch (final MalformedURLException e) { // Should never happen. throw new RuntimeException(e); } }
/** * <p>Constructs a URL instance based on the specified URL string, taking into account the fact that the * specified URL string may represent an <tt>"about:..."</tt> URL, a <tt>"javascript:..."</tt> URL, or * a <tt>data:...</tt> URL.</p> * * <p>The caller should be sure that URL strings passed to this method will parse correctly as URLs, as * this method never expects to have to handle {@link MalformedURLException}s.</p> * * @param url the URL string to convert into a URL instance * @return the constructed URL instance */ public static URL toUrlSafe(final String url) { try { return toUrlUnsafe(url); } catch (final MalformedURLException e) { // Should never happen. throw new RuntimeException(e); } }
/** * Convenient method to build a URL and load it into the current WebWindow as it would be done * by {@link #getPage(WebWindow, WebRequest)}. * @param url the URL of the new content * @param <P> the page type * @return the new page * @throws FailingHttpStatusCodeException if the server returns a failing status code AND the property * {@link WebClientOptions#setThrowExceptionOnFailingStatusCode(boolean)} is set to true. * @throws IOException if an IO problem occurs * @throws MalformedURLException if no URL can be created from the provided string */ @SuppressWarnings("unchecked") public <P extends Page> P getPage(final String url) throws IOException, FailingHttpStatusCodeException, MalformedURLException { return (P) getPage(UrlUtils.toUrlUnsafe(url)); }
/** * Expands a relative URL relative to the specified base. In most situations * this is the same as <code>new URL(baseUrl, relativeUrl)</code> but * there are some cases that URL doesn't handle correctly. See * <a href="http://www.faqs.org/rfcs/rfc1808.html">RFC1808</a> * regarding Relative Uniform Resource Locators for more information. * * @param baseUrl the base URL * @param relativeUrl the relative URL * @return the expansion of the specified base and relative URLs * @throws MalformedURLException if an error occurred when creating a URL object */ public static URL expandUrl(final URL baseUrl, final String relativeUrl) throws MalformedURLException { final String newUrl = UrlUtils.resolveUrl(baseUrl, relativeUrl); return UrlUtils.toUrlUnsafe(newUrl); }
/** * Expands a relative URL relative to the specified base. In most situations * this is the same as <code>new URL(baseUrl, relativeUrl)</code> but * there are some cases that URL doesn't handle correctly. See * <a href="http://www.faqs.org/rfcs/rfc1808.html">RFC1808</a> * regarding Relative Uniform Resource Locators for more information. * * @param baseUrl the base URL * @param relativeUrl the relative URL * @return the expansion of the specified base and relative URLs * @throws MalformedURLException if an error occurred when creating a URL object */ public static URL expandUrl(final URL baseUrl, final String relativeUrl) throws MalformedURLException { final String newUrl = UrlUtils.resolveUrl(baseUrl, relativeUrl); return UrlUtils.toUrlUnsafe(newUrl); }
/** * Convenient method to build an URL and load it into the current WebWindow as it would be done * by {@link #getPage(WebWindow, WebRequestSettings)}. * @param url the URL of the new content * @param <P> the page type * @return the new page * @throws FailingHttpStatusCodeException if the server returns a failing status code AND the property * {@link #setThrowExceptionOnFailingStatusCode(boolean)} is set to true. * @throws IOException if an IO problem occurs * @throws MalformedURLException if no URL can be created from the provided string */ @SuppressWarnings("unchecked") public <P extends Page> P getPage(final String url) throws IOException, FailingHttpStatusCodeException, MalformedURLException { return (P) getPage(UrlUtils.toUrlUnsafe(url)); }
/** * Convenient method to build an URL and load it into the current WebWindow as it would be done * by {@link #getPage(WebWindow, WebRequestSettings)}. * @param url the URL of the new content * @param <P> the page type * @return the new page * @throws FailingHttpStatusCodeException if the server returns a failing status code AND the property * {@link #setThrowExceptionOnFailingStatusCode(boolean)} is set to true. * @throws IOException if an IO problem occurs * @throws MalformedURLException if no URL can be created from the provided string */ @SuppressWarnings("unchecked") public <P extends Page> P getPage(final String url) throws IOException, FailingHttpStatusCodeException, MalformedURLException { return (P) getPage(UrlUtils.toUrlUnsafe(url)); }
/** * Convenient method to build an URL and load it into the current WebWindow as it would be done * by {@link #getPage(WebWindow, WebRequestSettings)}. * @param url the URL of the new content * @param <P> the page type * @return the new page * @throws FailingHttpStatusCodeException if the server returns a failing status code AND the property * {@link #setThrowExceptionOnFailingStatusCode(boolean)} is set to true. * @throws IOException if an IO problem occurs * @throws MalformedURLException if no URL can be created from the provided string */ @SuppressWarnings("unchecked") public <P extends Page> P getPage(final String url) throws IOException, FailingHttpStatusCodeException, MalformedURLException { return (P) getPage(UrlUtils.toUrlUnsafe(url)); }
/** * Expands a relative URL relative to the specified base. In most situations * this is the same as <code>new URL(baseUrl, relativeUrl)</code> but * there are some cases that URL doesn't handle correctly. See * <a href="http://www.faqs.org/rfcs/rfc1808.html">RFC1808</a> * regarding Relative Uniform Resource Locators for more information. * * @param baseUrl the base URL * @param relativeUrl the relative URL * @return the expansion of the specified base and relative URLs * @throws MalformedURLException if an error occurred when creating a URL object */ public static URL expandUrl(final URL baseUrl, final String relativeUrl) throws MalformedURLException { final String newUrl = UrlUtils.resolveUrl(baseUrl, relativeUrl); return UrlUtils.toUrlUnsafe(newUrl); }
/** * Expands a relative URL relative to the specified base. In most situations * this is the same as <code>new URL(baseUrl, relativeUrl)</code> but * there are some cases that URL doesn't handle correctly. See * <a href="http://www.faqs.org/rfcs/rfc1808.html">RFC1808</a> * regarding Relative Uniform Resource Locators for more information. * * @param baseUrl the base URL * @param relativeUrl the relative URL * @return the expansion of the specified base and relative URLs * @throws MalformedURLException if an error occurred when creating a URL object */ public static URL expandUrl(final URL baseUrl, final String relativeUrl) throws MalformedURLException { final String newUrl = UrlUtils.resolveUrl(baseUrl, relativeUrl); return UrlUtils.toUrlUnsafe(newUrl); }
/** * Expands a relative URL relative to the specified base. In most situations * this is the same as <code>new URL(baseUrl, relativeUrl)</code> but * there are some cases that URL doesn't handle correctly. See * <a href="http://www.faqs.org/rfcs/rfc1808.html">RFC1808</a> * regarding Relative Uniform Resource Locators for more information. * * @param baseUrl the base URL * @param relativeUrl the relative URL * @return the expansion of the specified base and relative URLs * @throws MalformedURLException if an error occurred when creating a URL object */ public static URL expandUrl(final URL baseUrl, final String relativeUrl) throws MalformedURLException { final String newUrl = UrlUtils.resolveUrl(baseUrl, relativeUrl); return UrlUtils.toUrlUnsafe(newUrl); }
/** * Convenient method to build a URL and load it into the current WebWindow as it would be done * by {@link #getPage(WebWindow, WebRequest)}. * @param url the URL of the new content * @param <P> the page type * @return the new page * @throws FailingHttpStatusCodeException if the server returns a failing status code AND the property * {@link WebClientOptions#setThrowExceptionOnFailingStatusCode(boolean)} is set to true. * @throws IOException if an IO problem occurs * @throws MalformedURLException if no URL can be created from the provided string */ @SuppressWarnings("unchecked") public <P extends Page> P getPage(final String url) throws IOException, FailingHttpStatusCodeException, MalformedURLException { return (P) getPage(UrlUtils.toUrlUnsafe(url)); }
/** * Creates an instance. * @param url a string representing an absolute or relative URL. * If url is a relative URL, base is required, and will be used * as the base URL. If url is an absolute URL, a given base will be ignored. * @param base a string representing the base URL to use in case url * is a relative URL. If not specified, it defaults to ''. */ @JsxConstructor({CHROME, FF, EDGE}) public URL(final String url, final Object base) { String baseStr = null; if (Undefined.instance != base) { baseStr = Context.toString(base); } try { if (StringUtils.isBlank(baseStr)) { url_ = UrlUtils.toUrlUnsafe(url); } else { final java.net.URL baseUrl = UrlUtils.toUrlUnsafe(baseStr); url_ = new java.net.URL(baseUrl, url); } } catch (final MalformedURLException e) { throw ScriptRuntime.typeError(e.toString()); } }
/** * Creates an instance. * @param url a string representing an absolute or relative URL. * If url is a relative URL, base is required, and will be used * as the base URL. If url is an absolute URL, a given base will be ignored. * @param base a string representing the base URL to use in case url * is a relative URL. If not specified, it defaults to ''. */ @JsxConstructor({CHROME, FF, EDGE}) public URL(final String url, final Object base) { String baseStr = null; if (Undefined.instance != base) { baseStr = Context.toString(base); } try { if (StringUtils.isBlank(baseStr)) { url_ = UrlUtils.toUrlUnsafe(url); } else { final java.net.URL baseUrl = UrlUtils.toUrlUnsafe(baseStr); url_ = new java.net.URL(baseUrl, url); } } catch (final MalformedURLException e) { throw ScriptRuntime.typeError(e.toString()); } }
final String tmpArchive = archives[i].trim(); final String tempUrl = UrlUtils.resolveUrl(baseUrl, tmpArchive); final URL archiveUrl = UrlUtils.toUrlUnsafe(tempUrl); final String tmpArchive = archives[i].trim(); final String tempUrl = UrlUtils.resolveUrl(baseUrl, tmpArchive); final URL archiveUrl = UrlUtils.toUrlUnsafe(tempUrl); final URL classUrl = UrlUtils.toUrlUnsafe(tempUrl); applet_ = appletClass.newInstance(); applet_.setStub(new AppletStubImpl(getHtmlPageOrNull(), params, UrlUtils.toUrlUnsafe(baseUrl), UrlUtils.toUrlUnsafe(documentUrl))); applet_.init(); applet_.start();
/** * Performs an HTTP POST request to the relative url. * * @param webClient the client * @param relative the url relative to the context path * @param expectedContentType if expecting specific content type or null if not * @param expectedStatus if expecting a failing http status code or null if not * @throws IOException if so */ private static void post(JenkinsRule.WebClient webClient, String relative, String expectedContentType, Integer expectedStatus) throws IOException { WebRequest request = new WebRequest( UrlUtils.toUrlUnsafe(webClient.getContextPath() + relative), HttpMethod.POST); try { Page p = webClient.getPage(request); if (expectedContentType != null) { assertThat(p.getWebResponse().getContentType(), is(expectedContentType)); } } catch (FailingHttpStatusCodeException e) { if (expectedStatus != null) { assertEquals(expectedStatus.intValue(), e.getStatusCode()); } else { throw e; } } } }
/** * Tests that configuring an existing project via jenkins http rest doesn't produce duplicated triggers * and that the trigger is configured for the new project pattern. * * @throws Exception if so */ @Test @LocalData public void testReconfigureUsingRestApi() throws Exception { assertNrOfEventListeners(0); TopLevelItem testProj = j.jenkins.getItem("testProj"); String gerritProjectPattern = "someotherproject"; XmlPage xmlPage = loadConfigXmlViaHttp(testProj); Document document = xmlPage.getXmlDocument(); String xml = changeConfigXml(gerritProjectPattern, document); URL url = UrlUtils.toUrlUnsafe(j.getURL().toExternalForm() + testProj.getUrl() + "config.xml"); WebRequest request = new WebRequest(url, HttpMethod.POST); request.setRequestBody(xml); j.jenkins.setCrumbIssuer(null); Page page = j.createWebClient().getPage(request); j.assertGoodStatus(page); assertNrOfEventListeners(0); assertEventListenerWithSomeOtherProjectSet(gerritProjectPattern); }