Android, SOAP Request geting errors
I Try to start SAOP request via android an i got some code:
WSRequests wsr = new WSRequests();
try {
WSRequests.getList(Constants.STUDY_WSDL,
Constants.OC_USERNAME, Constants.OC_PASSWORD);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
There i start a method in WSRequests, the Code from WSRequest:
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPException;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.imirwthaachen.camtests.constants.Constants;
import com.imirwthaachen.ws.study.StudyType;
import com.imirwthaachen.ws.study.WsService;
public class WSRequests {
public static List<StudyType> getList(String OpenclinicaWSurl, String
username, String hashedPassword) throws IOException {
HeaderHandler.username = username;
HeaderHandler.password = hashedPassword;
HeaderHandler.doc = null;
URL wsdlLocation = new URL (Constants.STUDY_WSDL);
WsService ws = new WsService(wsdlLocation, new
QName("http://openclinica.org/ws/study/v1", "wsService"));
ws.setHandlerResolver(new ClientHandlerResolver());
ws.getWsSoap11().listAll("");
List<StudyType> r = new ArrayList<StudyType>();
try{
NodeList nodes =
HeaderHandler.responseMessage.getSOAPBody().getElementsByTagName("study");
for(int index = 0; index < nodes.getLength(); index++){
Node node = nodes.item(index);
if(node.getNodeType() != Node.ELEMENT_NODE)
continue;
Element element = (Element)node;
StudyType study = new StudyType();
study.setIdentifier(element.getElementsByTagName("identifier").item(0).getTextContent());
study.setName(element.getElementsByTagName("name").item(0).getTextContent());
study.setOid(element.getElementsByTagName("oid").item(0).getTextContent());
r.add(study);
}
}
catch(SOAPException ex){
ex.printStackTrace();
}
return r;
}
and the Code from HeaderHandler is like :
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class HeaderHandler implements SOAPHandler<SOAPMessageContext> {
public static String username = "XXXXX";
public static String password = "XXXXXXXXX";
/** The soap response message */
public static SOAPMessage responseMessage;
public static Document doc;
public boolean handleMessage(SOAPMessageContext smc) {
Boolean outboundProperty = (Boolean) smc
.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty.booleanValue()) {
try {
SOAPEnvelope envelope = smc.getMessage().getSOAPPart()
.getEnvelope();
SOAPHeader header = envelope.addHeader();
SOAPElement security = header
.addChildElement(
"Security",
"wsse",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
SOAPElement usernameToken = security.addChildElement(
"UsernameToken", "wsse");
usernameToken
.addAttribute(
new QName("xmlns:wsu"),
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
SOAPElement username = usernameToken.addChildElement(
"Username", "wsse");
username.addTextNode(HeaderHandler.username);
SOAPElement password = usernameToken.addChildElement(
"Password", "wsse");
password.setAttribute(
"Type",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
password.addTextNode(HeaderHandler.password);
if (doc != null) {
Node odmNode = smc.getMessage().getSOAPBody()
.getOwnerDocument()
.importNode(doc.getDocumentElement(), true);
NodeList nodes = smc.getMessage().getSOAPBody()
.getChildNodes();
for (int index = 0; index < nodes.getLength(); index++) {
Node node = nodes.item(index);
if (node.getNodeType() == Node.ELEMENT_NODE) {
node.appendChild(odmNode);
break;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
try {
// This handler does nothing with the response from the Web
// Service so
// we just print out the SOAP message.
responseMessage = smc.getMessage();
// message.writeTo(System.out);
System.out.println("");
} catch (Exception ex) {
ex.printStackTrace();
}
}
return outboundProperty;
}
now to my problem, i know its a tone of code but i think these
Informations are nessesary after i run my app i will get an exeption. On
first :I/dalvikvm(632): Failed resolving
Lcom/imirwthaachen/ocws/HeaderHandler; interface 1883
'Ljavax/xml/ws/handler/soap/SOAPHandler;'
and at least : FATAL EXCEPTION: main 09-30 08:51:28.897:
E/AndroidRuntime(632): java.lang.NoClassDefFoundError:
com.imirwthaachen.ocws.HeaderHandler
i´m searching the internet for 2 days and tryed out many solutions but
nothing helps. please can someone explain me whats wrongwith my code /
Projekt setup?
PS.: I Treied to setup up the Play Store, movine gen on top, moveing
andorid on top, deleeting som references from build path... nothing works
Thanks a lot Christian
No comments:
Post a Comment