Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

evil fix for frozen objects problem

  • Loading branch information...
commit 7baa768904dfd0571de5de1cf6b0ef0951a9be08 1 parent c7f7ae7
mpclocal authored
65 lib/soap4r2ruby_helpers.rb
View
@@ -4,7 +4,40 @@
# this class is used to fetch the wsdl2ruby generated info
# examples of info this class returns are LiteralRegistry, EncodedRegistry, Method names schema info etc.
-class Object; attr_accessor :minoccurs, :maxoccurs; end
+
+require 'dl/struct'
+
+module Internal
+ extend DL::Importable
+
+ typealias "VALUE", nil, nil, nil, "unsigned long"
+ typealias "ID", nil, nil, nil, "unsigned long"
+
+ Basic = ["long flags", "VALUE klass"]
+
+ RBasic = struct Basic
+
+ RObject = struct(Basic + ["st_table *iv_tbl"])
+
+ FL_FREEZE = 1 << 10
+end
+
+
+class Object
+ attr_accessor :minoccurs, :maxoccurs;
+
+ def immediate?
+ [Fixnum, Symbol, NilClass, TrueClass, FalseClass].any?{|klass| klass === self}
+ end
+
+ def unfreeze
+ return self if immediate?
+
+ Internal::RObject.new(DL::PtrData.new(self.object_id * 2)).flags &= ~ Internal::FL_FREEZE
+ self
+ end
+end
+
class String
def to_array
@@ -180,26 +213,24 @@ def self.create_initializer(array)
result += '@'+array.last[1]+'='+array.last[1]+';end;'
end
- def self.mergeDefaultInstanceWithUnMarshalledValues(default_instance, unmarshalled_instance)
- if (unmarshalled_instance == nil && default_instance != nil)
- unmarshalled_instance = default_instance
- end
- unmarshalled_instance.minoccurs = default_instance.minoccurs
- unmarshalled_instance.maxoccurs = default_instance.maxoccurs
+ def self.mergeDefaultInstanceWithUnMarshalledValues(default_instance, unmarshalled_instance)
+ #handle Array
if(unmarshalled_instance.class == Array && default_instance.class == Array)
unmarshalled_instance.each do |e|
e = mergeDefaultInstanceWithUnMarshalledValues(default_instance.first, e)
end
end
- if(unmarshalled_instance.class == String && default_instance.class.ancestors[2] == Enumerable)
- puts "const getting #{unmarshalled_instance} at top level"
+
+ #handle Enum
+ if(unmarshalled_instance.class == String && default_instance.class.ancestors[2] == Enumerable && default_instance.class.ancestors[1] == String)
if unmarshalled_instance == "" or unmarshalled_instance == nil
unmarshalled_instance = (default_instance.class.constants - ['Enumerator'])[0]
else
unmarshalled_instance = default_instance.class.const_get(unmarshalled_instance)
end
end
-
+
+ #handle Complex Type
(default_instance.instance_variables- ["@minoccurs", "@maxoccurs"]).each do |i|
sub_unmarshalled = unmarshalled_instance.instance_variable_get(i)
sub_default = default_instance.instance_variable_get(i)
@@ -214,7 +245,7 @@ def self.mergeDefaultInstanceWithUnMarshalledValues(default_instance, unmarshall
end
end
- if(sub_unmarshalled.class == String && sub_default.class.ancestors[2] == Enumerable)
+ if(sub_unmarshalled.class == String && sub_default.class.ancestors[2] == Enumerable && default_instance.class.ancestors[1] == String)
if sub_unmarshalled == "" or sub_unmarshalled == nil
sub_unmarshalled = (sub_default.class.constants - ['Enumerator'])[0]
else
@@ -226,6 +257,18 @@ def self.mergeDefaultInstanceWithUnMarshalledValues(default_instance, unmarshall
end
unmarshalled_instance.instance_variable_set(i, sub_unmarshalled)
end
+
+ #handle nil unmarshalled vs anything default
+ if (unmarshalled_instance == nil && default_instance != nil)
+ unmarshalled_instance = default_instance
+ end
+
+ #handle simpleType
+ if unmarshalled_instance.frozen?
+ unmarshalled_instance.unfreeze
+ end
+ unmarshalled_instance.minoccurs = default_instance.minoccurs
+ unmarshalled_instance.maxoccurs = default_instance.maxoccurs
unmarshalled_instance
end
end
298 test/fixtures/sample_wsdls/discountService-V1-0.2009.09.03.wsdl
View
@@ -0,0 +1,298 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<wsdl:definitions targetNamespace="http://services.gid.gap.com/discountService/v1"
+ xmlns:faults="http://services.gid.gap.com/discountService/v1/faults"
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:tns="http://services.gid.gap.com/discountService/v1"
+ xmlns:types="http://schemas.gid.gap.com/discountService/v1"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:java="http://schemas.xmlsoap.org/wsdl/java/">
+ <wsdl:types>
+
+ <xs:schema targetNamespace="http://schemas.gid.gap.com/discountService/v1"
+ xmlns:alive="http://schemas.gid.gap.com/servicealive/v1"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+ <xs:import namespace="http://schemas.gid.gap.com/servicealive/v1"
+ schemaLocation="ServiceAlive-v1.0.xsd"/>
+
+ <xs:complexType name="DiscountServiceRequestType">
+ <xs:sequence>
+ <xs:element minOccurs="0" nillable="true" name="RequestDateTime" type="xs:string"/>
+ <xs:element name="StoreID" nillable="true" type="xs:string" minOccurs="0" />
+ <xs:element name="RequestType" nillable="true" type="xs:string" minOccurs="0" />
+ <xs:element minOccurs="1" name="orderRequest" nillable="true" type="types:OrderType"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="DiscountServiceResponseType">
+ <xs:sequence>
+ <xs:element minOccurs="1" name="orderResponse" nillable="true" type="types:OrderType"/>
+ </xs:sequence>
+ </xs:complexType>
+
+
+ <xs:complexType name="OrderType">
+ <xs:sequence>
+ <xs:element name="OrderID" type="xs:string" minOccurs="0" nillable="true" />
+ <xs:element minOccurs="0" name="QualifyType" nillable="false" type="types:QualifyTypeEnum"/>
+ <xs:element name="OrderDate" type="xs:string" minOccurs="0" nillable="true" />
+ <xs:element name="Channel" type="xs:string" minOccurs="0" nillable="true" />
+ <xs:element name="Brand" type="xs:string" minOccurs="0" nillable="true" />
+ <xs:element name="Market" type="xs:string" minOccurs="0" nillable="true" />
+ <xs:element name="OrderLineItems" type="types:OrderLineType" minOccurs="0" nillable="true" maxOccurs="unbounded"/>
+ <xs:element name="Promotions" type="types:PromotionType" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
+ <xs:element name="Tenders" minOccurs="0" nillable="true" type="types:TenderInfoType" maxOccurs="unbounded"/>
+ <xs:element name="MaxDiscountsAllowed" type="xs:int" minOccurs="0" nillable="false" />
+ <xs:element name="SellingOrganization" type="xs:string" minOccurs="0" nillable="true" />
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="TenderInfoType">
+ <xs:sequence>
+ <xs:element minOccurs="0" name="TenderType" type="xs:string"/>
+ <xs:element minOccurs="0" name="CreditCardHash" type="xs:string"/>
+ <xs:element minOccurs="0" name="CreditCardType" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="PromotionType">
+ <xs:sequence>
+ <!-- input -->
+ <xs:element name="SequenceNumber" type="xs:int"/>
+ <xs:element name="PromotionCode" type="xs:string"/>
+ <xs:element minOccurs="0" name="MembershipToken" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="MemberId" nillable="true" type="xs:string"/>
+ <!-- output -->
+ <xs:element minOccurs="0" name="PromotionID" type="xs:string"/>
+ <xs:element minOccurs="0" name="DiscountReasonCode" type="xs:string"/>
+ <xs:element minOccurs="0" name="AppliedStatus" nillable="false" type="types:AppliedStatusEnum"/>
+ <xs:element minOccurs="0" name="ReceiptMessages" nillable="true" type="types:ReceiptMessageType" maxOccurs="unbounded"/>
+ <xs:element minOccurs="0" name="PromoUsages" nillable="true" type="types:PromoUsageType" maxOccurs="unbounded"/>
+ <xs:element minOccurs="0" name="QualifyingTenders" nillable="true" type="xs:string" maxOccurs="unbounded"/>
+ <xs:element minOccurs="0" name="PromotionType" nillable="false" type="types:PromotionTypeEnum"/>
+ <xs:element minOccurs="0" name="HasExclusions" type="xs:boolean"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:simpleType name="PromotionTypeEnum">
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="TRANSACTION" />
+ <xs:enumeration value="LINE_ITEM" />
+ </xs:restriction>
+ </xs:simpleType>
+
+ <xs:complexType name="PromoUsageType">
+ <xs:sequence>
+ <xs:element minOccurs="0" name="StoreId" type="xs:string"/>
+ <xs:element minOccurs="0" name="TransactionId" type="xs:string"/>
+ <xs:element minOccurs="0" name="UsageDateTime" type="xs:string"/>
+ <xs:element minOccurs="0" name="Brand" type="xs:string"/>
+ <xs:element minOccurs="0" name="Channel" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="ReceiptMessageType">
+ <xs:sequence>
+ <xs:element minOccurs="0" name="message" type="xs:string"/>
+ <xs:element minOccurs="0" name="locale" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:simpleType name="QualifyTypeEnum">
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="QUALIFY_WITHOUT_TENDER" />
+ <xs:enumeration value="QUALIFY_WITH_TENDER" />
+ </xs:restriction>
+ </xs:simpleType>
+ <xs:simpleType name="AppliedStatusEnum">
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="CODE_APPLIED" />
+ <xs:enumeration value="CODE_APPLIED_QUALIFY_WITHOUT_TENDER" />
+ <xs:enumeration value="CODE_INVALID_CHANNEL" />
+ <xs:enumeration value="CODE_NOT_EXIST" />
+ <xs:enumeration value="CODE_NOT_ACTIVE" />
+ <xs:enumeration value="CODE_EXPIRED" />
+ <xs:enumeration value="CODE_INVALID_STORE_MARKET" />
+ <xs:enumeration value="CODE_INVALID_BRAND" />
+ <xs:enumeration value="CODE_USAGE_LIMIT_EXCEEDED" />
+ <xs:enumeration value="CODE_INVALID_MEMBERSHIP" />
+ <xs:enumeration value="INVALID_PRICE_TYPE" />
+ <xs:enumeration value="MERCHANDISE_NOT_MET" />
+ <xs:enumeration value="THRESHOLD_NOT_MET" />
+ <xs:enumeration value="CARD_INVALID_TYPE" />
+ <xs:enumeration value="CARD_INVALID_TIER" />
+ <xs:enumeration value="EXCEEDS_DISCOUNTS_ALLOWED" />
+ <xs:enumeration value="INVALID_MERCHANDISE_TYPE" />
+ </xs:restriction>
+ </xs:simpleType>
+
+ <xs:complexType name="OrderLineType">
+ <xs:sequence>
+ <!-- input -->
+ <xs:element name="SequenceNumber" type="xs:int"/>
+ <xs:element name="Product" type="types:ProductInfoType"/>
+ <xs:element name="Price" type="types:PriceInfoType"/>
+ <xs:element name="Quantity" type="xs:int"/>
+ <!-- output -->
+ <xs:element name="Awards" type="types:AwardType" nillable="false" minOccurs="0" maxOccurs="unbounded"/>
+ <xs:element name="IsLineItemExcluded" minOccurs="0" type="xs:boolean"/>
+ <xs:element name="NumberOfManualDiscountsApplied" minOccurs="0" type="xs:int"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="AwardType">
+ <xs:sequence>
+ <xs:element name="AwardID" type="xs:string" nillable="true" minOccurs="0"/>
+ <xs:element name="PromotionCode" type="xs:string" nillable="true" minOccurs="0"/>
+ <xs:element name="DiscountedAmount" type="xs:decimal" nillable="true" minOccurs="0"/>
+ <xs:element name="AwardMethod" type="types:AwardTypeEnum" nillable="false" minOccurs="0"/>
+ <xs:element name="AwardAmount" type="xs:decimal" nillable="true" minOccurs="0"/>
+ </xs:sequence>
+ </xs:complexType>
+
+
+ <xs:simpleType name="AwardTypeEnum">
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="PERCENT_OFF" />
+ <xs:enumeration value="DOLLAR_OFF" />
+ <xs:enumeration value="FIXED_PRICE" />
+ </xs:restriction>
+ </xs:simpleType>
+
+ <xs:complexType name="ProductInfoType">
+ <xs:sequence>
+ <xs:element name="Brand" type="xs:string" minOccurs="0" />
+ <xs:element minOccurs="0" name="MerchandiseType" nillable="false" type="xs:string"/>
+ <xs:element name="StyleColor" type="xs:string" minOccurs="0" />
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="PriceInfoType">
+ <xs:sequence>
+ <!-- input -->
+ <xs:element minOccurs="0" name="CurrentPrice" type="xs:decimal"/>
+ <xs:element minOccurs="0" name="NetPrice" type="xs:decimal"/>
+ <xs:element minOccurs="0" name="PriceType" nillable="false" type="types:PriceTypeEnum"/>
+ <xs:element minOccurs="0" name="IsPromotional" nillable="true" type="xs:boolean"/>
+ <!-- output -->
+ <xs:element minOccurs="0" name="DiscountPrice" type="xs:decimal" nillable="false" />
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:simpleType name="PriceTypeEnum">
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="REGULAR" />
+ <xs:enumeration value="MARKDOWN" />
+ <xs:enumeration value="OVERRIDE" />
+ </xs:restriction>
+ </xs:simpleType>
+
+ <xs:element name="DiscountServiceRequest" type="types:DiscountServiceRequestType" />
+ <xs:element name="DiscountServiceResponse" type="types:DiscountServiceResponseType" />
+
+ <xs:element name="ServiceAliveRequest" type="alive:ServiceAliveRequestType" />
+ <xs:element name="ServiceAliveResponse" type="alive:ServiceAliveResponseType" />
+ <xs:element name="ServiceUnavailableFaultMessage" type="alive:ServiceUnavailableFaultMessageType" />
+
+ </xs:schema>
+
+ <xs:schema targetNamespace="http://services.gid.gap.com/discountService/v1/faults">
+ <xs:element name="DiscountServiceFaultMessage" nillable="true" type="xs:string" />
+ </xs:schema>
+
+ </wsdl:types>
+
+ <wsdl:message name="DiscountServiceRequest">
+ <wsdl:part name="input" element="types:DiscountServiceRequest" />
+ </wsdl:message>
+
+ <wsdl:message name="DiscountServiceResponse">
+ <wsdl:part name="output" element="types:DiscountServiceResponse" />
+ </wsdl:message>
+
+ <wsdl:message name="DiscountServiceFault">
+ <wsdl:part name="message" element="faults:DiscountServiceFaultMessage" />
+ </wsdl:message>
+
+ <wsdl:message name="ServiceAliveRequest">
+ <wsdl:part name="input" element="types:ServiceAliveRequest" />
+ </wsdl:message>
+
+ <wsdl:message name="ServiceAliveResponse">
+ <wsdl:part name="output" element="types:ServiceAliveResponse" />
+ </wsdl:message>
+
+ <wsdl:message name="ServiceUnavailableFault">
+ <wsdl:part name="message" element="types:ServiceUnavailableFaultMessage" />
+ </wsdl:message>
+
+ <wsdl:portType name="DiscountServicePortType">
+
+ <wsdl:operation name="serviceAlive">
+ <wsdl:input name="ServiceAliveRequest" message="tns:ServiceAliveRequest" />
+ <wsdl:output name="ServiceAliveResponse" message="tns:ServiceAliveResponse" />
+ </wsdl:operation>
+
+ <wsdl:operation name="applyDiscount">
+ <wsdl:input name="DiscountServiceRequest" message="tns:DiscountServiceRequest" />
+ <wsdl:output name="DiscountServiceResponse" message="tns:DiscountServiceResponse" />
+ <wsdl:fault name="DiscountServiceFault" message="tns:DiscountServiceFault" />
+ </wsdl:operation>
+
+ </wsdl:portType>
+
+
+ <wsdl:binding name="DiscountServiceSoapBinding" type="tns:DiscountServicePortType">
+
+ <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
+
+ <wsdl:operation name="serviceAlive">
+
+ <soap:operation soapAction="serviceAlive" style="document"/>
+
+ <wsdl:input name="ServiceAliveRequest">
+ <soap:body use="literal"/>
+ </wsdl:input>
+
+ <wsdl:output name="ServiceAliveResponse">
+ <soap:body use="literal"/>
+ </wsdl:output>
+
+ </wsdl:operation>
+
+ <wsdl:operation name="applyDiscount">
+
+ <soap:operation soapAction="applyDiscount" style="document"/>
+
+ <wsdl:input name="DiscountServiceRequest">
+ <soap:body use="literal" />
+ </wsdl:input>
+
+ <wsdl:output name="DiscountServiceResponse">
+ <soap:body use="literal" />
+ </wsdl:output>
+
+ <wsdl:fault name="DiscountServiceFault">
+ <soap:fault name="DiscountServiceFault" use="literal" />
+ </wsdl:fault>
+
+ </wsdl:operation>
+
+ </wsdl:binding>
+
+
+ <wsdl:service name="DiscountService">
+
+ <wsdl:port name="DiscountServicePort"
+ binding="tns:DiscountServiceSoapBinding">
+ <soap:address location="https://ws-mpc-store.vdev.gid.gap.com/DiscountServiceProvider-V1-0/services/DiscountService"/>
+ </wsdl:port>
+ <wsdl:port name="DiscountServicejavaPort" binding="tns:DiscountServiceSoapBinding" >
+ <java:address className="com.gap.gid.services.discountservice.v1.adapter.DiscountServiceJavaClient" />
+ </wsdl:port>
+
+ </wsdl:service>
+
+</wsdl:definitions>
+
34 test/fixtures/sample_xmls/my_default_discount_2009.09.03.xml
View
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
+ <env:Body>
+ <DiscountServiceRequest>
+ <orderRequest>
+ <QualifyType>QUALIFY_WITH_TENDER</QualifyType>
+ <Brand>Gap</Brand>
+ <OrderLineItems>
+ <SequenceNumber></SequenceNumber>
+ <Product></Product>
+ <Price>
+ <PriceType>OVERRIDE</PriceType>
+ </Price>
+ <Quantity></Quantity>
+ <Awards>
+ <AwardMethod>PERCENT_OFF</AwardMethod>
+ </Awards>
+ </OrderLineItems>
+ <Promotions>
+ <SequenceNumber></SequenceNumber>
+ <PromotionCode></PromotionCode>
+ <AppliedStatus>CODE_NOT_EXIST</AppliedStatus>
+ <ReceiptMessages></ReceiptMessages>
+ <PromoUsages></PromoUsages>
+ <QualifyingTenders></QualifyingTenders>
+ <PromotionType>TRANSACTION</PromotionType>
+ </Promotions>
+ <Tenders></Tenders>
+ </orderRequest>
+ </DiscountServiceRequest>
+ </env:Body>
+</env:Envelope>
Please sign in to comment.
Something went wrong with that request. Please try again.