lucidsoftware / xtract

A library to make it easy to deserialize XML to user types in scala
Apache License 2.0
60 stars 20 forks source link

java.net.MalformedURLException: no protocol: #32

Closed juanmcarballo closed 4 years ago

juanmcarballo commented 4 years ago

Hi, it's giving me an error on the next code, I want the first two to be left in blank while the third one should be filled with an integer from the document

case class CustomerOrder(customerOrderKey: String, customerOrderLogKey: String, tenantId: Int)

object CustomerOrder {
  implicit val reader: XmlReader[CustomerOrder] = (
    (__ \ "noTag").readAttribute[String]("customerOrderKey"),
    (__ \ "noTag").readAttribute[String]("customerOrderLogKey"),
    (__ \ "fulfillCustomerOrderRequest" \ "messageHeader" \ "tenantId").readAttribute[Int]("tenantId")
    ).mapN(apply _)
}

But is giving me the next error while I don't have any urls except the dummy ones as text inside the tags.

Exception in thread "main" java.net.MalformedURLException: no protocol: <fulfillCustomerOrderRequest> <messageHeader> <tenantId>125</tenantId> <countryCode>MEX</countryCode> <locationId>ALG965</locationId> <msgId>MBSDL924</msgId> <msgTimestamp>2008-09-28T20:49:45</msgTimestamp> <version>1.0</version> </messageHeader> <messageBody> <action>ADD</action> <customerInfo> <id>QGSTE1923</id> <contactPoint> <email>jm.carb@gmail.com</email> <telephone>5554068837</telephone> </contactPoint> <name> <firstName>Juan</firstName> <middleName>Manuel</middleName> <lastName>Carballo</lastName> <legalName>Juan Manuel Carballo</legalName> </name> <geo> <postalAddress> <addressLine1>San José del Real 21B</addressLine1> <addressLine2>Lomas Verdes 5ta sección</addressLine2> <city>Naucalpan</city> <postalCode>53126</postalCode> <state>Edo. de Méx.</state> <country>MEX</country> <addressType>BILLING</addressType> </postalAddress> <timeZone>America/Mexico_City</timeZone> </geo> </customerInfo> <orderHeader> <srcOrderId>LIKSDCEOSLD</srcOrderId> <srcOrderCreateTime>2007-08-08T20:18:11-05:00</srcOrderCreateTime> <customerOrderId>ALGOTWWE</customerOrderId> <customerOrderCreateTime>2012-09-13T08:00:34-05:00</customerOrderCreateTime> <expirationDate>2009-10-14T02:16:36</expirationDate> <relativePriority>100</relativePriority> <totalOrderLines>1</totalOrderLines> <fulfillLocation> <locationId>985236</locationId> <geo> <postalAddress> <addressLine1>San José del Real 21B</addressLine1> <addressLine2>Lomas Verdes 5ta sección</addressLine2> <city>Naucalpan</city> <postalCode>53126</postalCode> <state>Edo. de Méx.</state> <country>MEX</country> <addressType>RESIDENTIAL</addressType> </postalAddress> <timeZone>America/Mexico_City</timeZone> </geo> <globalLocationNumber>895QSCGSDILFOEJSKDIU</globalLocationNumber> <locationCategory>warehouse</locationCategory> </fulfillLocation> <deliveryMethod> <onSitePickup> <pickupLocation> <locationId>1234</locationId> <geo> <postalAddress> <addressLine1>San José del Real 21B</addressLine1> <addressLine2>Lomas Verdes 5ta sección</addressLine2> <city>Naucalpan</city> <postalCode>53126</postalCode> <state>Edo. de Méx.</state> <country>MEX</country> <addressType>PICKUP_POINT</addressType> </postalAddress> <timeZone>America/Mexico_City</timeZone> </geo>                        <!--Optional:--> <globalLocationNumber>035QSCGSDIFOEJSKDQWE</globalLocationNumber> <locationCategory>driveThrough</locationCategory> </pickupLocation> <promisedPickupDateTime>2006-11-29T11:20:00</promisedPickupDateTime> <plannedPickupDateTime>2009-11-03T06:39:15-06:00</plannedPickupDateTime> <pickupSlot> <start>2014-06-27T14:41:15-05:00</start> <end>2017-08-17T00:44:20</end> </pickupSlot> <alternatePickupPerson> <id>QLCKSIDEADOL61674</id> <documentId>QSJDORLFASQ72015</documentId> <contactPoint> <email>carlavivani@gmail.com</email> <telephone>5554068834</telephone> </contactPoint> <name> <firstName>Carla</firstName> <middleName>Vivani</middleName> <lastName>Carballo</lastName> <legalName>Carla Vivani Carballo</legalName> </name> <geo> <postalAddress> <addressLine1>San José del Real 21B</addressLine1> <addressLine2>Lomas Verdes 5ta sección</addressLine2> <city>Naucalpan</city> <postalCode>53126</postalCode> <state>Edo. de Méx.</state> <country>MEX</country> <addressType>PICKUP_POINT</addressType> </postalAddress> <timeZone>America/Mexico_City</timeZone> </geo> </alternatePickupPerson> </onSitePickup> </deliveryMethod> <coupon> <id>ABW12</id> <name>CANDY</name> <description>CANDY</description> <amount>1.0000000</amount> <type>promotion</type> </coupon> <coupon> <id>ALO12</id> <name>BREAD</name> <description>BREAD</description> <amount>2.0000000</amount> <type>promotion</type> </coupon> <fee> <id>QWU23</id> <amount>3.0000000</amount> <tax> <amount>4.0000000</amount> <type>LMYHSR78</type> <discount> <amount>1.0000000</amount> <type>applied discount</type> <description>applied discount</description> <percent>0.1000000</percent> </discount> <taxAdjustment>0.0000000</taxAdjustment> <taxRate>0.1500000</taxRate> </tax> <type>my type</type> <feeRate>0.1500000</feeRate> </fee> </orderHeader> <!--1 or more repetitions:--> <promisedOrderLine> <product> <productId>1987542563</productId> <gtin>999991</gtin> <shortDescription>this is a short description</shortDescription> <longDescription>this is a longer description than de previous one</longDescription> <richInformation> <picture>ZmV0YQ==</picture> <pictureURL>http://image.url/1294</pictureURL> </richInformation> <sku>79512364589</sku> <category> <groupCode>JFUR6783</groupCode> <categoryCode>JR017935</categoryCode> <classCode>LOBC4567</classCode> <subClassCode>QWDS8976</subClassCode> <description>This is a longer description</description> </category> <physicalProperties> <temperatureBand>Ambient</temperatureBand> <color>RED</color> <dimensions> <height>1000.0000000</height> <width>1000.0000000</width> <length>1000.0000000</length> <depth>1000.0000000</depth> <uom>OZ</uom> </dimensions> <unitWeight> <amount>1000.0000000</amount> <uom>OZ</uom> </unitWeight> <isFragile>false</isFragile> <isHazmat>false</isHazmat> </physicalProperties> <effectiveTime>2013-08-22T18:50:52</effectiveTime> <expiryTime>2016-02-07T12:34:15-06:00</expiryTime> <additionalProperties> <!--Optional:--> <isVariableWeight>false</isVariableWeight> <!--Optional:--> <isMultiBox>false</isMultiBox> <!--Optional:--> <isRecalled>true</isRecalled> <!--Optional:--> <pickQuantityThreshold>7</pickQuantityThreshold> <!--Optional:--> <idealLowTemperature> <!--Optional:--> <amount>1000.0000000</amount> <!--Optional:--> <uom>string</uom> </idealLowTemperature> <!--Optional:--> <idealHighTemperature> <!--Optional:--> <amount>1000.0000000</amount> <!--Optional:--> <uom>string</uom> </idealHighTemperature> <!--Optional:--> <acceptableLowTemperature> <!--Optional:--> <amount>1000.0000000</amount> <!--Optional:--> <uom>string</uom> </acceptableLowTemperature> <!--Optional:--> <acceptableHighTemperature> <!--Optional:--> <amount>1000.0000000</amount> <!--Optional:--> <uom>string</uom> </acceptableHighTemperature> <!--Optional:--> <isAgeRestrictedToReceive>true</isAgeRestrictedToReceive> <!--Optional:--> <hasEASTag>false</hasEASTag> <!--Optional:--> <isGiveaway>true</isGiveaway> <!--Optional:--> <isBeverage>true</isBeverage> <!--Optional:--> <isWicEligible>true</isWicEligible> <!--Optional:--> <isSNAPEligible>true</isSNAPEligible> <!--Optional:--> <isLayawayEligible>false</isLayawayEligible> <!--Optional:--> <isFoodStampEligible>true</isFoodStampEligible> <!--Optional:--> <tareWeight> <!--Optional:--> <amount>1000.0000000</amount> <!--Optional:--> <uom>string</uom> </tareWeight> <!--Optional:--> <tarePercent>1000.00</tarePercent> <!--Optional:--> <isSoldByWeight>true</isSoldByWeight> <!--Optional:--> <isElectronicRegistration>true</isElectronicRegistration> <!--Optional:--> <serialNumberMask>AZLDFOEIDKS</serialNumberMask> <!--Optional:--> <serialCheckDigitMask>AB</serialCheckDigitMask> <!--Optional:--> <isWarrantyAvailable>true</isWarrantyAvailable> <!--Optional:--> <hasExtendedBarcode>false</hasExtendedBarcode> </additionalProperties> </product> <quantity> <amount>89.0000000</amount> <uom>OZ</uom> </quantity> <weight> <amount>99.0000000</amount> <uom>OZ</uom> </weight> <price> <price>9827.0000000</price> <currency>MXN</currency> <minPrice>13.0000000</minPrice> <maxPrice>25699.0000000</maxPrice> </price> <fulfillOptions> <isSubAllowed>true</isSubAllowed> <customerNotes>Debe ser entregado en las rejas de la casa</customerNotes> <preferredSubProduct> <productId>string</productId> <gtin>78787887</gtin> <shortDescription>string</shortDescription> <longDescription>string</longDescription> <richInformation> <picture>bW9udGlz</picture> <pictureURL>http://image.url/109215</pictureURL> </richInformation> <sku>9651236547</sku> <category> <groupCode>1SKDOL</groupCode> <categoryCode>123SKDLS</categoryCode> <classCode>1074LOCK</classCode> <subClassCode>OIYG6547</subClassCode> <description>09OLSD53</description> </category> <physicalProperties> <temperatureBand>Chilled</temperatureBand> <color>string</color> <dimensions> <height>1000.0000000</height> <width>1000.0000000</width> <length>1000.0000000</length> <depth>1000.0000000</depth> <uom>OZ</uom> </dimensions> <unitWeight> <amount>1000.0000000</amount> <uom>OZ</uom> </unitWeight> <isFragile>true</isFragile> <isHazmat>false</isHazmat> </physicalProperties> <effectiveTime>2011-11-02T14:53:12</effectiveTime> <expiryTime>2008-08-28T10:03:17-05:00</expiryTime> <additionalProperties> <isVariableWeight>true</isVariableWeight> <isMultiBox>false</isMultiBox> <isRecalled>false</isRecalled> <pickQuantityThreshold>7</pickQuantityThreshold> <idealLowTemperature> <amount>1000.0000000</amount> <uom>C</uom> </idealLowTemperature> <idealHighTemperature> <amount>1000.0000000</amount> <uom>C</uom> </idealHighTemperature> <acceptableLowTemperature> <amount>1000.0000000</amount> <uom>C</uom> </acceptableLowTemperature> <acceptableHighTemperature> <amount>1000.0000000</amount> <uom>C</uom> </acceptableHighTemperature> <isAgeRestrictedToReceive>true</isAgeRestrictedToReceive> <hasEASTag>true</hasEASTag> <isGiveaway>true</isGiveaway> <isBeverage>false</isBeverage> <isWicEligible>true</isWicEligible> <isSNAPEligible>false</isSNAPEligible> <isLayawayEligible>true</isLayawayEligible> <isFoodStampEligible>true</isFoodStampEligible> <tareWeight> <amount>1000.0000000</amount> <uom>OZ</uom> </tareWeight> <tarePercent>1000.00</tarePercent> <isSoldByWeight>false</isSoldByWeight> <isElectronicRegistration>false</isElectronicRegistration> <serialNumberMask>string</serialNumberMask> <serialCheckDigitMask>st</serialCheckDigitMask> <isWarrantyAvailable>false</isWarrantyAvailable> <hasExtendedBarcode>false</hasExtendedBarcode> </additionalProperties> </preferredSubProduct> </fulfillOptions> <coupon> <id>QWE345</id> <name>NAME FOR COUPON</name> <description>DESCRIPTION FOR COUPON</description> <amount>8.0000000</amount> <type>THIS IS A TYPE</type> </coupon> <fee> <id>LXCURY210</id> <amount>1000.0000000</amount> <tax> <amount>1000.0000000</amount> <type>string</type> <discount> <amount>1000.0000000</amount> <type>TYPE FOR DISCOUNT</type> <description>THIS IS A DESCRIPTION</description> <percent>1000.0000000</percent> </discount> <taxAdjustment>1000.0000000</taxAdjustment> <taxRate>1000.0000000</taxRate> </tax> <type>THIS IS A TYPE</type> <feeRate>0.1500000</feeRate> </fee> </promisedOrderLine> </messageBody> </fulfillCustomerOrderRequest>
    at java.base/java.net.URL.<init>(URL.java:645)
    at java.base/java.net.URL.<init>(URL.java:541)
    at java.base/java.net.URL.<init>(URL.java:488)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:649)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:150)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:860)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:824)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1216)
    at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:635)
    at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:324)
    at scala.xml.factory.XMLLoader.loadXML(XMLLoader.scala:41)
    at scala.xml.factory.XMLLoader.loadXML$(XMLLoader.scala:37)
    at scala.xml.XML$.loadXML(XML.scala:58)
    at scala.xml.factory.XMLLoader.load(XMLLoader.scala:55)
    at scala.xml.factory.XMLLoader.load$(XMLLoader.scala:55)
    at scala.xml.XML$.load(XML.scala:58)
    at com.scoperetail.op.Main$.delayedEndpoint$com$scoperetail$op$Main$1(Main.scala:14)
    at com.scoperetail.op.Main$delayedInit$body.apply(Main.scala:10)
    at scala.Function0.apply$mcV$sp(Function0.scala:39)
    at scala.Function0.apply$mcV$sp$(Function0.scala:39)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
    at scala.App.$anonfun$main$1(App.scala:73)
    at scala.App.$anonfun$main$1$adapted(App.scala:73)
    at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:553)
    at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:551)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:920)
    at scala.App.main(App.scala:73)
    at scala.App.main$(App.scala:71)
    at com.scoperetail.op.Main$.main(Main.scala:10)
    at com.scoperetail.op.Main.main(Main.scala)

Can someone please help me

tmccombs commented 4 years ago

From the stack trace, it looks like error is happening while parsing the xml, which would happen before xtract starts processing it. That said, it there may be a problem with an xml entity not having a valid url. It's hard to know what the problem is for sure without seeing the xml it is trying to process.

juanmcarballo commented 4 years ago

I was investigation the issue and there was a problem with the way I'm invoking the parser, here is my code:

val xml = XML.load("<path to file>")
val customerOrder = XmlReader.of[CustomerOrder].read(xml)
println(customerOrder)