• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

how to compile and run a SAAJ client without ANT

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am new to SAAJ. I could run the sample "MyUddiPing" example given in the sun j2ee tutorial-using 'asant'. but when I try to run the same application as a standalone program(with out the use of any ant tool), I am able to compile the code but when I run the application I get the following exception:

C:\uddi>java MyUddiPing
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/internet/P
arseException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:1610)
at java.lang.Class.getConstructor0(Class.java:1922)
at java.lang.Class.newInstance0(Class.java:278)
at java.lang.Class.newInstance(Class.java:261)
at javax.xml.soap.FactoryFinder.newInstance(Unknown Source)
at javax.xml.soap.FactoryFinder.find(Unknown Source)
at javax.xml.soap.MessageFactory.newInstance(Unknown Source)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.<init>(HttpS
OAPConnection.java:53)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnectionFactory.creat
eConnection(HttpSOAPConnectionFactory.java:25)
at MyUddiPing.main(MyUddiPing.java:33)


a. HOw can I run this programor any SAAJ client(the code is given below) with out the use of any ANT tool

b. I intend to develop a webservice using AXIS. then I intend to write a standalone SAAJ client that communicates with the Webservice-any suggestions

cheers

Ranjan (code follows)


import javax.xml.soap.*;
import java.net.*;
import java.util.*;
import java.io.*;

public class MyUddiPing {

public static void main(String[] args) {
try {


// Retrieve settings from uddi.properties file,
// add to system properties
Properties myprops = new Properties();

myprops.load(new FileInputStream("uddi.properties"));
Properties props = System.getProperties();

Enumeration enum = myprops.propertyNames();
while (enum.hasMoreElements()) {
String s = (String) enum.nextElement();
props.setProperty(s, myprops.getProperty(s));
}






// Create connection and message factory
SOAPConnectionFactory soapConnectionFactory =
SOAPConnectionFactory.newInstance();
SOAPConnection connection =
soapConnectionFactory.createConnection();
MessageFactory messageFactory =
MessageFactory.newInstance();

// Create a message
SOAPMessage message =
messageFactory.createMessage();

// Get the SOAP header and body from the message
// and remove the header
SOAPHeader header = message.getSOAPHeader();
SOAPBody body = message.getSOAPBody();
header.detachNode();

// Create a SOAP factory
// Create a UDDI v2 find_business body element
SOAPFactory soapFactory =
SOAPFactory.newInstance();
SOAPBodyElement findBusiness =
body.addBodyElement(soapFactory.createName(
"find_business", "",
"urn:uddi-org:api_v2"));
findBusiness.addAttribute(soapFactory.createName(
"generic"), "2.0");
findBusiness.addAttribute(soapFactory.createName(
"maxRows"), "100");
SOAPElement businessName =
findBusiness.addChildElement(
soapFactory.createName("name"));
businessName.addTextNode("food");

message.saveChanges();

// Display the message you are sending
System.out.println("\n--- Request Message ---\n");
message.writeTo(System.out);


URL endpoint = new URL("http://uddi.ibm.com/testregistry/inquiryapi");


// Send message and get reply
SOAPMessage reply =
connection.call(message, endpoint);

System.out.println("\n\nReceived reply from: " +
endpoint);
System.out.println("\n---- Reply Message ----\n");

// Display the reply
reply.writeTo(System.out);

// Now parse the reply
SOAPBody replyBody = reply.getSOAPBody();

/*
* The response to a find_business query is a
* businessList conformant to the UDDI V2 Data
* Structure specifications.
*/
System.out.println("\n\nContent extracted from " +
"the reply message:\n");

Iterator businessListIterator =
replyBody.getChildElements(
soapFactory.createName("businessList",
"", "urn:uddi-org:api_v2"));

/*
* businessList is a mandatory element in a
* successful response and appears only once.
*/
SOAPBodyElement businessList =
(SOAPBodyElement)businessListIterator.next();

/*
* Get the businessInfos element. This contains
* the business entries retrieved that match the
* criteria specified in the find_business
* request.
*/
Iterator businessInfosIterator =
businessList.getChildElements(
soapFactory.createName("businessInfos",
"", "urn:uddi-org:api_v2"));

/*
* businessInfos, too is a mandatory element in
* a successful response and appears only once.
*/
SOAPElement businessInfos =
(SOAPElement)businessInfosIterator.next();

/*
* The businessInfos contains zero or more
* businessInfo structures. Each businessInfo
* structure contains the company name and
* optional description data.
*/
Iterator businessInfoIterator =
businessInfos.getChildElements(
soapFactory.createName("businessInfo",
"", "urn:uddi-org:api_v2"));

if (! businessInfoIterator.hasNext()) {
System.out.println("No businesses found " +
"matching the name \"" + args[1] +
"\".");
} else {
while (businessInfoIterator.hasNext()) {
SOAPElement businessInfo = (SOAPElement)
businessInfoIterator.next();
// Extract name and description from the
// businessInfo
Iterator nameIterator =
businessInfo.getChildElements(
soapFactory.createName("name",
"", "urn:uddi-org:api_v2"));
while (nameIterator.hasNext()) {
businessName =
(SOAPElement)nameIterator.next();
System.out.println("Company name: " +
businessName.getValue());
}
Iterator descriptionIterator =
businessInfo.getChildElements(
soapFactory.createName(
"description", "",
"urn:uddi-org:api_v2"));
while (descriptionIterator.hasNext()) {
SOAPElement businessDescription =
(SOAPElement)
descriptionIterator.next();
System.out.println("Description: " +
businessDescription.getValue());
}
System.out.println("");
}
}

// Close the connection
connection.close();

} catch (Exception ex) {
ex.printStackTrace();
}
}
}
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apparently you're missing some dependencies from your classpath. Check out the Ant script to see which libraries it includes in the classpath when running the example (the error you're getting implies that you need at least some JavaMail libraries).
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The runtime environment for sending/Receving SOAP request requires quite a few jars in the classpath.

I guess, Your classpath is missing out mail.jar and activation.jar.
plz add those.

Thanks
-Kevin
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic