Tengo un servicio web al que intento crear un cliente.soap ui código generado
Tengo el siguiente WSDL:
http://www.cmicdataservices.com/datacenter/service.asmx?wsdl
Se requiere autenticación. Al observar la descripción de WSDL, no veo ningún método que tome como argumentos un objeto de autenticación, ni un nombre de usuario ni contraseñas. Usando Netbeans, he generado fuentes jax-ws para WSDL. Sin embargo, no puedo entender qué hacer después de eso.
Uso de soapui Puedo conectarme al servicio web y ejecutar todos los métodos. Pero una vez más, quiero construir esto en un cliente que pueda ejecutarse sin mi interacción.
Mi problema viene en descubrir cómo usar este código generado, que parece que netbeans.tv tenía un video (netbeans soapui plugin video 2) que se ha perdido desde entonces. ¿Alguien sabe de algún tutorial o conoce algún ejemplo de cómo puedo usar este código generado para acceder al servicio web?
por lo que tienen un método CheckifAuthorized()
Correr en soapUI me sale el siguiente XML
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:cmic="http://www.cmicdataservices.com/">
<soap:Header>
<cmic:Authentication>
<!--Optional:-->
<cmic:UserName>username</cmic:UserName>
<!--Optional:-->
<cmic:Password>password</cmic:Password>
</cmic:Authentication>
</soap:Header>
<soap:Body>
<cmic:CheckIfAuthorized/>
</soap:Body>
</soap:Envelope>
Entonces puede ejecutar esa petición en la interfaz de usuario de jabón y volver a la respuesta que la autenticación fue un éxito .
Con el código de JAX-WS generado con NetBeans y con soapUI así tengo el siguiente:
package javaapplication7;
/**
*
* @author grant
*/
public class Main {
public static void main(String[] args) {
Boolean result = checkIfAuthorized();
System.out.println("The result is: " + result);
}
private static boolean checkIfAuthorized() {
javaapplication7.CMICDatacenterService service = new javaapplication7.CMICDatacenterService();
javaapplication7.CMICDatacenterServiceSoap port = service.getCMICDatacenterServiceSoap();
return port.checkIfAuthorized();
}
}
Esto se producirá un error con el siguiente error
run:
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Server was unable to process request. ---> Object reference not set to an instance of an object.
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:111)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)
at $Proxy30.checkIfAuthorized(Unknown Source)
at javaapplication7.Main.checkIfAuthorized(Main.java:24)
at javaapplication7.Main.main(Main.java:17)
Java Result: 1
Este es el mismo problema que yo se topó cuando intentaba usar Python para el servicio. Desde entonces, he optado por ir con Java, ya que creo que puedo tener un cambio más rápido en el análisis del xml y la creación de objetos, ya que ya tengo las entidades creadas para este.
Gracias.
subvención
que no quería contestar a esto porque todavía me gustaría averiguar lo que puedo hacer aquí, pero me acaba de terminar de escribir la solicitud de la mano con lo siguiente. Ahora puedo convertir esto en un objeto xml y seguir mi camino, pero imagino que soapui hace todo esto mucho más fácil. Lo que realmente no entiendo es cómo utilizar soapUI para construir esta solicitud e incorporarlo en mi proyecto:
public class Main {
public final static String DEFAULT_SERVER =
"http://www.cmicdataservices.com/datacenter/service.asmx";
public final static String SOAP_ACTION =
"http://www.cmicdataservices.com/CheckIfAuthorized";
public static void main(String[] args) {
String server = DEFAULT_SERVER;
String UserName = "Username";
String Password="Password";
try{
URL url = new URL(server);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/soap+xml; charset=utf-8");
connection.setRequestProperty("Host", "www.cmicdataservices.com");
OutputStream out = connection.getOutputStream();
Writer wout = new OutputStreamWriter(out);
// Uncomment the following and comment out the previous two lines to see your xml
//BufferedWriter wout = new BufferedWriter(new FileWriter("/tmp/testXML.xml"));
//Start writing soap request - Envelope
wout.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n");
wout.write("<soap12:Envelope ");
wout.write("xmlns:xsi=");
wout.write("'http://www.w3.org/2001/XMLSchema-instance' ");
wout.write("xmlns:xsd=");
wout.write("'http://www.w3.org/2001/XMLSchema' ");
wout.write("xmlns:soap12=");
wout.write("'http://www.w3.org/2003/05/soap-envelope'>\r\n");
//Soap request header start
wout.write("<soap12:Header>\r\n");
//Start writing soap request - Authentication
wout.write("<Authentication xmlns=");
wout.write("'http://www.cmicdataservices.com/'>\r\n");
wout.write("<UserName>" + UserName + "</UserName>\r\n");
wout.write("<Password>" + Password + "</Password>\r\n");
// End Authentication
wout.write("</Authentication>\r\n");
//End the header
wout.write("</soap12:Header>\r\n");
//Start writing the body
wout.write("<soap12:Body>");
wout.write("<GetCurrentDataVer1 xmlns=");
wout.write("'http://www.cmicdataservices.com/' />\r\n");
// End the Body
wout.write("</soap12:Body>\r\n");
// End the Envelope
wout.write("</soap12:Envelope>\r\n");
wout.flush();
wout.close();
//BufferedWriter fout = new BufferedWriter(new FileWriter("/tmp/testXMLResponse.xml"));
InputStream in = connection.getInputStream();
createFile(in, "/tmp/testXMLResponse.xml");
}
catch (IOException e) {
System.err.println(e);
}
}
public static void createFile(InputStream io, String fileName) throws IOException {
FileOutputStream fout = new FileOutputStream(fileName);
byte[] buf = new byte[256];
int read = 0;
while ((read = io.read(buf)) != -1){
fout.write(buf, 0, read);
}
}
@grantk ¿resolvió esto nuestro problema? – tgkprog