Jump to content
Server Maintenance This Week. ×

This topic is 3842 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Here's my code for using the FedEx v6 tracking web services. Not pretty, but it works. Any comments and improvements welcome!

Fedex Track ( accountKey ; accountNumber ; accountPassword ; meterNumber ; trackingNumber )

// Send data

targetURL = "https://ws.fedex.com:443/web-services/ship";
targetNamespace = "http://fedex.com/ws/track/v6";

URL url = new URL( targetURL );
HttpURLConnection conn = url.openConnection();
//if( soapaction != null ) conn.setRequestProperty( "SOAPAction", soapaction );
conn.setRequestProperty( "content-type", "text/xml" );
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());

soapRequest = "<SOAP-ENV:Envelope";
soapRequest += " xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"";
soapRequest += " xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"";
soapRequest += " xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"";
soapRequest += " xmlns:xsd="http://www.w3.org/2001/XMLSchema"";
soapRequest += " xmlns="" + targetNamespace + "">";
soapRequest += "<SOAP-ENV:Body>";
soapRequest += "<TrackRequest>";
soapRequest += "<WebAuthenticationDetail>";
soapRequest += "<UserCredential>";
soapRequest += "<Key>" + accountKey + "</Key>";
soapRequest += "<Password>" + accountPassword + "</Password>";
soapRequest += "</UserCredential>";
soapRequest += "</WebAuthenticationDetail>";
soapRequest += "<ClientDetail>";
soapRequest += "<AccountNumber>" + accountNumber + "</AccountNumber>";
soapRequest += "<MeterNumber>" + meterNumber + "</MeterNumber>";
soapRequest += "</ClientDetail>";
soapRequest += "<Version>";
soapRequest += "<ServiceId>trck</ServiceId>";
soapRequest += "<Major>6</Major>";
soapRequest += "<Intermediate>0</Intermediate>";
soapRequest += "<Minor>0</Minor>";
soapRequest += "</Version>";
soapRequest += "<PackageIdentifier>";
soapRequest += "<Value>" + trackingNumber + "</Value>";
soapRequest += "<Type>TRACKING_NUMBER_OR_DOORTAG</Type>";
soapRequest += "</PackageIdentifier>";
soapRequest += "</TrackRequest>";
soapRequest += "</SOAP-ENV:Body>";
soapRequest += "</SOAP-ENV:Envelope>";

wr.write(soapRequest);
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();

replaceText = " xmlns="" + targetNamespace + """;

response=response.replace(replaceText,'');

return response;
Link to comment
Share on other sites

  • 2 weeks later...

use markupbuilder to create the XML - makes it easier to troubleshoot

 

investigate wslite as the soap wrapper.

the result  comes back in a XMLslurper ready to use.

 

Why are you declaring the namespaces when they are not being used??

import groovy.xml.MarkupBuilder

writer = new StringWriter()
xml = new MarkupBuilder(writer)
xml.getMkp().xmlDeclaration(version:'1.0', encoding: 'UTF-8')
xml.'SOAP-ENV:Envelope'('xmlns:SOAP-ENV': 'http://schemas.xmlsoap.org/soap/envelope/', 'xmlns:SOAP-ENC': 'http://schemas.xmlsoap.org/soap/encoding/', 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xmlns:xsd': 'http://www.w3.org/2001/XMLSchema' , 'xmlns':targetNamespace ){
'SOAP-ENV:Body'{
	TrackRequest{
		WebAuthenticationDetail{
			UserCredential{
				Key(accountKey)
				Password(accountPassword)
			}
		}
		ClientDetail{
			AccountNumber(accountNumber)
			MeterNumber(meterNumber)
		}
		Version{
			ServiceId('trck')
			Major(6)
			Intermediate(0)
			Minor(0)
		}
		PackageIdentifier{
			Value(trackingNumber)
			Type('TRACKING_NUMBER_OR_DOORTAG')
			}
		}
	}
}
soapRequest = writer.toString().trim()
Link to comment
Share on other sites

  • 5 months later...

Hello,

I'm also trying to make SOAP sending with scriptmaster and it's difficult for me.

I tried SOAPUI and got a good result with a normal XML structure but I don't know how to implement in scriptmaster.

can you help me please ?

Kind regards.

Antoine

 

 

my normal SOAPUI xml which is working is this one :

 

 

  <soapenv:Header>
   <soapenv:Body>
      <vet:vetTapswSearchProduct>
         <vet:searchCriteria>amoxi</vet:searchCriteria>
      </vet:vetTapswSearchProduct>
   </soapenv:Body>
</soapenv:Envelope>
 

 

I've tried to copy your solution John but  :

with your solution  I have this error :

 

groovy.lang.MissingPropertyException: No such property: targetNamespace for class: Script1

 

 

with this in script master I have an error

 

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

Script1.groovy: 1: unexpected token: XML @ line 1, column 6.

  

 

 

Post XML Data ( soapaction ; accountusername ; accountpassword )

 

// Send data

 

targetURL = "https://test.vetpoint.ch/webtools/control/SOAPService";

 

URL url = new URL( targetURL );

HttpURLConnection conn = url.openConnection();

//if( soapaction != null ) conn.setRequestProperty( "SOAPAction", soapaction );

conn.setRequestProperty( "content-type", "text/xml" );

conn.setDoOutput(true);

OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());

 

soapRequest = "<SOAP-ENV:Envelope";

soapRequest += " xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"";

soapRequest += " xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"";

soapRequest += " xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"";

soapRequest += " xmlns:xsd="http://www.w3.org/2001/XMLSchema"";

soapRequest += "<WebAuthenticationDetail>";

soapRequest += "<UserCredential>";

soapRequest += "<Key>" + accountusername + "</Key>";

soapRequest += "<Password>" + accountpassword + "</Password>";

soapRequest += "</UserCredential>";

soapRequest += "</WebAuthenticationDetail>";

soapRequest += "<SOAP-ENV:Body>";

soapRequest += "<vet:vetTapswSearchProduct>";

soapRequest += "<vet:searchCriteria>amoxi</vet:searchCriteria>";

soapRequest += "</vet:vetTapswSearchProduct>";

soapRequest += "</SOAP-ENV:Body>";

soapRequest += "</SOAP-ENV:Envelope>";

 

wr.write(soapRequest);

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();

 

replaceText = " xmlns="" + targetNamespace + """;

 

response=response.replace(replaceText,'');

 

return response;

 

 

with this in script master I have an error : groovy.lang.MissingPropertyException: No such property: targetNamespace for class: Script1 

 

 

 

// Send data

 

targetURL = "https://test.vetpoint.ch/webtools/control/SOAPService";

 

URL url = new URL( targetURL );

HttpURLConnection conn = url.openConnection();

//if( soapaction != null ) conn.setRequestProperty( "SOAPAction", soapaction );

conn.setRequestProperty( "content-type", "text/xml" );

conn.setDoOutput(true);

OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());

 

soapRequest = "<SOAP-ENV:Envelope";

soapRequest += " xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"";

soapRequest += " xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"";

soapRequest += " xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"";

soapRequest += " xmlns:xsd="http://www.w3.org/2001/XMLSchema"";

soapRequest += "<WebAuthenticationDetail>";

soapRequest += "<UserCredential>";

soapRequest += "<Key>" + accountusername + "</Key>";

soapRequest += "<Password>" + accountpassword + "</Password>";

soapRequest += "</UserCredential>";

soapRequest += "</WebAuthenticationDetail>";

soapRequest += "<SOAP-ENV:Body>";

soapRequest += "<vet:vetTapswSearchProduct>";

soapRequest += "<vet:searchCriteria>amoxi</vet:searchCriteria>";

soapRequest += "</vet:vetTapswSearchProduct>";

soapRequest += "</SOAP-ENV:Body>";

soapRequest += "</SOAP-ENV:Envelope>";

 

wr.write(soapRequest);

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();

 

replaceText = " xmlns="" + targetNamespace + """;

 

response=response.replace(replaceText,'');

 

return response;

 

 

 

 

Link to comment
Share on other sites

This topic is 3842 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.