diff options
| author | Endi S. Dewata <edewata@redhat.com> | 2013-08-26 13:45:55 -0400 |
|---|---|---|
| committer | Endi Sukma Dewata <edewata@redhat.com> | 2013-09-01 01:04:57 -0500 |
| commit | 15e029e97aea4a23f065e6bc7fbfa16cdae8c02d (patch) | |
| tree | f0b9f036f1ccd26ba4202af30e36957fec520a37 /base/common/src/com | |
| parent | a847bcb7c71836f7c0498163e31238f118740339 (diff) | |
Added TPS connection resource.
A skeleton for TPS connection services and the clients have been added.
The service implementation will be added later.
Ticket #652
Diffstat (limited to 'base/common/src/com')
7 files changed, 686 insertions, 0 deletions
diff --git a/base/common/src/com/netscape/certsrv/tps/TPSClient.java b/base/common/src/com/netscape/certsrv/tps/TPSClient.java index 94a906cdf..00da49b20 100644 --- a/base/common/src/com/netscape/certsrv/tps/TPSClient.java +++ b/base/common/src/com/netscape/certsrv/tps/TPSClient.java @@ -24,6 +24,7 @@ import com.netscape.certsrv.client.SubsystemClient; import com.netscape.certsrv.group.GroupClient; import com.netscape.certsrv.logging.ActivityClient; import com.netscape.certsrv.tps.cert.TPSCertClient; +import com.netscape.certsrv.tps.connection.ConnectionClient; import com.netscape.certsrv.tps.token.TokenClient; import com.netscape.certsrv.user.UserClient; @@ -39,6 +40,7 @@ public class TPSClient extends SubsystemClient { public void init() throws URISyntaxException { addClient(new ActivityClient(client, name)); + addClient(new ConnectionClient(client, name)); addClient(new GroupClient(client, name)); addClient(new TokenClient(client, name)); addClient(new TPSCertClient(client, name)); diff --git a/base/common/src/com/netscape/certsrv/tps/connection/ConnectionClient.java b/base/common/src/com/netscape/certsrv/tps/connection/ConnectionClient.java new file mode 100644 index 000000000..74ec14616 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/tps/connection/ConnectionClient.java @@ -0,0 +1,76 @@ +//--- 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.connection; + +import java.net.URISyntaxException; + +import org.jboss.resteasy.client.ClientResponse; + +import com.netscape.certsrv.client.Client; +import com.netscape.certsrv.client.PKIClient; + +/** + * @author Endi S. Dewata + */ +public class ConnectionClient extends Client { + + public ConnectionResource resource; + + public ConnectionClient(PKIClient client) throws URISyntaxException { + this(client, client.getSubsystem()); + } + + public ConnectionClient(PKIClient client, String subsystem) throws URISyntaxException { + super(client, subsystem, "connection"); + init(); + } + + public void init() throws URISyntaxException { + resource = createProxy(ConnectionResource.class); + } + + public ConnectionCollection findConnections(Integer start, Integer size) { + return resource.findConnections(start, size); + } + + public ConnectionData getConnection(String connectionID) { + return resource.getConnection(connectionID); + } + + public ConnectionData addConnection(ConnectionData connectionData) { + @SuppressWarnings("unchecked") + ClientResponse<ConnectionData> response = (ClientResponse<ConnectionData>)resource.addConnection(connectionData); + return client.getEntity(response); + } + + public ConnectionData updateConnection(String connectionID, ConnectionData connectionData) { + @SuppressWarnings("unchecked") + ClientResponse<ConnectionData> response = (ClientResponse<ConnectionData>)resource.updateConnection(connectionID, connectionData); + return client.getEntity(response); + } + + public ConnectionData modifyConnection(String connectionID, ConnectionModification connectionModification) { + @SuppressWarnings("unchecked") + ClientResponse<ConnectionData> response = (ClientResponse<ConnectionData>)resource.modifyConnection(connectionID, connectionModification); + return client.getEntity(response); + } + + public void removeConnection(String connectionID) { + resource.removeConnection(connectionID); + } +} diff --git a/base/common/src/com/netscape/certsrv/tps/connection/ConnectionCollection.java b/base/common/src/com/netscape/certsrv/tps/connection/ConnectionCollection.java new file mode 100644 index 000000000..b26a7308d --- /dev/null +++ b/base/common/src/com/netscape/certsrv/tps/connection/ConnectionCollection.java @@ -0,0 +1,38 @@ +// --- 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.connection; + +import java.util.Collection; + +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlRootElement; + +import com.netscape.certsrv.base.DataCollection; + +/** + * @author Endi S. Dewata + */ +@XmlRootElement(name="Connections") +public class ConnectionCollection extends DataCollection<ConnectionInfo> { + + @XmlElementRef + public Collection<ConnectionInfo> getEntries() { + return super.getEntries(); + } +} diff --git a/base/common/src/com/netscape/certsrv/tps/connection/ConnectionData.java b/base/common/src/com/netscape/certsrv/tps/connection/ConnectionData.java new file mode 100644 index 000000000..573bb9543 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/tps/connection/ConnectionData.java @@ -0,0 +1,169 @@ +// --- 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.connection; + +import java.io.StringReader; +import java.io.StringWriter; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.jboss.resteasy.plugins.providers.atom.Link; + +/** + * @author Endi S. Dewata + */ +@XmlRootElement(name="Connection") +public class ConnectionData { + + public static Marshaller marshaller; + public static Unmarshaller unmarshaller; + + static { + try { + marshaller = JAXBContext.newInstance(ConnectionData.class).createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + unmarshaller = JAXBContext.newInstance(ConnectionData.class).createUnmarshaller(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + String id; + String status; + String contents; + + Link link; + + @XmlAttribute(name="id") + public String getID() { + return id; + } + + public void setID(String id) { + this.id = id; + } + + @XmlElement(name="Status") + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + @XmlElement(name="Contents") + public String getContents() { + return contents; + } + + public void setContents(String contents) { + this.contents = contents; + } + + @XmlElement(name="Link") + public Link getLink() { + return link; + } + + public void setLink(Link link) { + this.link = link; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((contents == null) ? 0 : contents.hashCode()); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((link == null) ? 0 : link.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ConnectionData other = (ConnectionData) obj; + if (contents == null) { + if (other.contents != null) + return false; + } else if (!contents.equals(other.contents)) + return false; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (link == null) { + if (other.link != null) + return false; + } else if (!link.equals(other.link)) + return false; + if (status == null) { + if (other.status != null) + return false; + } else if (!status.equals(other.status)) + return false; + return true; + } + + public String toString() { + try { + StringWriter sw = new StringWriter(); + marshaller.marshal(this, sw); + return sw.toString(); + + } catch (Exception e) { + return super.toString(); + } + } + + public static ConnectionData valueOf(String string) throws Exception { + try { + return (ConnectionData)unmarshaller.unmarshal(new StringReader(string)); + } catch (Exception e) { + return null; + } + } + + public static void main(String args[]) throws Exception { + + ConnectionData before = new ConnectionData(); + before.setID("connection1"); + before.setStatus("ENABLED"); + before.setContents("name=connection1\nparam=value"); + + String string = before.toString(); + System.out.println(string); + + ConnectionData after = ConnectionData.valueOf(string); + System.out.println(before.equals(after)); + } +} diff --git a/base/common/src/com/netscape/certsrv/tps/connection/ConnectionInfo.java b/base/common/src/com/netscape/certsrv/tps/connection/ConnectionInfo.java new file mode 100644 index 000000000..d9d93517e --- /dev/null +++ b/base/common/src/com/netscape/certsrv/tps/connection/ConnectionInfo.java @@ -0,0 +1,152 @@ +// --- 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.connection; + +import java.io.StringReader; +import java.io.StringWriter; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.jboss.resteasy.plugins.providers.atom.Link; + +/** + * @author Endi S. Dewata + */ +@XmlRootElement(name="Connection") +public class ConnectionInfo { + + public static Marshaller marshaller; + public static Unmarshaller unmarshaller; + + static { + try { + marshaller = JAXBContext.newInstance(ConnectionInfo.class).createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + unmarshaller = JAXBContext.newInstance(ConnectionInfo.class).createUnmarshaller(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + String id; + String status; + + Link link; + + @XmlAttribute(name="id") + public String getID() { + return id; + } + + public void setID(String id) { + this.id = id; + } + + @XmlElement(name="Status") + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + @XmlElement(name="Link") + public Link getLink() { + return link; + } + + public void setLink(Link link) { + this.link = link; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((link == null) ? 0 : link.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ConnectionInfo other = (ConnectionInfo) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (link == null) { + if (other.link != null) + return false; + } else if (!link.equals(other.link)) + return false; + if (status == null) { + if (other.status != null) + return false; + } else if (!status.equals(other.status)) + return false; + return true; + } + + public String toString() { + try { + StringWriter sw = new StringWriter(); + marshaller.marshal(this, sw); + return sw.toString(); + + } catch (Exception e) { + return super.toString(); + } + } + + public static ConnectionInfo valueOf(String string) throws Exception { + try { + return (ConnectionInfo)unmarshaller.unmarshal(new StringReader(string)); + } catch (Exception e) { + return null; + } + } + + public static void main(String args[]) throws Exception { + + ConnectionInfo before = new ConnectionInfo(); + before.setID("connection1"); + before.setStatus("ENABLED"); + + String string = before.toString(); + System.out.println(string); + + ConnectionInfo after = ConnectionInfo.valueOf(string); + System.out.println(before.equals(after)); + } +} diff --git a/base/common/src/com/netscape/certsrv/tps/connection/ConnectionModification.java b/base/common/src/com/netscape/certsrv/tps/connection/ConnectionModification.java new file mode 100644 index 000000000..7e48074b2 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/tps/connection/ConnectionModification.java @@ -0,0 +1,169 @@ +// --- 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.connection; + +import java.io.StringReader; +import java.io.StringWriter; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.jboss.resteasy.plugins.providers.atom.Link; + +/** + * @author Endi S. Dewata + */ +@XmlRootElement(name="ConnectionModifyRequest") +public class ConnectionModification { + + public static Marshaller marshaller; + public static Unmarshaller unmarshaller; + + static { + try { + marshaller = JAXBContext.newInstance(ConnectionModification.class).createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + unmarshaller = JAXBContext.newInstance(ConnectionModification.class).createUnmarshaller(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + String id; + String status; + String contents; + + Link link; + + @XmlAttribute(name="id") + public String getID() { + return id; + } + + public void setID(String id) { + this.id = id; + } + + @XmlElement(name="Status") + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + @XmlElement(name="Contents") + public String getContents() { + return contents; + } + + public void setContents(String contents) { + this.contents = contents; + } + + @XmlElement(name="Link") + public Link getLink() { + return link; + } + + public void setLink(Link link) { + this.link = link; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((contents == null) ? 0 : contents.hashCode()); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((link == null) ? 0 : link.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ConnectionModification other = (ConnectionModification) obj; + if (contents == null) { + if (other.contents != null) + return false; + } else if (!contents.equals(other.contents)) + return false; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (link == null) { + if (other.link != null) + return false; + } else if (!link.equals(other.link)) + return false; + if (status == null) { + if (other.status != null) + return false; + } else if (!status.equals(other.status)) + return false; + return true; + } + + public String toString() { + try { + StringWriter sw = new StringWriter(); + marshaller.marshal(this, sw); + return sw.toString(); + + } catch (Exception e) { + return super.toString(); + } + } + + public static ConnectionModification valueOf(String string) throws Exception { + try { + return (ConnectionModification)unmarshaller.unmarshal(new StringReader(string)); + } catch (Exception e) { + return null; + } + } + + public static void main(String args[]) throws Exception { + + ConnectionModification before = new ConnectionModification(); + before.setID("connection1"); + before.setStatus("ENABLED"); + before.setContents("name=connection1\nparam=value"); + + String string = before.toString(); + System.out.println(string); + + ConnectionModification after = ConnectionModification.valueOf(string); + System.out.println(before.equals(after)); + } +} diff --git a/base/common/src/com/netscape/certsrv/tps/connection/ConnectionResource.java b/base/common/src/com/netscape/certsrv/tps/connection/ConnectionResource.java new file mode 100644 index 000000000..ee971b052 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/tps/connection/ConnectionResource.java @@ -0,0 +1,80 @@ +// --- 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.connection; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.jboss.resteasy.annotations.ClientResponseType; + + +/** + * @author Endi S. Dewata + */ +@Path("connections") +public interface ConnectionResource { + + @GET + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public ConnectionCollection findConnections( + @QueryParam("start") Integer start, + @QueryParam("size") Integer size); + + @GET + @Path("{connectionID}") + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public ConnectionData getConnection(@PathParam("connectionID") String connectionID); + + @POST + @ClientResponseType(entityType=ConnectionData.class) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public Response addConnection(ConnectionData connectionData); + + @PUT + @Path("{connectionID}") + @ClientResponseType(entityType=ConnectionData.class) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public Response updateConnection( + @PathParam("connectionID") String connectionID, + ConnectionData connectionData); + + @POST + @Path("{connectionID}") + @ClientResponseType(entityType=ConnectionData.class) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public Response modifyConnection( + @PathParam("connectionID") String connectionID, + ConnectionModification request); + + @DELETE + @Path("{connectionID}") + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public void removeConnection(@PathParam("connectionID") String connectionID); +} |
