dcsimg
SOAP!!!!!!! Please Help!!
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Monday, March 7, 2005 02:41 AM

Hi, I am trying to make soap connect with the following sample (from Copyright 2002 Sun Microsystems), but I get: java.security.PrivilegedActionExcption: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Bad Response please help!! may be u have another sampl??????????? thank Andy import java.io.*; import java.util.Iterator; import java.net.URL; import javax.activation.DataHandler; import javax.xml.soap.*; import javax.xml.transform.*; import javax.xml.transform.stream.*; import org.w3c.dom.Document; imp   More>>

Hi,

I am trying to make soap connect with the following sample
(from Copyright 2002 Sun Microsystems), but I get:


java.security.PrivilegedActionExcption:
com.sun.xml.messaging.saaj.SOAPExceptionImpl: Bad Response


please help!!



may be u have another sampl???????????


thank


Andy



import java.io.*;



import java.util.Iterator;

import java.net.URL;


import javax.activation.DataHandler;

import javax.xml.soap.*;

import javax.xml.transform.*;

import javax.xml.transform.stream.*;


import org.w3c.dom.Document;

import org.w3c.dom.Node;

import org.w3c.dom.NamedNodeMap;

import org.w3c.dom.NodeList;


/**

* Sample JAXM Client.

*/

public class JAXMClient{


/**
* URI for the server part

*/
static final String theURI
= "http://localhost:80/jaxmservice/service" ;


public static void main(String args[]) {


try {

URL endpoint=new URL(theURI);


//Create SOAP connection

SOAPConnectionFactory scf =
SOAPConnectionFactory.newInstance();

SOAPConnection connection = scf.createConnection();


// Create a message from the message factory.

MessageFactory mf = MessageFactory.newInstance();

SOAPMessage msg = mf.createMessage();


// Get the SOAP Part from the message

SOAPPart soapPart=msg.getSOAPPart();


// Get the SOAP Envelope from the SOAP Part

SOAPEnvelope envelope = soapPart.getEnvelope();


// Remove empty header from the Envelope

envelope.getHeader().detachNode();


// Create a soap body from the Envelope.

SOAPBody body = envelope.getBody();


// Add Items to the Order body

addItem(body, envelope, "101", "Java", "$29.99");

addItem(body, envelope, "102", "Java 2", "$39.99");

addItem(body, envelope, "103", "JAXM", "$19.99");

addItem(body, envelope, "104", "Web Services", "$49.99");


// Print the message to the standard output
System.out.println("
Content of the message:
");

msg.writeTo(System.out);


// Send the SOAP message and get reply
System.err.println("Sending message to URL: "+ endpoint);

SOAPMessage reply = connection.call(msg, endpoint);


// Print the reply message to the standard output

System.out.println("

Content of the reply message:

");
reply.writeTo(System.out);


//Parse the reply message to get the value of
Attribute "TOTAL"

SOAPPart part = reply.getSOAPPart( );

envelope = part.getEnvelope();

body = envelope.getBody();

Iterator items = body.getChildElements
(envelope.createName("Order"));


SOAPBodyElement element = null;


element = (SOAPBodyElement)items.next();

Name name = envelope.createName("ITEMS");

String numberOfItems = element.getAttributeValue(name);


name = envelope.createName("TOTAL");

String total = element.getAttributeValue(name);


//Print the number of Items and Total Price

System.out.println("

Order accepted.
Items in the
processed Order: " + numberOfItems + "
Total: " + total);


connection.close();


} catch(Throwable e) {

e.printStackTrace();

}

}


/**

* Add Item to the SOAP Body

* @param body - SOAP Body

* @param envelope - SOAP Envelope

* @param id - Item ID

* @param name - Item Name

* @param price - Item Price

*/

static void addItem(SOAPBody body, SOAPEnvelope envelope,
String id, String name, String price){

try{


// Add a SOAP body element to the soap body

SOAPBodyElement item = body.addBodyElement
(envelope.createName("Item"));


// Add a SOAP Attribute to the Item - Element

item.addAttribute(envelope.createName("ID"),id);

item.addAttribute(envelope.createName("NAME"),name);

item.addAttribute(envelope.createName("PRICE"),price);


} catch(Throwable e) {

e.printStackTrace();

}

}


}

   <<Less

Re: SOAP!!!!!!! Please Help!!

Posted By:   Ed_Hoden  
Posted On:   Monday, May 2, 2005 05:46 PM

I encountered this error when I did not have the servlet which was providing the web service properly mapped to the URL. You may want to check the configuration of your server to verify that this is the case. HTH -- Ed
About | Sitemap | Contact