Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. DEV381 .NET and J2EE: Strategies for Interoperability When you just know you're gonna need it
  2. 2. Credentials <ul><li>Who is this guy? </li></ul><ul><ul><li>Independent consultant (Sacramento, California) </li></ul></ul><ul><ul><li>Editor-in-Chief, TheServerSide.NET ( </li></ul></ul><ul><ul><li>Author </li></ul></ul><ul><ul><ul><li>Server-Based Java Programming (Manning, 2000) </li></ul></ul></ul><ul><ul><ul><li>Effective Enterprise Java (Addison-Wesley, 2Q 2004) </li></ul></ul></ul><ul><ul><ul><li>C# in a Nutshell (with Drayton, Albahari; OReilly, 2001) </li></ul></ul></ul><ul><ul><ul><li>SSCLI Essentials (with Stutz, Shilling; OReilly, 2003) </li></ul></ul></ul><ul><ul><li>Microsoft Valued Professional (MVP) </li></ul></ul><ul><ul><li>BEA Technical Director </li></ul></ul><ul><ul><li>Member, JSR 175 Expert Group </li></ul></ul><ul><ul><li>Instructor, Course Author, DevelopMentor (.NET & Java) </li></ul></ul><ul><ul><ul><li>&quot;.NET and J2EE Interoperability&quot; </li></ul></ul></ul><ul><ul><li>Website at </li></ul></ul>
  3. 3. Why interoperability? <ul><li>A (purely fictitious) story: </li></ul><ul><ul><li>Our hero: you </li></ul></ul><ul><ul><li>Our villian: your boss </li></ul></ul><ul><ul><li>The setting: an otherwise uneventful staff meeting </li></ul></ul><ul><ul><li>The hook: &quot;Oh, by the way, we need to meet with the HR department; we've been tasked with building some code to integrate our purchasing system with their employee system to streamline expense reports.&quot; </li></ul></ul><ul><ul><li>The plot twist: Their system is J2EE-based, yours .NET (or vice versa, take your pick) </li></ul></ul><ul><ul><li>The tragedy: &quot;Oh, and we got the assignment a few months ago, I just forgot to tell you. We ship two weeks from now.&quot; </li></ul></ul>
  4. 4. Why interoperability? <ul><li>Making two systems on different platforms work together </li></ul><ul><ul><li>3 basic approaches one can take </li></ul></ul><ul><ul><li>Migration: </li></ul></ul><ul><ul><ul><li>Rewrite everything from one system in the other platform </li></ul></ul></ul><ul><ul><ul><li>Takes a lot of time, effort and money </li></ul></ul></ul><ul><ul><ul><li>ROI of doing so is dubious </li></ul></ul></ul><ul><ul><li>Portability: </li></ul></ul><ul><ul><ul><li>Take the existing source code and cross-compile (C/C++) </li></ul></ul></ul><ul><ul><ul><li>Keeps a single source base </li></ul></ul></ul><ul><ul><ul><li>The only Java/.NET way to do this is through J#.NET/JLCA </li></ul></ul></ul><ul><ul><ul><li>Severe limitations on the portable code </li></ul></ul></ul>
  5. 5. Why interoperability? <ul><li>Interoperability seeks to reuse existing code w/o change </li></ul><ul><ul><li>&quot;Interoperability enables communication, data exchange, or program execution among various systems in a way that requires the user to have little or no awareness of the underlying operations of those systems.&quot; ( ISO Information Technology Vocabulary ) </li></ul></ul><ul><ul><li>&quot;If it ain't broke, don't fix it&quot; </li></ul></ul><ul><ul><li>in the case of Java and .NET, it means </li></ul></ul><ul><ul><ul><li>Java calling .NET code </li></ul></ul></ul><ul><ul><ul><li>.NET calling Java code </li></ul></ul></ul><ul><ul><ul><li>all while minimizing the pain of doing so </li></ul></ul></ul>
  6. 6. Why interoperability? <ul><li>Reuse of existing systems </li></ul><ul><ul><li>legacy systems have their place </li></ul></ul><ul><li>Delivery based on technical merit </li></ul><ul><ul><li>there's things that J2EE does better than .NET, and vice versa </li></ul></ul><ul><ul><li>not all technology makes it to both places </li></ul></ul><ul><li>Pilot for adoption </li></ul><ul><ul><li>zero-to-widespread-use usually requires trials and pilots </li></ul></ul><ul><li>Migration isn't atomic </li></ul><ul><ul><li>can't &quot;flip the switch&quot; overnight and go from one to the other </li></ul></ul>
  7. 7. Return to basics <ul><li>Go back to first principles: &quot; n -tier design&quot; </li></ul><ul><ul><li>3 tiers (physical hardware points): client, middleware, resource </li></ul></ul><ul><ul><li>3 layers (logical separation): presentation, logic, data storage </li></ul></ul><ul><ul><li>Mental note: don't confuse the two! </li></ul></ul>
  8. 8. 3 Tiers <ul><li>Client tier </li></ul><ul><ul><li>machine/device in front of the user </li></ul></ul><ul><ul><li>PC, Blackberry, PocketPC, Palm, etc. </li></ul></ul><ul><li>Middleware tier </li></ul><ul><ul><li>most often an off-resource processing tier </li></ul></ul><ul><ul><li>&quot;gather point&quot; for centralization of resource usage by clients </li></ul></ul><ul><ul><li>server to which client devices connect (usually through firewall) </li></ul></ul><ul><li>Resource tier </li></ul><ul><ul><li>some resource (data repository, most often) of interest to us </li></ul></ul><ul><ul><li>database, legacy mainframe, hardware control device, etc. </li></ul></ul>
  9. 9. 3 Layers <ul><li>Presentation layer </li></ul><ul><ul><li>responsible for the elements used to display data </li></ul></ul><ul><ul><li>in thin-client apps, generates and sends back the HTML </li></ul></ul><ul><ul><li>or, could be a Java WebStart- or Click-Once-deployed GUI </li></ul></ul><ul><li>Business layer </li></ul><ul><ul><li>represents the business processing that's UI-independent </li></ul></ul><ul><ul><li>what most people are referring to when they say &quot;middle tier&quot; </li></ul></ul><ul><ul><li>where most domain-specific programming goes </li></ul></ul><ul><li>Data access layer </li></ul><ul><ul><li>code used to access the resource tiers (database) </li></ul></ul><ul><ul><li>often deployed with business layer code; not always (sprocs) </li></ul></ul>
  10. 10. 3 Tiers, 3 Layers <ul><li>Layers don't map to Tiers 1:1 </li></ul><ul><ul><li>in traditional thin-client system, presentation layer is split across client tier (browser) and middle tier (web server) </li></ul></ul><ul><ul><li>data access layer often lives on middle tier (app or web server) </li></ul></ul><ul><ul><li>business layer can straddle all tiers (validation) </li></ul></ul><ul><li>This distinction is important to understand </li></ul><ul><ul><li>interoperability within layers is going to feel very different from interoperability across layers </li></ul></ul><ul><ul><li>interoperability across tiers is almost always going to be cross-proc, where across layers it's not so clear </li></ul></ul>
  11. 11. Interoperability points <ul><li>Interoperability can occur in several ways </li></ul><ul><ul><li>across layers: presentation calling business logic, business logic calling data access, and so forth </li></ul></ul><ul><ul><li>within layers: presentation calling other presentation code, business logic calling other business logic </li></ul></ul><ul><ul><li>classic examples: </li></ul></ul><ul><ul><ul><li>.NET WinForms app calling J2EE app server </li></ul></ul></ul><ul><ul><ul><li>Outlook plugin calling J2EE app server </li></ul></ul></ul><ul><ul><ul><li>J2EE calling COM+/EnterpriseServices </li></ul></ul></ul><ul><ul><ul><li>J2EE servlets, ASP.NET sharing session state </li></ul></ul></ul>
  12. 12. Interoperability points <ul><li>Interoperability essentially comes in three forms </li></ul><ul><ul><li>in-process: both platform code running side-by-side in-proc </li></ul></ul><ul><ul><li>out-of-process: communicating across the network </li></ul></ul><ul><ul><li>resource tier: simple data exchange through resources </li></ul></ul>
  13. 13. Interoperability points <ul><li>XML and Web services </li></ul><ul><ul><li>obviously Web services and XML play a role here </li></ul></ul><ul><ul><ul><li>XML is the ubiquitous data-exchange format </li></ul></ul></ul><ul><ul><ul><li>Web services leverage XML to enable interop </li></ul></ul></ul><ul><ul><li>but not all interoperability uses Web services </li></ul></ul><ul><ul><ul><li>example: servlets/JSP & ASP.NET sharing session state </li></ul></ul></ul><ul><ul><ul><li>example: GUI apps that must host components/controls (Swing app hosting native web browser) </li></ul></ul></ul><ul><ul><ul><li>example: single security token across sites </li></ul></ul></ul>
  14. 14. Interoperability points <ul><li>XML and Web services </li></ul><ul><ul><li>problem: Web services specs and/or implementations not ready for prime-time use yet </li></ul></ul><ul><ul><ul><li>WS-Security </li></ul></ul></ul><ul><ul><ul><li>WS-Transactions </li></ul></ul></ul><ul><ul><ul><li>WS-ReliableMessaging </li></ul></ul></ul><ul><ul><li>problem: XML is hierarchical data, not objects </li></ul></ul><ul><ul><ul><li>cyclic graphs of objects will throw fits </li></ul></ul></ul><ul><ul><ul><li>not all Web service platforms use objects! </li></ul></ul></ul><ul><ul><li>problem: all Web services assume cross-process semantics </li></ul></ul><ul><ul><ul><li>expensive to move across the network </li></ul></ul></ul><ul><ul><ul><li>usually implies multithreaded/reentrant access </li></ul></ul></ul>
  15. 15. Interoperability points <ul><li>XML & Web services are &quot;tomorrow's interop&quot; </li></ul><ul><ul><li>it's clear the future belongs to the angle-bracket crowd </li></ul></ul><ul><ul><li>but a lot of that infrastructure just doesn't exist </li></ul></ul><ul><li>XML & Web services are &quot; n -platform interop&quot; </li></ul><ul><ul><li>where n is a large number (> 2), there's no other way to go </li></ul></ul><ul><ul><li>where n == 2 (Java and .NET), other options are possible </li></ul></ul>
  16. 16. J2EE/.NET Interoperability <ul><li>In-process interoperability </li></ul><ul><ul><li>Java and the CLR coexisting in the same process </li></ul></ul><ul><ul><li>&quot;JNI meets Managed C++&quot; </li></ul></ul><ul><li>Data exchange </li></ul><ul><ul><li>using XML as the data-exchange format </li></ul></ul><ul><ul><li>.NET: XSD.exe and XmlSerializer </li></ul></ul><ul><ul><li>Java: Java API for XML Binding (JAXB) </li></ul></ul><ul><li>RPC and WSDL </li></ul><ul><ul><li>binary RPC toolkits like JaNET, JNBridge, Janeva, IIOP.NET </li></ul></ul><ul><ul><li>WSDL is often used as IDL-with-angle-brackets </li></ul></ul><ul><li>Messaging </li></ul><ul><ul><li>JMS, MSMQ, Simple messaging </li></ul></ul>
  17. 17. Data Exchange <ul><li>We start from this: </li></ul><ul><li>And we want to send it from one system to another </li></ul><ul><ul><li>from client to resource (database) </li></ul></ul><ul><ul><li>from resource to client </li></ul></ul><ul><ul><li>from processing layer (transaction server) to resource </li></ul></ul><ul><ul><li>from resource to processing layer </li></ul></ul><ul><ul><li>… and so on </li></ul></ul>public class Stock { public String name; public String tickerSymbol; public float closePrice; public int sharesOwned; } Stock s = new Stock();
  18. 18. Data Exchange <ul><li>Challenges </li></ul><ul><ul><li>data elements in .NET/Java fall into three categories </li></ul></ul><ul><ul><li>primitive data types </li></ul></ul><ul><ul><ul><li>strings, 32-bit unsigned integers, IEEE-standard floats, etc. </li></ul></ul></ul><ul><ul><ul><li>some are isomorphic (32-bit int is a 32-bit int) </li></ul></ul></ul><ul><ul><ul><li>some aren't: java.lang.String's layout == System.String's? </li></ul></ul></ul><ul><ul><li>complex data types </li></ul></ul><ul><ul><ul><li>data types made up of a composition of other data types, including other complex data types </li></ul></ul></ul><ul><ul><ul><li>heart of the object-oriented practice </li></ul></ul></ul><ul><ul><li>incompatible types </li></ul></ul><ul><ul><ul><li>some platform types have no equivalent in the other space </li></ul></ul></ul><ul><ul><ul><li>System.TimeSpan, java.util.TreeSet </li></ul></ul></ul>
  19. 19. Data Exchange <ul><li>Challenges </li></ul><ul><ul><li>Three basic &quot;formats&quot; we can store data to: </li></ul></ul><ul><ul><ul><li>text: human-consumable ASCII 7-bit &quot;clean&quot; values </li></ul></ul></ul><ul><ul><ul><li>binary: anything not textual in nature </li></ul></ul></ul><ul><ul><ul><li>resource: database, legacy storage, etc </li></ul></ul></ul>Stock s = new Stock(&quot;MSFT&quot;, &quot;Microsoft&quot;, 52.5, 100); MSFT, Microsoft, 52.5, 100 AE56757478FF00EAE356738125...
  20. 20. Data Exchange <ul><li>Challenges </li></ul><ul><ul><li>which do we support: binary or text? </li></ul></ul><ul><ul><ul><li>text is human-readable, easy for diagnostics and debugging </li></ul></ul></ul><ul><ul><ul><li>text is easier to parse by systems foreign to our own </li></ul></ul></ul><ul><ul><ul><li>binary is native to the machine, easy for machine to emit/consume </li></ul></ul></ul><ul><ul><ul><li>binary requires less &quot;translation&quot; </li></ul></ul></ul><ul><ul><ul><li>short answer: &quot;gee, we kinda want both&quot; </li></ul></ul></ul><ul><ul><li>and do you really want to write the code to emit/parse both? </li></ul></ul>
  21. 21. Data Exchange <ul><li>In essence, we want transparent transformation of objects to some kind of out-of-memory format: Serialization </li></ul><ul><ul><li>supported by both .NET and Java </li></ul></ul><ul><ul><li>requires minimal support from programmer to &quot;opt-in&quot; </li></ul></ul><ul><ul><ul><li>Java type must implement marker interface (Serializable) </li></ul></ul></ul><ul><ul><ul><li>.NET type must annotate custom attribute (Serializable) </li></ul></ul></ul><ul><ul><li>from there, libraries and runtime can handle the rest </li></ul></ul><ul><ul><ul><li>understands primitive data types intrinsically </li></ul></ul></ul><ul><ul><ul><li>walks the complete graph of object references </li></ul></ul></ul><ul><ul><ul><li>handles circular references transparently </li></ul></ul></ul><ul><ul><li>makes using Serialization (deceptively) easy </li></ul></ul>
  22. 22. Serialization <ul><li>Challenges </li></ul><ul><ul><li>Java and .NET binary serialization formats are incompatible </li></ul></ul><ul><ul><ul><li>shouldn't come as a major surprise :-) </li></ul></ul></ul><ul><ul><ul><li>Java: big-endian, .NET: little-endian (just for starters) </li></ul></ul></ul><ul><ul><li>thus, binary serialization data exchange doesn't work </li></ul></ul><ul><ul><ul><li>well, not exactly true: both platforms support custom serialization &quot;hooks&quot; that could be used to make it work </li></ul></ul></ul><ul><ul><ul><li>this is a formidable amount of code to have to write </li></ul></ul></ul><ul><ul><li>we hate to give up on the ease of the serialization approach </li></ul></ul><ul><ul><li>so let's just change target formats: XML </li></ul></ul><ul><ul><ul><li>XML is the Great Interop Format, so we're done, right? </li></ul></ul></ul>
  23. 23. Serialization <ul><li>XML Serialization: .NET </li></ul><ul><ul><li>System.Xml.Serialization.XmlSerializer </li></ul></ul>public class Stock { // . . . details unimportant } Stock s = new Stock(); XmlSerializer ser = new XmlSerializer(typeof(Stock)); FileStream fs = new FileStream(&quot;stock.xml&quot;, FileMode.Create); ser.Serialize(fs, s); XmlSerializer ser = new XmlSerializer(typeof(Stock)); FileStream fs = new FileStream(&quot;stock.xml&quot;, FileMode.Open); Stock s = (Stock)ser.Deserialize(fs);
  24. 24. Serialization <ul><li>XML Serialization: Java API for XML Binding (JAXB) </li></ul><ul><ul><li>javax.bind.*; </li></ul></ul>public class Stock { // . . . details unimportant } Stock s = new Stock(); JAXBContext ctx = JAXBContext.newInstance(&quot;com.test.Package&quot;); Marshaller m = ctx.createMarshaller(); FileOutputStream fs = new FileOutputStream(&quot;stocks.xml&quot;); m.marshal(s, fs); JAXBContext ctx = JAXBContext.newInstance(&quot;com.test.Package&quot;); Unmarshaller m = ctx.createUnmarshaller(); FileInputStream fs = new FileInputStream(&quot;stocks.xml&quot;); Stock s = m.unmarshal(fs);
  25. 25. Serialization <ul><li>Challenges </li></ul><ul><ul><li>unfortunately, the story doesn't stop here </li></ul></ul><ul><ul><ul><li>too easy to serialize incompatible types </li></ul></ul></ul><ul><ul><ul><li>.NET XmlSerializer only serializes public properties </li></ul></ul></ul><ul><ul><ul><li>JAXB has similar problem </li></ul></ul></ul><ul><ul><li>XmlSerializer provides attributes to control serialization </li></ul></ul><ul><ul><ul><li>to use effectively, you have to know XmlSerializer behavior </li></ul></ul></ul><ul><ul><li>JAXB uses package descriptors to control serialization </li></ul></ul><ul><ul><ul><li>to use effectively, you have to know JAXB's behavior </li></ul></ul></ul><ul><ul><li>In short, you have to know both sides' behavior well in order to customize the XML output appropriately for all types </li></ul></ul><ul><ul><ul><li>this is a lot of work! </li></ul></ul></ul><ul><ul><ul><li>would be easier if we could start with something &quot;neutral&quot; </li></ul></ul></ul>
  26. 26. Schema <ul><li>Schema provides metadata (data about data) </li></ul><ul><ul><li>in relational databases, schema defines relational tables and relationships between the tables </li></ul></ul><ul><ul><li>in XML, schema (XSD) defines XML types and their contents </li></ul></ul><ul><ul><ul><li>XML parsers can verify documents against schema </li></ul></ul></ul><ul><ul><ul><li>XML tools can ensure proper format and content </li></ul></ul></ul><ul><ul><ul><li>tools can generate producer/consumer code </li></ul></ul></ul>
  27. 27. Schema <ul><li>Example schema: </li></ul><?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?> <xs:schema targetNamespace=&quot;; elementFormDefault=&quot;qualified&quot; xmlns=&quot;; xmlns:mstns=&quot;; xmlns:xs=&quot;;> <xs:complexType name=&quot;Stock&quot;> <xs:sequence> <xs:element name=&quot;Ticker&quot; type=&quot;xs:string&quot; /> <xs:element name=&quot;Name&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;Price&quot; type=&quot;xs:float&quot;/> <xs:element name=&quot;Shares&quot; type=&quot;xs:int&quot;/> </xs:sequence> </xs:complexType> <xs:element name=&quot;Stock&quot; type=&quot;mstns:Stock&quot; /> </xs:schema>
  28. 28. Schema <ul><li>Schema-based data exchange: .NET XSD.exe </li></ul><ul><ul><li>xsd.exe generates classes from schema (/c option) </li></ul></ul><ul><ul><li>annotates classes with XmlSerializer attributes as necessary </li></ul></ul><ul><ul><li>supports most schema types </li></ul></ul>XmlSerializer sz = new XmlSerializer(typeof(Stock)); // Stock generated by &quot;xsd.exe /c stock.xsd&quot; Stock s = new Stock(); s.Ticker = &quot;ACME&quot;; s.Name = &quot;Acme Corp&quot;; s.Price = 5.25; FileStream fs = File.Open(&quot;acme.xml&quot;, FileMode.Create); sz.Serialize(fs, s);
  29. 29. Schema <ul><li>Schema-based data exchange: JAXB </li></ul><ul><ul><li>tool usually provided to generate code from schema </li></ul></ul><ul><ul><ul><li>JAXB originally (0.7 and earlier) used custom format, had no schema support </li></ul></ul></ul><ul><ul><ul><li>JAXB 1.0 supports schema </li></ul></ul></ul><ul><ul><li>important note: JAXB is specification, not implementation </li></ul></ul><ul><ul><ul><li>other vendors may use differing tools </li></ul></ul></ul><ul><ul><ul><li>all should conform to APIs described by JAXB </li></ul></ul></ul><ul><ul><li>JAXB Reference Implementation available from Sun </li></ul></ul>
  30. 30. So are we done? <ul><li>Not quite </li></ul><ul><ul><li>data exchange is useful for simple scenarios </li></ul></ul><ul><ul><li>but more complications arise as we get more sophisticated </li></ul></ul><ul><ul><ul><li>shared session state across ASP.NET & servlets/JSP </li></ul></ul></ul><ul><ul><ul><li>in-process execution between WinForms & Swing </li></ul></ul></ul><ul><ul><ul><li>… and so on </li></ul></ul></ul><ul><li>&quot;So how do I know when to use which?&quot; </li></ul>
  31. 31. The Ten Myths of Enterprise Computing <ul><li>&quot;Essentially everyone, when they first build an enterprise application, makes the following 10 assumptions. All turn out to be false in the long run and all cause big trouble and painful learning experiences.&quot; </li></ul><ul><ul><li>1) The network is reliable </li></ul></ul><ul><ul><li>2) Latency is zero </li></ul></ul><ul><ul><li>3) Bandwidth is infinite </li></ul></ul><ul><ul><li>4) The network is secure </li></ul></ul><ul><ul><li>5) Topology doesn't change </li></ul></ul><ul><ul><li>6) There is one administrator </li></ul></ul><ul><ul><li>7) Transport cost is zero </li></ul></ul><ul><ul><li>8) The network is homogeneous </li></ul></ul><ul><ul><li>9) The system is monolithic </li></ul></ul><ul><ul><li>10) The system is finished </li></ul></ul>
  32. 32. Myths in detail <ul><li>#8: The network is homogeneous </li></ul><ul><ul><li>you're in this class because you realize this already </li></ul></ul><ul><ul><li>again, most of the time, interop means J2EE/.NET </li></ul></ul><ul><ul><li>do you know that anything else will be used? </li></ul></ul><ul><ul><li>more importantly, are you going to willingly accept the overhead and implicit cost of adopting a Web service base? </li></ul></ul><ul><ul><li>Web services == interop for n plaforms, where n > 2 </li></ul></ul>
  33. 33. Myths in detail <ul><li>#9: The system is monolithic </li></ul><ul><ul><li>might have been true in the days of C/C++ (static linking) </li></ul></ul><ul><ul><li>impossible in the days of dynamically linked runtimes </li></ul></ul><ul><ul><ul><li>the platforms can and will change </li></ul></ul></ul><ul><ul><ul><li>the components you use can and will change </li></ul></ul></ul><ul><ul><ul><li>the containers you run can and will change </li></ul></ul></ul><ul><ul><li>even more irrelevant when you don’t own or administer both (or all) ends of the pipe </li></ul></ul><ul><ul><ul><li>enterprise systems imply lots of players </li></ul></ul></ul><ul><ul><ul><li>lots of players imply lots of different voices & decisions </li></ul></ul></ul><ul><ul><li>it's always ideal if a company can select a baseline platform </li></ul></ul><ul><ul><ul><li>but recognize that Web services is just another platform </li></ul></ul></ul><ul><ul><ul><li>(so was CORBA, or DCOM, or Java, for that matter) </li></ul></ul></ul>
  34. 34. Myths in detail <ul><li>#10: The system is finished </li></ul><ul><ul><li>projects that reach production never die </li></ul></ul><ul><ul><ul><li>for some reason, users keep wanting new features </li></ul></ul></ul><ul><ul><ul><li>something about &quot;raising productivity&quot; or some nonsense </li></ul></ul></ul><ul><ul><ul><li>hey, more work means you're still getting paid, right? </li></ul></ul></ul><ul><ul><li>part of what's never finished is the technology platform </li></ul></ul><ul><ul><ul><li>.NET and J2EE will continue to grow and evolve </li></ul></ul></ul><ul><ul><ul><li>this means infrastructure is constantly changing (see #9) </li></ul></ul></ul><ul><ul><ul><li>this in turn means interoperability will always be there </li></ul></ul></ul>
  35. 35. Basics <ul><li>Realize that the platforms create component boundaries </li></ul><ul><ul><li>loose coupling is the order of the day </li></ul></ul><ul><ul><ul><li>don't try to share object definitions across both platforms </li></ul></ul></ul><ul><ul><ul><li>instead, prefer to exchange data </li></ul></ul></ul><ul><ul><li>keep boundary-crossings to a minimum </li></ul></ul>
  36. 36. Basics <ul><li>Recognize the additional complexity you're facing </li></ul><ul><ul><li>easily an order of magnitude more complex than an all-Java/J2EE or all-.NET system </li></ul></ul><ul><ul><li>factor in the necessary: </li></ul></ul><ul><ul><ul><li>debugging & troubleshooting time </li></ul></ul></ul><ul><ul><ul><li>diagnostics support </li></ul></ul></ul><ul><ul><ul><li>cost (if you look to commercial toolkits) </li></ul></ul></ul><ul><ul><ul><li>topology and support (particularly security concerns) </li></ul></ul></ul>
  37. 37. Basics <ul><li>Understand that interoperability does not perform well </li></ul><ul><ul><li>sometimes you can get lucky and make it run fast… </li></ul></ul><ul><ul><li>… but don't assume this will be the case </li></ul></ul><ul><ul><li>cross-platform marshaling takes time </li></ul></ul><ul><ul><ul><li>low-endian to high-endian translations </li></ul></ul></ul><ul><ul><ul><li>string representations </li></ul></ul></ul><ul><ul><ul><li>and so on </li></ul></ul></ul><ul><ul><li>for this reason, try to take interop scenarios off critical-path performance scenarios </li></ul></ul>
  38. 38. Basics <ul><li>Where possible, try to avoid interop within layers </li></ul><ul><ul><li>prefer presentation-to-logic or logic-to-resource interop </li></ul></ul><ul><ul><li>presentation-to-presentation is a royal pain </li></ul></ul><ul><ul><ul><li>stateless presentation can be done with straight HTTP </li></ul></ul></ul><ul><ul><ul><li>shared session state almost demands in-proc interop, or… </li></ul></ul></ul><ul><ul><ul><li>storing session state externally is usually cross-tier (ouch) </li></ul></ul></ul><ul><ul><li>logic-to-logic interop has curious semantics </li></ul></ul><ul><ul><ul><li>EJB calls COM+: do you expect 2PC transaction support? </li></ul></ul></ul><ul><ul><ul><li>COM+ calls EJB: do you expect call context causality? </li></ul></ul></ul>
  39. 39. Basics <ul><li>Where possible, prefer resource-tier interop </li></ul><ul><ul><li>it's the easiest means for exchanging information </li></ul></ul><ul><ul><li>each side has well-defined, well-understood idioms for resource access and update </li></ul></ul><ul><ul><ul><li>filesystem-based exchange </li></ul></ul></ul><ul><ul><ul><li>relational database </li></ul></ul></ul><ul><ul><li>XML serialization can be of great help here </li></ul></ul><ul><ul><ul><li>again, start with XSD to ensure best portability </li></ul></ul></ul><ul><ul><ul><li>consider J# for these types to allow for single-source maintenance if you want to make them &quot;domain objects&quot; </li></ul></ul></ul><ul><ul><li>problem will come with request/response semantics </li></ul></ul>
  40. 40. Presentation/Presentation interop <ul><li>Thin client options </li></ul><ul><ul><li>Servlets hosting ASP.NET via System.Web.Hosting invoked via MC++ JNI DLL </li></ul></ul><ul><ul><ul><li>write servlet filter to replace standard servlet HttpSession and ServletRequest/ServletResponse objects </li></ul></ul></ul><ul><ul><ul><li>write ASP.NET host code to access servlet objects </li></ul></ul></ul><ul><ul><li>ASP.NET hosting servlet container </li></ul></ul><ul><ul><ul><li>not recommended—servlet containers heavierweight </li></ul></ul></ul><ul><ul><li>Neither hosts anything; share session state via resource tier </li></ul></ul><ul><ul><ul><li>expensive session state access </li></ul></ul></ul><ul><ul><ul><li>but you should minimize session state usage, anyway </li></ul></ul></ul>
  41. 41. Presentation/Presentation interop <ul><li>Smart/Thick/Rich client options </li></ul><ul><ul><li>Swing hosting WinForms: Really Bad Idea </li></ul></ul><ul><ul><ul><li>Swing does all of its own painting, Z-order, etc. (1 HWND) </li></ul></ul></ul><ul><ul><ul><li>will not play well with &quot;heavyweight&quot; WinForms widgets </li></ul></ul></ul><ul><ul><ul><li>(doesn't play well with &quot;heavyweight&quot; AWT, for that matter) </li></ul></ul></ul><ul><ul><li>WinForms hosting Swing: approachable, but… </li></ul></ul><ul><ul><ul><li>each assumes it has its own message loop </li></ul></ul></ul><ul><ul><ul><li>mixing the two is likely to cause problems over time </li></ul></ul></ul><ul><ul><li>SWT and WinForms </li></ul></ul><ul><ul><ul><li>SWT uses native USER32 functionality, like WinForms </li></ul></ul></ul><ul><ul><ul><li>HWNDs, ActiveX access possible (but not easy) </li></ul></ul></ul><ul><ul><ul><li>best bet is to not mix on single HWND; spawn top-level windows, dialogs where possible </li></ul></ul></ul>
  42. 42. Presentation/Business Logic interop <ul><li>.NET Presentation to J2EE Business Logic </li></ul><ul><ul><li>most likely scenario of all interop possibilities </li></ul></ul><ul><ul><ul><li>J2EE back-end infrastructure currently dominates </li></ul></ul></ul><ul><ul><ul><li>.NET front-end infrastructure currently dominates </li></ul></ul></ul><ul><ul><li>EJB: follow J2EE rules: </li></ul></ul><ul><ul><ul><li>never access entity beans directly from client </li></ul></ul></ul><ul><ul><ul><li>treat beans as opaque services, not objects </li></ul></ul></ul><ul><ul><li>probably best to use IIOP tools to access J2EE </li></ul></ul><ul><ul><ul><li>no change in J2EE footprint required </li></ul></ul></ul><ul><ul><ul><li>servers have had this (debugged) for some time now </li></ul></ul></ul><ul><ul><ul><li>allows for easier diagnostics (via Java/IIOP clients) </li></ul></ul></ul><ul><ul><li>future: use messaging/JMS/SOAP/Message-Driven Beans </li></ul></ul><ul><ul><ul><li>best scalability, evolution possibilities </li></ul></ul></ul><ul><ul><ul><li>easy to adopt in basic forms using data exchange </li></ul></ul></ul>
  43. 43. Presentation/Business Logic interop <ul><li>Java Presentation to .NET Business Logic </li></ul><ul><ul><li>binary RPC proxies to COM+ servers </li></ul></ul><ul><ul><ul><li>requires out-of-proc call and activation modes </li></ul></ul></ul><ul><ul><li>in-proc MC++ JNI DLL calls to COM+ objects </li></ul></ul><ul><ul><ul><li>allows for either in-proc hosting or out-of-proc </li></ul></ul></ul><ul><ul><ul><li>can't run on non-Windows clients </li></ul></ul></ul><ul><ul><li>COM+ SOAP Activation semantics </li></ul></ul><ul><ul><ul><li>security concerns </li></ul></ul></ul><ul><ul><ul><li>starting-from-.NET type mismatch concerns </li></ul></ul></ul><ul><ul><li>Swing/SWT/AWT: zero difference between them </li></ul></ul><ul><ul><li>Servlets: easier to do JNI, since it's server-based </li></ul></ul><ul><ul><ul><li>be careful of COM+ impersonation, or you'll be running with servlet container authentication credentials </li></ul></ul></ul>
  44. 44. Business Logic/Business Logic interop <ul><li>J2EE calling COM+ </li></ul><ul><ul><li>best bet is probably SOAP Activation approach </li></ul></ul><ul><ul><ul><li>hosting JNI DLLs in J2EE servers is tricky </li></ul></ul></ul><ul><ul><ul><li>if RPC toolkit has zero native footprint, might be doable </li></ul></ul></ul><ul><ul><ul><li>almost guarantees out-of-process connection </li></ul></ul></ul><ul><ul><li>or, create a front-end channel to the COM+ component </li></ul></ul><ul><ul><ul><li>web service or remoting target (IIOP, preferably) </li></ul></ul></ul><ul><ul><ul><li>more work, more maintenance </li></ul></ul></ul><ul><ul><li>be careful of security concerns </li></ul></ul><ul><ul><ul><li>remember, don't rely on the firewall or HTTP/S </li></ul></ul></ul><ul><ul><ul><li>assume insecurity </li></ul></ul></ul>
  45. 45. Business Logic/Business Logic interop <ul><li>COM+ calling J2EE </li></ul><ul><ul><li>best bet is probably IIOP approach </li></ul></ul><ul><ul><ul><li>interfaces are tightly-coupled anyway </li></ul></ul></ul><ul><ul><ul><li>better reliability from IIOP than J2EE web services right now </li></ul></ul></ul><ul><ul><li>if JMS vendor has .NET bindings, use those! </li></ul></ul><ul><ul><ul><li>as said before, Message-Driven Beans give best scalability </li></ul></ul></ul><ul><ul><li>again, remember security </li></ul></ul><ul><ul><ul><li>J2EE access (almost) always out-of-proc </li></ul></ul></ul><ul><ul><ul><li>J2EE has no concept of &quot;call context&quot; </li></ul></ul></ul>
  46. 46. Business Logic/Data Access interop <ul><li>Generally no reason for .NET business logic component to call Java data access (or vice versa) </li></ul><ul><ul><li>one exception might be legacy systems (3270 terminals) </li></ul></ul><ul><ul><li>J2EE has rich &quot;Connector&quot; API for &quot;external access&quot; </li></ul></ul><ul><ul><li>probably best accessed through stateless session bean front </li></ul></ul>
  47. 47. In-proc interoperability <ul><li>Due to complexity of in-process interop, avoid when possible </li></ul><ul><ul><li>that said, certain scenarios will demand it </li></ul></ul><ul><ul><ul><li>sharing session state (ASP.NET and servlets) </li></ul></ul></ul><ul><ul><ul><li>hosting controls in a GUI app </li></ul></ul></ul><ul><ul><li>ManagedC++ is probably the best route to take </li></ul></ul><ul><ul><ul><li>unmanaged MC++ code handles JNI well </li></ul></ul></ul><ul><ul><ul><li>consider JACE ( http:// ) </li></ul></ul></ul><ul><ul><ul><li>be very careful of unmanaged threads, though; prefer to use the managed threading APIs whenever possible </li></ul></ul></ul><ul><ul><li>for best results, build, buy or download &quot;wrapper&quot; libraries </li></ul></ul><ul><ul><ul><li>build JMS wrappers for messaging access </li></ul></ul></ul><ul><ul><ul><ul><li>( ), for example </li></ul></ul></ul></ul><ul><ul><ul><li>do the same for Java access to MSMQ </li></ul></ul></ul>
  48. 48. Binary RPC <ul><li>RPC is a tightly-coupled step </li></ul><ul><ul><li>understands object references across the network </li></ul></ul><ul><ul><li>clearly an easy way to maintain state across calls </li></ul></ul><ul><ul><li>well-understood by object-oriented programmers </li></ul></ul><ul><ul><li>due to identity , doesn't scale well </li></ul></ul><ul><ul><li>concurrency concerns: multiple clients accessing concurrently </li></ul></ul><ul><ul><li>evolution concerns: changing types on both ends </li></ul></ul>
  49. 49. Binary RPC <ul><li>CORBA/IIOP protocol </li></ul><ul><ul><li>has advantage of native bindings to J2EE-compliant servers </li></ul></ul><ul><ul><li>Janeva, IIOP.NET provide good bindings </li></ul></ul><ul><ul><li>distinct disadvantage of being &quot;out of favor&quot; in industry </li></ul></ul><ul><li>SOAP/HTTP protocols </li></ul><ul><ul><li>a number of toolkits offer bindings over HTTP/SOAP </li></ul></ul><ul><ul><li>uses WSDL-as-RPC, which is deprecated and a Bad Idea </li></ul></ul>
  50. 50. WSDL != Distributed Objects <ul><li>Despite its apparent similarities, don't use it as RPC </li></ul><ul><ul><li>remember, not all languages are O-O (for good reasons) </li></ul></ul><ul><ul><li>never generate WSDL from language interfaces </li></ul></ul><ul><ul><li>for the same reasons, never use rpc/encoded bindings </li></ul></ul><ul><ul><li>use it solely to describe message-based services </li></ul></ul><ul><ul><li>look for WSDL 1.2/2.0/v.Next to ship sometime in 2004 </li></ul></ul>
  51. 51. Messaging <ul><li>Messaging represents best bet for interoperability </li></ul><ul><ul><li>&quot;context complete&quot; communication approach </li></ul></ul><ul><ul><ul><li>in WSDL, this begins with doc/literal </li></ul></ul></ul><ul><ul><ul><li>extended by WS-Security & friends </li></ul></ul></ul><ul><ul><ul><li>in essence, capture everything needed in one logical packet </li></ul></ul></ul><ul><ul><li>allows for async communications </li></ul></ul><ul><ul><ul><li>remember, interop is expensive </li></ul></ul></ul><ul><ul><ul><li>adds Quality-of-Service capabilities (Myth #1) </li></ul></ul></ul><ul><ul><li>reflected well in all platforms </li></ul></ul><ul><ul><ul><li>JMS </li></ul></ul></ul><ul><ul><ul><li>MSMQ </li></ul></ul></ul><ul><ul><ul><li>SOAP, WS-ReliableMessaging, WS-Eventing, … </li></ul></ul></ul><ul><ul><li>allows for higher-order mechanisms </li></ul></ul><ul><ul><ul><li>WS-Routing, WS-Referral, etc </li></ul></ul></ul>
  52. 52. Messaging <ul><li>Interoperability advantages </li></ul><ul><ul><li>crossing platforms is relatively trivial: Messaging Bridge (133) </li></ul></ul><ul><ul><li>moving to a different channel: Channel Adapter (127) </li></ul></ul><ul><ul><li>easy interception-like behavior: Detour (545), Wire Tap (547) </li></ul></ul><ul><ul><li>better scalability due to lack of object identity </li></ul></ul><ul><ul><li>quality-of-service assurances: Guaranteed Delivery (122) </li></ul></ul><ul><ul><li>evolution support: Messaging Mapper (477) </li></ul></ul><ul><ul><li>prioritization </li></ul></ul><ul><ul><li>transactional semantics </li></ul></ul>
  53. 53. Web services <ul><li>Remember, &quot;here there be dragons&quot; </li></ul><ul><ul><li>Web services are obviously the future direction of interop </li></ul></ul><ul><ul><li>future isn't guaranteed to be pleasant, however </li></ul></ul><ul><ul><ul><li>vendor relations are crucial: remember CORBA? </li></ul></ul></ul><ul><ul><ul><li>what degree of &quot;standardization&quot; is necessary? </li></ul></ul></ul><ul><ul><ul><li>when will the &quot;future&quot; == &quot;today&quot;? </li></ul></ul></ul><ul><ul><ul><li>when we get there, will it resemble what we predicted? (witness J2EE/EJB, for example) </li></ul></ul></ul>
  54. 54. Web services <ul><li>Remember, XML is always applicable w/o &quot;Web services&quot; </li></ul><ul><ul><li>REST is a simplistic, straightforward model </li></ul></ul><ul><ul><ul><li>simplistic != &quot;easy&quot;, though </li></ul></ul></ul><ul><ul><ul><li>lots of work required on your part over time </li></ul></ul></ul><ul><ul><li>email as a messaging architecture, too (REST-ful mail?) </li></ul></ul><ul><ul><li>be careful not to assume that XML == objects </li></ul></ul><ul><ul><ul><li>as discussed, XML/object marshaling is not always easy </li></ul></ul></ul><ul><ul><ul><li>use XML &quot;at the edges&quot; of components, not as objects </li></ul></ul></ul><ul><ul><li>XML through the resource tier </li></ul></ul><ul><ul><ul><li>example: SQLServer Yukon Reporting Services does XML </li></ul></ul></ul><ul><ul><ul><li>example: database stored procs returning XML </li></ul></ul></ul><ul><ul><ul><li>filesystem messaging </li></ul></ul></ul>
  55. 55. Summary <ul><li>Interoperability scenarios can be designed or refactored </li></ul><ul><ul><li>requires that you keep &quot;channels&quot; separate from &quot;logic&quot; </li></ul></ul><ul><ul><li>think of &quot;presentation&quot; as a channel and you're not far off </li></ul></ul><ul><ul><li>keep coupling loose across layers </li></ul></ul><ul><ul><li>prefer messaging to RPC for scalability, evolution & flexibility </li></ul></ul><ul><li>Remember, this is bleeding-edge stuff </li></ul><ul><ul><li>the moral of the story is, &quot;Risk Management&quot; </li></ul></ul><ul><ul><li>lots of research </li></ul></ul><ul><ul><li>lots of &quot;spikes&quot; </li></ul></ul><ul><ul><li>lots of cynicism: take no vendor at their word </li></ul></ul><ul><ul><ul><li>even to the point of distrusting these slides (until proven) </li></ul></ul></ul>