Lucio Lelii 2016-06-15 11:46:54 +00:00
parent fea33de67b
commit 68ceb8f9fd
3 changed files with 28 additions and 11 deletions

View File

@ -6,13 +6,16 @@ import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name="auhtorization-endpoint") @XmlRootElement(name="authorization-endpoint")
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public final class AuthorizationEndpoint implements Comparable<AuthorizationEndpoint>{ public final class AuthorizationEndpoint implements Comparable<AuthorizationEndpoint>{
@XmlAttribute @XmlAttribute
private int priority = 0; private int priority = 0;
@XmlElement
private String infrastructure;
@XmlElement @XmlElement
private String host; private String host;
@ -21,13 +24,18 @@ public final class AuthorizationEndpoint implements Comparable<AuthorizationEndp
protected AuthorizationEndpoint() {} protected AuthorizationEndpoint() {}
public AuthorizationEndpoint(int priority, String host, int port) { public AuthorizationEndpoint(String infrastructure, int priority, String host, int port) {
super(); super();
this.infrastructure = infrastructure;
this.host = host; this.host = host;
this.priority = priority; this.priority = priority;
this.port = port; this.port = port;
} }
protected String getInfrastructure() {
return infrastructure;
}
public String getHost() { public String getHost() {
return host; return host;
} }
@ -51,7 +59,7 @@ public final class AuthorizationEndpoint implements Comparable<AuthorizationEndp
@Override @Override
public String toString() { public String toString() {
return "AuthorizationEndpoint [priority=" + priority + ", host=" + host return "AuthorizationEndpoint [infrastructure= "+infrastructure+" priority=" + priority + ", host=" + host
+ ", port=" + port + "]"; + ", port=" + port + "]";
} }
@ -60,6 +68,8 @@ public final class AuthorizationEndpoint implements Comparable<AuthorizationEndp
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((host == null) ? 0 : host.hashCode()); result = prime * result + ((host == null) ? 0 : host.hashCode());
result = prime * result
+ ((infrastructure == null) ? 0 : infrastructure.hashCode());
result = prime * result + port; result = prime * result + port;
result = prime * result + priority; result = prime * result + priority;
return result; return result;
@ -79,6 +89,11 @@ public final class AuthorizationEndpoint implements Comparable<AuthorizationEndp
return false; return false;
} else if (!host.equals(other.host)) } else if (!host.equals(other.host))
return false; return false;
if (infrastructure == null) {
if (other.infrastructure != null)
return false;
} else if (!infrastructure.equals(other.infrastructure))
return false;
if (port != other.port) if (port != other.port)
return false; return false;
if (priority != other.priority) if (priority != other.priority)
@ -86,4 +101,6 @@ public final class AuthorizationEndpoint implements Comparable<AuthorizationEndp
return true; return true;
} }
} }

View File

@ -1 +1 @@
<auhtorization-endpoint priority="10"><host>node7.d.d4science.research-infrastructures.eu</host><port>9000</port></auhtorization-endpoint> <authorization-endpoint priority="10"><host>node7.d.d4science.research-infrastructures.eu</host><port>9000</port></authorization-endpoint>

View File

@ -25,7 +25,7 @@ public class EndpointBinder {
public void bind() throws Exception{ public void bind() throws Exception{
JAXBContext context = getContext(); JAXBContext context = getContext();
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
AuthorizationEndpoint ae1 = new AuthorizationEndpoint(2, "146.48.85.179", 8080); AuthorizationEndpoint ae1 = new AuthorizationEndpoint("/myInfra", 2, "146.48.85.179", 8080);
context.createMarshaller().marshal(ae1, sw); context.createMarshaller().marshal(ae1, sw);
AuthorizationEndpoint ae2 = (AuthorizationEndpoint)context.createUnmarshaller().unmarshal(new StringReader(sw.toString())); AuthorizationEndpoint ae2 = (AuthorizationEndpoint)context.createUnmarshaller().unmarshal(new StringReader(sw.toString()));
Assert.assertEquals(ae1, ae2); Assert.assertEquals(ae1, ae2);
@ -33,17 +33,17 @@ public class EndpointBinder {
@Test @Test
public void compare(){ public void compare(){
AuthorizationEndpoint ae1 = new AuthorizationEndpoint(2, "146.48.85.179", 8080); AuthorizationEndpoint ae1 = new AuthorizationEndpoint("/myInfra", 2, "146.48.85.179", 8080);
AuthorizationEndpoint ae2 = new AuthorizationEndpoint(1, "146.48.85.179", 8080); AuthorizationEndpoint ae2 = new AuthorizationEndpoint("/myInfra", 1, "146.48.85.179", 8080);
Assert.assertTrue(ae1.compareTo(ae2)>0); Assert.assertTrue(ae1.compareTo(ae2)>0);
} }
@Test @Test
public void order(){ public void order(){
AuthorizationEndpoint ae1 = new AuthorizationEndpoint(2, "146.48.85.179", 8080); AuthorizationEndpoint ae1 = new AuthorizationEndpoint("/myInfra" ,2, "146.48.85.179", 8080);
AuthorizationEndpoint ae2 = new AuthorizationEndpoint(1, "146.48.85.179", 8080); AuthorizationEndpoint ae2 = new AuthorizationEndpoint("/myInfra" ,1, "146.48.85.179", 8080);
AuthorizationEndpoint ae3 = new AuthorizationEndpoint(3, "146.48.85.179", 8080); AuthorizationEndpoint ae3 = new AuthorizationEndpoint("/myInfra", 3, "146.48.85.179", 8080);
AuthorizationEndpoint[] arr1 = new AuthorizationEndpoint[]{ae1, ae2, ae3}; AuthorizationEndpoint[] arr1 = new AuthorizationEndpoint[]{ae1, ae2, ae3};