I am unable to properly read a XML file with XMLBeam:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<ns1:storeTokenResponse xmlns:ns1="http://recurring.services.adyen.com">
<ns1:result>
<additionalData xmlns="http://recurring.services.adyen.com" xsi:nil="true" />
<alias xmlns="http://recurring.services.adyen.com">ALIAS</alias>
<aliasType xmlns="http://recurring.services.adyen.com">Default</aliasType>
<params xmlns="http://recurring.services.adyen.com" xsi:nil="true" />
<pspEchoData xmlns="http://recurring.services.adyen.com" xsi:nil="true" />
<pspReference xmlns="http://recurring.services.adyen.com">PSPREFERENCE</pspReference>
<recurringDetailReference xmlns="http://recurring.services.adyen.com">RECURRINGDETAILREFERENCE</recurringDetailReference>
<redirectType xmlns="http://recurring.services.adyen.com" xsi:nil="true" />
<redirectUrl xmlns="http://recurring.services.adyen.com" xsi:nil="true" />
<result xmlns="http://recurring.services.adyen.com">RESULT</result>
</ns1:result>
</ns1:storeTokenResponse>
</soap:Body>
with given Java class:
public interface PaymentResponse {
#XBRead("/soap:Envelope/soap:Body/ns1:storeTokenResponse/ns1:result/ns1:alias")
String getAlias();
#XBRead("/soap:Envelope/soap:Body/ns1:storeTokenResponse/ns1:result/ns1:recurringDetailReference")
String getRecurringDetailReference();
#XBRead("/soap:Envelope/soap:Body/ns1:storeTokenResponse/ns1:result/ns1:pspReference")
String getPspReference();
#XBRead("/soap:Envelope/soap:Body/ns1:storeTokenResponse/ns1:result/ns1:result")
String getResult();
}
I was doing it like this :
final PaymentResponse paymentResponse = new XBProjector.onXMLString(xml).read(PaymentResponse.class);
Assert.assertTrue("ALIAS",paymentResponse.getAlias());
And yes, proper XPath is ns1:alias, as I've tested.
But looks like XMLBeam is not properly recognizing the values.
Can anyone help, please ?
Related
I need to generate a soap request like the below one :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Document xmlns:ns2="http://www.xyz" xmlns="thsss.738.syhd.738">
<Customer>
<Group>
<Message>Something</Message>
</Group>
</Customer>
</Document>
But the request getting generated is as below:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://eygyjdg.dbajshb/" xmlns:thss="thsss.738.syhd.738" xmlns:xyz="http://www.xyz">
<soapenv:Header/>
<soapenv:Body>
<Document>
<Customer>
<Group>
<Message>Something</Message>
</Group>
</Customer>
</Document>
</soapenv:Body>
</soapenv:Envelope>
Hence i get a namespace on the "Document" element, is not a valid SOAP version
Can you please tell me how to go about this.
I have a following xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<Abc version="3" xmlns="urn:Abc-v3">
<Ele1>
<SubElement name ="name" description="DO">
<Node version="C" siteURL="https://example.com" />
<Client>
<ClientId>1</ClientId>
<ClientSecret>Yes</ClientSecret>
</Client>
</SubElement>
<SubElement name ="SharePointOLDev1" description="DEV1">
<Node version="C" siteURL="https://example.com" />
<Local>
<LocalId>id</LocalId>
<Password>password</Password>
</Local>
</SubElement>
<SubElement name="AS" description="wow">
<DB connection="connection" />
</SubElement>
</Ele1>
<Ele2>
<Content ID="A" co="LD">
<Description>Simple Docs</Description>
<Serve
Lib1="TEST"
Lib2="yes"
Lib3="yes"
Lib4="no"
Lib5="no"
Lib6="name">
<Hole enabled="false" count="200" />
<Fol enabled="false" count="100" />
<Role enabled="No" validate="false" />
<FetchFilenameAttribute connection="SAP-AS" delay="3" />
</Serve>
</Content>
<Content ID="B" co="OL">
<Description>Simple Docs </Description>
<Serve
Lib1="TEST"
Lib2="yes"
Lib3="yes"
Lib4="no"
Lib5="no"
Lib6="name"">
<Hole enabled="false" count="200" />
<Fol enabled="false" count="100" />
<Role enabled="No" validate="false" />
</Serve>
</Content>
</Ele2>
<Ele3>
<CNode attr="hai" attr1="bye" />
</Ele3>
</Abc>
I need to parse this XML file and assign values to its corresponding class objects.Which is the best option to parse such an xml file.
JAXB sounds good to me but the POJOs were already written by someone and now i will have to rewrite and deploy them.ALso teh xml file has some errors while running xjc command.
DOM approach seems to be very cumbersome n error prone.
Please suggest.
PS:Kindly excuse my beginner level knowledge.
the JDK project comes with SAX(Simple API for XML) accessible by importing org.xml.sax.*.
You may take a look at this https://www.tutorialspoint.com/java_xml/java_sax_parse_document.htm for an introduction to the subject.
Is it possible to retrieve the stored procedure result in XML format? I am using Java to call the stored procedure and Microsoft SQL Server management studio to test my stored procedures. Could someone provide a sample code?
Found something like this
SELECT
CustomerID AS '#CustomerID',
CustName AS '#Name',
(SELECT ProductName AS '#productname'
FROM dbo.Products p
WHERE p.CustomerID = c.CustomerID
FOR XML PATH('Product'), TYPE) AS 'Products',
(SELECT HobbyName AS '#hobbyname'
FROM dbo.Hobbies h
WHERE h.CUstomerID = c.CustomerID
FOR XML PATH('Hobby'), TYPE) AS 'Hobbies'
FROM
dbo.Customers c
FOR XML PATH('Customer'), ROOT('Customers')
Gives following output
<Customers>
<Customer CustomerID="1" Name="Fred">
<Products>
<Product productname="Table" />
<Product productname="Wardrobe" />
<Product productname="Chair" />
</Products>
<Hobbies>
<Hobby hobbyname="Golf" />
<Hobby hobbyname="Swimming" />
</Hobbies>
</Customer>
<Customer CustomerID="2" Name="Sue">
<Products>
<Product productname="CD Player" />
<Product productname="Picture frame" />
</Products>
<Hobbies>
<Hobby hobbyname="Dancing" />
<Hobby hobbyname="Gardening" />
<Hobby hobbyname="Reading" />
</Hobbies>
</Customer>
</Customers>
Is this correct?
I am in the process of moving an older web service that had dependency on Weblogic 8 (servicegen) to a JAX WS implementation using annotations. I used the existing WSDL and JAXB to generate the data objects (marshalling/unmarshalling). However, I notice a difference in the SOAP response that is now being generated with JAXWS. I need to generate the same response, as there are over 900 clients, and can’t ask them to modify their code to use the new response schema.
The existing response looks like this:
<env:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Header/>
<env:Body>
<m:findAllCertInfoByOwnerResponse xmlns:m="http://uum.webservices.com">
<n1:result xsi:type="n2:ArrayOfWSCertInfo" xmlns:n1="http://uum.webservices.com" xmlns:n2="java:com.service.data">
<n2:WSCertInfo>
<n2:CPCreateDate> </n2:CPCreateDate>
<n2:CPExpireDate> </n2:CPExpireDate>
<n2:CPStatus> </n2:CPStatus>
<n2:PrevUniqueId>123456</n2:PrevUniqueId>
<n2:UniqueId></n2:UniqueId>
<n2:certID xsi:nil="true"/>
<n2:certStatus/>
<n2:endDate xsi:nil="true"/>
<n2:issuerDN> </n2:issuerDN>
<n2:owner></n2:owner>
<n2:profileName> </n2:profileName>
<n2:renewalStatus xsi:nil="true"/>
<n2:revokeReason/>
<n2:serialNo xsi:nil="true"/>
<n2:startDate xsi:nil="true"/>
<n2:subjectDN xsi:nil="true"/>
<n2:validCertificate>false</n2:validCertificate>
<n2:validEnrollment>true</n2:validEnrollment>
</n2:WSCertInfo>
</n1:result>
</m:findAllCertInfoByOwnerResponse>
</env:Body>
</env:Envelope>
The new JAX WS SOAP response has the following format:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:findLatestCertInfoByOwnerResponse xmlns:ns3="java:com.service.data" xmlns:ns2="http://uum.webservices.com">
<result>
<ns2:result>
<ns3:WSCertInfo>
<ns3:CPCreateDate xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:CPExpireDate xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:CPStatus xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:PrevUniqueId>123456</ns3:PrevUniqueId>
<ns3:UniqueId xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:certID xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:certStatus xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:endDate xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:issuerDN xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:owner xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:profileName xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:renewalStatus xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:revokeReason xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:serialNo xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:startDate xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:subjectDN xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns3:validCertificate>false</ns3:validCertificate>
<ns3:validEnrollment>false</ns3:validEnrollment>
</ns3:WSCertInfo>
</ns2:result>
</result>
</ns2:findLatestCertInfoByOwnerResponse>
</S:Body>
</S:Envelope>
The JAXWS SOAP response is pretty close except for the following:
JAXWS response is missing the xsi:type and xmlns info. Plus it is nested in the attribute.
How can I add the xsi:type and xmlns to the attribute?
I am including the example class to show the defined web annotations.
Thanks in advance for your assistance!!!!!
The Web Service class looks like the following:
#WebService(
name = "UUMCertLocatorService",
serviceName = "UUMCertLocatorService",
portName = "UUMCertLocatorServicePort",
targetNamespace = "http://uum.webservices.com",
wsdlLocation = "UUMCertLocatorService.wsdl")
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.WRAPPED,
style = SOAPBinding.Style.DOCUMENT,
use = SOAPBinding.Use.LITERAL)
public class UUMCertLocatorServiceEndPoint {
#WebMethod(action="",operationName="findLatestCertInfoByOwner")
#WebResult(name="findLatestCertInfoByOwnerResponse",header=true,targetNamespace="java:com.service.data",partName="http://uum.webservices.com")
public FindAllCertInfoByOwnerResponse findAllCertInfoByOwner(
#WebParam(targetNamespace="http://uum.webservices.com",
partName="http://uum.webservices.com",
name="string")String uniqueID,
#WebParam(targetNamespace="http://uum.webservices.com",
partName="http://uum.webservices.com",
name="string0")String adminSessionSpec,
#WebParam(targetNamespace="http://uum.webservices.com",
partName="http://uum.webservices.com",
name="string1")String webKey) throws WSUUMException
{
LogHelper.debug(UUMCertLocatorServiceEndPoint.class, "Params: {} {} {} ", uniqueID,adminSessionSpec,webKey);
final ObjectFactory objectFactory = new ObjectFactory();
FindAllCertInfoByOwnerResponse response = objectFactory.createFindAllCertInfoByOwnerResponse();
WSCertInfo certinfo = objectFactory.createWSCertInfo();
certinfo.setBofaPrevUniqueId("123456");
ArrayOfWSCertInfo arraycert = objectFactory.createArrayOfWSCertInfo();
arraycert.getWSCertInfo().add(certinfo);
response.setResult(arraycert);
return response;
}
}
I'm parsing xml file and trying to create model from it. I'm using Simple XML library. My xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<root cycles_count="2">
<shifts>
<shift id="0" name="first"/>
<shift id="1" name="second"/>
<shift id="2" name="third"/>
<shift id="3" name="fourth"/>
</shifts>
<cycles>
<cycle name="A" start_date="1334620800000">
<cycle_shift id="0" />
<cycle_shift id="0" />
<cycle_shift id="1" />
</cycle>
<cycle name="B" start_date="1334620800000">
<cycle_shift id="1" />
<cycle_shift id="1" />
<cycle_shift id="2" />
</cycle>
</cycles>
</root>
Is there any way how to create object reference from cycle_shift to shift based on the same id? I want to achieve something like this (simplified version):
#Root
public class Shift {
#Attribute
int id;
#Attribute
String name;
}
#Root
public class Cycle {
#ElementList
List<Shift> shifts; // shifts connected by id's
}
Change of xml schema is possible too. Thanks in advance.
Cycle through the Shifts and create those objects
Create a dictionary with the id of the Shift as the key and the Shift itself as the value
Loop through all your Cycles and create those objects
When creating the List of Shifts belonging to that Cycle, just reference the id from the Cycle's property and look up the Shift from the dictionary you created earlier and add it to the list.
Would that work?
You can set the name attribute optional on Shift, and get rid of cycle_shift and use only shift instead
<?xml version="1.0" encoding="utf-8"?>
<root cycles_count="2">
<shifts>
<shift id="0" name="first"/>
<shift id="1" name="second"/>
<shift id="2" name="third"/>
<shift id="3" name="fourth"/>
</shifts>
<cycle name="B" start_date="1334620800000">
<cycle_shift id="1" />
<cycle_shift id="1" />
<cycle_shift id="2" />
</cycle>
And your pseudo code will be like this: (I'm using the inline modifier)
#Root
public class Cycle {
#ElementList(inline=true)
List<Shift> shifts; // shifts connected by id's
}