summaryrefslogtreecommitdiffstats
path: root/base/common/src/com
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2014-02-10 13:56:15 -0500
committerEndi S. Dewata <edewata@redhat.com>2014-03-04 22:41:46 -0500
commit56b9ead088c59ea76d796002e74d42d7e31eac44 (patch)
tree38473afc8d126936ef806b44af2aae01f2ab8fcd /base/common/src/com
parent9e14d6f3e5e69093067f0a76e5b7090c102e11d3 (diff)
Added CLI parameter to select message format.
A new CLI parameter has been added to allow the user select the REST message format. This is done by setting the default consumes and produces when creating the client proxy. For this to work the hard-coded @Consumes and @Produces annotations need to be removed from the interface definition. A new interceptor has been added to validate the message format before executing the operation. Ticket #554
Diffstat (limited to 'base/common/src/com')
-rw-r--r--base/common/src/com/netscape/certsrv/base/PKIException.java5
-rw-r--r--base/common/src/com/netscape/certsrv/client/ClientConfig.java16
-rw-r--r--base/common/src/com/netscape/certsrv/client/PKIClient.java2
-rw-r--r--base/common/src/com/netscape/certsrv/client/PKIConnection.java17
4 files changed, 39 insertions, 1 deletions
diff --git a/base/common/src/com/netscape/certsrv/base/PKIException.java b/base/common/src/com/netscape/certsrv/base/PKIException.java
index ad55d139e..f89c1b18c 100644
--- a/base/common/src/com/netscape/certsrv/base/PKIException.java
+++ b/base/common/src/com/netscape/certsrv/base/PKIException.java
@@ -31,6 +31,11 @@ public class PKIException extends RuntimeException {
public int code;
+ public PKIException(Response.Status status) {
+ super(status.getReasonPhrase());
+ code = status.getStatusCode();
+ }
+
public PKIException(String message) {
super(message);
code = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
diff --git a/base/common/src/com/netscape/certsrv/client/ClientConfig.java b/base/common/src/com/netscape/certsrv/client/ClientConfig.java
index c85db52d3..da4e3d780 100644
--- a/base/common/src/com/netscape/certsrv/client/ClientConfig.java
+++ b/base/common/src/com/netscape/certsrv/client/ClientConfig.java
@@ -55,6 +55,7 @@ public class ClientConfig {
String certPassword;
String username;
String password;
+ String messageFormat;
@XmlElement(name="ServerURI")
public URI getServerURI() {
@@ -123,6 +124,15 @@ public class ClientConfig {
this.password = password;
}
+ @XmlElement(name="MessageFormat")
+ public String getMessageFormat() {
+ return messageFormat;
+ }
+
+ public void setMessageFormat(String messageFormat) {
+ this.messageFormat = messageFormat;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
@@ -130,6 +140,7 @@ public class ClientConfig {
result = prime * result + ((certDatabase == null) ? 0 : certDatabase.hashCode());
result = prime * result + ((certNickname == null) ? 0 : certNickname.hashCode());
result = prime * result + ((certPassword == null) ? 0 : certPassword.hashCode());
+ result = prime * result + ((messageFormat == null) ? 0 : messageFormat.hashCode());
result = prime * result + ((password == null) ? 0 : password.hashCode());
result = prime * result + ((serverURI == null) ? 0 : serverURI.hashCode());
result = prime * result + ((username == null) ? 0 : username.hashCode());
@@ -160,6 +171,11 @@ public class ClientConfig {
return false;
} else if (!certPassword.equals(other.certPassword))
return false;
+ if (messageFormat == null) {
+ if (other.messageFormat != null)
+ return false;
+ } else if (!messageFormat.equals(other.messageFormat))
+ return false;
if (password == null) {
if (other.password != null)
return false;
diff --git a/base/common/src/com/netscape/certsrv/client/PKIClient.java b/base/common/src/com/netscape/certsrv/client/PKIClient.java
index 2b455fa8c..4f5a98d25 100644
--- a/base/common/src/com/netscape/certsrv/client/PKIClient.java
+++ b/base/common/src/com/netscape/certsrv/client/PKIClient.java
@@ -33,6 +33,8 @@ import com.netscape.cmsutil.util.Utils;
public class PKIClient {
+ public final static String[] MESSAGE_FORMATS = { "xml", "json" };
+
public ClientConfig config;
public PKIConnection connection;
diff --git a/base/common/src/com/netscape/certsrv/client/PKIConnection.java b/base/common/src/com/netscape/certsrv/client/PKIConnection.java
index 1c3e58a1b..06c51aaad 100644
--- a/base/common/src/com/netscape/certsrv/client/PKIConnection.java
+++ b/base/common/src/com/netscape/certsrv/client/PKIConnection.java
@@ -17,12 +17,14 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
@@ -511,7 +513,20 @@ public class PKIConnection {
public <T> T createProxy(URI uri, Class<T> clazz) throws URISyntaxException {
ResteasyWebTarget target = resteasyClient.target(uri);
- return ProxyBuilder.builder(clazz, target).build();
+ ProxyBuilder<T> builder = ProxyBuilder.builder(clazz, target);
+
+ String messageFormat = config.getMessageFormat();
+ if (messageFormat == null) messageFormat = PKIClient.MESSAGE_FORMATS[0];
+
+ if (!Arrays.asList(PKIClient.MESSAGE_FORMATS).contains(messageFormat)) {
+ throw new Error("Unsupported message format: " + messageFormat);
+ }
+
+ MediaType contentType = MediaType.valueOf("application/" + messageFormat);
+ builder.defaultConsumes(contentType);
+ builder.defaultProduces(contentType);
+
+ return builder.build();
}
public <T> T getEntity(Response response, Class<T> clazz) {