vCenter proxy implementation - java

I am writing a vCenter proxy using ssl-sockets in order to reduce number of connections to the vCenter.
I have one connection using vi-java to update vCenter inventory (PropertyCollector, PropertyFilter, etc.) and I want to translate the objects return to vi-java to SOAP XML to write to the socket.
Is there a package that does it for all vi-java types?
This is a serialization of the PropertyCollector object for example:
<com.vmware.vim25.mo.PropertyCollector>
<serverConnection>
....
</serverConnection>
<mor>
<val>session[b7ea29d3-92e3-0ac9-e017-2748a3120379]52aab664-bb24-845a-7189-d48085e866aa</val>
<type>PropertyCollector</type>
</mor>
</com.vmware.vim25.mo.PropertyCollector>
While this is the expected SOAP response:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<CreatePropertyCollectorResponse xmlns="urn:vim25"><returnval type="PropertyCollector">session[b7ea29d3-92e3-0ac9-e017-2748a3120379]52aab664-bb24-845a-7189-d48085e866aa</returnval></CreatePropertyCollectorResponse>
</soapenv:Body>
</soapenv:Envelope>

In vi-java, XmlGen.toXml(...) does the trick

Related

SOAP XML request returning "Request is not well formed" fault

I am converting Python code to Java. The code is SOAP 1.5 client code which communicates with a SOAP server endpoint.
What doesn't make sense is that the Python code sends the XML request and gets the accepted response from the server. With the Java code however, the response is a fault stating "Request is not well formed".
Below I am showing the XML requests, the one which is sent in Python and the other in Java. How can the Java one sent by Java return a fault, but the Python is fine / accepted. They are both valid requests. Or perhaps I am missing something obvious.
Request in Python :
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsa="http://www.w3.org/2005/08/addressing"
xmlns:cs="urn://Ocpp/Cp/2012/06/">
<SOAP-ENV:Header>
<cs:chargeBoxIdentity>Test</cs:chargeBoxIdentity>
<wsa:MessageID>Fake OCPP571322528896</wsa:MessageID>
<wsa:Action>/ChangeConfiguration</wsa:Action>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<cs:changeConfigurationRequest>
<cs:key>LaMa_ConnectionRate</cs:key>
<cs:value>5120</cs:value>
</cs:changeConfigurationRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Request in Java :
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:cs="urn://Ocpp/Cp/2012/06/"
xmlns:wsa="http://www.w3.org/2005/08/addressing">
<SOAP-ENV:Header>
<cs:chargeBoxIdentity>Test</cs:chargeBoxIdentity>
<wsa:Action>/ChangeConfiguration</wsa:Action>
<wsa:MessageID>Fake OCPP571322528896</wsa:MessageID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<cs:changeConfigurationRequest>
<cs:key>LaMa_ConnectionRate</cs:key>
<cs:value>5120</cs:value>
</cs:changeConfigurationRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Fault response to Java :
<?xml version="1.0" encoding="UTF-8"?><env:Envelope
xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Header/>
<env:Body>
<env:Fault>
<env:Code>
<env:Value>env:Sender</env:Value>
</env:Code>
<env:Reason>
<env:Text xml:lang="en-US">XML Request is not well formed!</env:Text>
</env:Reason>
</env:Fault>
</env:Body>
</env:Envelope>
Update :
My Java code should be sending "http://www.w3.org/2003/05/soap-envelope" for "SOAP-ENV", as shown below in my code. However it somehow sends "http://schemas.xmlsoap.org/soap/envelope/" instead. I don't understand why.
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("SOAP-ENV", "http://www.w3.org/2003/05/soap-envelope");

how to retrieve specific web service response from the server

Web service provider has provided us(Client) a wsdl to use their service and consume data. Our requirement is, we just need specific node value called "CHASE", see below test data. We don't want to get all records of info and corresponding nodes in the response.
Here is an example that we have tested in SOAPUI tool. Please suggest and help us how can we frame the web service request technically from the URL provided(http://host:port/ValueMappingInService/ValueMappingInImplBean)? Is it at all possible to drill down the request and get specific response from client side?
Web service Request:-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:bas="http://sap.com/xi/BASIS">
<soapenv:Header/>
<soapenv:Body>
<bas:ValueMappingReadRequest>
<!--Optional:-->
<ReadContext>User</ReadContext>
<!--Zero or more repetitions:-->
<ValueMappingID>c44f541f-c8ac-11e8-86e5-0050569d98cc</ValueMappingID>
</bas:ValueMappingReadRequest>
</soapenv:Body>
</soapenv:Envelope>
Web service Response:-
<SOAP-ENV:Envelope xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-
ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<ns2:ValueMappingReadResponse xmlns:ns2="http://sap.com/xi/BASIS">
<ValueMapping>
<MasterLanguage>EN</MasterLanguage>
<AdministrativeData>
<ResponsibleUserAccountID>gdonna</ResponsibleUserAccountID>
<LastChangeUserAccountID>gdonna</LastChangeUserAccountID>
<LastChangeDateTime>2018-10-05T09:47:38.237-05:00</LastChangeDateTime>
<FolderPathID>/</FolderPathID>
</AdministrativeData>
<ValueMappingID>c44f541f-c8ac-11e8-86e5-0050569d98cc</ValueMappingID>
<GroupName>Mercedes</GroupName>
<Representation schemeAgencyID="LOC_BANK" schemeID="BANK">CHASE</Representation>
<Representation schemeAgencyID="LOC_SITE" schemeID="DIR">comm/as2/chase/receive/</Representation>
<Representation schemeAgencyID="LOC_COUNTRY" schemeID="CODE">US</Representation>
</ValueMapping>
<LogMessageCollection/>
</ns2:ValueMappingReadResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Try using a Groovy Script. I really like the features of the XMLSlurper, which lets me ignore the namespaces if/when they change.
Just add a new Groovy Script teststep, and put this into it. You just need to adjust the name of your Soap Request teststep, which should be placed just before this teststep.
/** The name should be modified to match the request/response you want to validate */
def holder = new com.eviware.soapui.support.GroovyUtils( context ).getXmlHolder("The Name Of Your Soap Request TestStep#Response")
def response = new XmlSlurper().parseText(holder.getXml())
for (def element : response.Body.ValueMappingReadResponse.ValueMapping.Representation)
{
log.info element
log.info element.#'schemeAgencyID'
}

How to get two responses for a single request in soap web services

I need two responses from soap web service where I should get the first response and after some time based on the element (ResponseCode in my case) in the first response, the second response should come. Below are the sample 2 responses I need form the soap web service
Response1:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://cp.abc.com/cpinterface/request">
<soapenv:Header/>
<soapenv:Body>
<req:ResponseMsg><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<Response>
<ResponseCode>0</ResponseCode>
<ResponseDesc>The service request is processed successfully.</ResponseDesc>
<ServiceStatus>0</ServiceStatus>
</Response>]]></req:ResponseMsg>
</soapenv:Body>
</soapenv:Envelope>
Response2:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<res:ResultMsg xmlns:res="http://cp.abc.com/cpinterface/result"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<Result>
<ResultType>0</ResultType>
<ResultCode>0</ResultCode>
<ResultDesc>Process service request successfully.</ResultDesc>
<ResultParameters>
<ResultParameter>
<Key>EndDate</Key>
<Value>20140103</Value>
</ResultParameter>
<ResultParameter>
<Key>EndTime</Key>
<Value>210156</Value>
</ResultParameter>
<ResultParameter>
<Key>Fee</Key>
<Value>0.89</Value>
</ResultParameter>
</ResultParameters>
</Result>]]></req:ResultMsg>
</soapenv:Body>
</soapenv:Envelope>
I don't think that's possible, HTTP(S) is one-on-one in the sense that there's one response to one request. There is potentially a loophole you may be able to exploit by using the HTTP status code 100 (continue). Status code 100 means; 'Sofar everything is fine, but more information is coming'. Your client should then continue to wait for the final SOAP response; which then has status code 200 (OK) or 500 (Error). Although in theory it is possible to use a different application protocol (e.g. JMS, SMTP or FTP) to transport SOAP messages, in practice it is usually HTTP(S).
Having said this, I think you shouldn't go down the statuscode 100 route but instead rethink your approach, stick with the 'one response for one request'. The above would be very hacky and tricky to implement.

Java web service in .NET proxy class returns null

When I access a Java web service in a .NET proxy class, I get the reply string as null.
With the help of SOAP extensions, I found that this is the reply that I get from the web service:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getInfoResponse xmlns="http://services">
<getInfoReturn>
<full_Name xsi:nil="true"/>
</getInfoReturn>
</getInfoResponse>
</soapenv:Body>
</soapenv:Envelope>
This is the client class that i am using
cardInfo = new global::CardInfoService.CardInfoService.CardInfoService();
card = cardInfo.getCardInfo(value, number);
System.Console.WriteLine("Got the Card Holder name " + card.full_Name);
Thanks in advance.

WCF Client / Java Web Service - SOAP

I need to send a SOAP Message with the following format (cut down from example I was given): -
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ret="http://www.another.com/ret"
xmlns:ser="http://www.another.com/ret/retTransaction/service"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<ser:store>
<ret:retTransaction>
<ret:retailTransaction xsi:type="ret:NormalTransaction"> <ret:applicationId>POS</ret:applicationId>
</ret:retailTransaction>
</ret:retTransaction>
</ser:store>
</soapenv:Body>
</soapenv:Envelope>
The operation in question is "store". That operation has an "object" parameter in the proxy following Add Service Reference.
How do I ensure that a message with the correct format is sent? Particularly the multiple namespaces in the SOAP Envelope?
Thanks

Categories

Resources