Skip to content

Commit 943231e

Browse files
committed
Add odm to build
Issue gh-610
1 parent 53ae532 commit 943231e

File tree

5 files changed

+194
-7
lines changed

5 files changed

+194
-7
lines changed

dependencies/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ dependencies {
3434
api "com.squareup.okhttp3:okhttp:3.14.9"
3535
api "com.unboundid:unboundid-ldapsdk:4.0.14"
3636
api "commons-codec:commons-codec:1.15"
37+
api "commons-cli:commons-cli:1.2"
3738
api "commons-collections:commons-collections:3.2.2"
3839
api "commons-io:commons-io:2.11.0"
3940
api "commons-lang:commons-lang:2.6"
@@ -47,6 +48,7 @@ dependencies {
4748
api "jakarta.xml.bind:jakarta.xml.bind-api:3.0.1"
4849
api "jakarta.persistence:jakarta.persistence-api:3.0.0"
4950
api "javax.activation:activation:1.1"
51+
api "jdepend:jdepend:2.9.1"
5052
api "ldapsdk:ldapsdk:4.1"
5153
api "net.sourceforge.htmlunit:htmlunit:2.54.0"
5254
api "net.sourceforge.nekohtml:nekohtml:1.9.22"
@@ -65,6 +67,7 @@ dependencies {
6567
api "org.easymock:easymock:2.5.1"
6668
api "org.eclipse.jetty:jetty-server:11.0.6"
6769
api "org.eclipse.jetty:jetty-servlet:11.0.6"
70+
api "org.freemarker:freemarker:2.3.20"
6871
api "jakarta.persistence:jakarta.persistence-api:3.0.0"
6972
api "org.hamcrest:hamcrest:2.2"
7073
api "org.hibernate:hibernate-core-jakarta:5.6.0.Final"

odm/build.gradle

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,32 @@ jar {
77
}
88

99
dependencies {
10+
management platform(project(":spring-ldap-dependencies"))
1011
implementation project(":spring-ldap-core"),
1112
project(":spring-ldap-core-tiger"),
1213
"org.springframework:spring-core",
13-
"org.freemarker:freemarker:2.3.20",
14+
"org.freemarker:freemarker",
1415
"commons-logging:commons-logging",
15-
"commons-cli:commons-cli:1.2"
16+
"commons-cli:commons-cli"
1617

1718
runtimeOnly "org.springframework:spring-context"
1819

1920
provided "commons-pool:commons-pool",
20-
"com.sun:ldapbp:1.0",
2121
"commons-lang:commons-lang",
2222
"org.springframework:spring-context",
2323
"org.springframework:spring-jdbc",
2424
"org.springframework:spring-orm"
2525

2626
testImplementation project(":spring-ldap-test"),
2727
"junit:junit",
28-
"jdepend:jdepend:2.9.1",
28+
"jdepend:jdepend",
2929
"commons-io:commons-io"
30+
testImplementation "org.apache.directory.server:apacheds-core-entry"
31+
testImplementation "org.apache.directory.server:apacheds-core"
32+
testImplementation "org.apache.directory.server:apacheds-protocol-ldap"
33+
testImplementation "org.apache.directory.server:apacheds-protocol-shared"
34+
testImplementation "org.apache.directory.server:apacheds-server-jndi"
35+
testImplementation "org.apache.directory.shared:shared-ldap"
36+
testImplementation platform('org.junit:junit-bom')
37+
testImplementation "org.junit.vintage:junit-vintage-engine"
3038
}
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/*
2+
* Copyright 2002-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.apache.directory.server.core.avltree;
18+
19+
import java.io.ByteArrayInputStream;
20+
import java.io.ByteArrayOutputStream;
21+
import java.io.DataInputStream;
22+
import java.io.DataOutputStream;
23+
import java.io.IOException;
24+
import java.util.Comparator;
25+
26+
import org.apache.directory.shared.ldap.util.StringTools;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
29+
30+
/**
31+
* Class to serialize the Array data.
32+
*
33+
* @author <a href="mailto:[email protected]">Apache Directory Project</a>
34+
* @version $Rev$, $Date$
35+
*/
36+
@SuppressWarnings("unchecked")
37+
public class ArrayMarshaller<E> implements Marshaller<ArrayTree<E>> {
38+
39+
/** static logger */
40+
private static final Logger LOG = LoggerFactory.getLogger(ArrayMarshaller.class);
41+
42+
/** used for serialized form of an empty AvlTree */
43+
private static final byte[] EMPTY_TREE = new byte[1];
44+
45+
/** marshaller to be used for marshalling the keys */
46+
private Marshaller<E> keyMarshaller;
47+
48+
/** key Comparator for the AvlTree */
49+
private Comparator<E> comparator;
50+
51+
/**
52+
* Creates a new instance of AvlTreeMarshaller with a custom key Marshaller.
53+
* @param comparator Comparator to be used for key comparision
54+
* @param keyMarshaller marshaller for keys
55+
*/
56+
public ArrayMarshaller(Comparator<E> comparator, Marshaller<E> keyMarshaller) {
57+
this.comparator = comparator;
58+
this.keyMarshaller = keyMarshaller;
59+
}
60+
61+
/**
62+
* Creates a new instance of AvlTreeMarshaller with the default key Marshaller which
63+
* uses Java Serialization.
64+
* @param comparator Comparator to be used for key comparision
65+
*/
66+
public ArrayMarshaller(Comparator<E> comparator) {
67+
this.comparator = comparator;
68+
this.keyMarshaller = DefaultMarshaller.INSTANCE;
69+
}
70+
71+
/**
72+
* Marshals the given tree to bytes
73+
* @param tree the tree to be marshalled
74+
*/
75+
public byte[] serialize(ArrayTree<E> tree) {
76+
if ((tree == null) || (tree.size() == 0)) {
77+
return EMPTY_TREE;
78+
}
79+
80+
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
81+
DataOutputStream out = new DataOutputStream(byteStream);
82+
byte[] data = null;
83+
84+
try {
85+
out.writeByte(0); // represents the start of an Array byte stream
86+
out.writeInt(tree.size());
87+
88+
for (int position = 0; position < tree.size(); position++) {
89+
E value = tree.get(position);
90+
byte[] bytes = this.keyMarshaller.serialize(value);
91+
92+
// Write the key length
93+
out.writeInt(bytes.length);
94+
95+
// Write the key if its length is not null
96+
if (bytes.length != 0) {
97+
out.write(bytes);
98+
}
99+
}
100+
101+
out.flush();
102+
data = byteStream.toByteArray();
103+
104+
// Try to deserialize, just to see
105+
try {
106+
deserialize(data);
107+
}
108+
catch (NullPointerException npe) {
109+
System.out.println("Bad serialization, tree : [" + StringTools.dumpBytes(data) + "]");
110+
throw npe;
111+
}
112+
113+
out.close();
114+
}
115+
catch (IOException ex) {
116+
ex.printStackTrace();
117+
}
118+
119+
return data;
120+
}
121+
122+
/**
123+
* Creates an Array from given bytes of data.
124+
* @param data byte array to be converted into an array
125+
*/
126+
public ArrayTree<E> deserialize(byte[] data) throws IOException {
127+
try {
128+
if ((data == null) || (data.length == 0)) {
129+
throw new IOException("Null or empty data array is invalid.");
130+
}
131+
132+
if ((data.length == 1) && (data[0] == 0)) {
133+
E[] array = (E[]) new Object[] {};
134+
ArrayTree<E> tree = new ArrayTree<E>(this.comparator, array);
135+
return tree;
136+
}
137+
138+
ByteArrayInputStream bin = new ByteArrayInputStream(data);
139+
DataInputStream din = new DataInputStream(bin);
140+
141+
byte startByte = din.readByte();
142+
143+
if (startByte != 0) {
144+
throw new IOException("wrong array serialized data format");
145+
}
146+
147+
int size = din.readInt();
148+
E[] nodes = (E[]) new Object[size];
149+
150+
for (int i = 0; i < size; i++) {
151+
// Read the object's size
152+
int dataSize = din.readInt();
153+
154+
if (dataSize != 0) {
155+
byte[] bytes = new byte[dataSize];
156+
157+
din.read(bytes);
158+
E key = this.keyMarshaller.deserialize(bytes);
159+
nodes[i] = key;
160+
}
161+
}
162+
163+
ArrayTree<E> arrayTree = new ArrayTree<E>(this.comparator, nodes);
164+
165+
return arrayTree;
166+
}
167+
catch (NullPointerException npe) {
168+
System.out.println("Bad tree : [" + StringTools.dumpBytes(data) + "]");
169+
throw npe;
170+
}
171+
}
172+
173+
}

odm/src/test/java/org/springframework/ldap/odm/test/TestLdap.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
import org.apache.commons.cli.Options;
2323
import org.apache.commons.cli.ParseException;
2424
import org.apache.commons.cli.PosixParser;
25-
import org.apache.commons.codec.binary.Base64;
25+
import java.util.Base64;
26+
import org.junit.Ignore;
2627
import org.slf4j.Logger;
2728
import org.slf4j.LoggerFactory;
2829
import org.junit.After;
@@ -56,6 +57,8 @@
5657
import javax.naming.Name;
5758
import javax.naming.directory.SearchControls;
5859
import javax.naming.ldap.LdapName;
60+
import javax.naming.spi.NamingManager;
61+
5962
import java.awt.image.BufferedImage;
6063
import java.io.IOException;
6164
import java.lang.reflect.Method;
@@ -124,7 +127,7 @@ public final class TestLdap {
124127
"Rn0HStE+IrZSQbEuRxvU4De4yc0UVFKCnuerms2vZryP/Z";
125128

126129
byte[] photoBytes=photoString.getBytes("US-ASCII");
127-
photo=Base64.decodeBase64(photoBytes);
130+
photo=Base64.getDecoder().decode(photoBytes);
128131
} catch (IOException e) {
129132
throw new RuntimeException("Problem decoding photo", e);
130133
}

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ include 'core-tiger'
2727
include 'dependencies'
2828
include 'test-support'
2929
include 'ldif/ldif-core'
30-
//include 'odm'
30+
include 'odm'
3131
////include 'sandbox'
3232
//include 'test/integration-tests'
3333
//include 'test/integration-tests-spring20'

0 commit comments

Comments
 (0)