this the a web technology that is used in many web applications . xmlrpc is mainly used to transport request for input parameter and output parameters .
Database Programming: The Design of JDBC, The Structured Query Language, Basic JDBC Programming Concepts,
Result Sets, Metadata, Row Sets, Transactions
This document discusses Java Database Connectivity (JDBC) and provides details on connecting to a database from a Java application. There are 4 types of JDBC drivers that enable connection. Connecting involves 5 steps - registering the driver class, creating a connection, creating a statement, executing queries, and closing the connection. Examples are provided for connecting to MySQL and MS Access databases.
The document discusses using JDBC (Java Database Connectivity) for object-relational mapping in Java. It covers connecting to databases, executing SQL statements and queries, working with ResultSets, and best practices for managing database connections. Key points include using the DriverManager class to obtain database connections, preparing statements for parameterized queries, and implementing a DAO (Data Access Object) layer to encapsulate data access logic.
The document provides an overview of AJAX and web services. It discusses AJAX architecture and how it uses XMLHttpRequest objects to asynchronously exchange data with web servers without reloading pages. It also covers web services, describing them as software modules that can be published, located, and invoked over a network to perform tasks. The key components of web services are defined as SOAP, WSDL, and UDDI, which handle messaging, description, and discovery.
Description:
This project is an online Chat Room System which is built in Java Swing. The system adopts 3 tier architecture in which the client request server to register itself to the room, server register’s the user to the room and finally the client can share content with other registered client via server.
The system allows the user to connect from different location in a common chat-room where they can broadcast text messages and share drawing with other registered users.
Features:
• Apart from sharing content, the server broadcast entry and exist of the user.
• The chat window of every user is registered with client specific Title.
• Messages from client are pre-pend with their name.
• Cosmetic color change is implemented on-hover, on-active on the chat window, its borders and buttons.
• System allows tracking the user who is currently present in the chat room.
• System has the feature to save text messages/history in a text file from the chat window to the client local system.
The document discusses the servlet model and how servlets handle HTTP requests and responses. Some key points:
- Servlets use doXXX methods like doGet, doPost to handle different HTTP request methods. These methods receive a request and response object to access data and send a response.
- The request object provides access to parameters, headers, and attributes while the response object sets headers and content type for the response.
- Sessions allow servlets to access user data across multiple requests using attributes. Cookies can also be used to manage sessions between the client and server.
The document provides templates and examples for creating Swing-based GUI applications, servlets, Java Server Pages (JSP), Java Database Connectivity (JDBC), Java Server Faces (JSF), Enterprise Java Beans (EJB), Hibernate, Struts, and web services in Java. It includes templates for common GUI components, servlets, JSP tags, database queries, managed beans, navigation rules, entity beans, Hibernate mappings, actions, and web service providers/consumers.
This document provides an overview of Java servlets. It defines servlets as Java programs that extend the capabilities of servers and respond to web requests. It compares servlets to CGI scripts, noting that servlets have better performance since they use threads instead of processes to handle requests. The document outlines the servlet lifecycle and architecture, how to create a servlet class, and key interfaces in the servlet API like Servlet, GenericServlet, and HttpServlet.
Database Programming: The Design of JDBC, The Structured Query Language, Basic JDBC Programming Concepts,
Result Sets, Metadata, Row Sets, Transactions
This document discusses Java Database Connectivity (JDBC) and provides details on connecting to a database from a Java application. There are 4 types of JDBC drivers that enable connection. Connecting involves 5 steps - registering the driver class, creating a connection, creating a statement, executing queries, and closing the connection. Examples are provided for connecting to MySQL and MS Access databases.
The document discusses using JDBC (Java Database Connectivity) for object-relational mapping in Java. It covers connecting to databases, executing SQL statements and queries, working with ResultSets, and best practices for managing database connections. Key points include using the DriverManager class to obtain database connections, preparing statements for parameterized queries, and implementing a DAO (Data Access Object) layer to encapsulate data access logic.
The document provides an overview of AJAX and web services. It discusses AJAX architecture and how it uses XMLHttpRequest objects to asynchronously exchange data with web servers without reloading pages. It also covers web services, describing them as software modules that can be published, located, and invoked over a network to perform tasks. The key components of web services are defined as SOAP, WSDL, and UDDI, which handle messaging, description, and discovery.
Description:
This project is an online Chat Room System which is built in Java Swing. The system adopts 3 tier architecture in which the client request server to register itself to the room, server register’s the user to the room and finally the client can share content with other registered client via server.
The system allows the user to connect from different location in a common chat-room where they can broadcast text messages and share drawing with other registered users.
Features:
• Apart from sharing content, the server broadcast entry and exist of the user.
• The chat window of every user is registered with client specific Title.
• Messages from client are pre-pend with their name.
• Cosmetic color change is implemented on-hover, on-active on the chat window, its borders and buttons.
• System allows tracking the user who is currently present in the chat room.
• System has the feature to save text messages/history in a text file from the chat window to the client local system.
The document discusses the servlet model and how servlets handle HTTP requests and responses. Some key points:
- Servlets use doXXX methods like doGet, doPost to handle different HTTP request methods. These methods receive a request and response object to access data and send a response.
- The request object provides access to parameters, headers, and attributes while the response object sets headers and content type for the response.
- Sessions allow servlets to access user data across multiple requests using attributes. Cookies can also be used to manage sessions between the client and server.
The document provides templates and examples for creating Swing-based GUI applications, servlets, Java Server Pages (JSP), Java Database Connectivity (JDBC), Java Server Faces (JSF), Enterprise Java Beans (EJB), Hibernate, Struts, and web services in Java. It includes templates for common GUI components, servlets, JSP tags, database queries, managed beans, navigation rules, entity beans, Hibernate mappings, actions, and web service providers/consumers.
This document provides an overview of Java servlets. It defines servlets as Java programs that extend the capabilities of servers and respond to web requests. It compares servlets to CGI scripts, noting that servlets have better performance since they use threads instead of processes to handle requests. The document outlines the servlet lifecycle and architecture, how to create a servlet class, and key interfaces in the servlet API like Servlet, GenericServlet, and HttpServlet.
1) The document discusses XPath, an XML query language used to select nodes from an XML document. It provides examples of how XPath can be used to query nodes based on attributes, children, and other properties.
2) The document then discusses how XPath injection could allow an attacker to bypass authentication, bypass business logic, or extract arbitrary data from an XML database if user input is not sanitized in XPath queries.
3) Useful XPath functions like count, name, substring are demonstrated that could help an attacker crawl through and extract information from an XML structure. True/false-based blind XPath injection techniques are also presented.
The document outlines the content of a Java threading module which includes processes, threads, creating threads using the Thread class and Runnable interface, thread priority, and network server thread programming. It provides code examples of defining and starting threads using both Thread and Runnable, setting thread priority, and creating a multi-threaded network server using threads to handle client connections and requests.
This document provides code for implementing remote method invocation (RMI) between a client and server in Java. It includes code for the interface, server, and client. The interface defines the remote method. The server implements the interface and exports the remote object. It registers the object with the RMI registry. The client looks up the remote object from the registry and invokes the remote method on the server. The client and server communicate over RMI to call the method remotely.
Network programming in java - PPT with Easy Programs and examples of Java InetAddress Class and java socket programming example.
Learn more @ http://java2all.com/technology/network-programming
The document discusses Structured Query Language (SQL) and Java Database Connectivity (JDBC). It provides examples of using SQL statements like SELECT, INSERT, UPDATE, DELETE to query and manipulate data in database tables. It also demonstrates how to connect to databases like MySQL from Java using JDBC, execute SQL queries to retrieve and manipulate data, handle transactions and exceptions. Key classes discussed are Connection, Statement, PreparedStatement, CallableStatement and their methods.
This document discusses XML and XPath injection vulnerabilities. It begins with an overview of XML basics like structure and components. It then covers different types of XML injections like in node attributes, node values, and CDATA sections. Next, it discusses XPath basics like syntax and functions. The document outlines techniques for XPath injection vulnerabilities, including blind XPath injection to extract XML file structure. It concludes with recommendations for XPath injection tools and references.
This document describes the dw::Runtime module in DataWeave, which contains functions that allow interaction with the DataWeave engine. It defines several functions including fail, failIf, locationString, orElse, orElseTry, prop, and props. These functions allow throwing exceptions, conditional failure, getting location strings, chaining try blocks, retrieving properties, and more. Examples are provided for each function to demonstrate their usage.
The document describes the steps to develop a simple remote method invocation (RMI) application in Java. It includes:
1. Defining a remote interface with methods like addition, subtraction etc.
2. Implementing the interface in a class that defines the method bodies.
3. Creating a server class that binds the remote object to the registry.
4. Making a client class that looks up the remote object and calls methods.
5. Compiling the classes, running the registry, then server and client separately to test the application.
EJB 3.0 introduced major changes from previous EJB versions to address criticisms and simplify development. Key changes include support for POJO-based development with annotations, optional deployment descriptors, the removal of home interfaces, and a new entity persistence model based on Hibernate that allows for ORM-style development and querying. The presentation provides examples to illustrate how sessions, dependencies, interceptors, and entity relationships work in EJB 3.0 compared to previous versions.
The document provides an overview of various Android training topics including threads and concurrency, using SD cards, XML and JSON parsing, accessing phone status information, and monitoring network connectivity. It discusses common concurrency constructs in Android like Handler and AsyncTask. It also covers permissions needed to access phone services, using the TelephonyManager class to listen to call and data states, and monitoring battery status. Code samples are provided for tasks like XML parsing, JSON parsing, accessing phone states, and tracking battery level. The document aims to educate developers on key aspects of Android application development.
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Knoldus Inc.
This document provides an introduction and overview of the Play web application framework. It discusses key components of Play like Actions, Controllers, Results, routing, templates, and forms. It also covers how to develop a basic application using Play including setting up a new project, defining routes and controllers, rendering templates, and submitting forms. Finally, it demonstrates persisting application data in a database.
The document discusses using Ajax with jQuery to make requests to a server. It provides an overview of Ajax, describes how to make GET and POST requests with jQuery's $.get() and $.getJSON() methods, and gives an example of loading dependent dropdowns by making cascading Ajax calls based on user selection. Key points covered include initializing XHR objects, handling responses, and loading/filtering HTML snippets or JSON data into the DOM.
This document provides an overview of Java servlets, including:
- Servlets reside on the server-side and generate dynamic web pages. They handle HTTP requests and responses.
- Servlets have a lifecycle of initialization, processing requests, and destruction. The servlet receives a request from the web server, processes it, and returns a response which is sent back to the client.
- Servlets offer advantages over CGI like better performance through multithreading and portability through the Java programming language. Common servlet APIs and interfaces are described.
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISEHitesh Mohapatra
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS
CREATING AND MANAGING ACTIVE DIRECTORY OBJECTS
CONFIGURING NETWORK SETTINGS ON WINDOWS SERVER
CREATING A WEB SITE
SELECTING, SORTING, AND DISPLAYING DATA
FILTERING OBJECTS AND ENUMERATING OBJECTS
Rhino Mocks is a .NET mocking framework that allows developers to easily create and setup mock objects to test interactions using unit tests. It generates both mocks, which allow expectations to be set and verified, and stubs, which simply return preset values without verification. The document provides examples of using Rhino Mocks to generate mocks and stubs of interfaces, set expectations on mocks, and verify mock interactions using the AAA (Arrange, Act, Assert) syntax. It also distinguishes between mocks and stubs.
JDBC stands for Java Database Connectivity and is an API that allows Java programs to execute SQL statements and retrieve results from a database. It uses JDBC drivers to connect to different database types and provides interfaces for establishing a connection, executing queries, and processing result sets. Some common uses of JDBC include building Java applications, applets, servlets, and JSPs that need to access and manipulate data stored in relational databases.
[3.3] Detection & exploitation of Xpath/Xquery Injections - Boris SavkovOWASP Russia
This document summarizes techniques for detecting and exploiting XPath and XQuery injections. It discusses Boolean-based, time-based, request-based, and union-based injection techniques and provides examples of vulnerable XML documents and code. Specific techniques covered include using functions like count(), string-length(), and substring() for Boolean-based injections, time delays with reverse() for time-based injections, and concatenating URLs and files with doc() and unparsed-text() for request-based injections.
This document defines key concepts in service-oriented architectures (SOA) including services, components, standards like SOAP, WSDL, and UDDI. It describes how SOA uses loosely coupled services that communicate through standardized web protocols. Services are defined through WSDL interfaces and discovered through UDDI directories. SOAP is the messaging standard used to enable communication between services. Orchestration and choreography standards like WS-BPEL and WS-CDL are used to compose services to create new composite applications and define allowable message exchanges.
This is a PHP talk about consuming web services, dealing with XML and JSON and serialised PHP. It covers use of services using SOAP, XML-RPC, JSON-RPC and some RESTful concepts with plenty of code examples. Examples of making web service clients using streams, pecl_http and curl are included
1) The document discusses XPath, an XML query language used to select nodes from an XML document. It provides examples of how XPath can be used to query nodes based on attributes, children, and other properties.
2) The document then discusses how XPath injection could allow an attacker to bypass authentication, bypass business logic, or extract arbitrary data from an XML database if user input is not sanitized in XPath queries.
3) Useful XPath functions like count, name, substring are demonstrated that could help an attacker crawl through and extract information from an XML structure. True/false-based blind XPath injection techniques are also presented.
The document outlines the content of a Java threading module which includes processes, threads, creating threads using the Thread class and Runnable interface, thread priority, and network server thread programming. It provides code examples of defining and starting threads using both Thread and Runnable, setting thread priority, and creating a multi-threaded network server using threads to handle client connections and requests.
This document provides code for implementing remote method invocation (RMI) between a client and server in Java. It includes code for the interface, server, and client. The interface defines the remote method. The server implements the interface and exports the remote object. It registers the object with the RMI registry. The client looks up the remote object from the registry and invokes the remote method on the server. The client and server communicate over RMI to call the method remotely.
Network programming in java - PPT with Easy Programs and examples of Java InetAddress Class and java socket programming example.
Learn more @ http://java2all.com/technology/network-programming
The document discusses Structured Query Language (SQL) and Java Database Connectivity (JDBC). It provides examples of using SQL statements like SELECT, INSERT, UPDATE, DELETE to query and manipulate data in database tables. It also demonstrates how to connect to databases like MySQL from Java using JDBC, execute SQL queries to retrieve and manipulate data, handle transactions and exceptions. Key classes discussed are Connection, Statement, PreparedStatement, CallableStatement and their methods.
This document discusses XML and XPath injection vulnerabilities. It begins with an overview of XML basics like structure and components. It then covers different types of XML injections like in node attributes, node values, and CDATA sections. Next, it discusses XPath basics like syntax and functions. The document outlines techniques for XPath injection vulnerabilities, including blind XPath injection to extract XML file structure. It concludes with recommendations for XPath injection tools and references.
This document describes the dw::Runtime module in DataWeave, which contains functions that allow interaction with the DataWeave engine. It defines several functions including fail, failIf, locationString, orElse, orElseTry, prop, and props. These functions allow throwing exceptions, conditional failure, getting location strings, chaining try blocks, retrieving properties, and more. Examples are provided for each function to demonstrate their usage.
The document describes the steps to develop a simple remote method invocation (RMI) application in Java. It includes:
1. Defining a remote interface with methods like addition, subtraction etc.
2. Implementing the interface in a class that defines the method bodies.
3. Creating a server class that binds the remote object to the registry.
4. Making a client class that looks up the remote object and calls methods.
5. Compiling the classes, running the registry, then server and client separately to test the application.
EJB 3.0 introduced major changes from previous EJB versions to address criticisms and simplify development. Key changes include support for POJO-based development with annotations, optional deployment descriptors, the removal of home interfaces, and a new entity persistence model based on Hibernate that allows for ORM-style development and querying. The presentation provides examples to illustrate how sessions, dependencies, interceptors, and entity relationships work in EJB 3.0 compared to previous versions.
The document provides an overview of various Android training topics including threads and concurrency, using SD cards, XML and JSON parsing, accessing phone status information, and monitoring network connectivity. It discusses common concurrency constructs in Android like Handler and AsyncTask. It also covers permissions needed to access phone services, using the TelephonyManager class to listen to call and data states, and monitoring battery status. Code samples are provided for tasks like XML parsing, JSON parsing, accessing phone states, and tracking battery level. The document aims to educate developers on key aspects of Android application development.
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Knoldus Inc.
This document provides an introduction and overview of the Play web application framework. It discusses key components of Play like Actions, Controllers, Results, routing, templates, and forms. It also covers how to develop a basic application using Play including setting up a new project, defining routes and controllers, rendering templates, and submitting forms. Finally, it demonstrates persisting application data in a database.
The document discusses using Ajax with jQuery to make requests to a server. It provides an overview of Ajax, describes how to make GET and POST requests with jQuery's $.get() and $.getJSON() methods, and gives an example of loading dependent dropdowns by making cascading Ajax calls based on user selection. Key points covered include initializing XHR objects, handling responses, and loading/filtering HTML snippets or JSON data into the DOM.
This document provides an overview of Java servlets, including:
- Servlets reside on the server-side and generate dynamic web pages. They handle HTTP requests and responses.
- Servlets have a lifecycle of initialization, processing requests, and destruction. The servlet receives a request from the web server, processes it, and returns a response which is sent back to the client.
- Servlets offer advantages over CGI like better performance through multithreading and portability through the Java programming language. Common servlet APIs and interfaces are described.
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISEHitesh Mohapatra
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS
CREATING AND MANAGING ACTIVE DIRECTORY OBJECTS
CONFIGURING NETWORK SETTINGS ON WINDOWS SERVER
CREATING A WEB SITE
SELECTING, SORTING, AND DISPLAYING DATA
FILTERING OBJECTS AND ENUMERATING OBJECTS
Rhino Mocks is a .NET mocking framework that allows developers to easily create and setup mock objects to test interactions using unit tests. It generates both mocks, which allow expectations to be set and verified, and stubs, which simply return preset values without verification. The document provides examples of using Rhino Mocks to generate mocks and stubs of interfaces, set expectations on mocks, and verify mock interactions using the AAA (Arrange, Act, Assert) syntax. It also distinguishes between mocks and stubs.
JDBC stands for Java Database Connectivity and is an API that allows Java programs to execute SQL statements and retrieve results from a database. It uses JDBC drivers to connect to different database types and provides interfaces for establishing a connection, executing queries, and processing result sets. Some common uses of JDBC include building Java applications, applets, servlets, and JSPs that need to access and manipulate data stored in relational databases.
[3.3] Detection & exploitation of Xpath/Xquery Injections - Boris SavkovOWASP Russia
This document summarizes techniques for detecting and exploiting XPath and XQuery injections. It discusses Boolean-based, time-based, request-based, and union-based injection techniques and provides examples of vulnerable XML documents and code. Specific techniques covered include using functions like count(), string-length(), and substring() for Boolean-based injections, time delays with reverse() for time-based injections, and concatenating URLs and files with doc() and unparsed-text() for request-based injections.
This document defines key concepts in service-oriented architectures (SOA) including services, components, standards like SOAP, WSDL, and UDDI. It describes how SOA uses loosely coupled services that communicate through standardized web protocols. Services are defined through WSDL interfaces and discovered through UDDI directories. SOAP is the messaging standard used to enable communication between services. Orchestration and choreography standards like WS-BPEL and WS-CDL are used to compose services to create new composite applications and define allowable message exchanges.
This is a PHP talk about consuming web services, dealing with XML and JSON and serialised PHP. It covers use of services using SOAP, XML-RPC, JSON-RPC and some RESTful concepts with plenty of code examples. Examples of making web service clients using streams, pecl_http and curl are included
UDDI is a platform-independent framework for describing web services, discovering businesses, and integrating services over the Internet using a publicly available registry. It provides a standardized way to describe services, discover businesses, and view technical details through a registry implemented as a web service. Businesses can publish service descriptions to the registry to facilitate discovery and integration between services.
Short overview of the XML-RPC protocol for XML-based RPC services.
XML-RPC is a remote procedure call protocol using XML as data format and HTTP as transport protocol.
It is a simple mechanism to call remote procedures on a machine with a different operating system.
XML-RPC is language and platform independent. XML-RPC libraries are available in Java and other languages.
XML-RPC is not more than its name implies and thus is very simple and lean. This means that it lacks most of the features that SOAP/WSDL web services provide.
The document discusses different types of web services including XML-RPC, SOAP, and REST. It provides examples of consuming SOAP services in PHP and describes the simple REST API used by the popular bookmarking site Delicious, which allows resources to be easily accessed via URI endpoints for common operations like updating tags, retrieving posts, and managing bundles.
This document introduces web services and their key components. Web services allow different systems to communicate over the web through open standards like SOAP, WSDL and XML. SOAP defines how to structure service requests and responses as XML messages. WSDL provides an interface definition for web services by describing operations, messages and protocols. Together, SOAP and WSDL enable web services to expose functionality to clients in a standardized way.
Web services tutorial slides from my session at DPC 2012 in Amsterdam. In this 3-hour session we built the simplest possible service, and then extended it, looking at RPC, REST and SOAP along the way.
1. Introduction to Web Services
2. Web Service Architecture
3. What are Web Services?
4. Why are Web Services?
5. The base of WS
6. What is SOAP?
7. What is WSDL?
8. How to test a web service?
9. Examples
Abstract:
Jini has served Orbitz well, but at the cost of tight coupling due in part to shared code and Java™ platform serialization rules. To improve agility, Orbitz is migrating to a RESTful Web services architecture using protocol buffers to define message formats. The result is loosely coupled services with autonomous lifecycles supporting evolvability and innovative mashup-style development.
This session is intended for experienced architects and tech leads who are familiar with distributed systems and data encoding methods.
It covers
• Using document schemas to constitute language-neutral contracts
• Using standard HTTP plumbing and intermediaries
• Implementing a reverse proxy for request routing based on RESTful URLs
• Applying OLAs for governance and service isolation
• Writing automated service layer tests to ensure backward compatibility
The document discusses object oriented programming concepts. It describes key object oriented programming concepts like encapsulation, inheritance, polymorphism, and message passing. It also discusses benefits of object oriented programming like modularity, reusability and extensibility. Some disadvantages discussed are compiler overhead, runtime overhead and need for reorientation of developers to object oriented thinking. The document also covers C++ programming concepts like data types, control flow, functions, arrays, strings, pointers and storage classes.
1.1 For each of the HTTP methods,GET,POST, andPUT, identifythe corresponding method in the HttpServletclass.
1.3 For each of the following operations, identify the interfaceand method name that should be used:
Retrieve HTML form parameters from the request
Retrieve a servlet initialization parameter
Retrieve HTTP request header information
Set an HTTP response header
set the content type of the response
Acquire a text stream for the response
Acquire a binary stream for the response
Redirect an HTTP request to another URL
1.4 Identify the interface and method to access values and resources and to set object attributes within the following three web scopes:
Request
Session
Context
1.5 Given a life-cycle method: init,service , or destroy, identify correct statements bout its purpose or about how and when it is invoked.
1.6 Use a RequestDispatcher to include or forward to a web resource.
Mining Code Examples with Descriptive Text from Software ArtifactsPreetha Chatterjee
The document describes an exploratory study conducted to understand the types of information provided about code snippets embedded in different software-related documents. The study analyzed 60 documents across 12 categories and identified 17 labels and sub-labels for annotating the information about code snippets. Research papers were found to contain the most code snippets on average (8.6 per paper) with the longest descriptions (439 lines of text on average). The study aims to help develop techniques for mining relevant information from various document types to assist with software engineering tasks.
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...WebStackAcademy
Setting up a servlet environment
Servlets are Java programs that run on a Web server and build Web pages. Here are a few definitions:
Servlet Development Kits
Java Servlet Development Kit (JSDK) provides Servlet API classes (servlet.jar). Place servlet.jar into CLASSPATH, so that java classes can access it.
Servlet Engines
A servlet is a Java class that needs to be executed in a Java VM by servlet engine. The servlet engine loads the servlet class the first time the servlet is requested. The servlet then stays loaded to handle multiple requests until it is explicitly unloaded or the servlet engine is shut down.
Following are few WebServers that supports servlets:
Apache Tomcat
BEA WebLogic
IBM Websphere
Sun's Java Web Server (JWS)
Apache Tomcat.
Java Servlet Development Kit (JSDK)
My presentation at MWLUG 2015. I show how to build and connect a modern looking website, built with HTML, CSS, and Javascript/jQuery, to your existing IBM Domino backend data using Ajax and JSON and some simple Lotusscript code.
JDBC (Java Database Connectivity) provides a standard interface for connecting Java applications to different database systems. There are four main types of JDBC drivers:
1. JDBC-ODBC bridge driver - Used to connect to any ODBC compliant database. It is platform dependent.
2. Native-API (partially Java) driver - Uses a database vendor's native API. Faster than JDBC-ODBC but still platform dependent.
3. Network protocol driver - Uses a database-independent protocol like ODBC or SQL/CLI. Platform independent but not as fast as native.
4. Pure Java driver - Written entirely in Java. Fastest,
The document discusses Oracle system catalogs which contain metadata about database objects like tables and indexes. System catalogs allow accessing information through views with prefixes like USER, ALL, and DBA. Examples show how to query system catalog views to get information on tables, columns, indexes and views. Query optimization and evaluation are also covered, explaining how queries are parsed, an execution plan is generated, and the least cost plan is chosen.
This document discusses rule engines and the Drools rule engine. It provides an overview of rule engine concepts like facts, rules, and actions. It explains the different types of rules and why rule engines are useful. It then focuses on specifics of Drools, including how it represents facts as objects, supports different rule patterns and operators, and handles performance and conflict resolution. It also provides an example of how rules could be used for a data mining use case.
The document summarizes some of the key new features in Java 17 including:
1. Long-term support for Java 17 which will be available in September 2021 and include features like records, text blocks, and enhanced null pointer exceptions.
2. Records, text blocks, helpful null pointer exceptions, pattern matching for switches, and sealed classes as some of the top new features in Java 17.
3. Enhancements to pseudo-random number generators with a new RandomGenerator interface and refactoring of legacy random classes.
The document provides an overview of client-server technology, networking concepts like sockets and remote procedure calls, XML, web services, SOAP, and RESTful architectures. It defines key terms like web services, SOAP, WSDL, UDDI, and REST. It describes how SOAP uses XML to define an envelope and headers to package messages and how REST relies on lightweight HTTP to perform CRUD operations on resources identified by URIs.
1. The document provides an introduction to the Node.js course, covering topics like JavaScript basics, Node.js fundamentals, Express.js, debugging, and more.
2. Key concepts discussed include how the Node.js runtime works, using core modules, asynchronous programming with callbacks and promises, and the module system.
3. Express.js is introduced as a popular web framework that handles requests and responses, routing, and other complex server tasks so developers can focus on business logic. Debugging tools are also covered.
AJAX is a new approach to web application development that uses asynchronous JavaScript and XML to transmit small amounts of data in the background without interfering with the display and behavior of the existing page. Some key aspects of AJAX include asynchronous data retrieval using XMLHttpRequest, data interchange formats like XML/JSON, dynamic display using the DOM, and JavaScript binding it all together for a more responsive user experience compared to traditional full page loads. Common AJAX design patterns address issues like predictive fetching of likely next data, throttling frequent submissions, periodic refreshing of data, and multi-stage downloading of pages and components.
The document discusses server-side programming and Java 2 Enterprise Edition (J2EE). It explains what J2EE is, its architecture and components. It describes the lifecycle of a servlet, including initialization, request handling, and destruction. It also discusses session management techniques in servlets like using cookies, URL rewriting, and hidden form fields to track user requests across multiple pages. Exception handling using request dispatchers is also covered.
GAC Java Presentation_Server Side Include_Cookies_Filters 2022.pptCUO VEERANAN VEERANAN
This document provides information about Server Side Includes (SSI) and how they allow embedding instructions inside HTML documents to add dynamic content. SSI uses special tags and the file must have a .shtml extension. It discusses how servlets can also be used to add dynamic content. The document then covers Server Side Include tags and provides an example. It also discusses cookies, how they work, and some cookie methods. Finally, it summarizes what filters are, their benefits, types, how to program them, and how they are registered and mapped to servlets.
This document discusses Python database programming. It introduces databases and how they store data in tables connected through columns. It discusses SQL for creating, accessing, and manipulating database data. It then discusses how Python supports various databases and database operations. It covers the Python DB-API for providing a standard interface for database programming. It provides examples of connecting to a database, executing queries, and retrieving and inserting data.
The document provides an introduction to stored procedures in SQL. Key points include:
- Stored procedures allow code to be executed faster than batches by pre-compiling the code.
- They centralize business logic and error handling routines for consistent implementation across users.
- Parameters can be passed into stored procedures to make them more flexible. Output parameters allow returning values.
- Best practices include adding comments, error handling, and using transactions for consistency across nested stored procedures.
The document provides an introduction to stored procedures in SQL. Key points include:
- Stored procedures allow code to be executed as a batch after being compiled once, improving performance over executing individual SQL statements.
- Stored procedures can accept input parameters, return output parameters, and be used to enforce consistent implementation of business logic and error handling.
- Best practices for stored procedures include adding documentation, error handling, and using input/output parameters to make procedures more flexible and reusable.
The document discusses SOAP services in Mule ESB. It begins by defining web services as interfaces that allow network access through standardized XML messaging. SOAP is introduced as a protocol for web service messaging and invocation that takes advantage of XML namespaces and schemas. The document then covers SOAP architecture, including the envelope, header and body, as well as examples of SOAP messages for remote procedure calls.
1. XML-RPC Copyright 2006 by Ken Slonneger 1
XML-RPC
XML-RPC is a protocol that uses XML to describe method
calls and method results, and a collection of implementations
that allow software running on disparate operating systems,
running in different environments (different programming
languages) to make method calls to each other over the
internet.
RPC stands for Remote Procedure Call.
Other Solutions to this Problem
CORBA
• Common Object Request Broker Architecture
• Designed for interoperability between different languages
as well as different machines.
DCOM or COM
• Distributed Component Object Model
• Interoperability between different machines and languages
as long as they are Wintel.
RMI
• Remote Method Invocation (Java only).
• Interoperability for any machines that are running the Java
virtual machine.
These solutions are complex and opaque, relying on
particular platforms or programming languages, or dependent
on a complicated methodology for describing data types.
2. 2 Copyright 2006 by Ken Slonneger XML-RPC
Properties of XML-RPC
• Designed to be as simple as possible, solving only part
of the problem, but solving the most important part.
Nonprogrammers can write XML-RPC calls.
• Encodes messages for calling methods and describing
the results of method calls with a standard vocabulary
using XML.
• Has a limited vocabulary of XML tags for describing the
types of parameters and the type of a return value from
a function.
• Uses HTTP as the transport over the internet.
• HTTP is normally used for person-to-person communication
between a browser and a server using HTML.
• XML-RPC uses HTTP for computer-to-computer
communication with no browser involved.
• Using HTTP allows XML-RPC communication to bypass
firewalls.
• Many implementations of XML-RPC servers and XML-RPC
clients are available currently.
• See www.xmlrpc.com for more information.
3. XML-RPC Copyright 2006 by Ken Slonneger 3
XML-RPC Lifecyle
Client Side Server Side
1. Client builds an XML
element methodCall that
names the method to be
called and provides the
actual parameters for the
method.
2. Client sends a POST
request whose payload
(content) is the XML
element just built.
3.Server receives the request
and uses the HTTP header
Content-Length to read the
payload XML element.
4.Server parses the XML
element, extracts the
method name, and retrieves
the actual parameters for
the method from the XML
element.
5.Server searches for the
desired method and, if
found, invokes it with the
given parameters.
6.If the method is called and
executes successfully, the
server packages its return
value in an XML element
methodResponse with a
params element and sends
it back to the client.
4. 4 Copyright 2006 by Ken Slonneger XML-RPC
7.If the method is not found
or cannot be executed for
some reason, the server
builds an XML element
methodResponse whose
value element contains a
fault element and sends it
back to the client.
8. Client receives the re-
sponse, parses the XML
element returned (a return
value or fault), and reports
the outcome to the client
user.
Data Types in XML-RPC
Integers (32-bit values)
Elements: int or i4
Examples: <int>3928</int>
<i4>-703</i4>
Floating-point Values
Element: double
Examples: <double>5.489</double>
<double>-877.23</double>
Boolean Values
Element: boolean
Examples: <boolean>0</boolean>
<boolean>1</boolean>
5. XML-RPC Copyright 2006 by Ken Slonneger 5
Strings (ascii characters)
Element: string
Examples: <string>This is a short string.</string>
<string>May need entity references.</string>
Date and Time
Element: dateTime.iso8601
Format: ccyymmddThh:mm:ss
Example: <dateTime.iso8601>
20061208T15:04:45
</dateTime.iso8601>
Binary Data
Element: base64
Example: <base64>
VGhpcyBpcyBhIHNob3J0IHN0cmluZy4K
</base64>
Arrays
Element: array
Example: <array>
<data>
<value>
<double>43.7</double>
</value>
<value>
<double>91.3</double>
</value>
<value>
<double>18.8</double>
</value>
<value>
<double>33.6</double>
</value>
</data>
</array>
6. 6 Copyright 2006 by Ken Slonneger XML-RPC
Structures or Records
Element: struct
Format: An unordered list of member elements, each
of which contains a name element and a
value element.
Example: <struct>
<member>
<name>spots1</name>
<value><int>5</int></value>
</member>
<member>
<name>spots2</name>
<value><int>9</int></value>
</member>
<member>
<name>faceUp</name>
<value><boolean>1</boolean></value>
</member>
</struct>
Correspondence with Types in Java
XML-RPC Type Java Type
int and i4 int
double double
boolean boolean
string String
dateTime.iso8601 ?
base64 byte [] or String
array array object
struct Map object
7. XML-RPC Copyright 2006 by Ken Slonneger 7
Method Calls
A method call is defined by the methodCall element, which
contains two elements, methodName and params.
The params element contains zero or more param elements
that specify the actual parameters to be passed to the method.
Example
Suppose we have a Java method
double compute(int num, String str, boolean bn)
that we want to call, say compute(96, "A Java string", false)
XML Equivalent
<?xml version="1.0"?>
<methodCall>
<methodName>compute</methodName>
<params>
<param>
<value>
<int>96</int>
</value>
</param>
<param>
<value>
<string>A Java string</string>
</value>
</param>
<param>
<value>
<boolean>0</boolean>
</value>
</param>
</params>
</methodCall>
8. 8 Copyright 2006 by Ken Slonneger XML-RPC
Method Responses
A method returns at most one value.
That value is defined as a single parameter inside a params
element inside a methodResponse element.
Example
Suppose the compute method returns the value 16.25.
XML Code
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value>
<double>16.25</double>
</value>
</param>
</params>
</methodResponse>
If the method cannot be executed for some reason, say it can
not be found, the methodResponse element will contain a fault
element with a value element that has a struct element to
describe the mistake.
XML Code
<?xml version="1.0"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>fault</name>
<value><int>99</int></value>
</member>
9. XML-RPC Copyright 2006 by Ken Slonneger 9
<member>
<name>faultString</name>
<value>
<string>No such method</string>
</value>
</member>
</struct>
<value>
</fault>
</methodResponse>
This response indicates that the method called can not be
found.
Other faults might describe computations that went awry for
some reason, resulting in an exception being thrown by the
method.
Another Example
Suppose the method called returns an array of int values.
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value>
<array>
<data>
<value><int>0</int></value>
<value><int>1</int></value>
<value><int>8</int></value>
<value><int>27</int></value>
<value><int>64</int></value>
</data>
</array>
</value>
</param>
</params>
</methodResponse>
10. 10 Copyright 2006 by Ken Slonneger XML-RPC
DTD for XML-RPC
<!ELEMENT methodCall (methodName, params)>
<!ELEMENT methodName (#PCDATA)>
<!ELEMENT params (param*)>
<!ELEMENT param (value)>
<!ELEMENT value (i4 | int | string | double | boolean |
dateTime.iso8601 | base64 |
struct | array)>
<!ELEMENT i4 (#PCDATA)>
<!ELEMENT int (#PCDATA)>
<!ELEMENT double (#PCDATA)>
<!ELEMENT boolean (#PCDATA)>
<!ELEMENT string (#PCDATA)>
<!ELEMENT dateTime.iso8601 (#PCDATA)>
<!ELEMENT base64 (#PCDATA)>
<!ELEMENT array (data)>
<!ELEMENT data (value*)>
<!ELEMENT struct (member+)>
<!ELEMENT member (name, value)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT methodResponse (params | fault)>
<!ELEMENT fault (value)>
15. XML-RPC Copyright 2006 by Ken Slonneger 15
Using HTTP for XML-RPC
Both method calls and method responses are sent
using HTTP.
Both kinds of message require certain header values
to be included.
Method Call
POST / HTTP 1.1
Host: server host name
User-Agent: software making the request
Content-Type: text/xml
Content-Length: number of bytes in payload
payload
Method Response
HTTP 200 OK
Content-Type: text/xml
Content-Length: number of bytes in payload
payload
The method response sends the code 200 no matter what
happens with the method execution.
The HTTP response indicates success, but the content of
the message (the payload) can show method failure by a
fault element.
Note that XML-RPC has no standard or predefined error
codes for the fault element in a method response.
16. 16 Copyright 2006 by Ken Slonneger XML-RPC
Implementing XML-RPC
Many implementations of XML-RPC have been developed, but
they are not always easy to install.
To illustrate the basic idea, we provide a relatively simple
implementation of an XML-RPC server and an XML-RPC
client written in Java.
This system has weak error handling capabilities, but works
fine when given correct XML messages.
Server Side
We begin on the server side where four classes provide the
functionality of an XML-RPC server.
The first class creates a ServerSocket and waits for clients
to connect to the server.
When a connection is made, the Socket object is passed
on to a thread that handles the communication between
the server and the client.
File: Server.java
import java.io.*;
import java.net.*;
public class Server
{
public static void main(String [] args) throws IOException
{
ServerSocket serversocket = new ServerSocket(8000);
System.out.println(
"HTTP Server running on port 8000.");
System.out.println("Use control-c to stop server.");
17. XML-RPC Copyright 2006 by Ken Slonneger 17
while (true)
{
Socket sock = serversocket.accept();
String client = sock.getInetAddress().getHostName();
System.out.println("Connected to client " + client);
new Handler(sock).start();
}
}
}
The Handler class does most of the work on the server side.
Parsing the headers in the HTTP request and retrieving the
payload is done by the Request class, which comes after the
Handler code.
The Handler class parses the XML payload from the request
to identify the method name and the actual parameters to the
method.
It then uses Java Reflection to find the method requested and
invoke it on the actual parameters.
The function call RpcMethods.class.getMethods() returns an
array of all public methods available to the RpcMethods class.
This array of Method objects is searched for the one we want.
The response to the client is built from the result produced by
the method call. In so doing, we use a number of methods for
converting Java values, simple and array, into the strings that
XML-RPC expects.
The various tasks performed by the server are labeled with
the steps for the XML-RPC lifecycle.
These utility methods are described with comments in the
Java code.
Sections of the main processing code, found in the run
method, are labeled to describe the stages of the XML-RPC
lifecycle that are being dealt with.
18. 18 Copyright 2006 by Ken Slonneger XML-RPC
File: Handler.java
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import java.lang.reflect.*;
import java.io.*;
import java.net.*;
import java.util.*;
public class Handler extends Thread
{
private Socket sock;
Handler(Socket sk)
{ sock = sk; }
public void run()
{
/* 3. Read request (method call) from client */
try
{
BufferedInputStream bis =
new BufferedInputStream(
sock.getInputStream());
byte [] buffer = new byte [2000];
int num = bis.read(buffer);
System.out.println("Handler got " + num + " bytes.");
byte [] request = new byte [num];
System.arraycopy(buffer, 0, request, 0, num);
19. XML-RPC Copyright 2006 by Ken Slonneger 19
Request req = new Request(request);
byte [] xmlrpcRequest = req.getContent();
/* 4. Parse method call */
byte [] response;
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder domParser =
factory.newDocumentBuilder();
Document dom = null;
try
{ dom = domParser.parse(new InutSource(
new StringReader(
new String(xmlrpcRequest))));
}
catch (SAXException e)
{ response = e.getMessage().getBytes(); }
Element el =
(Element)dom.getElementsByTagName(
"methodName").item(0);
String methodName =
el.getFirstChild().getNodeValue();
NodeList parms =
dom.getElementsByTagName("param");
List<Object> pList = new ArrayList<Object>();
for (int k=0; k<parms.getLength(); k++)
{
Node parm = parms.item(k);
Node value = parm.getFirstChild();
Node type = value.getFirstChild();
Node actVal = type.getFirstChild();
Object ob =
mapArgToType(type.getNodeName(), actVal);
pList.add(ob);
}
20. 20 Copyright 2006 by Ken Slonneger XML-RPC
/* 5. Search for method and call it */
Object [] args = new Object[pList.size()];
Class [] argTypes = new Class[pList.size()];
for (int k=0; k<pList.size(); k++)
{
args[k] = pList.get(k);
argTypes[k] = pList.get(k).getClass();
}
String methodResponse = "";
try
{
Method [] meths = RpcMethods.class.getMethods();
Method m = null;
int k = 0;
boolean found = false;
while (k < meths.length && !found)
{
m = meths[k];
Class [] paramTypes = m.getParameterTypes();
if (m.getName().equals(methodName) &&
match(argTypes, paramTypes))
found = true;
k++;
}
if (found)
{
Object value = m.invoke(null, args);
/* 6. Build method response for a successful call */
StringBuffer returnValue = new StringBuffer();
if (value.getClass().isArray())
{ // Need to build array
Class cT =
value.getClass().getComponentType();
21. XML-RPC Copyright 2006 by Ken Slonneger 21
if (cT.isPrimitive())
value = wrap(value);
Object [] array = (Object [])value;
returnValue.append("<array><data>");
for (int k=0; k<array.length; k++)
returnValue.append("<value>" +
mapValueFromType(array[k])+"</value>");
returnValue.append("</data></array>");
}
else
returnValue.append(
mapValueFromType(value));
methodResponse =
"<?xml version="1.0"?>" +
"<methodResponse><params><param>" +
"<value>" + returnValue + "</value>" +
"</param></params></methodResponse>";
}
else // not found
/* 7. Build method response for a failed call */
methodResponse =
"<?xml version="1.0"?>" +
"<methodResponse><fault><value>" +
"<struct><member><name>fault</name>" +
"<value><int>88</int></value></member>" +
"<member><name>faultString</name>" +
"<value><string>No such method" +
"</string></value></member></struct>" +
"</value></fault></methodResponse>";
}
catch (Exception e)
{
methodResponse =
"<?xml version="1.0"?>" +
"<methodResponse><fault><value>" +
22. 22 Copyright 2006 by Ken Slonneger XML-RPC
"<struct><member><name>fault</name>" +
"<value><int>99</int></value></member>" +
"<member><name>faultString</name>" +
"<value><string> " + e.toString() +
"</string></value></member></struct>" +
"</value></fault></methodResponse>";
}
response = methodResponse.getBytes();
/* 6. and 7. Return response to client */
BufferedOutputStream client =
new BufferedOutputStream(
sock.getOutputStream());
String headers =
"HTTP 200 OKrn" +
"Content-Type: text/xml rn" +
"Content-Length: " + response.length +
"rnrn";
client.write(headers.getBytes());
client.write(response); // write data of payload
client.close();
}
catch (Exception e)
{ System.out.println(e); }
}
/* mapArgToType takes an XML-RPC type and a Node value
and returns that value as a Java object of the correct type. */
private Object mapArgToType(String type, Node value)
{
if (type.equals("i4") || type.equals("int"))
return new Integer(value.getNodeValue());
else if (type.equals("boolean"))
return
new Boolean("1".equals(value.getNodeValue()));
23. XML-RPC Copyright 2006 by Ken Slonneger 23
else if (type.equals("double"))
return new Double(value.getNodeValue());
else if (type.equals("string"))
return new String(value.getNodeValue());
else if (type.equals("array"))
return mkArray(value);
else return null;
}
/* mkArray takes the Node value and builds a Java array of
primitive components or strings from the data in the Node
value. */
private Object mkArray(Node value)
{
NodeList values = value.getChildNodes();
String compType =
values.item(0).getFirstChild().getNodeName();
if (compType.equals("int"))
{
int [] ia = new int [values.getLength()];
for (int k=0; k<values.getLength(); k++)
{
String ival =
values.item(k).getFirstChild().getNodeValue();
ia[k] = Integer.parseInt(ival);
}
return ia;
}
else if (compType.equals("double"))
{
double [] da = new double [values.getLength()];
for (int k=0; k<values.getLength(); k++)
{
String dval = values.item(k).getFirstChild().
getFirstChild().getNodeValue();
da[k] = Double.parseDouble(dval);
}
24. 24 Copyright 2006 by Ken Slonneger XML-RPC
return da;
}
else if (compType.equals("boolean"))
{
boolean [] ba = new boolean [values.getLength()];
for (int k=0; k<values.getLength(); k++)
{
String bval = values.item(k).getFirstChild().
getFirstChild().getNodeValue();
ba[k] = bval.equals("1");
}
return ba;
}
else if (compType.equals("string"))
{
String [] sa = new String [values.getLength()];
for (int k=0; k<values.getLength(); k++)
sa[k] = values.item(k).getFirstChild().
getFirstChild().getNodeValue();
return sa;
}
return null;
} // end of run method
/* mapValueFromType takes a Java object and creates a
corresponding XML-RPC element for its value. */
private String mapValueFromType(Object value)
{
Class type = value.getClass();
if (type.equals(Integer.class))
return "<int>" + value + "</int>";
else if (type.equals(Boolean.class))
return "<boolean>" +
(value.equals(new Boolean(true)):"1":"0") +
"</boolean>";
else if (type.equals(String.class))
return "<string>" + value + "</string>";
else if (type.equals(Double.class))
25. XML-RPC Copyright 2006 by Ken Slonneger 25
return "<double>" + value + "</double>";
else return "";
}
/* wrap takes a Java array of primitive values and returns a
corresponding Java array of wrapper values. */
private Object wrap(Object value)
{
Class cT = value.getClass().getComponentType();
if (cT.equals(int.class))
{
int [] ia = (int [])value;
Integer [] iA = new Integer [ia.length];
for (int k=0; k<ia.length; k++)
iA[k] = new Integer(ia[k]);
return iA;
}
else if (cT.equals(double.class))
{
double [] da = (double [])value;
Double [] dA = new Double [da.length];
for (int k=0; k<da.length; k++)
dA[k] = new Double(da[k]);
return dA;
}
else if (cT.equals(boolean.class))
{
boolean [] ba = (boolean [])value;
Boolean [] bA = new Boolean [ba.length];
for (int k=0; k<ba.length; k++)
bA[k] = new Boolean(ba[k]);
return bA;
}
return value;
}
26. 26 Copyright 2006 by Ken Slonneger XML-RPC
/* match takes Class arrays representing the types of the
actual parameters and the formal parameters and sees
if they are the same. */
private boolean match(Class [] at, Class [] pt)
{
if (at.length != pt.length)
return false;
for (int k=0; k<at.length; k++)
if (!at[k].equals(adjust(pt[k])))
return false;
return true;
}
/* adjust converts a primitive type into its corresponding
object (wrapper) type. This method is used by match. */
private Class adjust(Class paramType)
{
Class c = paramType;
if (c.equals(int.class))
return Integer.class;
else if (c.equals(double.class))
return Double.class;
else if (c.equals(boolean.class))
return Boolean.class;
else
return c;
}
}
The Request class processes a request, placing the header
information into a Map object by tokenizing the header
information, and extracts the payload in the request.
It is used to process both the method call request and the
method response request.
27. XML-RPC Copyright 2006 by Ken Slonneger 27
File: Request.java
import java.util.*;
import java.io.*;
public class Request
{
private Map<String,String> headers =
new HashMap<String,String>();
private byte [] content = null;
private String requestURI = "";
Request(byte [] rawData)
{ parseHeaders(rawData); }
private void parseHeaders(byte [] rawData)
{
/* 3. and 8. Read request (method call and method response) */
int eoh = findEOH(rawData); // Find end of Headers
String heads = new String(rawData, 0, eoh);
StringTokenizer st = new StringTokenizer(heads, "rn");
String firstLine = st.nextToken();
while (st.hasMoreTokens()) // Process the headers
{
String requestLine = st.nextToken();
int separator = requestLine.indexOf(": ");
String header = requestLine.substring(0, separator);
String value = requestLine.substring(separator+1);
headers.put(header.trim(), value.trim());
}
int length = Integer.parseInt(getHeader("Content-Length"));
content = new byte [length];
28. 28 Copyright 2006 by Ken Slonneger XML-RPC
System.arraycopy(rawData, eoh+4, content, 0, length);
System.out.println(new String(rawData)); // display payload
}
public String getHeader(String name)
{ return headers.get(name); }
public byte [] getContent()
{ return content; }
public int findEOH(byte [] headers)
{
String heads = new String(headers);
return heads.indexOf("rnrn");
}
}
The RpcMethods class contains the methods that can be
called remotely.
Each method is a public class method.
The methods are designed to illustrate each type of
parameter that the system allows: int, double, boolean, String,
Integer, Double, Boolean, and one-dimensional arrays of
these types.
File: RpcMethods.java
import java.util.*;
import java.lang.reflect.*;
import java.math.BigInteger;
29. XML-RPC Copyright 2006 by Ken Slonneger 29
public class RpcMethods
{
public static String reverse(String s)
{
StringBuffer sb = new StringBuffer(s);
return sb.reverse().toString();
}
public static String concat(String [] sa)
{
StringBuffer sb = new StringBuffer();
for (int k=0; k<sa.length; k++)
sb.append(sa[k]);
return sb.toString();
}
public static int add(int num1, int num2)
{
return num1 + num2;
}
public static String [] listMethods()
{
Class c = Rpc0Methods.class;
Method [] methods = c.getMethods();
List<String> meths = new ArrayList<String>();
for (int k=0; k<methods.length; k++)
{
Method m = methods[k];
int mods = m.getModifiers();
if (Modifier.isStatic(mods))
meths.add(m.getName());
}
return (String [])meths.toArray(new String [0]);
}
30. 30 Copyright 2006 by Ken Slonneger XML-RPC
public static Double sum(Double [] da)
{
double sm = 0.0;
for (int k=0; k<da.length; k++)
sm = sm + da[k];
return sm; // note autoboxing
}
public static boolean and(boolean [] ba)
{
boolean result = true;
for (int k=0; k<ba.length; k++)
result = result && ba[k];
return result;
}
public static Double product(Double x, Double y)
{
return x*y; // note autoboxing
}
public static Integer [] mkArray(int size)
{
Integer [] ia = new Integer [size];
for (int k=0; k<ia.length; k++)
ia[k] = new Integer(k*k*k);
return ia;
}
public static double [] mkArray()
{
double [] da = new double [5];
for (int k=1; k<=da.length; k++)
da[k-1] = k*k*k*k/100.0;
return da;
}
31. XML-RPC Copyright 2006 by Ken Slonneger 31
public static String [] fibo(int m, int n, int num)
{
String [] fibs = new String [num];
BigInteger low = BigInteger.ONE;
BigInteger high = BigInteger.ONE;
low = BigInteger.valueOf(m);
high = BigInteger.valueOf(n);
for (int k=1; k<=num; k++)
{
fibs[k-1] = low.toString();
BigInteger temp = high;
high = high.add(low);
low = temp;
}
return fibs;
}
}
Client Side
The client side has a class Test that creates an RpcClient
object that will connect with the RPC server and then calls
each of the remote methods using an instance method
execute for the RpcClient object.
Parameters are collected in a List object and are passed to
the method execute with the name of the method to be called.
The value returned by the execute method is displayed by the
Test class.
Note the use of generic containers in this code.
32. 32 Copyright 2006 by Ken Slonneger XML-RPC
File: Test.java
import java.util.*;
public class Test
{
public static void main(String [] args) throws Exception
{
RpcClient rpcClient =
new RpcClient("r-lnx233.cs.uiowa.edu", 8000);
System.out.println("-----------------------------------------");
List<Object> parms = new ArrayList<Object>();
parms.add("XML-RPC Hello");
Object result = rpcClient.execute("reverse", parms);
System.out.println("nResult: " + result);
System.out.println("-----------------------------------------");
parms = new ArrayList<Object>();
List<String> sa = new ArrayList<String>();
sa.add("abc"); sa.add("DEFG"); sa.add("highlmnop");
parms.add(sa);
result = rpcClient.execute("concat", parms);
System.out.println("nResult: " + result);
System.out.println("-----------------------------------------");
parms = new ArrayList<Object>();
parms.add(new Integer(368));
parms.add(new Integer(927));
result = rpcClient.execute("add", parms);
System.out.println("nResult: " + result);
System.out.println("-----------------------------------------");
parms = new ArrayList<Object>();
List methods =
(List)rpcClient.execute("listMethods", parms);
System.out.println("nResult: ");
for (Iterator it = methods.iterator(); it.hasNext(); )
System.out.println(it.next());
33. XML-RPC Copyright 2006 by Ken Slonneger 33
System.out.println("-----------------------------------------");
parms = new ArrayList<Object>();
parms.add(new Double(3.68));
parms.add(new Double(9.27));
result = rpcClient.execute("product", parms);
System.out.println("nResult: " + result);
System.out.println("-----------------------------------------");
parms = new ArrayList<Object>();
List<Boolean> ba = new ArrayList<Boolean>();
ba.add(new Boolean(true));
ba.add(new Boolean(false));
ba.add(new Boolean(true));
parms.add(ba);
result = rpcClient.execute("and", parms);
System.out.println("Result: " + result);
System.out.println("-----------------------------------------");
parms = new ArrayList<Object>();
Object obj = rpcClient.execute("unknown", parms);
System.out.println("nResult: " + obj);
System.out.println("-----------------------------------------");
parms = new ArrayList<Object>();
nums = (List)rpcClient.execute("mkArray", parms);
System.out.println("nResult: ");
for (Iterator it = nums.iterator(); it.hasNext(); )
System.out.println(it.next());
System.out.println("-----------------------------------------");
parms = new ArrayList<Object>();
parms.add(new Integer(12));
nums = (List)rpcClient.execute("mkArray", parms);
System.out.println("nResult: ");
for (Iterator it = nums.iterator(); it.hasNext(); )
System.out.println(it.next());
34. 34 Copyright 2006 by Ken Slonneger XML-RPC
System.out.println("-----------------------------------------");
parms = new ArrayList<Object>();
List<Double> da = new ArrayList<Double>();
da.add(new Double(43.7)); da.add(new Double(91.3));
da.add(new Double(18.8)); da.add(new Double(33.6));
da.add(new Double(83.5)); da.add(new Double(76.1));
parms.add(da);
result = rpcClient.execute("sum", parms);
System.out.println("Result: " + result);
System.out.println("-----------------------------------------");
parms = new ArrayList<Object>();
parms.add(new Integer(3));
parms.add(new Integer(5));
parms.add(new Integer(22));
nums = (List)rpcClient.execute("fibo", parms);
System.out.println("nResult: ");
for (Iterator it = nums.iterator(); it.hasNext(); )
System.out.println(it.next());
System.out.println("-----------------------------------------");
}
}
The RpcClient class builds the XML payload for the method
call and sends it to the server.
When the response returns, it parses the XML to extract the
value produced by the method or the nature of the fault if the
method failed for some reason.
The various tasks performed by the server are labeled with
the steps from the XML-RPC lifecycle.
35. XML-RPC Copyright 2006 by Ken Slonneger 35
File: RpcClient.java
import org.xml.sax.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.net.*;
import java.util.*;
import java.io.*;
public class RpcClient
{
private String server = "";
private int srvPort;
public RpcClient(String host, int port)
{
server = host;
srvPort = port;
}
public Object execute(String method, List parms)
throws Exception
{
Socket sock = new Socket(server, srvPort);
DataOutputStream out =
new DataOutputStream(sock.getOutputStream());
/* 1. Construct XML for method call */
String methodCall =
"<?xml version="1.0"?>" +
"<methodCall><methodName>” +
method + "</methodName>" +
"<params>" + buildParams("param", parms) +
"</params></methodCall>";
36. 36 Copyright 2006 by Ken Slonneger XML-RPC
/* 2. Send HTTP request for method call */
String request =
"POST / HTTP 1.1rn" +
"Host: " + server + ":" + srvPort + "rn" +
"User-Agent: RPCClientrn" +
"Content-Type: text/xmlrn" +
"Content-Length: " + methodCall.length() +
"rnrn";
String bothParts = request + methodCall;
out.write(bothParts.getBytes());
/* 8. Read response from method call */
BufferedReader reader = new BufferedReader(
new InputStreamReader(sock.getInputStream()));
ByteArrayOutputStream reqBA =
new ByteArrayOutputStream();
int ch = reader.read();
while (ch > -1)
{
reqBA.write(ch);
ch = reader.read();
}
reader.close(); out.close(); sock.close();
Request req = new Request(reqBA.toByteArray());
int length = Integer.parseInt(
req.getHeader("Content-Length"));
byte [] response = new byte [length];
int eoh = req.findEOH(reqBA.toByteArray());
System.arraycopy(reqBA.toByteArray(), eoh+4,
response, 0, length);
37. XML-RPC Copyright 2006 by Ken Slonneger 37
/* 8. Parse response from method call */
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder domParser =
factory.newDocumentBuilder();
Document dom = null;
try
{
dom = domParser.parse(new InputSource(
new StringReader(new String(response))));
}
catch (Exception e)
{ System.out.println(e); }
NodeList pList = dom.getElementsByTagName("fault");
if (pList.getLength() > 0)
{
Text text =
(Text)pList.item(0).getFirstChild().
getFirstChild().getLastChild().getLastChild().
getFirstChild().getFirstChild();
String errorMessage = text.getData();
return errorMessage;
}
pList = dom.getElementsByTagName("param");
Object actualValue = "";
Node parm = pList.item(0);
Node value = parm.getFirstChild();
Node type = value.getFirstChild();
if (type.getNodeName().equals("array"))
actualValue = buildList((Element)type);
else
actualValue = type.getFirstChild().getNodeValue();
return actualValue;
}
38. 38 Copyright 2006 by Ken Slonneger XML-RPC
/* buildList extracts the values from the array and returns
them as a list object. */
private List buildList(Element element)
{
List<Object> returnValues = new ArrayList<Object>();
NodeList values =
element.getElementsByTagName("value");
for (int k=0; k<values.getLength(); k++)
{
Node value = values.item(k);
Node type = value.getFirstChild();
String actualValue =
type.getFirstChild().getNodeValue();
String actualType = type.getNodeName();
returnValues.add(mapArgToObject(actualType,
actualValue));
}
return returnValues;
}
/* buildParams builds an XML element representing an array
of values to be sent as a parameter to the method. */
private String buildParams(String tag, List parms)
{
String start = "", end = "";
if (!tag.equals(""))
{
start = "<" + tag + ">";
end = "</" + tag + ">";
}
StringBuffer returnedParms = new StringBuffer();
Iterator type = parms.iterator();
while (type.hasNext())
{
Object aType = type.next();
40. 40 Copyright 2006 by Ken Slonneger XML-RPC
/* mapArgToObject takes an XML-RPC type and a value as
a string and returns that value as a Java object of the
correct type. */
private Object mapArgToObject(String type, String value)
{
if (type.equals("i4") || type.equals("int"))
return new Integer(value);
else if (type.equals("string"))
return new String(value);
else if (type.equals("double"))
return new Double(value);
else if (type.equals("boolean"))
return new Boolean("1".equals(value));
else
return null;
}
}
Limitations of XML-RPC
• Limited choice of data types.
• No provision for passing objects.
• Little or no security since firewalls are bypassed.
• No type checking of array values; mixed type not forbidden.
• No check that a struct has no duplicate names.
• Strings allow only ascii.
• No representation of NaN for double.