У меня есть простой сервер веб-сервиса SOAP, такой как:
public class receiver extends JAXMServlet implements ReqRespListener {
public SOAPMessage onMessage(SOAPMessage soapm) {
return soapm;
}
}
В клиенте я отправляю сообщение на этот сервер:
public class sender {
/** This is a sample web service operation */
SOAPConnectionFactory scfac = null;
SOAPConnection con =null;
MessageFactory fac = null;
SOAPMessage message = null;
SOAPMessage response = null;
@WebMethod(operationName = "sender")
public String sender(@WebParam(name = "a") String a)
{
try{
//Creat Connection
scfac = SOAPConnectionFactory.newInstance();
con = scfac.createConnection();
fac = MessageFactory.newInstance();
message = fac.createMessage();
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPHeader header = envelope.getHeader();
header.detachNode();
SOAPBody body = envelope.getBody();
body.addTextNode(a);
URL endpoint = new URL("http://localhost:8080/Target/receiver");
//log("Bat dau gui");
response = con.call(message, endpoint);
//log("Da nhan ve");
SOAPPart sp = response.getSOAPPart();
SOAPEnvelope ev = sp.getEnvelope();
SOAPBody bd = ev.getBody();
String result = bd.getValue();
return result;
}
catch (Exception e)
{
String fail = "Fail to send";
return fail;
}
}
}
Я вызвал функцию отправителя в jsp-файле и передал ей строку.
Я построил его с Netbeans и сервером Tomcat, но он просто отвечает нулевым сообщением.
Как я могу решить проблему?