Search in sources :

Example 96 with MalformedURLException

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);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) Map(java.util.Map) URL(java.net.URL)

Example 97 with MalformedURLException

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);
}
Also used : MalformedURLException(java.net.MalformedURLException) FQDNUrl(com.sun.identity.shared.FQDNUrl)

Example 98 with MalformedURLException

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ClickEvent(com.vaadin.ui.Button.ClickEvent) InfoWindow(org.opennms.features.topology.api.support.InfoWindow) URI(java.net.URI) URL(java.net.URL) Button(com.vaadin.ui.Button) DialogWindow(org.opennms.features.topology.api.support.DialogWindow) ClickListener(com.vaadin.ui.Button.ClickListener) LabelCreator(org.opennms.features.topology.api.support.InfoWindow.LabelCreator)

Example 99 with MalformedURLException

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) HttpURLConnection(java.net.HttpURLConnection) InputStream(java.io.InputStream) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) URL(java.net.URL)

Example 100 with MalformedURLException

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);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) HttpURLConnection(java.net.HttpURLConnection) InputStream(java.io.InputStream) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) IOException(java.io.IOException) URL(java.net.URL)

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