I am testing a webservice method which accepts session-id as a parameter.
While testing the same method via SoapUI with a dummy sessionID-Parameter, the server is rejecting the request as it is expecting proper session-id.
How can I solve this? Is there any way where SoapUI can bind the session-id before sending the request?
Please advice me. Thanks
Below is the sample-request which is triggered from SOAP-UI:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.local.com">
<soapenv:Header/>
<soapenv:Body>
<ser:getMultiple>
<!--Optional:-->
<ser:sessionId>1000AJHEFG0987</ser:sessionId>
<!--Optional:-->
<ser:lessonId>95101</ser:lessonId>
<!--Optional:-->
<ser:quantity>1</ser:quantity>
<!--Optional:-->
<ser:impressionRow>1</ser:impressionRow>
</ser:getParametersMultiple>
</soapenv:Body>
</soapenv:Envelope>
Let's say, if you get sessionid in first request's response, and the next request should go here http://{{original endpoint}}/{{SESSION_ID}}), this definitely works:
go to request (not the test request inside test case) where session id should be put into
add a parameter on 'request' tab
name=sessionid, style=template, level=resource. now it is empty in all related test requests
go to test request, 'request' tab
put the path to sessionid value from previous request into 'value' field of sessionid parameter. for example, it is like ${users#Response#$.session_id} where 'users' is the name of endpoint resource, 'session_id' is the name of parameter inside response
Found the solution,
Design your login method which will accept certain inputs and will
return the sessionID as a string
Hit that login method from SOAP-UI and you will get the sessionID in
your response
Use "Property Transfer" option in soap-ui and transfer the received
sessionID to all other requests
Helpful Link : soapui.org/Functional-Testing/transferring-property-values.html
Simple !! :)
Related
I'm trying to send a SOAP Request to a webservice in Delphi XE5. Actually there is a WSDL available which I imported via WSDL Importer. I established a connection to this webservice with the components THTTPRIO (rio) and IdEncoderMIME1 for the HTTP Authentication Request.
The SOAP Request was build via TXMLDocument and has the following structure:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cod=NS_Codelist>
<soapenv:Header/>
<soapenv:Body>
<cod:GetLatestChangeDatesRequest>
<!--Zero or more repetitions:-->
<CodeListID>1035</CodeListID>
</cod:GetLatestChangeDatesRequest>
</soapenv:Body>
</soapenv:Envelope>
Furthermore I received the Porttype of the webservice.
codeserv:= GetCodeListPortType(true,'',rio);
These are methods from the WSDL:
codeserv.GetLatestChangeDates(const body:GetLatestChangeDatesRequestType):GetLatestChangeDatesResponseType
GetLatestChangeDatesRequestType = array of Int64;
GetLatestChangeDatesRequest = GetLatestChangeDatesRequestType;
GetLatestChangeDatesResponseType = array of CodeListLatestChangeDateType;
GetLatestChangeDatesResponse = GetLatestChangeDatesResponseType;
CodeListLatestChangeDateType
property CodeListID: Int64
property LatestChangeDate: TXSDate
I have already tried to set an array of Int64 for the parameter but then it says "element CodeListID is missing".
Unfortunately I don't find a way to send this XML SOAP Request to the webservice and to receive the response. Any ideas?
EDIT: I have tried to use the WSDL methods
var
codeserv: CodeListPortType;
arrIDs: GetLatestChangeDatesRequest;
response: GetLatestChangeDatesResponse;
begin
codeserv:= GetCodeListPortType(true,'',rio);
SetLength(arrIDs,1);
arrIDs[0]:= 1035;
response:= codeserv.GetLatestChangeDates(arrIDs);
But then I receive the following error message: 'invalid content was found starting with element 'long'. One of '{CodeListID}' is expected.'
In the SOAP Request there have to be the element CodeListID. Unfortunately it seems the method GetLatestChangeDates isn't creating the elements in the SOAP Request. The SOAP Request posted above should have been created with this method (hopefully).
Can some explain the best way on SOAP UI Free to achieve the below scenario
Load the response value from one Test Case Web service as a request value on second Test Case Web service.
in Test case 1 Script Assertion
import com.eviware.soapui.support.XmlHolder
def respXmlHolder = new XmlHolder(messageExchange.getResponseContentAsXml())
respXmlHolder.declareNamespace("ns1","http://www.moj.com/api/services/checkout")
def finsess = respXmlHolder.getNodeValue("//ns1:sessresp/ns1:sessionId")
log.info finsess
Log Info shows below 70c8a6f80b6ff0c72502
Now how to automatically load this above sessionid onto Test Case 2 Web Service as shown below.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://www.moj.com/api/services/final">
<soapenv:Header/>
<soapenv:Body>
<typ:FinSessionRequest>
<typ:correlationId>1234</typ:correlationId>
<typ:sessionId>70c8a6f80b6ff0c72502</typ:sessionId>
<typ:username>abcd</typ:username>
<typ:password>1234</typ:password>
</typ:FinSessionRequest>
</soapenv:Body>
</soapenv:Envelope>
You can use Property transfer test step for this task, without Groovy scripting. See more at SoapUI docs. You just pick the source XML element with XPath and similarly the target element. SoapUI will do the replacement when you execute the test step (or the test case). I recommend to use this way as it is transparent.
If you really need to transfer the value with Groovy scripting, you can set a test suite property value in your assertion script:
def testSuite = context.getTestCase().getTestSuite()
testSuite.setPropertyValue("MyId", finsess)
And then place the MyId into your request message:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://www.moj.com/api/services/final">
<soapenv:Header/>
<soapenv:Body>
<typ:FinSessionRequest>
<typ:correlationId>1234</typ:correlationId>
<typ:sessionId>${#TestSuite#MyId}</typ:sessionId>
<typ:username>abcd</typ:username>
<typ:password>1234</typ:password>
</typ:FinSessionRequest>
</soapenv:Body>
</soapenv:Envelope>
This works as long as the two test cases belong to the same test suite.
Karel
I want to set the value of token in this soap ws header
<soapenv:Enveloppe ...
<soapenv:Header>
<web:token>123456 </web:token>
FROM step named test get idSession in response
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:authentification xmlns:ns1="http://ws.demowebservices.com/">
<bloc1>
<bloc2>
<idSession>e1c64cd9-b933-4f56-ae1f-0f7d7f23942b</idSession>
</bloc2>
I tried to put in-between web:token tag
${test#Response#//ns1:authentification/bloc1/bloc2/idSession}
but it does not work
What should I put instead ?
I'm not sure if this is what you're trying to achieve, however If you have a SOAP Test step called Test Request and you want to use the value of the <soapenv:Header><web:token></soapenv:Header> of this request in another SOAP Test step you can refer this value in the second SOAP Test step request using the follow syntax:
<soapenv:Enveloppe ...
<soapenv:Header>
<web:token>${Test Request#Request#//soapenv:Header/web:token}</web:token>
The syntax ${Test Request#Request#//soapenv:Header/web:token} has three parts, the name of the test step, followed by the property (could be #Request or #Response), and finally the xpath to get the value //soapenv:Header/web:token.
UPDATED:
As you said you've two SOAP Test Request, the first one is called test an has the follow response:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:authentification xmlns:ns1="http://ws.demowebservices.com/">
<bloc1>
<bloc2>
<idSession>e1c64cd9-b933-4f56-ae1f-0f7d7f23942b</idSession>
</bloc2>
</bloc1>
</ns1:authentification>
</soap:Body>
</soap:Envelope>
The second is named for example test 2 (don't care because the second name not affect your purpose) and has the follow request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<web:token>${test#Response#//ns1:authentification/bloc1/bloc2/idSession}</web:token>
</soapenv:Header>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope>
With ${test#Response#//ns1:authentification/bloc1/bloc2/idSession} you're referencing the idSession value of the test response correctly. Take a look on the http log tab when you send your test 2 as shown in the follow image:
Hope this helps,
I created a service webservices in Saels Force, from the class created soliceitei generation of WSDL and went to the company that will consume the service. However there are some header information that can not preecher, someone could help me?
<soapenv:Header>
<atu:AllowFieldTruncationHeader>
<atu:allowFieldTruncation>???????????</atu:allowFieldTruncation>
</atu:AllowFieldTruncationHeader>
<atu:DebuggingHeader>
<!--Zero or more repetitions:-->
<atu:categories>
<atu:category>??????????</atu:category>
<atu:level>???????????</atu:level>
</atu:categories>
<atu:debugLevel>????????????</atu:debugLevel>
</atu:DebuggingHeader>
<atu:CallOptions>
<atu:client>??????????????</atu:client>
</atu:CallOptions>
<atu:SessionHeader>
<atu:sessionId>?????????????</atu:sessionId>
</atu:SessionHeader>
For the session Id, you will have to login using the login method provided by Enterprise.WSDL or Partner.wsdl.
Below is a soap of exeplo filled with the header.
<soapenv:Header>
<atu:AllowFieldTruncationHeader>
<atu:allowFieldTruncation>**true**</atu:allowFieldTruncation>
</atu:AllowFieldTruncationHeader>
<atu:DebuggingHeader>
<!--Zero or more repetitions:-->
<atu:categories>
<atu:category>**Apex_Code**</atu:category>
<atu:level>**Debug**</atu:level>
</atu:categories>
<atu:debugLevel>**Debugonly**</atu:debugLevel>
</atu:DebuggingHeader>
<atu:CallOptions>
<atu:client>**true**</atu:client>
</atu:CallOptions>
<atu:SessionHeader>
<atu:sessionId>**YOUR_SESSION_ID**</atu:sessionId>
</atu:SessionHeader>
I hope that helped.
I want to use JAX-WS API to create a WS-Addressing enabled web service client. I used wsimport to create the client stub from the WSDL file, and can enable/disable WS-Addressing by using the AddressingFeature, e.g.
Hello hello = service.getHelloSoap11(new AddressingFeature(true, true));
However, I cannot find any samples in web that customize the WS-Addressing ReplyTo/FaultTo endpoint reference. Basically I want to create a WS request like the following (see the wsa:ReplyTo element):
<soapenv:Envelope ...>
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To soapenv:mustUnderstand="1">http://localhost:8080/poc/helloService/
</wsa:To>
<wsa:ReplyTo>
<wsa:Address>http://mycompany.com/poc/reply</wsa:Address>
<wsa:ReferenceParameters>
<field1 xmlns="http://mycompany.com/poc/cust">some value1</field1>
<field2 xmlns="http://mycompany.com/poc/cust">some value2</field2>
</wsa:ReferenceParameters>
</wsa:ReplyTo>
<wsa:Action>http://mycompany.com/poc/sayHello</wsa:Action>
<wsa:MessageID>urn:uuid:7849b04f-c74e-4836-99e4-8e25d2700fae
</wsa:MessageID>
</soapenv:Header>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope>
I can add endpoint reference if using Spring Web Service client. However, I need to do it using JAX-WS. Any ideas?
I answer my own question.
It seems that the standard JAX-WS API does not provide a convenient way to customize the WS-Addressing From/ReplyTo/FaultTo endpoint references. However, each JAX-WS runtime may provide additional proprietary API to set the headers.
For example, the IBM JAX-WS RI provides an EndpointReferenceManager SPI to create the endpoint reference:
import com.ibm.wsspi.wsaddressing.EndpointReference;
import com.ibm.wsspi.wsaddressing.EndpointReferenceManager;
import com.ibm.wsspi.wsaddressing.WSAConstants;
public void testWSAddressing () {
// get the port
Hello hello = service.getHelloSoap11();
// build a EndpiontReference of <wsa:ReplyTo>
BindingProvider bp = (BindingProvider) hello;
EndpointReference epr = EndpointReferenceManager.createEndpointReference(new URI(
"http://www.w3.org/2005/08/addressing/anonymous"));
epr.setReferenceParameter(new QName("http://mycompany.com/test", "someRefParam"),
"12345678");
((BindingProvider) hello).getRequestContext()
.put(WSAConstants.WSADDRESSING_REPLYTO_EPR, epr);
...
HelloResponse response = hello.hello(request);
}
The above code, when running inside IBM Websphere, will produce a SOAP message like the following:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To>http://localhost:8080/poc/helloService/</wsa:To>
<wsa:ReplyTo>
<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous
</wsa:Address>
<wsa:ReferenceParameters>
<someRefParam xmlns="http://mycompany.com/test">12345678</someRefParam>
</wsa:ReferenceParameters>
</wsa:ReplyTo>
<wsa:MessageID>urn:uuid:BE9E173A35BAB51CB31338454394298
</wsa:MessageID>
<wsa:Action>http://mycompany.com/Hello</wsa:Action>
</soapenv:Header>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope >
I've found a way to do this with standard JAX-WS.
When getting a port, use both AddressingFeature and OneWayFeature.
AddressingFeature addressingfeature = new AddressingFeature();
OneWayFeature onewayfeature = new OneWayFeature(true, new WSEndpointReference(YOUR_REPLY_TO_ADDRESS, AddressingVersion.W3C));
// get the port
Hello hello = service.getHelloSoap11(addressingfeature, onewayfeature);
This will produce messages with "ReplyTo" tag.
You may have to grab "com.sun.xml.ws:jaxws-rt" dependency for this.