import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
-import org.apache.maven.archiva.configuration.InvalidConfigurationException;
import org.apache.maven.archiva.configuration.NetworkProxyConfiguration;
import org.apache.maven.archiva.configuration.functors.NetworkProxySelectionPredicate;
import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.codehaus.plexus.security.ui.web.interceptor.SecureActionException;
import org.codehaus.plexus.xwork.action.PlexusActionSupport;
-import java.io.IOException;
-
/**
* ConfigureNetworkProxyAction
*
public String delete()
{
- return INPUT;
+ Configuration config = archivaConfiguration.getConfiguration();
+
+ String id = getProxyid();
+ if ( StringUtils.isBlank( id ) )
+ {
+ addActionError( "Unable to delete network proxy with blank id." );
+ return SUCCESS;
+ }
+
+ NetworkProxySelectionPredicate networkProxySelection = new NetworkProxySelectionPredicate( id );
+ NetworkProxyConfiguration proxyConfig = (NetworkProxyConfiguration) CollectionUtils.find( config
+ .getNetworkProxies(), networkProxySelection );
+ if ( proxyConfig == null )
+ {
+ addActionError( "Unable to remove network proxy, proxy with id [" + id + "] not found." );
+ return SUCCESS;
+ }
+
+ archivaConfiguration.getConfiguration().removeNetworkProxy( proxyConfig );
+ addActionMessage( "Successfully removed network proxy [" + id + "]" );
+ return saveConfiguration();
}
public String edit()
{
return proxy;
}
-
+
public String getProxyid()
{
return proxyid;
removeNetworkProxy( id );
}
- try
- {
- addNetworkProxy( getProxy() );
- saveConfiguration();
- }
- catch ( IOException e )
- {
- addActionError( "I/O Exception: " + e.getMessage() );
- }
- catch ( InvalidConfigurationException e )
- {
- addActionError( "Invalid Configuration Exception: " + e.getMessage() );
- }
- catch ( RegistryException e )
- {
- addActionError( "Configuration Registry Exception: " + e.getMessage() );
- }
-
- return SUCCESS;
+ addNetworkProxy( getProxy() );
+ return saveConfiguration();
}
public void setMode( String mode )
}
private String saveConfiguration()
- throws IOException, InvalidConfigurationException, RegistryException
{
- archivaConfiguration.save( archivaConfiguration.getConfiguration() );
-
- addActionMessage( "Successfully saved configuration" );
+ try
+ {
+ archivaConfiguration.save( archivaConfiguration.getConfiguration() );
+ addActionMessage( "Successfully saved configuration" );
+ }
+ catch ( RegistryException e )
+ {
+ addActionError( "Unable to save configuration: " + e.getMessage() );
+ }
return SUCCESS;
}