dreamhead / moco

Easy Setup Stub Server
MIT License
4.37k stars 1.08k forks source link

throw exception when extract response body by xpath #205

Open alex0119 opened 7 years ago

alex0119 commented 7 years ago

XML request body:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:Envelope xmlns="http://api.channeladvisor.com/webservices/" xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns3="http://api.channeladvisor.com/datacontracts/orders">
    <ns2:Header>
        <APICredentials/>
    </ns2:Header>
    <ns2:Body>
        <SubmitOrder>
            <accountID>09766818-7b8b-4d2c-ada6-3538740470a0</accountID>
            <order>
                <ns3:OrderTimeGMT>2017-07-11T07:40:00.000Z</ns3:OrderTimeGMT>
                <ns3:ClientOrderIdentifier>596480d04e397b7f83073c60</ns3:ClientOrderIdentifier>
                <ns3:EmailOptIn>false</ns3:EmailOptIn>
                <ns3:BillingInfo>
                    <ns3:AddressLine1>16010 Bloomfield Ave.</ns3:AddressLine1>
                    <ns3:AddressLine2>596480d04e397b7f83073c60</ns3:AddressLine2>
                    <ns3:City>Cerritos</ns3:City>
                    <ns3:Region>CA</ns3:Region>
                    <ns3:RegionDescription/>
                    <ns3:PostalCode>90703</ns3:PostalCode>
                    <ns3:CountryCode>US</ns3:CountryCode>
                    <ns3:CompanyName/>
                    <ns3:FirstName>VoyageOne Receiving Dept</ns3:FirstName>
                    <ns3:LastName>ATTN: LuckyVitamin</ns3:LastName>
                    <ns3:PhoneNumberDay>1-562-977-6408</ns3:PhoneNumberDay>
                    <ns3:PhoneNumberEvening>1-562-977-6408</ns3:PhoneNumberEvening>
                </ns3:BillingInfo>
                <ns3:ShoppingCart>
                    <ns3:CartID>0</ns3:CartID>
                    <ns3:CheckoutSource>Unspecified</ns3:CheckoutSource>
                    <ns3:LineItemSKUList>
                        <ns3:OrderLineItemItem>
                            <ns3:UnitPrice>27.41</ns3:UnitPrice>
                            <ns3:LineItemID>1</ns3:LineItemID>
                            <ns3:AllowNegativeQuantity>true</ns3:AllowNegativeQuantity>
                            <ns3:Quantity>2</ns3:Quantity>
                            <ns3:ItemSaleSource>DIRECT_SALE</ns3:ItemSaleSource>
                            <ns3:SKU>salley-sku224</ns3:SKU>
                            <ns3:BuyerFeedbackRating>0</ns3:BuyerFeedbackRating>
                            <ns3:TaxCost>0</ns3:TaxCost>
                            <ns3:ShippingCost>0</ns3:ShippingCost>
                            <ns3:ShippingTaxCost>0</ns3:ShippingTaxCost>
                            <ns3:GiftWrapCost>0</ns3:GiftWrapCost>
                            <ns3:GiftWrapTaxCost>0</ns3:GiftWrapTaxCost>
                            <ns3:RecyclingFee>0</ns3:RecyclingFee>
                        </ns3:OrderLineItemItem>
                    </ns3:LineItemSKUList>
                    <ns3:LineItemInvoiceList>
                        <ns3:OrderLineItemInvoice>
                            <ns3:LineItemType>Shipping</ns3:LineItemType>
                            <ns3:UnitPrice>0.00</ns3:UnitPrice>
                        </ns3:OrderLineItemInvoice>
                    </ns3:LineItemInvoiceList>
                    <ns3:LineItemPromoList>
                        <ns3:OrderLineItemPromo>
                            <ns3:LineItemType>AdditionalCostOrDiscount</ns3:LineItemType>
                            <ns3:UnitPrice>0</ns3:UnitPrice>
                        </ns3:OrderLineItemPromo>
                    </ns3:LineItemPromoList>
                </ns3:ShoppingCart>
                <ns3:ShippingInfo>
                    <ns3:AddressLine1>16010 Bloomfield Ave.</ns3:AddressLine1>
                    <ns3:AddressLine2>596480d04e397b7f83073c60</ns3:AddressLine2>
                    <ns3:City>Cerritos</ns3:City>
                    <ns3:Region>CA</ns3:Region>
                    <ns3:RegionDescription/>
                    <ns3:PostalCode>90703</ns3:PostalCode>
                    <ns3:CountryCode>US</ns3:CountryCode>
                    <ns3:CompanyName/>
                    <ns3:FirstName>VoyageOne Receiving Dept</ns3:FirstName>
                    <ns3:LastName>ATTN: LuckyVitamin</ns3:LastName>
                    <ns3:PhoneNumberDay>1-562-977-6408</ns3:PhoneNumberDay>
                    <ns3:PhoneNumberEvening>1-562-977-6408</ns3:PhoneNumberEvening>
                    <ns3:ShipmentList>
                        <ns3:Shipment>
                            <ns3:ShippingCarrier>Standard</ns3:ShippingCarrier>
                            <ns3:ShippingClass>Shipping</ns3:ShippingClass>
                        </ns3:Shipment>
                    </ns3:ShipmentList>
                    <ns3:ShippingInstructions>596480d04e397b7f83073c60</ns3:ShippingInstructions>
                    <ns3:EstimatedShipDate xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                    <ns3:DeliveryDate xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                </ns3:ShippingInfo>
            </order>
        </SubmitOrder>
    </ns2:Body>
</ns2:Envelope>

the config response section is:

"response":{
        "status" : 200,
        "text": {
            "template": {
                "with" : "${foo[0]}",
                "vars" : {
                    "foo" : {"xpath": "/ns2:Envelope/ns2:Body/SubmitOrder/order/ns3:ClientOrderIdentifier"}
                }
            }
        }
    }

I got following exception:

java.lang.NullPointerException: null value in entry: foo=null
        at com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:34)
        at com.google.common.collect.SingletonImmutableBiMap.<init>(SingletonImmutableBiMap.java:40)
        at com.google.common.collect.ImmutableBiMap.of(ImmutableBiMap.java:49)
        at com.google.common.collect.ImmutableMap.of(ImmutableMap.java:70)
        at com.google.common.collect.ImmutableMap.copyOf(ImmutableMap.java:353)
        at com.google.common.collect.ImmutableMap.copyOf(ImmutableMap.java:332)
        at com.github.dreamhead.moco.resource.reader.TemplateResourceReader.toVariableString(TemplateResourceReader.java:108)
        at com.github.dreamhead.moco.resource.reader.TemplateResourceReader.variables(TemplateResourceReader.java:98)
        at com.github.dreamhead.moco.resource.reader.TemplateResourceReader.readFor(TemplateResourceReader.java:64)
        at com.github.dreamhead.moco.resource.Resource.readFor(Resource.java:34)
        at com.github.dreamhead.moco.handler.ContentHandler.responseContent(ContentHandler.java:23)
        at com.github.dreamhead.moco.handler.AbstractContentResponseHandler.requireResponseContent(AbstractContentResponseHandler.java:46)
        at com.github.dreamhead.moco.handler.AbstractContentResponseHandler.doWriteToResponse(AbstractContentResponseHandler.java:36)
        at com.github.dreamhead.moco.handler.AbstractContentResponseHandler.writeToResponse(AbstractContentResponseHandler.java:27)
        at com.github.dreamhead.moco.handler.AndResponseHandler.writeToResponse(AndResponseHandler.java:21)
        at com.github.dreamhead.moco.setting.BaseSetting.writeToResponse(BaseSetting.java:35)
        at com.github.dreamhead.moco.internal.MocoHandler.doGetHttpResponse(MocoHandler.java:77)
        at com.github.dreamhead.moco.internal.MocoHandler.getHttpResponse(MocoHandler.java:61)
        at com.github.dreamhead.moco.internal.MocoHandler.handleRequest(MocoHandler.java:51)
        at com.github.dreamhead.moco.internal.MocoHandler.channelRead0(MocoHandler.java:40)
        at com.github.dreamhead.moco.internal.MocoHandler.channelRead0(MocoHandler.java:25)
        at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
        at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438)
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:284)
        at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:134)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458)
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
        at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)
        at java.lang.Thread.run(Unknown Source)