Author: jbernhardt
Date: Tue Jan 29 08:28:59 2013
New Revision: 1439782

URL: http://svn.apache.org/viewvc?rev=1439782&view=rev
Log:
[SYNCOPE-231]
* Added missing URLEncoder.encode()
* Code cleanup

Modified:
    
syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ConfigurationServiceProxy.java
    
syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/NotificationServiceProxy.java
    
syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ResourceServiceProxy.java
    
syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/SchemaServiceProxy.java
    
syncope/trunk/common/src/main/java/org/apache/syncope/common/SyncopeConstants.java

Modified: 
syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ConfigurationServiceProxy.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ConfigurationServiceProxy.java?rev=1439782&r1=1439781&r2=1439782&view=diff
==============================================================================
--- 
syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ConfigurationServiceProxy.java
 (original)
+++ 
syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ConfigurationServiceProxy.java
 Tue Jan 29 08:28:59 2013
@@ -19,14 +19,18 @@
 package org.apache.syncope.client.services.proxy;
 
 import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
 import java.net.URI;
+import java.net.URLEncoder;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.core.Response;
 
+import org.apache.syncope.common.SyncopeConstants;
 import org.apache.syncope.common.services.ConfigurationService;
 import org.apache.syncope.common.to.ConfigurationTO;
 import org.apache.syncope.common.to.MailTemplateTO;
@@ -42,10 +46,19 @@ public class ConfigurationServiceProxy e
 
     @Override
     public Response create(final ConfigurationTO configurationTO) {
-        ConfigurationTO created = getRestTemplate().postForObject(baseUrl + 
"configuration/create",
-                configurationTO, ConfigurationTO.class);
-        URI location = URI.create(baseUrl + "configuration/read/" + 
created.getKey() + ".json");
-        return Response.created(location).build();
+        ConfigurationTO created = getRestTemplate().postForObject(baseUrl + 
"configuration/create", configurationTO,
+                ConfigurationTO.class);
+        try {
+            URI location = URI.create(baseUrl
+                    + "configuration/read/"
+                    + URLEncoder.encode(created.getKey(), 
SyncopeConstants.DEFAULT_ENCODING)
+                    + ".json");
+            return Response.created(location)
+                    .header(SyncopeConstants.REST_HEADER_ID, created.getKey())
+                    .build();
+        } catch (UnsupportedEncodingException e) {
+            throw new InternalServerErrorException(e);
+        }
     }
 
     @Override
@@ -66,8 +79,7 @@ public class ConfigurationServiceProxy e
 
     @Override
     public void update(final String key, final ConfigurationTO 
configurationTO) {
-        getRestTemplate().postForObject(baseUrl + "configuration/update", 
configurationTO,
-                ConfigurationTO.class);
+        getRestTemplate().postForObject(baseUrl + "configuration/update", 
configurationTO, ConfigurationTO.class);
     }
 
     @Override

Modified: 
syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/NotificationServiceProxy.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/NotificationServiceProxy.java?rev=1439782&r1=1439781&r2=1439782&view=diff
==============================================================================
--- 
syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/NotificationServiceProxy.java
 (original)
+++ 
syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/NotificationServiceProxy.java
 Tue Jan 29 08:28:59 2013
@@ -36,23 +36,29 @@ public class NotificationServiceProxy ex
     }
 
     @Override
-    public NotificationTO read(final Long notificationId) {
-        return getRestTemplate().getForObject(baseUrl + 
"notification/read/{notificationId}.json",
+    public Response create(final NotificationTO notificationTO) {
+        NotificationTO notification = getRestTemplate().postForObject(baseUrl 
+ "notification/create.json",
+                notificationTO, NotificationTO.class);
+        URI location = URI.create(baseUrl + "notification/read/" + 
notification.getId() + ".json");
+        return 
Response.created(location).header(SyncopeConstants.REST_HEADER_ID, 
notification.getId()).build();
+    }
+
+    @Override
+    public NotificationTO delete(final Long notificationId) {
+        return getRestTemplate().getForObject(baseUrl + 
"notification/delete/{notificationId}.json",
                 NotificationTO.class, notificationId);
     }
 
     @Override
     public List<NotificationTO> list() {
-        return Arrays.asList(getRestTemplate().getForObject(baseUrl + 
"notification/list.json",
-                NotificationTO[].class));
+        return Arrays
+                .asList(getRestTemplate().getForObject(baseUrl + 
"notification/list.json", NotificationTO[].class));
     }
 
     @Override
-    public Response create(final NotificationTO notificationTO) {
-        NotificationTO notification = getRestTemplate().postForObject(baseUrl 
+ "notification/create.json", notificationTO,
-                NotificationTO.class);
-        URI location = URI.create(baseUrl + "notification/read/" + 
notification.getId() + ".json");
-        return 
Response.created(location).header(SyncopeConstants.REST_HEADER_ID, 
notification.getId()).build();
+    public NotificationTO read(final Long notificationId) {
+        return getRestTemplate().getForObject(baseUrl + 
"notification/read/{notificationId}.json",
+                NotificationTO.class, notificationId);
     }
 
     @Override
@@ -60,10 +66,4 @@ public class NotificationServiceProxy ex
         return getRestTemplate().postForObject(baseUrl + 
"notification/update.json", notificationTO,
                 NotificationTO.class);
     }
-
-    @Override
-    public NotificationTO delete(final Long notificationId) {
-        return getRestTemplate().getForObject(baseUrl + 
"notification/delete/{notificationId}.json",
-                NotificationTO.class, notificationId);
-    }
 }

Modified: 
syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ResourceServiceProxy.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ResourceServiceProxy.java?rev=1439782&r1=1439781&r2=1439782&view=diff
==============================================================================
--- 
syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ResourceServiceProxy.java
 (original)
+++ 
syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ResourceServiceProxy.java
 Tue Jan 29 08:28:59 2013
@@ -18,14 +18,18 @@
  */
 package org.apache.syncope.client.services.proxy;
 
+import java.io.UnsupportedEncodingException;
 import java.net.URI;
+import java.net.URLEncoder;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.core.Response;
 
+import org.apache.syncope.common.SyncopeConstants;
 import org.apache.syncope.common.services.ResourceService;
 import org.apache.syncope.common.to.ConnObjectTO;
 import org.apache.syncope.common.to.PropagationActionClassTO;
@@ -45,7 +49,17 @@ public class ResourceServiceProxy extend
         ResourceTO resource = getRestTemplate().postForObject(baseUrl + 
"resource/create.json", resourceTO,
                 ResourceTO.class);
 
-        return Response.created(URI.create(baseUrl + "resource/read/" + 
resource.getName() + ".json")).build();
+        try {
+            URI location = URI.create(baseUrl
+                    + "resource/read/"
+                    + URLEncoder.encode(resource.getName(), 
SyncopeConstants.DEFAULT_ENCODING)
+                    + ".json");
+            return Response.created(location)
+                    .header(SyncopeConstants.REST_HEADER_ID, 
resource.getName())
+                    .build();
+        } catch (UnsupportedEncodingException e) {
+            throw new InternalServerErrorException(e);
+        }
     }
 
     @Override

Modified: 
syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/SchemaServiceProxy.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/SchemaServiceProxy.java?rev=1439782&r1=1439781&r2=1439782&view=diff
==============================================================================
--- 
syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/SchemaServiceProxy.java
 (original)
+++ 
syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/SchemaServiceProxy.java
 Tue Jan 29 08:28:59 2013
@@ -18,12 +18,16 @@
  */
 package org.apache.syncope.client.services.proxy;
 
+import java.io.UnsupportedEncodingException;
 import java.net.URI;
+import java.net.URLEncoder;
 import java.util.Arrays;
 import java.util.List;
 
+import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.core.Response;
 
+import org.apache.syncope.common.SyncopeConstants;
 import org.apache.syncope.common.services.SchemaService;
 import org.apache.syncope.common.to.AbstractSchemaTO;
 import org.apache.syncope.common.to.DerivedSchemaTO;
@@ -44,8 +48,18 @@ public class SchemaServiceProxy extends 
             final T schemaTO) {
         AbstractSchemaTO schema = getRestTemplate().postForObject(baseUrl + 
type.toSpringURL() + "/{kind}/create",
                 schemaTO, getTOClass(type), kind);
-        return Response.created(
-                URI.create(baseUrl + type.toSpringURL() + "/" + kind + 
"/read/" + schema.getName() + ".json")).build();
+
+        try {
+            URI location = URI.create(baseUrl
+                    + type.toSpringURL() + "/" + kind + "/read/"
+                    + URLEncoder.encode(schema.getName(), 
SyncopeConstants.DEFAULT_ENCODING)
+                    + ".json");
+            return Response.created(location)
+                    .header(SyncopeConstants.REST_HEADER_ID, schema.getName())
+                    .build();
+        } catch (UnsupportedEncodingException e) {
+            throw new InternalServerErrorException(e);
+        }
     }
 
     @Override
@@ -87,7 +101,8 @@ public class SchemaServiceProxy extends 
     public <T extends AbstractSchemaTO> void update(final AttributableType 
kind, final SchemaType type,
             final String schemaName, final T schemaTO) {
 
-        getRestTemplate().postForObject(baseUrl + type.toSpringURL() + 
"/{kind}/update", schemaTO, getTOClass(type), kind);
+        getRestTemplate().postForObject(baseUrl + type.toSpringURL() + 
"/{kind}/update", schemaTO, getTOClass(type),
+                kind);
     }
 
     private Class<? extends AbstractSchemaTO> getTOClass(final SchemaType 
type) {

Modified: 
syncope/trunk/common/src/main/java/org/apache/syncope/common/SyncopeConstants.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/SyncopeConstants.java?rev=1439782&r1=1439781&r2=1439782&view=diff
==============================================================================
--- 
syncope/trunk/common/src/main/java/org/apache/syncope/common/SyncopeConstants.java
 (original)
+++ 
syncope/trunk/common/src/main/java/org/apache/syncope/common/SyncopeConstants.java
 Tue Jan 29 08:28:59 2013
@@ -38,4 +38,6 @@ public class SyncopeConstants {
      */
     public static final String REST_HEADER_ID = "org.apache.syncope.id";
 
+    public static final String DEFAULT_ENCODING = "UTF-8";
+
 }


Reply via email to