You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ve...@apache.org on 2005/04/13 08:43:07 UTC
svn commit: r161159 [2/2] - in
webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/saaj: ./ bin/
src/java/javax/xml/soap/ src/java/org/apache/axis/saaj/
src/java/org/apache/axis/util/ src/test/org/apache/axis/saaj/
Added: webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/saaj/src/java/org/apache/axis/util/SessionUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/saaj/src/java/org/apache/axis/util/SessionUtils.java?view=auto&rev=161159
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/saaj/src/java/org/apache/axis/util/SessionUtils.java (added)
+++ webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/saaj/src/java/org/apache/axis/util/SessionUtils.java Tue Apr 12 23:43:02 2005
@@ -0,0 +1,99 @@
+/*
+ * Created on Apr 8, 2005
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.apache.axis.util;
+
+import java.util.Random;
+
+/**
+ * Code borrowed from AuthenticatorBase.java for generating a secure id's.
+ */
+public class SessionUtils {
+
+ /**
+ * The number of random bytes to include when generating a
+ * session identifier.
+ */
+ protected static final int SESSION_ID_BYTES = 16;
+
+ /**
+ * A random number generator to use when generating session identifiers.
+ */
+ protected static Random random = null;
+
+ /**
+ * The Java class name of the random number generator class to be used
+ * when generating session identifiers.
+ */
+ protected static String randomClass = "java.security.SecureRandom";
+
+ /**
+ * Host name/ip.
+ */
+ private static String thisHost = null;
+
+ /**
+ * Generate and return a new session identifier.
+ *
+ * @return a new session id
+ */
+ public static synchronized String generateSessionId() {
+ // Generate a byte array containing a session identifier
+ byte bytes[] = new byte[SESSION_ID_BYTES];
+
+ getRandom().nextBytes(bytes);
+
+ // Render the result as a String of hexadecimal digits
+ StringBuffer result = new StringBuffer();
+
+ for (int i = 0; i < bytes.length; i++) {
+ byte b1 = (byte) ((bytes[i] & 0xf0) >> 4);
+ byte b2 = (byte) (bytes[i] & 0x0f);
+
+ if (b1 < 10) {
+ result.append((char) ('0' + b1));
+ } else {
+ result.append((char) ('A' + (b1 - 10)));
+ }
+ if (b2 < 10) {
+ result.append((char) ('0' + b2));
+ } else {
+ result.append((char) ('A' + (b2 - 10)));
+ }
+ }
+ return (result.toString());
+ }
+
+ /**
+ * Generate and return a new session identifier.
+ *
+ * @return a new session.
+ */
+ public static synchronized Long generateSession() {
+ return new Long(getRandom().nextLong());
+ }
+
+ /**
+ * Return the random number generator instance we should use for
+ * generating session identifiers. If there is no such generator
+ * currently defined, construct and seed a new one.
+ *
+ * @return Random object
+ */
+ private static synchronized Random getRandom() {
+ if (random == null) {
+ try {
+ Class clazz = Class.forName(randomClass);
+ random = (Random) clazz.newInstance();
+ } catch (Exception e) {
+ random = new java.util.Random();
+ }
+ }
+ return (random);
+ }
+
+}
+
Added: webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/saaj/src/java/org/apache/axis/util/XMLUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/saaj/src/java/org/apache/axis/util/XMLUtils.java?view=auto&rev=161159
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/saaj/src/java/org/apache/axis/util/XMLUtils.java (added)
+++ webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/saaj/src/java/org/apache/axis/util/XMLUtils.java Tue Apr 12 23:43:02 2005
@@ -0,0 +1,60 @@
+/*
+ * Created on Apr 11, 2005
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.apache.axis.util;
+
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * @author shaas02
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class XMLUtils {
+
+ /**
+ * Get an empty new Document
+ *
+ * @return Document
+ * @throws ParserConfigurationException if construction problems occur
+ */
+ public static Document newDocument()
+ throws ParserConfigurationException {
+ DocumentBuilder db = null;
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ db = dbf.newDocumentBuilder();
+ Document doc = db.newDocument();
+ return doc;
+ }
+
+ /**
+ * Method newDocument
+ *
+ * @param in
+ * @return
+ * @throws ParserConfigurationException
+ * @throws SAXException
+ * @throws IOException
+ */
+ public static Document newDocument(InputStream in)
+ throws ParserConfigurationException, SAXException, IOException {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ return db.parse(in);
+ }
+
+}
Added: webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/saaj/src/test/org/apache/axis/saaj/TestClient2.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/saaj/src/test/org/apache/axis/saaj/TestClient2.java?view=auto&rev=161159
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/saaj/src/test/org/apache/axis/saaj/TestClient2.java (added)
+++ webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/saaj/src/test/org/apache/axis/saaj/TestClient2.java Tue Apr 12 23:43:02 2005
@@ -0,0 +1,68 @@
+/*
+ * Created on Apr 8, 2005
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.apache.axis.saaj;
+
+import javax.xml.soap.Name;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPConnection;
+import javax.xml.soap.SOAPConnectionFactory;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.XMLStreamException;
+/**
+ * @author shaas02
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class TestClient2 {
+
+ public static void main(String[] args){
+ try{
+ javax.xml.soap.MessageFactory fact = javax.xml.soap.MessageFactory.newInstance();
+ javax.xml.soap.SOAPMessage message = fact.createMessage();
+ javax.xml.soap.SOAPPart soapPart = message.getSOAPPart();
+ SOAPEnvelopeImpl env = (SOAPEnvelopeImpl)soapPart.getEnvelope();
+ Name ns = env.createName("EchoOM", "test1", "http://MyClient.org/MyClient");
+ SOAPBody body = env.getBody();
+ SOAPElement bodyElmnt = body.addBodyElement(ns);
+ Name ns2 = env.createName("Text","test2", "http://MyClient.org/ABC");
+ SOAPElement text = bodyElmnt.addChildElement(ns2);
+ text.addTextNode("Echo String");
+ // TODO: Test with TextImpl, need some fix
+ //TextImpl data = new TextImpl((SOAPElementImpl)text, "Echo String");
+ //System.out.println(data.getParentElement().getElementName());
+ //data.setParentElement(text);
+
+
+ SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();
+ SOAPConnection connection = factory.createConnection();
+ javax.xml.soap.SOAPMessage respMsg = ((SOAPConnectionImpl)connection).call(message, "http://localhost:8080/axis2/services/myecho");
+ SOAPEnvelope response = respMsg.getSOAPPart().getEnvelope();
+
+ org.apache.axis.om.SOAPEnvelope omEnv = env.getOMEnvelope();
+ System.out.println("Request sent ...");
+ XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out);
+ omEnv.serialize(writer,true);
+ writer.flush();
+ System.out.println();
+ org.apache.axis.om.SOAPEnvelope omResp = ((SOAPEnvelopeImpl)response).getOMEnvelope();
+ System.out.println("Response received ...");
+ omResp.serialize(writer,true);
+ writer.flush();
+
+ } catch(SOAPException e){
+ e.printStackTrace();
+ } catch(XMLStreamException e1){
+ e1.printStackTrace();
+ }
+ }
+
+}