You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2001/10/12 13:46:05 UTC
cvs commit: xml-axis/java/test build_functional_tests.xml
dims 01/10/12 04:46:05
Modified: java/samples/echo EchoService.java TestClient.java
java/src/org/apache/axis/encoding Hex.java
HexSerializer.java SOAPTypeMappingRegistry.java
java/src/org/apache/axis/wsdl Type.java
java/test build_functional_tests.xml
Log:
- Support for hexBinary
- Make latest Jikes compiler happy
- Pick up jars from java\lib for running functional tests.
Revision Changes Path
1.8 +7 -0 xml-axis/java/samples/echo/EchoService.java
Index: EchoService.java
===================================================================
RCS file: /home/cvs/xml-axis/java/samples/echo/EchoService.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- EchoService.java 2001/08/17 18:55:15 1.7
+++ EchoService.java 2001/10/12 11:46:05 1.8
@@ -143,6 +143,13 @@
}
/**
+ * This methods accepts a hex object and echoes it back to the client.
+ */
+ public org.apache.axis.encoding.Hex echoHex(org.apache.axis.encoding.Hex input) {
+ return input;
+ }
+
+ /**
* This method accepts a Date/Time and echoes it back to the client.
*/
public Date echoDate(Date input) {
1.29 +1 -0 xml-axis/java/samples/echo/TestClient.java
Index: TestClient.java
===================================================================
RCS file: /home/cvs/xml-axis/java/samples/echo/TestClient.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- TestClient.java 2001/09/12 14:57:42 1.28
+++ TestClient.java 2001/10/12 11:46:05 1.29
@@ -212,6 +212,7 @@
new SOAPStruct(3, "three", 3.3F)});
test("Void ", null);
test("Base64 ", "Base64".getBytes());
+ test("Hex ", new org.apache.axis.encoding.Hex("3344"));
test("Date ", new Date());
test("Decimal ", new BigDecimal("3.14159"));
test("Boolean ", Boolean.TRUE);
1.2 +142 -173 xml-axis/java/src/org/apache/axis/encoding/Hex.java
Index: Hex.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/Hex.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Hex.java 2001/10/10 12:58:11 1.1
+++ Hex.java 2001/10/12 11:46:05 1.2
@@ -54,212 +54,181 @@
*/
package org.apache.axis.encoding ;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
/**
+ * Custom class for supporting primitive XSD data type hexBinary.
*
- * @author TAMURA Kent <kent@trl.ibm.co.jp>
+ * @author Davanum Srinivas <di...@yahoo.com>
*/
-public class Hex {
- private static final char[] S_HEXCHAR = {
- '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
- };
- private static final char S_HEXPAD = '=';
- private static final byte[] S_DECODETABLE = new byte[32];
- static {
- for (int i = 0; i < S_DECODETABLE.length; i ++)
- S_DECODETABLE[i] = Byte.MAX_VALUE; // 127
- for (int i = 0; i < S_HEXCHAR.length; i ++) // 0 to 15
- S_DECODETABLE[S_HEXCHAR[i]] = (byte)i;
+public class Hex extends Object{
+
+ byte[] m_value = null;
+
+ public Hex() {
}
- private static int decode0(char[] ibuf, byte[] obuf, int wp) {
- int b0 = S_DECODETABLE[ibuf[0]];
- int b1 = S_DECODETABLE[ibuf[1]];
- obuf[wp] = (byte)(b0 << 2 & 0xfc | b1 >> 4 & 0x3);
- return 1;
+ public Hex(String string){
+ m_value = decode(string);
}
- /**
- *
- */
- public static byte[] decode(char[] data, int off, int len) {
- char[] ibuf = new char[2];
- int ibufcount = 0;
- byte[] obuf = new byte[len/2*1+1];
- int obufcount = 0;
- for (int i = off; i < off+len; i ++) {
- char ch = data[i];
- if (ch == S_HEXPAD
- || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
- ibuf[ibufcount++] = ch;
- if (ibufcount == ibuf.length) {
- ibufcount = 0;
- obufcount += decode0(ibuf, obuf, obufcount);
- }
- }
- }
- if (obufcount == obuf.length)
- return obuf;
- byte[] ret = new byte[obufcount];
- System.arraycopy(obuf, 0, ret, 0, obufcount);
- return ret;
+ public byte[] getBytes(){
+ return m_value;
}
- /**
- *
- */
- public static byte[] decode(String data) {
- char[] ibuf = new char[2];
- int ibufcount = 0;
- byte[] obuf = new byte[data.length()/2*1+1];
- int obufcount = 0;
- for (int i = 0; i < data.length(); i ++) {
- char ch = data.charAt(i);
- if (ch == S_HEXPAD
- || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
- ibuf[ibufcount++] = ch;
- if (ibufcount == ibuf.length) {
- ibufcount = 0;
- obufcount += decode0(ibuf, obuf, obufcount);
- }
- }
- }
- if (obufcount == obuf.length)
- return obuf;
- byte[] ret = new byte[obufcount];
- System.arraycopy(obuf, 0, ret, 0, obufcount);
- return ret;
+ public String toString(){
+ return encode(m_value);
}
- /**
- *
- */
- public static void decode(char[] data, int off, int len, OutputStream ostream) throws IOException {
- char[] ibuf = new char[2];
- int ibufcount = 0;
- byte[] obuf = new byte[1];
- for (int i = off; i < off+len; i ++) {
- char ch = data[i];
- if (ch == S_HEXPAD
- || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
- ibuf[ibufcount++] = ch;
- if (ibufcount == ibuf.length) {
- ibufcount = 0;
- int obufcount = decode0(ibuf, obuf, 0);
- ostream.write(obuf, 0, obufcount);
- }
- }
- }
+ public int hashCode(){
+ //TODO: How do we hash this?
+ return super.hashCode();
+ }
+
+ public boolean equals(java.lang.Object object){
+ //TODO: Is this good enough?
+ String s1 = object.toString();
+ String s2 = this.toString();
+ return s1.equals(s2);
}
+ public static final String ERROR_ODD_NUMBER_OF_DIGITS="Odd number of digits hex string";
+ public static final String ERROR_BAD_CHARACTER_IN_HEX_STRING="Bad character or insufficient number of characters in hex string";
+
+ // Code from Ajp11, from Apache's JServ
+
+ // Table for HEX to DEC byte translation
+ public static final int[] DEC = {
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 00, 01, 02, 03, 04, 05, 06, 07, 8, 9, -1, -1, -1, -1, -1, -1,
+ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ };
+
/**
+ * Convert a String of hexadecimal digits into the corresponding
+ * byte array by encoding each two hexadecimal digits as a byte.
*
- */
- public static void decode(String data, OutputStream ostream) throws IOException {
- char[] ibuf = new char[2];
- int ibufcount = 0;
- byte[] obuf = new byte[1];
- for (int i = 0; i < data.length(); i ++) {
- char ch = data.charAt(i);
- if (ch == S_HEXPAD
- || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
- ibuf[ibufcount++] = ch;
- if (ibufcount == ibuf.length) {
- ibufcount = 0;
- int obufcount = decode0(ibuf, obuf, 0);
- ostream.write(obuf, 0, obufcount);
- }
- }
+ * @param digits Hexadecimal digits representation
+ *
+ * @exception IllegalArgumentException if an invalid hexadecimal digit
+ * is found, or the input string contains an odd number of hexadecimal
+ * digits
+ */
+ public static byte[] decode(String digits) {
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ for (int i = 0; i < digits.length(); i += 2) {
+ char c1 = digits.charAt(i);
+ if ((i+1) >= digits.length())
+ throw new IllegalArgumentException
+ (ERROR_ODD_NUMBER_OF_DIGITS);
+ char c2 = digits.charAt(i + 1);
+ byte b = 0;
+ if ((c1 >= '0') && (c1 <= '9'))
+ b += ((c1 - '0') * 16);
+ else if ((c1 >= 'a') && (c1 <= 'f'))
+ b += ((c1 - 'a' + 10) * 16);
+ else if ((c1 >= 'A') && (c1 <= 'F'))
+ b += ((c1 - 'A' + 10) * 16);
+ else
+ throw new IllegalArgumentException
+ (ERROR_BAD_CHARACTER_IN_HEX_STRING);
+ if ((c2 >= '0') && (c2 <= '9'))
+ b += (c2 - '0');
+ else if ((c2 >= 'a') && (c2 <= 'f'))
+ b += (c2 - 'a' + 10);
+ else if ((c2 >= 'A') && (c2 <= 'F'))
+ b += (c2 - 'A' + 10);
+ else
+ throw new IllegalArgumentException
+ (ERROR_BAD_CHARACTER_IN_HEX_STRING);
+ baos.write(b);
}
- }
+ return (baos.toByteArray());
- /**
- * Returns hex representation of specified byte array.
- */
- public static String encode(byte[] data) {
- return encode(data, 0, data.length);
}
+
/**
- * Returns hex representation of specified byte array.
+ * Convert a byte array into a printable format containing a
+ * String of hexadecimal digit characters (two per byte).
+ *
+ * @param bytes Byte array representation
*/
- public static String encode(byte[] data, int off, int len) {
- if (len <= 0) return "";
- char[] out = new char[len/1*2+2];
- int rindex = off;
- int windex = 0;
- int rest = len-off;
- while (rest >= 1) {
- int i = ((data[rindex]&0xff)<<8)
- +(data[rindex+1]&0xff);
- out[windex++] = S_HEXCHAR[(i>>6)&0x3f];
- out[windex++] = S_HEXCHAR[i&0x3f];
- rindex += 3;
- rest -= 3;
- }
- if (rest == 1) {
- int i = data[rindex]&0xff;
- out[windex++] = S_HEXCHAR[i>>2];
- out[windex++] = S_HEXPAD;
+ public static String encode(byte bytes[]) {
+
+ StringBuffer sb = new StringBuffer(bytes.length * 2);
+ for (int i = 0; i < bytes.length; i++) {
+ sb.append(convertDigit((int) (bytes[i] >> 4)));
+ sb.append(convertDigit((int) (bytes[i] & 0x0f)));
}
- return new String(out, 0, windex);
+ return (sb.toString());
+
}
/**
- * Outputs hex representation of the specified byte array to a byte stream.
+ * Convert 4 hex digits to an int, and return the number of converted
+ * bytes.
+ *
+ * @param hex Byte array containing exactly four hexadecimal digits
+ *
+ * @exception IllegalArgumentException if an invalid hexadecimal digit
+ * is included
*/
- public static void encode(byte[] data, int off, int len, OutputStream ostream) throws IOException {
- if (len <= 0) return;
- byte[] out = new byte[4];
- int rindex = off;
- int rest = len-off;
- while (rest >= 1) {
- int i = ((data[rindex]&0xff)<<8)
- +(data[rindex+1]&0xff);
- out[0] = (byte)S_HEXCHAR[(i>>6)&0x3f];
- out[1] = (byte)S_HEXCHAR[i&0x3f];
- ostream.write(out, 0, 2);
- rindex += 1;
- rest -= 1;
- }
- if (rest == 1) {
- int i = data[rindex]&0xff;
- out[0] = (byte)S_HEXCHAR[i>>2];
- out[1] = (byte)S_HEXCHAR[(i<<4)&0x3f];
- ostream.write(out, 0, 2);
- }
+ public static int convert2Int( byte[] hex ) {
+ // Code from Ajp11, from Apache's JServ
+
+ // assert b.length==4
+ // assert valid data
+ int len;
+ if(hex.length < 4 ) return 0;
+ if( DEC[hex[0]]<0 )
+ throw new IllegalArgumentException(ERROR_BAD_CHARACTER_IN_HEX_STRING);
+ len = DEC[hex[0]];
+ len = len << 4;
+ if( DEC[hex[1]]<0 )
+ throw new IllegalArgumentException(ERROR_BAD_CHARACTER_IN_HEX_STRING);
+ len += DEC[hex[1]];
+ len = len << 4;
+ if( DEC[hex[2]]<0 )
+ throw new IllegalArgumentException(ERROR_BAD_CHARACTER_IN_HEX_STRING);
+ len += DEC[hex[2]];
+ len = len << 4;
+ if( DEC[hex[3]]<0 )
+ throw new IllegalArgumentException(ERROR_BAD_CHARACTER_IN_HEX_STRING);
+ len += DEC[hex[3]];
+ return len;
}
/**
- * Outputs hex representation of the specified byte array to a character stream.
+ * [Private] Convert the specified value (0 .. 15) to the corresponding
+ * hexadecimal digit.
+ *
+ * @param value Value to be converted
*/
- public static void encode(byte[] data, int off, int len, Writer writer) throws IOException {
- if (len <= 0) return;
- char[] out = new char[4];
- int rindex = off;
- int rest = len-off;
- int output = 0;
- while (rest >= 1) {
- int i = ((data[rindex]&0xff)<<8)
- +(data[rindex+1]&0xff);
- out[0] = S_HEXCHAR[(i>>6)&0x3f];
- out[1] = S_HEXCHAR[i&0x3f];
- writer.write(out, 0, 2);
- rindex += 1;
- rest -= 1;
- output += 2;
- if (output % 19 == 0)
- writer.write("\n");
- }
- if (rest == 1) {
- int i = data[rindex]&0xff;
- out[0] = S_HEXCHAR[i>>2];
- out[1] = S_HEXCHAR[(i<<4)&0x3f];
- writer.write(out, 0, 2);
- }
+ private static char convertDigit(int value) {
+
+ value &= 0x0f;
+ if (value >= 10)
+ return ((char) (value - 10 + 'a'));
+ else
+ return ((char) (value + '0'));
+
}
}
1.2 +3 -3 xml-axis/java/src/org/apache/axis/encoding/HexSerializer.java
Index: HexSerializer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/HexSerializer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HexSerializer.java 2001/10/10 12:58:11 1.1
+++ HexSerializer.java 2001/10/12 11:46:05 1.2
@@ -73,7 +73,7 @@
public void characters(char [] chars, int start, int end)
throws SAXException
{
- value = Hex.decode(chars, start, end);
+ value = new Hex(new String(chars, start, end));
}
}
@@ -90,10 +90,10 @@
Object value, SerializationContext context)
throws IOException
{
- byte[] data = (byte[]) value;
+ Hex data = (Hex) value;
context.startElement(name, attributes);
- context.writeString(Hex.encode(data, 0, data.length));
+ context.writeString(data.toString());
context.endElement();
}
}
1.38 +2 -2 xml-axis/java/src/org/apache/axis/encoding/SOAPTypeMappingRegistry.java
Index: SOAPTypeMappingRegistry.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/SOAPTypeMappingRegistry.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- SOAPTypeMappingRegistry.java 2001/10/10 12:58:11 1.37
+++ SOAPTypeMappingRegistry.java 2001/10/12 11:46:05 1.38
@@ -252,7 +252,7 @@
addSerializer(java.lang.Byte.TYPE, XSD_BYTE, se);
addSerializer(java.util.Date.class, XSD_DATE, new DateSerializer());
addSerializer(byte[].class, XSD_BASE64, new Base64Serializer());
-// addSerializer(byte[].class, XSD_HEXBIN, new HexSerializer());
+ addSerializer(Hex.class, XSD_HEXBIN, new HexSerializer());
addSerializer(java.math.BigDecimal.class, XSD_DECIMAL, se);
addDeserializersFor(XSD_STRING, java.lang.String.class, factory);
@@ -290,7 +290,7 @@
addDeserializerFactory(XSD_BASE64, byte[].class, base64Ser);
// handle the hexBinary QName...
- addDeserializerFactory(XSD_HEXBIN, byte[].class, hexSer);
+ addDeserializerFactory(XSD_HEXBIN, Hex.class, hexSer);
// !!! Seems a little weird to pass a null class here...?
addDeserializerFactory(SOAP_ARRAY, null, ArraySerializer.factory);
1.6 +1 -1 xml-axis/java/src/org/apache/axis/wsdl/Type.java
Index: Type.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/Type.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Type.java 2001/10/10 13:45:04 1.5
+++ Type.java 2001/10/12 11:46:05 1.6
@@ -186,7 +186,7 @@
} else if (localName.equals("base64Binary")) {
return "byte[]";
} else if (localName.equals("hexBinary")) {
- return "byte[]";
+ return "org.apache.axis.encoding.Hex";
} else if (localName.equals("date")) {
return "java.util.Date";
} else if (localName.equals("void")) {
1.10 +4 -0 xml-axis/java/test/build_functional_tests.xml
Index: build_functional_tests.xml
===================================================================
RCS file: /home/cvs/xml-axis/java/test/build_functional_tests.xml,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- build_functional_tests.xml 2001/09/16 19:58:46 1.9
+++ build_functional_tests.xml 2001/10/12 11:46:05 1.10
@@ -28,6 +28,10 @@
<pathelement location="${build.dir}" />
<pathelement location="${build.dest}" />
<pathelement path="${java.class.path}" />
+ <pathelement location="${log4j-core.jar}"/>
+ <fileset dir="../java/lib">
+ <include name="*.jar"/>
+ </fileset>
</path>
<taskdef name="runaxisfunctionaltests"