Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ClassCastException on casting a Parameter (Vector)

Status
Not open for further replies.

lubywan

Programmer
Mar 27, 2009
5
0
0
US
I'm trying to cast a Parameter from a Vector, but keep running into a ClassCastException error. My ultimate goal is to send XML data to an external web service. Pertinent code is below (I marked the trouble spot with *** It Blows up here ***):

URL url = new URL(" services url...");
String xmlString;
xmlString = "<soap:Envelope xmlns:soap=' etc, etc,... </soap:Body></soap:Envelope>";

Parameter parm = new Parameter("xml", String.class,xmlString,"");
Vector params = new Vector();
params.addElement(xmlString);

Call call = new Call(); // prepare the service invocation
call.setMethodName( "process" );
call.setParams( params );

Response response = call.invoke( url, 30000, "" ); // invoke the service
...
marshall(params, getMethodName());

private void marshall(Vector params, String actionStub)throws MyGenericException
{
*** Blows up here! *** Parameter parm = (Parameter)params.firstElement();
...
}



Thanks in advance!

- Lou
 
You are adding the xmlString to the vector (params.addElement(xmlString);). I think you should be adding the parm object.
 
Thanks for your speedy reply and it worked; however, I ran into more problems so I decided to do a couple of tutorials! Now, I'm running into problems with the tutorials!

I'm doing a tutorial at and can't get the SOAPConstants.DYNAMIC_SOAP_PROTOCOL (line 1) to be recognized (also it says that "The method addBodyElement(Name) in the type SOAPBody is not applicable for the arguments
(QName)" (line 7), "The method addChildElement(Name) in the type SOAPElement is not applicable for the arguments
(QName)" (line 8), AND "Syntax error on token ""SUNW"", delete this token" (line 9). Pretty frustrating trying to learn when you can even get the tutorials to work!!!!

(I realize that I might have overdone the imports, but I was desparate)! Once again, thanks for your time.


I have this:

import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPConstants;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.namespace.QName;
import javax.xml.*;

public class OrderToCash {

1 MessageFactory factory = MessageFactory.newInstance(SOAPConstants.DYNAMIC_SOAP_PROTOCOL);
2 SOAPMessage message = factory.createMessage();

3 SOAPPart soapPart = message.getSOAPPart();

4 SOAPHeader header = message.getSOAPHeader();
5 SOAPBody body = message.getSOAPBody();

6 QName bodyName = new QName(" "GetLastTradePrice", "m");
7 SOAPBodyElement bodyElement = body.addBodyElement(bodyName);

8 QName name = new QName("symbol");
SOAPElement symbol = bodyElement.addChildElement(name);
9 symbol.addTextNode("SUNW");
 
Check your classpath: looks like you're mixing different versions of java.xml.soap classes.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top