From: Brett Porter Date: Tue, 25 Mar 2008 07:34:25 +0000 (+0000) Subject: [MRM-626] ClassCastException when saving proxy connector with property defined X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=af26985ef0e288843abc61c2dd85464980d24f7c;p=archiva.git [MRM-626] ClassCastException when saving proxy connector with property defined git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@640726 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-1.0.x/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java b/archiva-1.0.x/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java index cee8a8fa6..68adb6c57 100644 --- a/archiva-1.0.x/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java +++ b/archiva-1.0.x/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java @@ -20,7 +20,6 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy; */ import com.opensymphony.xwork.Preparable; - import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import org.apache.maven.archiva.policies.DownloadPolicy; @@ -29,6 +28,7 @@ import org.apache.maven.archiva.policies.PreDownloadPolicy; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -399,6 +399,19 @@ public abstract class AbstractProxyConnectorFormAction continue; } + Map properties = connector.getProperties(); + for ( Iterator j = properties.keySet().iterator(); j.hasNext(); ) + { + String key = (String) j.next(); + + Object value = properties.get( key ); + if ( value.getClass().isArray() ) + { + String[] arr = (String[]) value; + properties.put( key, arr[0] ); + } + } + // Ugly hack to compensate for ugly browsers. Object o = connector.getPolicies().get( policyId ); String value; diff --git a/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorActionTest.java b/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorActionTest.java index a5cd1ba11..b4747e393 100644 --- a/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorActionTest.java +++ b/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorActionTest.java @@ -20,7 +20,6 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy; */ import com.opensymphony.xwork.Action; - import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; @@ -126,6 +125,8 @@ public class AddProxyConnectorActionTest action.prepare(); ProxyConnectorConfiguration connector = action.getConnector(); populateProxyConnector( connector ); + // forms will use an array + connector.getProperties().put( "eat-a", new String[] { "gramov-a-bits" } ); // Create the input screen. assertRequestStatus( action, Action.SUCCESS, "commit" ); @@ -143,6 +144,7 @@ public class AddProxyConnectorActionTest assertNull( actualConnector.getProxyId() ); assertEquals( "corporate", actualConnector.getSourceRepoId() ); assertEquals( "central", actualConnector.getTargetRepoId() ); + assertEquals( "gramov-a-bits", actualConnector.getProperties().get( "eat-a" ) ); } public void testAddProxyConnectorInitialPage() diff --git a/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorActionTest.java b/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorActionTest.java index f24918d68..626cf5654 100644 --- a/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorActionTest.java +++ b/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorActionTest.java @@ -20,7 +20,6 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy; */ import com.opensymphony.xwork.Action; - import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; @@ -122,6 +121,7 @@ public class EditProxyConnectorActionTest // Should have no error, and 1 property added. assertNoErrors( action ); assertEquals( 1, connector.getProperties().size() ); + assertEquals( "gramov-a-bits", connector.getProperties().get( "eat-a" ) ); } public void testAddWhiteListPattern() @@ -169,6 +169,8 @@ public class EditProxyConnectorActionTest action.prepare(); ProxyConnectorConfiguration connector = action.getConnector(); assertInitialProxyConnector( connector ); + // forms will use an array + connector.getProperties().put( "eat-a", new String[] { "gramov-a-bits" } ); // Create the input screen. assertRequestStatus( action, Action.SUCCESS, "commit" ); @@ -186,6 +188,7 @@ public class EditProxyConnectorActionTest assertNull( actualConnector.getProxyId() ); assertEquals( "corporate", actualConnector.getSourceRepoId() ); assertEquals( "central", actualConnector.getTargetRepoId() ); + } public void testEditProxyConnectorInitialPage()