Forum Discussion

UPS_Support's avatar
UPS_Support
Occasional Contributor
13 years ago

Decode image returned in the response

I'm working with a response that returns two base64 encoded images. I would like to add a groovy script that will decode images and save them to my hard drive.

----------------------------------------------------------------------------------------------------------------------------------------
<ShipmentAcceptResponse>
<Response>
<TransactionReference>
<CustomerContext>Success; Includes new CompanyDisplayableName</CustomerContext>
</TransactionReference>
<ResponseStatusCode>1</ResponseStatusCode>
<ResponseStatusDescription>Success</ResponseStatusDescription>
</Response>
<ShipmentResults>
<ShipmentCharges>
<TransportationCharges>
<CurrencyCode>USD</CurrencyCode>
<MonetaryValue>12.63</MonetaryValue>
</TransportationCharges>
<ServiceOptionsCharges>
<CurrencyCode>USD</CurrencyCode>
<MonetaryValue>0.00</MonetaryValue>
</ServiceOptionsCharges>
<TotalCharges>
<CurrencyCode>USD</CurrencyCode>
<MonetaryValue>12.63</MonetaryValue>
</TotalCharges>
</ShipmentCharges>
<BillingWeight>
<UnitOfMeasurement>
<Code>LBS</Code>
<Description>Pounds</Description>
</UnitOfMeasurement>
<Weight>15.0</Weight>
</BillingWeight>
<ShipmentIdentificationNumber>1Z3906WW0394214460</ShipmentIdentificationNumber>
<PackageResults>
<TrackingNumber>1Z3906WW0394214460</TrackingNumber>
<ServiceOptionsCharges>
<CurrencyCode>USD</CurrencyCode>
<MonetaryValue>0.00</MonetaryValue>
</ServiceOptionsCharges>
<LabelImage>
<LabelImageFormat>
<Code>GIF</Code>
</LabelImageFormat>
<GraphicImage>R0lGODdheAUgA+cAAAAAAAEBAQ…</GraphicImage>
<HTMLImage>PCFET0NUWVBFIEhUTUwg…</HTMLImage>
</LabelImage>
</PackageResults>
</ShipmentResults>
</ShipmentAcceptResponse>

3 Replies

  • UPS_Support's avatar
    UPS_Support
    Occasional Contributor
    That was helpful. After chaning the part is red, it worked.
    Thank you!

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    import groovy.swing.SwingBuilder
    import javax.swing.ImageIcon
    import groovy.swing.SwingBuilder
    import org.apache.commons.codec.binary.Base64

    teststep=context.testCase.getTestStepAt(context.getCurrentStepIndex()).getLabel()
    Image='$'+"{#Response#//ship:ShipmentResults/ship:PackageResults/ship:ShippingLabel/ship:GraphicImage}"Label=context.expand(Image)
    b64 = new Base64()
    swing = new groovy.swing.SwingBuilder()
    i1 = swing.label(icon:new ImageIcon(b64.decode(Label.getBytes())))

    frame = swing.frame(title:"Ship Label", defaultCloseOperation:javax.swing.WindowConstants.DISPOSE_ON_CLOSE) {
    panel(){
    widget(i1)
    }
    }
    frame.pack()
    frame.show()
  • Great to hear. Thanks for confirming that your issues were resolved!

    Regards,

    Arian
    SmartBear Sweden