Search in sources :

Example 91 with MalformedURLException

use of java.net.MalformedURLException in project OpenAM by OpenRock.

the class SiteConfigValidator method validateSiteUrlSyntax.

private void validateSiteUrlSyntax(String site) {
    boolean valid = true;
    try {
        String[] params = { site };
        toolOutWriter.printMessage("site-url-syntax");
        URL url = new URL(site);
        if (!isValidHost(url.getHost())) {
            toolOutWriter.printError("site-invalid-site-host", new String[] { url.getHost() });
            valid = false;
        }
        toolOutWriter.printStatusMsg(valid, "site-host-validate");
        String deploymentURI = SystemProperties.get(AM_SERVICES_DEPLOYMENT_DESCRIPTOR);
        valid = false;
        if (deploymentURI != null && deploymentURI.length() > 0) {
            int idx = site.indexOf(deploymentURI);
            if (idx != -1) {
                if ((site.length() - deploymentURI.length()) == (idx - 1)) {
                    toolOutWriter.printError("site-uri-misplace", params);
                } else {
                    valid = true;
                }
            } else {
                toolOutWriter.printError("site-url-syntax-err", params);
            }
        } else {
            toolOutWriter.printError("site-missing-svr-uri");
        }
        toolOutWriter.printStatusMsg(valid, "site-url-validate");
    } catch (MalformedURLException e) {
        Debug.getInstance(DEBUG_NAME).error("SiteConfigValidator.validateSiteUrlSyntax: " + "Invalid URL syntax Exception", e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) URL(java.net.URL)

Example 92 with MalformedURLException

use of java.net.MalformedURLException in project OpenAM by OpenRock.

the class SiteConfigValidator method checkOrganizationAlias.

private void checkOrganizationAlias(SSOToken ssoToken, String siteURL) throws SMSException {
    String[] params = { siteURL };
    toolOutWriter.printMessage("site-org-alias-check");
    try {
        URL url = new URL(siteURL);
        if (!existsInOrganizationAlias(ssoToken, url.getHost())) {
            toolOutWriter.printError("site-org-alias-fail", new String[] { url.getHost() });
        }
    } catch (MalformedURLException e) {
        toolOutWriter.printError("site-invalid-url", params);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) URL(java.net.URL)

Example 93 with MalformedURLException

use of java.net.MalformedURLException in project OpenAM by OpenRock.

the class ServerConfigValidator method getURIFromComponents.

/**
     * Helper method to construct the URI from host, port, protocol
     * from the configuration properties for the server.
     */
private String getURIFromComponents(String urlStr) {
    String uri = null;
    try {
        URL url = new URL(urlStr);
        String hostname = url.getHost();
        String port = Integer.toString(url.getPort());
        String protocol = url.getProtocol();
        uri = protocol + "://" + hostname + ":" + port;
    } catch (MalformedURLException mfe) {
        Debug.getInstance(DEBUG_NAME).error("ServerConfigValidator.getURIFromComponents: " + "Invalid  URL exception", mfe);
    }
    return uri;
}
Also used : MalformedURLException(java.net.MalformedURLException) URL(java.net.URL)

Example 94 with MalformedURLException

use of java.net.MalformedURLException in project OpenAM by OpenRock.

the class ServerConfiguration method createServerInstance.

/**
     * Creates a server instance.
     *
     * @param ssoToken Single Sign-On Token which is used to access to the
     *        service management datastore.
     * @param instanceName Name of the server instance.
     * @param instanceId Identifier of the server instance.
     * @param values Set of string with this format <code>key=value</code>.
     * @param serverConfigXML Service configuration XML.
     * @throws SMSException if errors access in the service management
     *         datastore.
     * @throws SSOException if the <code>ssoToken</code> is not valid.
     * @throws UnknownPropertyNameException if property names are unknown.
     * @throws ConfigurationException  if the property name and values are not
     *         valid.
     */
public static boolean createServerInstance(SSOToken ssoToken, String instanceName, String instanceId, Set values, String serverConfigXML) throws SMSException, SSOException, ConfigurationException, UnknownPropertyNameException {
    boolean created = false;
    if (!instanceName.equals(DEFAULT_SERVER_CONFIG)) {
        validateProperty(ssoToken, values);
    }
    ServiceConfig sc = getRootServerConfig(ssoToken);
    if (sc != null) {
        if (!instanceName.equals(DEFAULT_SERVER_CONFIG)) {
            try {
                new URL(instanceName);
            } catch (MalformedURLException ex) {
                String[] param = { instanceName };
                throw new ConfigurationException("invalid.server.name", param);
            }
        }
        Map serverValues = new HashMap(4);
        Set setServerId = new HashSet(2);
        setServerId.add(instanceId);
        serverValues.put(ATTR_SERVER_ID, setServerId);
        if (values.isEmpty()) {
            values = new HashSet(2);
        }
        values.add(Constants.PROPERTY_NAME_LB_COOKIE_VALUE + "=" + instanceId);
        Set setServerConfigXML = new HashSet(2);
        setServerConfigXML.add(serverConfigXML);
        serverValues.put(ATTR_SERVER_CONFIG_XML, setServerConfigXML);
        serverValues.put(ATTR_SERVER_CONFIG, values);
        if (!instanceName.equals(DEFAULT_SERVER_CONFIG)) {
            setProtocolHostPortURI(serverValues, instanceName);
        }
        sc.addSubConfig(instanceName, SUBSCHEMA_SERVER, 0, serverValues);
        created = true;
    }
    if (created && !instanceName.equals(DEFAULT_SERVER_CONFIG)) {
        updateOrganizationAlias(ssoToken, instanceName, true);
    }
    return created;
}
Also used : MalformedURLException(java.net.MalformedURLException) HashSet(java.util.HashSet) Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) URL(java.net.URL) HashSet(java.util.HashSet)

Example 95 with MalformedURLException

use of java.net.MalformedURLException in project OpenAM by OpenRock.

the class TestHarness method executeJSP.

private void executeJSP(String strJSP) {
    String jsp = strJSP.substring(0, strJSP.lastIndexOf(".jsp"));
    jsp = SystemProperties.getServerInstanceName() + "/unittest/" + jsp.replace('.', '/') + ".jsp";
    UnittestLog.logMessage("Executing JSP, " + jsp);
    try {
        URL url = new URL(jsp);
        URLConnection conn = HttpURLConnectionManager.getConnection(url);
        conn.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write("hello=1");
        wr.flush();
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = rd.readLine()) != null) {
        //
        }
        wr.close();
        rd.close();
    } catch (MalformedURLException e) {
        UnittestLog.logError("TestHarness.executeJSP: execute JSP failed", e);
    } catch (IOException e) {
        UnittestLog.logError("TestHarness.executeJSP: execute JSP failed", e);
    }
    UnittestLog.logMessage("Executed JSP, " + jsp);
}
Also used : MalformedURLException(java.net.MalformedURLException) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection)

Aggregations

MalformedURLException (java.net.MalformedURLException)3838 URL (java.net.URL)2885 IOException (java.io.IOException)1194 File (java.io.File)910 ArrayList (java.util.ArrayList)372 InputStream (java.io.InputStream)367 HttpURLConnection (java.net.HttpURLConnection)295 URISyntaxException (java.net.URISyntaxException)270 URI (java.net.URI)239 InputStreamReader (java.io.InputStreamReader)226 BufferedReader (java.io.BufferedReader)208 HashMap (java.util.HashMap)200 URLClassLoader (java.net.URLClassLoader)168 Map (java.util.Map)166 URLConnection (java.net.URLConnection)148 FileNotFoundException (java.io.FileNotFoundException)137 Matcher (java.util.regex.Matcher)132 Test (org.junit.Test)129 UnsupportedEncodingException (java.io.UnsupportedEncodingException)119 Pattern (java.util.regex.Pattern)113