You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by ru...@apache.org on 2001/11/10 03:28:10 UTC
cvs commit: xml-soap/java/src/org/apache/soap/encoding/soapenc HexDeserializer.java
rubys 01/11/09 18:28:10
Modified: java/samples/interop DeploymentDescriptor.xml
EchoTestClient.java EchoTestService.java
java/src/org/apache/soap Constants.java
java/src/org/apache/soap/encoding SOAPMappingRegistry.java
Added: java/src/org/apache/soap/encoding Hex.java
java/src/org/apache/soap/encoding/soapenc
HexDeserializer.java
Log:
Add Hex support
Revision Changes Path
1.10 +5 -1 xml-soap/java/samples/interop/DeploymentDescriptor.xml
Index: DeploymentDescriptor.xml
===================================================================
RCS file: /home/cvs/xml-soap/java/samples/interop/DeploymentDescriptor.xml,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DeploymentDescriptor.xml 2001/08/17 19:40:33 1.9
+++ DeploymentDescriptor.xml 2001/11/10 02:28:09 1.10
@@ -3,7 +3,7 @@
checkMustUnderstands="true">
<isd:provider type="java"
scope="Application"
- methods="nop echoInteger echoString echoFloat echoStruct echoIntegerArray echoFloatArray echoStringArray echoStructArray echoVoid echoBase64 echoDate echoDecimal echoBoolean echoMap echoMapArray">
+ methods="nop echoInteger echoString echoFloat echoStruct echoIntegerArray echoFloatArray echoStringArray echoStructArray echoVoid echoBase64 echoHexBinary echoDate echoDecimal echoBoolean echoMap echoMapArray">
<isd:java class="samples.interop.EchoTestService" static="false"/>
</isd:provider>
@@ -44,6 +44,10 @@
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:inputBase64"
xml2JavaClassName="org.apache.soap.encoding.soapenc.Base64Serializer"/>
+
+ <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
+ xmlns:x="" qname="x:inputHexBinary"
+ xml2JavaClassName="org.apache.soap.encoding.soapenc.HexSerializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:inputDate"
1.14 +5 -0 xml-soap/java/samples/interop/EchoTestClient.java
Index: EchoTestClient.java
===================================================================
RCS file: /home/cvs/xml-soap/java/samples/interop/EchoTestClient.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- EchoTestClient.java 2001/08/17 19:40:33 1.13
+++ EchoTestClient.java 2001/11/10 02:28:09 1.14
@@ -57,6 +57,7 @@
import java.util.Vector;
import org.apache.soap.*;
+import org.apache.soap.encoding.Hex;
import org.apache.soap.encoding.SOAPMappingRegistry;
import org.apache.soap.encoding.soapenc.*;
import org.apache.soap.rpc.*;
@@ -196,6 +197,10 @@
p = new Parameter("inputBase64", byte[].class, "ciao".getBytes(), null);
smr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName("", "return"), null, null, base64Ser);
doCall(url, "echoBase64", p);
+
+ p = new Parameter("inputHexBinary", Hex.class, new Hex("3344"), null);
+ smr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName("", "return"), null, null, dataSer);
+ doCall(url, "echoHexBinary", p);
p = new Parameter("inputDate", Date.class, new Date(), null);
smr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName("", "return"), null, null, dateSer);
1.7 +7 -0 xml-soap/java/samples/interop/EchoTestService.java
Index: EchoTestService.java
===================================================================
RCS file: /home/cvs/xml-soap/java/samples/interop/EchoTestService.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- EchoTestService.java 2001/09/04 14:44:55 1.6
+++ EchoTestService.java 2001/11/10 02:28:09 1.7
@@ -60,6 +60,8 @@
import java.util.Hashtable;
import java.util.Map;
+import org.apache.soap.encoding.Hex;
+
/** An implementation of the interop echo service as defined at
* http://www.xmethods.net/ilab.
*
@@ -118,6 +120,11 @@
public byte[] echoBase64(byte[] b64)
{
return b64;
+ }
+
+ public Hex echoHexBinary(Hex bytes)
+ {
+ return bytes;
}
public Date echoDate(Date d)
1.24 +6 -0 xml-soap/java/src/org/apache/soap/Constants.java
Index: Constants.java
===================================================================
RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/Constants.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- Constants.java 2001/07/09 23:24:34 1.23
+++ Constants.java 2001/11/10 02:28:09 1.24
@@ -232,6 +232,8 @@
new QName(Constants.NS_URI_1999_SCHEMA_XSD, "short");
public static final QName byte1999QName =
new QName(Constants.NS_URI_1999_SCHEMA_XSD, "byte");
+ public static final QName hex1999QName =
+ new QName(Constants.NS_URI_1999_SCHEMA_XSD, "hex");
public static final QName qName1999QName =
new QName(Constants.NS_URI_1999_SCHEMA_XSD, "QName");
public static final QName timeInst1999QName =
@@ -259,6 +261,8 @@
new QName(Constants.NS_URI_2000_SCHEMA_XSD, "short");
public static final QName byte2000QName =
new QName(Constants.NS_URI_2000_SCHEMA_XSD, "byte");
+ public static final QName hex2000QName =
+ new QName(Constants.NS_URI_2000_SCHEMA_XSD, "hex");
public static final QName qName2000QName =
new QName(Constants.NS_URI_2000_SCHEMA_XSD, "QName");
public static final QName timeInst2000QName =
@@ -286,6 +290,8 @@
new QName(Constants.NS_URI_2001_SCHEMA_XSD, "short");
public static final QName byte2001QName =
new QName(Constants.NS_URI_2001_SCHEMA_XSD, "byte");
+ public static final QName hex2001QName =
+ new QName(Constants.NS_URI_2001_SCHEMA_XSD, "hexBinary");
public static final QName qName2001QName =
new QName(Constants.NS_URI_2001_SCHEMA_XSD, "QName");
public static final QName timeInst2001QName =
1.25 +7 -0 xml-soap/java/src/org/apache/soap/encoding/SOAPMappingRegistry.java
Index: SOAPMappingRegistry.java
===================================================================
RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/encoding/SOAPMappingRegistry.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- SOAPMappingRegistry.java 2001/07/09 14:17:25 1.24
+++ SOAPMappingRegistry.java 2001/11/10 02:28:10 1.25
@@ -105,6 +105,7 @@
private static LongDeserializer longDeser = new LongDeserializer();
private static ShortDeserializer shortDeser = new ShortDeserializer();
private static ByteDeserializer byteDeser = new ByteDeserializer();
+ private static HexDeserializer hexDeser = new HexDeserializer();
private static QNameSerializer qNameSer = new QNameSerializer();
private static ParameterSerializer paramSer = new ParameterSerializer();
@@ -144,6 +145,7 @@
Constants.short1999QName,
Constants.byte1999QName,
Constants.byte1999QName,
+ Constants.hex1999QName,
Constants.qName1999QName,
Constants.date1999QName,
Constants.timeInst1999QName,
@@ -171,6 +173,7 @@
Constants.short2000QName,
Constants.byte2000QName,
Constants.byte2000QName,
+ Constants.hex2000QName,
Constants.qName2000QName,
Constants.date2000QName,
Constants.timeInst2000QName,
@@ -198,6 +201,7 @@
Constants.short2001QName,
Constants.byte2001QName,
Constants.byte2001QName,
+ Constants.hex2001QName,
Constants.qName2001QName,
Constants.date2001QName,
Constants.timeInst2001QName,
@@ -225,6 +229,7 @@
short.class,
Byte.class,
byte.class,
+ Hex.class,
QName.class,
GregorianCalendar.class,
Date.class,
@@ -304,6 +309,7 @@
ser, // short
ser, // Byte
ser, // byte
+ ser, // Hex
qNameSer, // QName
calSer, // GregorianCalendar
dateSer, // Date
@@ -331,6 +337,7 @@
shortDeser,
null,
byteDeser,
+ hexDeser,
qNameSer,
calSer,
dateSer,
1.1 xml-soap/java/src/org/apache/soap/encoding/Hex.java
Index: Hex.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Axis" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.soap.encoding ;
import java.io.ByteArrayOutputStream;
/**
* Custom class for supporting primitive XSD data type hexBinary.
*
* @author Davanum Srinivas <di...@yahoo.com>
*/
public class Hex extends Object{
byte[] m_value = null;
public Hex() {
}
public Hex(String string){
m_value = decode(string);
}
public byte[] getBytes(){
return m_value;
}
public String toString(){
return encode(m_value);
}
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 in 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.
*
* @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());
}
/**
* 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 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 (sb.toString());
}
/**
* 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 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;
}
/**
* [Private] Convert the specified value (0 .. 15) to the corresponding
* hexadecimal digit.
*
* @param value Value to be converted
*/
private static char convertDigit(int value) {
value &= 0x0f;
if (value >= 10)
return ((char) (value - 10 + 'a'));
else
return ((char) (value + '0'));
}
}
1.1 xml-soap/java/src/org/apache/soap/encoding/soapenc/HexDeserializer.java
Index: HexDeserializer.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "SOAP" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2000, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.soap.encoding.soapenc;
import java.io.*;
import org.w3c.dom.*;
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.util.*;
import org.apache.soap.rpc.*;
import org.apache.soap.encoding.Hex;
/**
* This deserializer can be used to deserialize something into a boolean.
* Its needed when defining mappings for base types via the deployment
* descriptor (or equivalent on the client-side).
*
* @author Sam Ruby (rubys@us.ibm.com)
*/
public class HexDeserializer implements Deserializer {
public Bean unmarshall(String inScopeEncStyle, QName elementType,
Node src, XMLJavaMappingRegistry xjmr,
SOAPContext ctx)
throws IllegalArgumentException {
Element root = (Element)src;
String value = DOMUtils.getChildCharacterData(root);
return new Bean(Hex.class, new Hex(value));
}
}