240 likes | 343 Views
WS/XML Service Utility Library (WS and LEGO?). Aleksander Slominski. XML Web Services Fusion. Transport (ex. HTTP). Security (XML dsig.). WS/XML Service. RPC style. Reliable Messaging. Type Mapping. Future? WS-Stuff. Puzzle of WS-Standards? How to connect blocks? XML Infoset
E N D
WS/XML Service Utility Library(WS and LEGO?) Aleksander Slominski
XML Web Services Fusion Transport (ex. HTTP) Security (XML dsig.) WS/XMLService RPC style Reliable Messaging Type Mapping Future?WS-Stuff
Puzzle of WS-Standards? How to connect blocks? XML Infoset Unlimited Number Of Connections As much as you need?! Build Your Own LEGO Set Keep Experimenting! LEGO comes from Danish words "LEg GOdt" meaning "play well". Ironically, in Latin the lego means "I study" or "I put together" WS/LEGO Game
More Bricks,More Fun Reliable Messaging Layer RPC Layer DSig Layer HTTP Transport SMTP Transport
Virtual Laboratory • Toolset: Very Quick XML Service Creation • Allow Building Any Kind of XML Services • From XML router to RMI runtime • Encourage Experimentations • Set of Small Modules • Allow Easy Code Recombination • XML Infoset as connecting glue
XSUL Layers Client Stack Server Stack Soap RPC Client Invoke Java interface Type Mapping (XML Java) Soap RPC Service Use Java Object Invoker send XML document Processor receive XML document Pluggable Module SOAP/HTTP Invoker SOAP/HTTP Processor Globus / XML Digital sig. HTTP 1.x Client (HTTP 1.x POST/GET) HTTP 1.x Server (HTTP 1.x POST/GET) Common / Utility Legend: depends on XML Infoset
Modules Theory vs. Practice
HTTP Client private HttpClientConnectionManagerconnMgr = HttpClientConnectionManager.newInstance(); HttpClientRequest req = connMgr.connect(host, port, 4 * 60 * 1000); req.setRequestLine("POST", requestUri, "HTTP/1.0"); HttpClientResponse resp = req.sendHeaders(); OutputStream out = resp.getBodyOutputStream(); Writer utf8Writer = new Utf8Writer(out, 8*1024); …more
Invoker (SOAP 1.1 / HTTP) Soap11HttpDynamicInfosetInvoker invoker = new Soap11HttpDynamicInfosetInvoker() invoker.setLocation("http://localhost:"+port); XmlElement request = builder.parseFragmentFromReader(new StringReader("<getN><arg>/hello</></>")); XmlElement response = invoker.invokeMessage(request);
SOAP RPC Client TypeHandlerRegistrytypeMapping= XsdTypeHandlerRegistry.getInstance(); Soap11InvocationHandlerhandler = new Soap11InvocationHandler(invoker, typeMapping); XDirectoryService ref = (XDirectoryService) Proxy.newProxyInstance( Thread.currentThread().getContextClassLoader(), new Class[] { XDirectoryService.class }, handler); XmlNode result = ref.getNode("/hello");
Client Stack • RPC Client • Translates Java Interface into XML message • Invoker (SOAP 1.1 / HTTP) • XML Message is wrapped into SOAP 1.1 Envelope and serialized into transport output stream • HTTP Client • Actual sending happens here! • Design Issues • Can add new transport (new invoker)? • Can inject XML processing layers? • XML transformations: digital signatures?
Adding DSig Module To Client App Soap11HttpDynamicInfosetInvoker invoker = new Soap11HttpDynamicInfosetInvoker() { public XmlDocument invokeXml(XmlDocument request) throws DynamicInfosetInvokerException { // WSRMHandler.getInstance().augmentRequest(request); XmlDocument signedRequest = GlobusCredSOAPEnvelopeSigner.getInstance().signSoapMessage(request); XmlDocument response = super.invokeXml(signedRequest); GlobusCredSOAPEnvelopeVerifier.getInstance().verifySoapMessage(response); // WSRMHandler.getInstance().processResponse(response); return response; } };
HTTP Server server = new HttpMiniServer(serverPort); servlet= new MyServlet(); server.useServlet(servlet); server.startServer(); class MyServlet extends HttpMiniServlet { public void service(HttpServerRequest req, HttpServerResponse res) { …more } }
Processor (SOAP 1.1 / HTTP) Soap11HttpDynamicInfosetProcessor processor = new Soap11HttpDynamicInfosetProcessor() { public XmlElement processMessage(XmlElement message) { message.setParent(null); message.setName(message.getName()+"Response"); return message; } }; processor.setServerPort(port); processor.start(); Full SOAP Echo Service Impl!
SOAP RPC Server TypeHandlerRegistrytypeMapping= XsdTypeHandlerRegistry.getInstance() XDirectoryService serviceLogic = new XDirectoryServiceImpl(); final Soap11ReflectionBasedService service = new Soap11ReflectionBasedService(serviceLogic, typeMapping); … Soap11HttpDynamicInfosetProcessor processor = new Soap11HttpDynamicInfosetProcessor() { public XmlElement processMessage(XmlElement requestMsg) { XmlElement responseMsg = service.processMessage(requestMsg); return responseMsg; } };
Server Stack • RPC Server • User Java Reflection to convert XML message into Java invocation • Processor (SOAP 1.1 / HTTP) • Accept XML Message that is wrapped into SOAP 1.1 Envelope and unwrap it • HTTP Server • Listen for XML messages! • Design Issues • Can add new transport (new listening server) • Can inject XML processing layers • XML transformations: digital signatures and authorization checks?
Using DSig/Authz in App Soap11HttpDynamicInfosetProcessor processor = new Soap11HttpDynamicInfosetProcessor() { public XmlDocument processSoap11Envelope(XmlElement envelope) { XmlDocument respDoc = null; SignatureInfo si = SOAPEnvelopeVerifier.getInstance().verifySoapMessage(envelope); if(!isAuthorized(si.getSubjectDn(), envelope)) { XmlDocument fault = Soap11Util.wrapBodyContent(Soap11Util.generateSoap11Fault( XmlConstants.NS_URI_SOAP11, "Client", "unathorized access")); respDoc = fault; } else { respDoc = super.processSoap11Envelope(envelope); } XmlDocument signedDoc = GlobusCredSOAPEnvelopeSigner.getInstance().signSoapMessage(respDoc); return signedDoc; } };
WORK IN PROGRESS!!! • OSS site (CVS hosted in SourceForge) • www.extreme.indiana.edu/xgws/xsul • www.extreme.indiana.edu/viewcvs/xsul • WikiWiki And Blog • portal.extreme.indiana.edu:3456/xsul • Place to Track Progress And Gather Feedback • Bugzilla • www.extreme.indiana.edu/bugs • Your Feedback is Welcome • Use Modules and Build Your Own Module
Conclusions • Encourages experimentation • LEGO “experience” • Easy to add new modules • WS-RM, WSS4J, WSDL Invoker, … • Better Than CORBA? • Maybe … • … but higher “playability” level • Add what needed • Piece by piece …
Addendum As More is Better …
Adding Caching to Improve DSig Performance Soap11HttpDynamicInfosetProcessor processor = new Soap11HttpDynamicInfosetProcessor() { public XmlDocument processSoap11Envelope(XmlElement envelope) { XmlDocument respDoc = null; if( (respDoc = lookupCachedResponse(envelope) ) != null ) { { //NOTE: needs to check that request is idempotent and resource is not changed! return respDoc; } SignatureInfo si = GlobusCredSOAPEnvelopeVerifier.getInstance().verifySoapMessage(envelope); if(!isAuthorized(si.getSubjectDn(), envelope)) { XmlDocument fault = Soap11Util.wrapBodyContent(Soap11Util.generateSoap11Fault( XmlConstants.NS_URI_SOAP11, "Client", "unathorized access")); respDoc = fault; } else { XmlDocument respDoc = super.processSoap11Envelope(envelope); } XmlDocument signedDoc = GlobusCredSOAPEnvelopeSigner.getInstance().signSoapMessage(respDoc); return signedDoc; } };
Generate SOAP call Sign Send … wait Receive Verify DSig Pass result Receive SOAP Message Verify DSig Reflection Based Invocation Sign Send SOAP Message DSig Steps Breakdown Client Server
RPC Client implementation details(Using Dynamic Proxy, without WSDL) class Soap11InvocationHandler implements InvocationHandler { public Object invoke(Object proxy, Method method, Object[] params) throws Throwable { String methodName = method.getName(); XmlElement request = builder.newFragment( methodName ); for (int i = 0; i < params.length; i++) { XmlElement param = registry.javaToXmlElement(params[i],null, "param"+i); request.addChild(param); } XmlElement response = invoker.invokeMessage(request); // map back to Java return type or Exception if S:Fault … }
Client Side APIs WSDL/RMI GlobalWeatherSoap gws = (GlobalWeatherSoap) WsdlNaming.lookup("http://www.example.com/weather?WSDL"); String s = gws.GetWeather(cityName, countryName) WSDL/Dynamic Proxy Stub GlobalWeatherSoap ref = (GlobalWeatherSoap) WsdlNaming.lookup("http://www.example.com/weather?WSDL“, GlobalWeatherSoap.class); String s = gws.GetWeather(cityName, countryName) WSDL/Dynamic Invocation Interface (DII) WsdlDynamicInfosetInvoker dii = WsdlNaming.lookup("http://www.example.com/weather?WSDL"); //NOTE: invoke() uses new JDK 1.5 multi args. “...” instead new Object[] {}); XmlElement result = dii.invoke("GetWeather", cityName, countryName); String cityName = result.string("cityName");