Thursday, October 13, 2011

XML Processing in Java EE 5

All of the new Web Services API requires XML processing. Thankfully there have been changes to how Java EE will handle that as well with a fresh batch of updates.

JAXB 2.0: Improves vastly over JAXB 1.0

W3C XML Schema features (fixes missing bindings)

Adds javax.xml.bind.annotation and supports Java-to-XML binding.

Reduction in generated schema-derived classes.

Validation via JAXP 1.3 validation APIs

Smaller runtime binaries.

Schema compiler, Schema generator and Binding runtime framework.

JAXB 1.0 allowed validation: at unmarshall time, and on-demand validation on the content tree. JAXB 2.0 allows validation at marshall time and unmarshall time.


Streaming API for XML (StAX)

StAX is the all new efficient API for XML, it has a lot of great features:

  • Stream-oriented
  • Event-Driven
  • Pull-design
  • Read/WriteYou can create fast, light-weight, bi-directional parsers that is easy on the heap.
    JAXP (Java API for XML Processing) family includes StAX, TrAX, SAX, and DOM. StAX is good for low memory and limited extensibility applications.
    Pull Parser – simpler than SAX, more memory efficient than DOM.
    SAX can’t write – and isn’t bidirectional. DOM is way more powerful and flexible. One would dump SAX for StAX. An iterative pull parser – stax, an event driven push parser – then go for SAX.
    I can’t see anyone using SAX anymore. Why would you? Unless you don’t want a cursor and iterator concept in your code – or you simply hate procedural and believe everything should be read-only events for XML processing. XMLStreamReader or XMLEventReader are the Cursor and Iterator APIs – well, Iterator APIs can do things a Cursor cannot do: Iterator is more extensible and flexible. Cursor is efficient, performant and memory friendly – ideal for small JVMs and JME

        Wednesday, October 12, 2011

        JAX-WS in Java EE 5

        JAX-WS: Java API for XML Web Services. Does message oriented as well as RPC oriented services. Hides complexities of SOAP. No need to generate or parse SOAP messages (or understand the structure or format).

        The JAX-WS endpoints must be annotated with @WebService or @WebServiceProvider. The business method must be annotated @WebMethod – a Service Endpoint Implementation (SEI) will be generated for this. JAXB compatible parameters are required.

        Um, if you think Web Services or Clouds are NOT important, I hope the following stat will convince you.

         

        The Client needs @WebServiceRef – the reference to the service (or wsdlLocation). Get the port from the service and then invoke the exposed method on the service. Yes you need the interface to the service.

        JAX-WS 2.0 Support WS-I Basic Profile Version 1.1, SOAP 1.1 and WSDL 1.1.

        There is support for doc/lit, rpc/lit, static ports, dynamic proxies, and DII.

        All in all JAX-WS seems like a winner!

        Well, can you still use SAAJ? Yes – it gives you direct access to the SOAP protocol and the SAAJ 1.3 API supports SOAP 1.1 and SOAP 1.2 specifications.

        <Message>

        <Part>

        <Envelope>

        <Header>

        </Header>

        <Body>

        </Body>

        </Envelope>

        </Part>

        </Message>

        You can have Attachment Parts as peers to the Part. all Under the soap message but outside the envelope.

        The attachment part will contain MIME headers and the content (any).

        Um – BTW – you can use JAX-B to send SOAP Attachments too – so why would you want to bother with the SAAJ APIs is going to remain a mystery. But it’s there.

        i18n APIs

        If you’re designing an application that may be distributed to other nations, what you want to avoid is hardcoding English user text.

        The following interfaces and objects are foundational to enable internationalization (i18n).

        java.text package

        Locale: Where is this running?

        Resource Bundle: Alien language resource (LOL)

        InputStreamReader OutputStreamWriter: UTF-8 and UTF-16

        Internationalization is essential for a global impact


        Abstraction, abstraction and more abstraction. Decouple everything with a minimal surface area allows for a low friction system. Internationalizing any application is probably a great test of software flexibility.

        In order to prepare an application, several changes need to be considered:

        1. Screen Text

        2. Dates, Calendars

        3. Numbers, Formats, Currency

        4. Icons, Images

        5. Text File formats (e.g. UTF-8, UTF-16).

         

        It is possible that your program writes to ASCII, however that’s not going to work for the Japan market, you need to be able to write in UTF-16.

        Tuesday, October 11, 2011

        Distributed Garbage Collection and Stub Downloads–and other dirty solution architecture alternatives

        Technology choices can make the difference between meeting the customers’ immediate needs and failing to complete a project on time. No can do if you’re using IIOP. If you’re still stuck in CORBA or IIOP, and trying to get remote objects talking to one another – don’t expect RMI-IIOP to help do what pure RMI does – DGC. Stub downloads and DGC are never going to be supported across technologies – it’s not possible to standardize it.

        Think about refactoring to expose encapsulated business services instead. Use HTTP – it is connection based and stateless. Alternatively think about using messaging architectures, if you are at the systems programming level – IP Multicasting can be used of TCP that can serve as an unreliable messaging infrastructure – but it can also have layers of high speed health checks and retry mechanisms built. Virtual channels like queues (p2p) and topics with durability attributes can be used as well.

        If a non-EJB Java application requires integration with your CORBA system, Java IDL is officially recommended – the communication protocol then is native IIOP. CORBA clients needs to talk to Java, Java IDL on the client end don’t make sense. If you want to integrate with the mainframe, and all you need is some fancy GUI, but the mainframe source code is unavailable – guess what? Screen scrapers via terminal emulator inputs may be recommended. Depends. If the goal is to meet the customer’s need quickly – don’t forget to do a trade off analysis and make target state recommendations. An architects job is to accelerate business not make perfect solutions at all costs. Judging trade offs is where we make money for the clients. Know when where and how to make short cuts if needed. Use a reverse proxy to target different servers for servicing different types of requests. Have failure management systems up to the wazoo. Avoid EJBs if you have no need for transactions and business logic in the solution. KISS.

        If you must use CORBA and RMI-IIOP (for EJB type communications), and Session Beans provide good memory management like Pooling and Passivation (SLSB & SFSB). If you must integrate with existing native C++ code/business logic, it is advisable to wrap that with JNI calls, and remote it via RMI. Don’t over use web-services if you don’t need a business service. SOA isn’t API over the web.

        All in all, Java IDL is business as usual for CORBA programming. Use RMI-IIOP is for Java programming over IIOP, it can interoperate with CORBA objects but those interfaces must be available as Java RMI. If you must use pure IIOP – then you have existing CORBA objects in play that can’t have Java interfaces – so you must use Java IDL. CORBA provides lots and lots of nice services; Naming Services, Security, Transaction Service, Event and Concurrency Control.

        Regardless of how you meet your customers’ expectations – plan to leave them with an awesome build/deploy strategy & matching execution.

        Monday, October 10, 2011

        Cloud 9? Don’t forget data replication strategies

        It is still important to decide on your data, server replication strategy when you deploy your core business services and data assets to an internal, external or hybrid cloud models.

        Understanding the implications of Active Replication, Passive Replication, Hot Backup, Warm Backup, Cold Backup, State Change Synchronization, Load Balancing and Fault Tolerance are key to making essential choices for a solid deployment architecture on the cloud.

        Elasticity, capacity flexibility, horizontal and vertical scalability and dynamic resource allocation makes life a lot easy on the cloud.

        Active replication is not achieved by taking cold backups, state changes are not logged for periodic flushes to the replicas, state is not synchronized to only support backup replica when the primary fails. Instead each replica is identical, each replica attempts to process each request – an interceptor takes care of idem potency between replicas. If you want a Primary Service to support all incoming requests, and periodically synchronize its state with the replicas – what you have is a Warm Backup or Passive Replication.

        Take a hot backup during times when you have low scalability needs on the RDBMS systems, whereas a cold backup should be reserved for “Sundays” or in the 70s. If you’re going to support the cloud – forger cold backups and start thinking CA (Continuous Availability).

        Sunday, October 9, 2011

        Dealing with $$$$? You need ACID

         

        If you’re deploying business logic to an EJB container, you’re probably dealing with some durable transactional stuff that’s needed by the customer. You need som ACID baby!

        Atomicity – do it all or don’t do anything at all.
        Consistency – Ensure everything is left integral.

        Isolated – Nothing else should alter or interfere.

        Durable – persist prior to finishing.

        For financially significant applications you need transactions – with four quality attributes together: ACID.

        Saturday, October 8, 2011

        How to remove Linux partition from a dual-boot PC? lilo & gparted

        Now that Windows 7 and Macs have improved their security architectures, it is possible to take tentative steps away from linux for desktop computing, if cost is not a factor.

        Every GB counts, so machines that have dual partitions, freeing up the swap, home and primary partition is the only reasonable option.

        Remove grub, linux distro and reallocate space.

        If you have a dual-boot PC with a Windows XP partition and an Ubuntu 11.04 (or other) partition – and want to simply have the windows partition only then read on.

        One 4-letter word: lilo

        It can create an MBR on your Windows partition.

        Before you do that, make sure you run check disk on all drives from your windows partition. Then boot up with a live Ubuntu CD and run GParted. Delete the partitions, and resize them as needed.

        Run lilo to recreate your MBR on the windows main partition, and you are all set.

        Tuesday, October 4, 2011

        Creating Objects Design Situations

         

        Understanding how to create an object goes beyond the new() syntax, a good designer will think about the current requirement and future requirements to ensure decoupling layers, build in flexibility and maintainability. For example,

        So you have an object that needs to create another class, however

        …it cannot anticipate the class of objects it must create

        …it wants only its subclass to specify the object it wants to create

        …it wants to localize knowledge of which helper subclass is the delegate

        How would you design for these quality attributes?

        How about the following:

        A client class needs a complex object, however it also

        … wants to vary the product’s internal representation

        …isolate code for construction and representation

        …gives you greater control over the construction process

        How would you design for these quality attributes?

         

        What if you wanted to:

        … isolate the concrete class from the client that needs it, and

        … allow for exchanging classes of products easily

        …enforce a common consistent product interface across families of products

        What’s going to be the pattern of choice, designer?

        If you answered Factory, Builder and Abstract Factory – then that’s pretty darn good – you remember your GOFs, which are like the ABCs for software architects (or should be).

        Monday, October 3, 2011

        Java EE 5 Security

        Enterprise Java provides abstracted security APIs and concept that sit on a robust security foundation at the Java Language Specification and implemented by Java Virtual Machines:

        Automatic Memory Management

        Secure Class Loading

        Strong Typing

        Byte code Verification

        At the time the security design was unprecedented, nothing came close to the security model of an interoperable platform. However with the advent of Java Applets and sandboxing, clunky jar signing processes and key stores, users and system designers shed away.

        Java EE 5 continues to build and extend a robust security platform for its EJB and Web containers – the simplified API looks for isCallerInRole and isUserInRole respectively. Unfortunately not all real security threats can be handled from within the container.

        Denial Of Service attacks require man-in-the-middle and session hijacking to be addressed, typically outside the container – at the network layer. Additionally, nothing can be done to prevent social engineering. That’s a human only vector.

        Saturday, September 24, 2011

        JMS Header Values, who sets what

        JMS API defines headers for messages that are sent asynchronously to a message destination (Queue or Topic).

        A Client that sends a message has the ability to select 3 values:

        1. JMSCorrelationID

        2. JMSReplyTo

        3. JMSType

         

        These 3 values have meaning to the receiver of the message, and may have pre-defined semantics.

        These can be useful to Browse the messages, a QueueBrowser object can read and display messages that are sitting in the queue by reading its header messages. Note, that the API doesn’t support browsing topics. It is advisable to keep an internal xml database record of messages that are destined for a topic, and wrap the commit atomically using a 2 phased commit protocol.

        The Human-AI Partnership: Why Mastering Touch Typing is Your Next Generative AI Superpower

        Generative AI requires humans to establish thought partnership rather than allow AI to take over critical thinking skills. I believe that ty...