100 likes | 178 Views
Single SOAP Update Operation. CS526 George E. Turner Spring 2009. George Turner CS526. Current Implementation Four standard methods used to manipulate complex types in SOAP Create Read Update Delete. George Turner CS526. The Update method is extremely inefficient
E N D
Single SOAP Update Operation CS526 George E. Turner Spring 2009
George Turner CS526 Current Implementation • Four standard methods used to manipulate complex types in SOAP • Create • Read • Update • Delete
George Turner CS526 • The Update method is extremely inefficient • Comparison to current data to determine “What’s changed?” • Bandwidth is abused when only updating a single field “Why send data that isn’t different?” • Requires a separate method for every field “Additional code to support each new method”
George Turner CS526 Proposal • Create a single update method to update ANY field or child object <xs:complexType> <xs:sequence> <xs:element name="className" type="xs:QName"/> <xs:element name="xpathValue" type="xs:string"/> <xs:any/> </xs:sequence> </xs:complexType>
George Turner CS526 • The QNameclassname value defines what is being updated • Fully qualified description of the top level object • Example: shop:ShoppingCart (namespace:localPart) • The String xpathValue defines the keys to distinguish the part to update • key=value[<,key=value>…][ / attribute:key=value[<,attribute:key=value>…]] • Example: id=12345/Item:id=3
George Turner CS526 • The any is the new value, ANY valid XML • Example: <shop:MeatItem>Pork</shop:MeatItem> • Full SOAP Example <soapenv:Envelopexmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:UpdateService:Operations" xmlns:shop="urn:UpdateService:Shopping"> <soapenv:Header/> <soapenv:Body> <urn:update> <urn:className>shop:ShoppingCart</urn:className> <urn:xpathValue>id=12345/Item:id=3</urn:xpathValue> <shop:MeatItem>Pork</shop:MeatItem> </urn:update> </soapenv:Body> </soapenv:Envelope>
George Turner CS526 • This solution uses a combination of • Java Persistence API (JPA) • Java Reflection • Modifications to generated JAXB classes @XmlRegistry public class ObjectFactory { private final static QName _ShoppingCart_QNAME = new QName("urn:UpdateService:Shopping", "ShoppingCart"); private final static QName _OrderItem_QNAME = new QName("urn:UpdateService:Shopping", "OrderItem");
George Turner CS526 New Code private static final Map<QName, Class> QNAME_CLASS_MAP; static { Map<QName, Class> tmp = new HashMap<QName, Class>(2); tmp.put(_ShoppingCart_QNAME, ShoppingCartType.class); tmp.put(_OrderItem_QNAME, OrderItemType.class); QNAME_CLASS_MAP = Collections.unmodifiableMap(tmp); } public Class getClass(QNameqname) { return QNAME_CLASS_MAP.get(qname); }
George Turner CS526 Conclusion • This prototype is not the final solution • A Document Object Model solution may be easier • Changes to the generated JAXB classes are required • Submission to W3C for acceptance and inclusion into milestone releases and specification
George Turner CS526 References: • JAXB – Reference Implementation – http://jaxb.dev.java.net • JAXWS – Reference Implementation – http://jaxws.dev.java.net • METRO – Reference Implementation – http://metro.dev.java.net • JPA - Persistence API - http://java.sun.com/javaee/technologies/persistence.jsp