use of java.net.MalformedURLException in project OpenAM by OpenRock.
the class ConfigurationBase method updateOrganizationAlias.
protected static void updateOrganizationAlias(SSOToken ssoToken, String instanceName, boolean bAdd) throws SMSException {
String hostName = null;
try {
URL url = new URL(instanceName);
hostName = url.getHost();
} catch (MalformedURLException e) {
throw new RuntimeException(e.getMessage());
}
OrganizationConfigManager ocm = new OrganizationConfigManager(ssoToken, "/");
Map allAttrs = ocm.getAttributes(ServiceManager.REALM_SERVICE);
Set values = (Set) allAttrs.get(OrganizationConfigManager.SUNORG_ALIAS);
if (bAdd) {
if (!values.contains(hostName)) {
values.add(hostName);
ocm.setAttributes(ServiceManager.REALM_SERVICE, allAttrs);
}
} else {
if (values.contains(hostName)) {
values.remove(hostName);
ocm.setAttributes(ServiceManager.REALM_SERVICE, allAttrs);
}
}
}
use of java.net.MalformedURLException in project OpenAM by OpenRock.
the class AgentConfiguration method createAgent.
/**
* Creates an agent.
*
* @param ssoToken Single Sign On token that is to be used for creation.
* @param realm Realm where agent resides.
* @param agentName Name of agent.
* @param agentType Type of agent.
* @param attrValues Map of attribute name to its values.
* @param serverURL Server URL.
* @param agentURL Agent URL.
* @throws IdRepoException if there are Id Repository related errors.
* @throws SSOException if the Single Sign On token is invalid or has
* expired.
* @throws SMSException if there are errors in service management layers.
* @throws ConfigurationException if there are missing information in
* server or agent URL; or invalid agent type.
*/
public static void createAgent(SSOToken ssoToken, String realm, String agentName, String agentType, Map attrValues, String serverURL, String agentURL) throws IdRepoException, SSOException, SMSException, ConfigurationException {
if ((serverURL == null) || (serverURL.trim().length() == 0)) {
throw new ConfigurationException("create.agent.invalid.server.url", null);
}
if ((agentURL == null) || (agentURL.trim().length() == 0)) {
throw new ConfigurationException("create.agent.invalid.agent.url", null);
}
FQDNUrl serverFQDNURL = null;
FQDNUrl agentFQDNURL = null;
try {
serverFQDNURL = new FQDNUrl(serverURL);
} catch (MalformedURLException e) {
throw new ConfigurationException("create.agent.invalid.server.url", null);
}
try {
agentFQDNURL = new FQDNUrl(agentURL);
} catch (MalformedURLException e) {
throw new ConfigurationException("create.agent.invalid.agent.url", null);
}
createAgentEx(ssoToken, realm, agentName, agentType, attrValues, serverFQDNURL, agentFQDNURL);
}
use of java.net.MalformedURLException in project opennms by OpenNMS.
the class AlarmIdColumnLinkGenerator method generateCell.
@Override
public Object generateCell(final Table source, Object itemId, Object columnId) {
// no source
if (source == null)
return null;
Property<Integer> alarmIdProperty = source.getContainerProperty(itemId, alarmIdPropertyName);
final Integer alarmId = alarmIdProperty.getValue();
// no value
if (alarmId == null)
return null;
// create Link
Button button = new Button("" + alarmId);
button.setStyleName(BaseTheme.BUTTON_LINK);
button.addClickListener(new ClickListener() {
private static final long serialVersionUID = 3698209256202413810L;
@Override
public void buttonClick(ClickEvent event) {
// try if alarm is there, otherwise show information dialog
OnmsAlarm alarm = alarmDao.get(alarmId);
if (alarm == null) {
new DialogWindow(source.getUI(), "Alarm does not exist!", "The alarm information cannot be shown. \nThe alarm does not exist anymore. \n\nPlease refresh the Alarm Table.");
return;
}
// alarm still exists, show alarm details
final URI currentLocation = Page.getCurrent().getLocation();
final String contextRoot = VaadinServlet.getCurrent().getServletContext().getContextPath();
final String redirectFragment = contextRoot + "/alarm/detail.htm?quiet=true&id=" + alarmId;
LOG.debug("alarm {} clicked, current location = {}, uri = {}", alarmId, currentLocation, redirectFragment);
try {
source.getUI().addWindow(new InfoWindow(new URL(currentLocation.toURL(), redirectFragment), new LabelCreator() {
@Override
public String getLabel() {
return "Alarm Info " + alarmId;
}
}));
} catch (MalformedURLException e) {
LOG.error(e.getMessage(), e);
}
}
});
return button;
}
use of java.net.MalformedURLException in project OpenAM by OpenRock.
the class OAuth method getContentStreamByPOST.
public InputStream getContentStreamByPOST(String serviceUrl, String authorizationHeader) throws LoginException {
InputStream is = null;
try {
OAuthUtil.debugMessage("OAuth.getContentStreamByPOST: URL = " + serviceUrl);
URL url = new URL(serviceUrl);
String query = url.getQuery();
OAuthUtil.debugMessage("OAuth.getContentStreamByPOST: Query: " + query);
HttpURLConnection connection = HttpURLConnectionManager.getConnection(url);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
if (authorizationHeader != null) {
connection.setRequestProperty("Authorization", authorizationHeader);
}
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(query);
writer.close();
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
OAuthUtil.debugMessage("OAuth.getContentStreamByPOST: HTTP Conn OK");
is = connection.getInputStream();
} else {
// Error Code
String[] data2 = { String.valueOf(connection.getResponseCode()) };
OAuthUtil.debugError("OAuth.getContentStreamByPOST: HTTP Conn Error:\n" + " Response code: " + connection.getResponseCode() + "\n" + " Response message: " + connection.getResponseMessage() + "\n" + " Error stream: " + getErrorStream(connection) + "\n");
throw new AuthLoginException(BUNDLE_NAME, "httpErrorCode", data2);
}
} catch (MalformedURLException e) {
throw new AuthLoginException(BUNDLE_NAME, "malformedURL", null, e);
} catch (IOException e) {
throw new AuthLoginException(BUNDLE_NAME, "ioe", null, e);
}
return is;
}
use of java.net.MalformedURLException in project OpenAM by OpenRock.
the class OAuth method getContentStreamByGET.
public InputStream getContentStreamByGET(String serviceUrl, String authorizationHeader) throws LoginException {
OAuthUtil.debugMessage("service url: " + serviceUrl);
try {
InputStream is;
URL urlC = new URL(serviceUrl);
HttpURLConnection connection = HttpURLConnectionManager.getConnection(urlC);
connection.setDoOutput(true);
connection.setRequestMethod("GET");
if (authorizationHeader != null) {
connection.setRequestProperty("Authorization", authorizationHeader);
}
connection.connect();
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
OAuthUtil.debugMessage("OAuth.getContentStreamByGET: HTTP Conn OK");
is = connection.getInputStream();
} else {
// Server returned HTTP error code.
String errorStream = getErrorStream(connection);
if (OAuthUtil.debugMessageEnabled()) {
OAuthUtil.debugMessage("OAuth.getContentStreamByGET: HTTP Conn Error:\n" + " Response code: " + connection.getResponseCode() + "\n " + " Response message: " + connection.getResponseMessage() + "\n" + " Error stream: " + errorStream + "\n");
}
is = getContentStreamByPOST(serviceUrl, authorizationHeader);
}
return is;
} catch (MalformedURLException mfe) {
throw new AuthLoginException(BUNDLE_NAME, "malformedURL", null, mfe);
} catch (IOException ioe) {
throw new AuthLoginException(BUNDLE_NAME, "ioe", null, ioe);
}
}
Aggregations