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);
}
}
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);
}
}
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;
}
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;
}
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);
}
Aggregations