Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Groovy或Java发送SOAP_Java_Web Services_Soap_Groovy - Fatal编程技术网

使用Groovy或Java发送SOAP

使用Groovy或Java发送SOAP,java,web-services,soap,groovy,Java,Web Services,Soap,Groovy,我使用了红色并尝试了多次SOAP消息。我试图将它们粘贴到我的解决方案中,但没有办法得到答案 我使用此Groovy代码发送SOAP请求并获得SOAP应答。它适用于2个web服务。我使用SoapUI编写XML,我在这里使用的XML是在SoapUI上工作的,我从服务器上得到答案 现在,我的工作XML和我的工作Groovy脚本(用于其他服务)不能一起工作,我不知道问题出在哪里。我不是一个开发人员。我有一个SSL错误,但我确信这台服务器上没有SSL证书,并且使用没有SSL的SoapUI,它可以工作,提供商

我使用了红色并尝试了多次SOAP消息。我试图将它们粘贴到我的解决方案中,但没有办法得到答案

我使用此Groovy代码发送SOAP请求并获得SOAP应答。它适用于2个web服务。我使用SoapUI编写XML,我在这里使用的XML是在SoapUI上工作的,我从服务器上得到答案

现在,我的工作XML和我的工作Groovy脚本(用于其他服务)不能一起工作,我不知道问题出在哪里。我不是一个开发人员。我有一个SSL错误,但我确信这台服务器上没有SSL证书,并且使用没有SSL的SoapUI,它可以工作,提供商告诉我没有证书

你能帮我看看哪里出了问题吗?事先非常感谢。
亲切的问候。 安托万

Groovy脚本:

// Send data
URL url = new URL(url);
HttpURLConnection conn = url.openConnection();
conn.setDoOutput(true);
if( soapaction != null ) conn.setRequestProperty( "SOAPAction", soapaction );
conn.setRequestProperty( "Content-Type", "text/xml" );
String authorizationString = "Basic " + (username + ":" +  password).bytes.encodeBase64();
conn.setRequestProperty ("Authorization", authorizationString);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(xml);
wr.close();

// Get the response
String response;
InputStream responseStream;
try {
    responseStream = conn.getInputStream();
    success = 1;
} catch( IOException e ) {
    success = 0;
    if( conn.getResponseCode() == 500 ) {
        responseStream = conn.getErrorStream();
    } else throw e;
}
response = responseStream.getText("utf-8");
responseStream.close();
return response;
此脚本的某些参数:
XML
soapaction:getAnimals
网址:
密码:test
用户名:613731

XML:


371066
613731
测试
756000100230345
您可以使用更少的代码来做同样的事情(但工作):

@Grab( 'com.github.groovy-wslite:groovy-wslite:0.8.0' )
import wslite.soap.*
import wslite.http.auth.*

def client = new SOAPClient( 'https://test.anis.ch/HTDB.WebService/AnimalImportService.asmx' )

client.authorization = new HTTPBasicAuthorization( "613731", "test" )

// Trust the ssl for this site
client.httpClient.sslTrustAllCerts = true

def response = client.send(SOAPAction:'urn:tvd:heimtierdatenbanksql:webservice:animalimportservcie:v1:getAnimalsIn') {
    body {
        getAnimals( 'xmlns':'urn:tvd:heimtierdatenbanksql:webservice:animalimportmessages:v1' ) {
            getMessage {
                Header( 'xmlns':'urn:tvd:heimtierdatenbanksql:webservice:animalimportdata:v1' ) {
                    P_Praxisnummer( '371066' )
                    P_Account( '613731' )
                    P_PIN( 'test' )
                }
                Body( 'xmlns':'urn:tvd:heimtierdatenbanksql:webservice:animalimportdata:v1' ) {
                    KZ_Kennzeichnung( '756000100230345' )
                }
            }
        }
    }
}

println XmlUtil.serialize( response.getAnimalResponse )
祝你好运

我得到:

<tag0:getAnimalResponse xmlns:tag0="urn:tvd:heimtierdatenbanksql:webservice:animalimportmessages:v1">
  <tag0:outputMessage>
    <R_Fehlertext xmlns="urn:tvd:heimtierdatenbanksql:webservice:animalimportdata:v1">Account-Informationen nicht plausibel</R_Fehlertext>
    <R_FehlerCode xmlns="urn:tvd:heimtierdatenbanksql:webservice:animalimportdata:v1">109</R_FehlerCode>
  </tag0:outputMessage>
</tag0:getAnimalResponse>

不合理的账户信息
109
因此,我想我的凭证可能有问题…

您可以使用更少的代码来完成同样的事情(但可以工作):

@Grab( 'com.github.groovy-wslite:groovy-wslite:0.8.0' )
import wslite.soap.*
import wslite.http.auth.*

def client = new SOAPClient( 'https://test.anis.ch/HTDB.WebService/AnimalImportService.asmx' )

client.authorization = new HTTPBasicAuthorization( "613731", "test" )

// Trust the ssl for this site
client.httpClient.sslTrustAllCerts = true

def response = client.send(SOAPAction:'urn:tvd:heimtierdatenbanksql:webservice:animalimportservcie:v1:getAnimalsIn') {
    body {
        getAnimals( 'xmlns':'urn:tvd:heimtierdatenbanksql:webservice:animalimportmessages:v1' ) {
            getMessage {
                Header( 'xmlns':'urn:tvd:heimtierdatenbanksql:webservice:animalimportdata:v1' ) {
                    P_Praxisnummer( '371066' )
                    P_Account( '613731' )
                    P_PIN( 'test' )
                }
                Body( 'xmlns':'urn:tvd:heimtierdatenbanksql:webservice:animalimportdata:v1' ) {
                    KZ_Kennzeichnung( '756000100230345' )
                }
            }
        }
    }
}

println XmlUtil.serialize( response.getAnimalResponse )
祝你好运

我得到:

<tag0:getAnimalResponse xmlns:tag0="urn:tvd:heimtierdatenbanksql:webservice:animalimportmessages:v1">
  <tag0:outputMessage>
    <R_Fehlertext xmlns="urn:tvd:heimtierdatenbanksql:webservice:animalimportdata:v1">Account-Informationen nicht plausibel</R_Fehlertext>
    <R_FehlerCode xmlns="urn:tvd:heimtierdatenbanksql:webservice:animalimportdata:v1">109</R_FehlerCode>
  </tag0:outputMessage>
</tag0:getAnimalResponse>

不合理的账户信息
109

所以我猜我的凭证有问题…

您必须在脚本中添加下一行:

conn.setRequestProperty( "Content-Type", "charset=utf-8"); 

您必须在脚本中添加下一行:

conn.setRequestProperty( "Content-Type", "charset=utf-8"); 

始终存在带有HTTPS的证书。考虑使用JAX-WS。总是有一个带有HTTPS的证书。考虑使用JAX-WS不危险吗?这样做不危险吗?