summaryrefslogtreecommitdiffstats
path: root/base/common
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2013-08-26 13:21:58 -0400
committerEndi Sukma Dewata <edewata@redhat.com>2013-09-01 01:04:48 -0500
commita847bcb7c71836f7c0498163e31238f118740339 (patch)
tree9701c88ce01db56118585ade51013837f0496b7c /base/common
parentbc2df101c9fbd0f9468573de0a0dbe14ca16dc92 (diff)
downloadpki-a847bcb7c71836f7c0498163e31238f118740339.tar.gz
pki-a847bcb7c71836f7c0498163e31238f118740339.tar.xz
pki-a847bcb7c71836f7c0498163e31238f118740339.zip
Reorganized TPS classes.
The TPS classes have been reorganized as follows: * common: com.netscape.certsrv.tps * CLI: com.netscape.cmstools.tps * server: org.dogtagpki.server.tps TPSConnection and TPSMessage were moved from server package into common package. The build script and configuration files have been modified accordingly.
Diffstat (limited to 'base/common')
-rw-r--r--base/common/src/com/netscape/certsrv/tps/TPSClient.java2
-rw-r--r--base/common/src/com/netscape/certsrv/tps/TPSConnection.java98
-rw-r--r--base/common/src/com/netscape/certsrv/tps/TPSMessage.java101
-rw-r--r--base/common/src/com/netscape/certsrv/tps/token/TokenClient.java (renamed from base/common/src/com/netscape/certsrv/token/TokenClient.java)2
-rw-r--r--base/common/src/com/netscape/certsrv/tps/token/TokenCollection.java (renamed from base/common/src/com/netscape/certsrv/token/TokenCollection.java)2
-rw-r--r--base/common/src/com/netscape/certsrv/tps/token/TokenData.java (renamed from base/common/src/com/netscape/certsrv/token/TokenData.java)2
-rw-r--r--base/common/src/com/netscape/certsrv/tps/token/TokenModifyRequest.java (renamed from base/common/src/com/netscape/certsrv/token/TokenModifyRequest.java)2
-rw-r--r--base/common/src/com/netscape/certsrv/tps/token/TokenResource.java (renamed from base/common/src/com/netscape/certsrv/token/TokenResource.java)2
8 files changed, 205 insertions, 6 deletions
diff --git a/base/common/src/com/netscape/certsrv/tps/TPSClient.java b/base/common/src/com/netscape/certsrv/tps/TPSClient.java
index 65a1997ba..94a906cdf 100644
--- a/base/common/src/com/netscape/certsrv/tps/TPSClient.java
+++ b/base/common/src/com/netscape/certsrv/tps/TPSClient.java
@@ -23,8 +23,8 @@ import com.netscape.certsrv.client.PKIClient;
import com.netscape.certsrv.client.SubsystemClient;
import com.netscape.certsrv.group.GroupClient;
import com.netscape.certsrv.logging.ActivityClient;
-import com.netscape.certsrv.token.TokenClient;
import com.netscape.certsrv.tps.cert.TPSCertClient;
+import com.netscape.certsrv.tps.token.TokenClient;
import com.netscape.certsrv.user.UserClient;
/**
diff --git a/base/common/src/com/netscape/certsrv/tps/TPSConnection.java b/base/common/src/com/netscape/certsrv/tps/TPSConnection.java
new file mode 100644
index 000000000..00e201c25
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/tps/TPSConnection.java
@@ -0,0 +1,98 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package com.netscape.certsrv.tps;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+
+/**
+ * @author Endi S. Dewata <edewata@redhat.com>
+ */
+public class TPSConnection {
+
+ public InputStream in;
+ public PrintStream out;
+ public boolean chunked;
+
+ public TPSConnection(InputStream in, OutputStream out) {
+ this(in, out, false);
+ }
+
+ public TPSConnection(InputStream in, OutputStream out, boolean chunked) {
+ this.in = in;
+ this.out = new PrintStream(out);
+ this.chunked = chunked;
+ }
+
+ public TPSMessage read() throws IOException {
+
+ StringBuilder sb = new StringBuilder();
+ int b;
+
+ // read the first parameter
+ while ((b = in.read()) >= 0) {
+ char c = (char)b;
+ if (c == '&') break;
+ sb.append(c);
+ }
+
+ if (b < 0) throw new IOException("Unexpected end of stream");
+
+ // parse message size
+ String nvp = sb.toString();
+ String[] s = nvp.split("=");
+ int size = Integer.parseInt(s[1]);
+
+ sb.append('&');
+
+ // read the rest of message
+ for (int i=0; i<size; i++) {
+
+ b = in.read();
+ if (b < 0) throw new IOException("Unexpected end of stream");
+
+ char c = (char)b;
+ sb.append(c);
+ }
+
+ // parse the entire message
+ return new TPSMessage(sb.toString());
+ }
+
+ public void write(TPSMessage message) throws IOException {
+ String s = message.encode();
+
+ if (chunked) {
+ // send message length + EOL
+ out.print(Integer.toHexString(s.length()));
+ out.print("\r\n");
+ }
+
+ // send message
+ out.print(s);
+
+ if (chunked) {
+ // send EOL
+ out.print("\r\n");
+ }
+
+ out.flush();
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/tps/TPSMessage.java b/base/common/src/com/netscape/certsrv/tps/TPSMessage.java
new file mode 100644
index 000000000..c25459b2a
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/tps/TPSMessage.java
@@ -0,0 +1,101 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package com.netscape.certsrv.tps;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * @author Endi S. Dewata <edewata@redhat.com>
+ */
+public class TPSMessage {
+
+ Map<String, String> map = new LinkedHashMap<String, String>();
+
+ public TPSMessage() {
+ }
+
+ public TPSMessage(String message) {
+ decode(message);
+ }
+
+ public TPSMessage(Map<String, String> map) {
+ this.map.putAll(map);
+ }
+
+ public void put(String key, String value) {
+ map.put(key, value);
+ }
+
+ public void put(String key, Integer value) {
+ map.put(key, value.toString());
+ }
+
+ public void put(String key, byte[] bytes) {
+ StringBuilder sb = new StringBuilder();
+
+ for (byte b : bytes) {
+ sb.append("%");
+ sb.append(String.format("%02X", b));
+ }
+
+ map.put(key, sb.toString());
+ }
+
+ public void decode(String message) {
+
+ for (String nvp : message.split("&")) {
+ String[] s = nvp.split("=");
+
+ String key = s[0];
+ String value = s[1];
+
+ // skip message size
+ if (key.equals("s")) continue;
+
+ map.put(key, value);
+ }
+ }
+
+ public String encode() {
+
+ StringBuilder sb = new StringBuilder();
+
+ // encode message type
+ String type = map.get("msg_type");
+ sb.append("msg_type=" + type);
+
+ // encode other parameters
+ for (String key : map.keySet()) {
+
+ if (key.equals("msg_type")) continue;
+
+ String value = map.get(key);
+ sb.append("&" + key + "=" + value);
+ }
+
+ String message = sb.toString();
+
+ // encode message_size
+ return "s=" + message.length() + "&" + message;
+ }
+
+ public String toString() {
+ return map.toString();
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/token/TokenClient.java b/base/common/src/com/netscape/certsrv/tps/token/TokenClient.java
index d6fbd4e1f..48bddded6 100644
--- a/base/common/src/com/netscape/certsrv/token/TokenClient.java
+++ b/base/common/src/com/netscape/certsrv/tps/token/TokenClient.java
@@ -15,7 +15,7 @@
//(C) 2013 Red Hat, Inc.
//All rights reserved.
//--- END COPYRIGHT BLOCK ---
-package com.netscape.certsrv.token;
+package com.netscape.certsrv.tps.token;
import java.net.URISyntaxException;
diff --git a/base/common/src/com/netscape/certsrv/token/TokenCollection.java b/base/common/src/com/netscape/certsrv/tps/token/TokenCollection.java
index e5de21f74..8af483b8a 100644
--- a/base/common/src/com/netscape/certsrv/token/TokenCollection.java
+++ b/base/common/src/com/netscape/certsrv/tps/token/TokenCollection.java
@@ -16,7 +16,7 @@
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
-package com.netscape.certsrv.token;
+package com.netscape.certsrv.tps.token;
import java.util.Collection;
diff --git a/base/common/src/com/netscape/certsrv/token/TokenData.java b/base/common/src/com/netscape/certsrv/tps/token/TokenData.java
index 9dc8a9cec..cbd8275b2 100644
--- a/base/common/src/com/netscape/certsrv/token/TokenData.java
+++ b/base/common/src/com/netscape/certsrv/tps/token/TokenData.java
@@ -16,7 +16,7 @@
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
-package com.netscape.certsrv.token;
+package com.netscape.certsrv.tps.token;
import java.io.StringReader;
import java.io.StringWriter;
diff --git a/base/common/src/com/netscape/certsrv/token/TokenModifyRequest.java b/base/common/src/com/netscape/certsrv/tps/token/TokenModifyRequest.java
index bf0c4b6ea..b4168261f 100644
--- a/base/common/src/com/netscape/certsrv/token/TokenModifyRequest.java
+++ b/base/common/src/com/netscape/certsrv/tps/token/TokenModifyRequest.java
@@ -16,7 +16,7 @@
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
-package com.netscape.certsrv.token;
+package com.netscape.certsrv.tps.token;
import java.io.StringReader;
import java.io.StringWriter;
diff --git a/base/common/src/com/netscape/certsrv/token/TokenResource.java b/base/common/src/com/netscape/certsrv/tps/token/TokenResource.java
index 8fe733d88..5f98845e3 100644
--- a/base/common/src/com/netscape/certsrv/token/TokenResource.java
+++ b/base/common/src/com/netscape/certsrv/tps/token/TokenResource.java
@@ -15,7 +15,7 @@
// (C) 2013 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
-package com.netscape.certsrv.token;
+package com.netscape.certsrv.tps.token;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;