Archive for the 'Web Service' Category

The correct way to deploy Java web project

I developed a Java Web Service project on my local box. It has been working fine with my testing. Now I need to deploy this project to a remote server, which will be assigned a static domain name for our department. I searched everywhere, and finally find the following ways to deploy a web project.

Continue »

Access ServletContext from within a JAX-WS Web Service

In a typical J2EE project, we put the application level initial parameter in context-param tag in web.xml, such as database configuration, administrator’s email address, etc.

The values within the element can be accessed like so:

String value = 
getServletContext().getInitParameter("name_of_context_initialization_parameter");

When dealing with Web Service, the same problem comes up.

Continue »

File Transfer through Java Web Service — Solution

I talked this topic in my previous post. Now I have completed the Centralized Document Transfer and Sharing System. I found that it’s not that useful to put my code here. Only how to solve the problem is worth to write.  I use the Netbeans to build this application which is very fast. Netbeans is a great tool to build web service. Here are the steps to make the application run.

1. Use FTP to upload a file. Set up an FTP server first using FileZilla. Open a count for a client to connect and upload files.

2. Use Netbeans to build web service which can store file’s information including: file name, version number, file type, and all file information. You will need a database to store those informations. The following is the database diagram.

Continue »

Requirement Analysis for Centralized File Management System

The following is the requirement summary for building a new centralized file management system (FMS):

1. After merging the central FMS, each individual system will use web service to connect to it. And all files and related information will be put in a central place.

2. The central should have the following functions:

a. Authenticate

b. Upload (with all related information, such as file name, version number and category)

c. Update (reversion)

d. ListFile (all versions of a file)

e. Download

f. Delete

g. Rename

h. AccessVerify

3. Let each system change as few as possible, when merging the central FMS.

To issustrate the situation, please read the following diagram.

fms requirement Analysis

fms requirement Analysis

Using Alfresco PHP Web Service to upload files

The following is the PHP code for uploading files using Alfresco Web Service. I put some comments inside the code. If there is anything confuses you, please leave your comment and I hope I can help.

if (isset($_SERVER["ALF_AVAILABLE"]) == false)
				{
					require_once "./alfresco_sdk/remote/Alfresco/Service/Repository.php";
					require_once "./alfresco_sdk/remote/Alfresco/Service/Session.php";
					require_once "./alfresco_sdk/remote/Alfresco/Service/SpacesStore.php";
					require_once "./alfresco_sdk/remote/Alfresco/Service/ContentData.php";
				}
				$repositoryUrl = "http://localhost:8080/alfresco/api";
				$userName = "admin";
				$password = "admin";
 
				// Authenticate the user and create a session
				$repository = new Repository($repositoryUrl);
				$ticket = $repository->authenticate($userName, $password);
				$session = $repository->createSession($ticket);
 
				// Create a reference to the 'SpacesStore'
				$spacesStore = new SpacesStore($session);
 
				$dir_name =  "s".$irbID;
 
				// Use a serach to get the guest home space we will use to place the new content in
				$nodes = $session->query($spacesStore, "PATH:\"app:company_home/cm:testing/cm:$dir_name\"");
 
				if(!empty($nodes)){
					echo "good, no need to do anything.";
				}else{
					$nodes = $session->query($spacesStore, "PATH:\"app:company_home/cm:testing\"");
					$contentNode = $nodes[0];
					$newSpace = $contentNode->createChild('cm_folder', 'cm_contains', 'cm_'.$dir_name);//here has to be cm_ as it is here.
					$newSpace->cm_name = $dir_name;
					$newSpace->cm_title = "This is a title";
					$newSpace->cm_description = 'Description of Space';
					$session->save();
					unset($session);
					$session = $repository->createSession($ticket);
					$nodes = $session->query($spacesStore, "PATH:\"app:company_home/cm:testing/cm:$dir_name\"");
				}
 
				$guestHome = $nodes[0];
 
				// Get the name of the new node
				$name = $_POST['txt_docs_title'];
 
				$contentNode = $guestHome->createChild("cm_content", "cm_contains", "cm_".$name);//!!the folder's name has to begin with 'cm_' otherwise, using web service can not find it later.
				$contentNode->addAspect("cm_titled");
 
				// Set the name, title and description property values
				$contentNode->cm_name = $name;
				$contentNode->cm_title = $_POST['num_ct_ID'];
				$contentNode->cm_description = "testing description --program creek";
 
				// Set the content onto the standard content property for nodes of type cm:content.
				// We are going to assume the mimetype and encoding for ease
				$contentData = $contentNode->updateContent("cm_content", $_FILES['document']['type'], "UTF-8");
 
				// Set the content to be the content file uploaded from the client
				$contentData->writeContentFromFile($_FILES["document"]["tmp_name"]);
 
				// Save the new node
				$session->save();

FAQ about Web Services and Related Technologies

I got this from JavaRanch, can not hesitate to put it here.

What is a Web Service?

In simple terms a Web Service is an application or business logic that is accessible using standard Internet protocols.

Can I access a web services from any application?

Yes, if your application supports XML based object request and response.

Are there any real web services available for testing?

Yes, check http://xmethods.net/

What is the best Web Service Testing tools?

I would say SoapUI, it is perfectly for installation and implementation. Now if you know some about Web Service, you can start practice with SoupUI and xmethods.net. This can help you understand Web Service.

What are the current free and commercial implementations available for Web Services?

Web Service protocols and supporting package

Web Service protocols and supporting package

Can I access a web service from within a browser?

You can use the JavaScript XmlHttpRequest object (read introductions here and here). You’ll have to create and process the XML requests and responses yourself, though. This works in Internet Explorer, Safari and Mozilla-based browsers like FireFox.

What are the differences between JAX-RPC, JAX-WS, Apache Axis, SAAJ, Apache SOAP, JWSDP, Metro, Jersey and GlassFish?

  • JAX-RPC is a specification/API for Java developers to develop SOAP based interoperable web services. This API is now obsolete, and may be dropped from the next JEE version.
  • JAX-WS is the successor to JAX-RPC. It requires Java 5.0, and is not backwards-compatible to JAX-RPC. This article describes the high-level differences to JAX-RPC.
  • SAAJ is another specification/API for using SOAP envelopes with or without attachments. It operates on a lower level than JAX-RPC or JAX-WS, both of which will use SOAP envelopes based on SAAJ if needed.
  • Apache Axis is an open source implementation of the Java WS APIs for sending and receiving SOAP messages. Axis 1 supports JAX-RPC and SAAJ, while Axis 2 supports SAAJ and JAX-WS.
  • Apache SOAP was the first SOAP implementation. It is now obsolete. It’s better to use Apache Axis to avail oneself of the latest features.
  • Sun JWSDP – Sun Java Webservices Developer Pack, is an implementation of JAX-RPC, SAAJ and various other XML Java technologies. It is now deprecated in favor of GlassFish.
  • GlassFish is the open source reference implementation of J2EE 5. As such, it contains an implementation of JAX-WS.
  • Metro is the web services stack used in GlassFish?. It supports SAAJ, JAX-WS, WS-Security and other standards.
  • Jersey is the reference implementation of the JSR-311 standard for RESTful web services.

What is REST?

Where can I find the relevant standards?


How do I get started building a web service? Show me some code!

Some useful code snippets

  • How can I set HTTP headers like SOAPAction or Basic Authentication in my SOAP request? (link)
  • How can I use HTTP Basic Authentication in my JAX-RPC client? (link)
  • With Axis, how can I access authentication information if I use HTTP Authentication? (link)
  • With Axis, how can I find out which service and operation was invoked? (link)
  • What is the simplest possible Java client for a web service? (link)
  • How do I handle WS-Security UsernameTokens with WSS4J? (link)

What other sources of information are available particularly for Java Web Services?

Which other software packages help implement Java Web Services?

  • Sandesha implements WS-ReliableMessaging
  • BPEL:

More articles on specific topics


Books

Check the JavaRanch Bunkhouse Web Services And SOAP category.

The book title is linked to the publisher where sample content may reside. The ISBN links to Amazon US which tends to list reviews.

SOA Using Java™ Web Services (2007) ISBN 0130449687 Web page Bunkhouse Review

Examines web service technology in a Java EE 5 context as implemented on the Glassfish application server. Covers JAX-WS 2.0 and JAXB 2.0. Mark D. Hansen’s posts during the book promotion. Why is Java Web Services so Hard?

RESTful Web Services (2007) ISBN 0596529260

Explains the principles of REpresentational STate transfer and Resource Oriented Architecture (ROA). Specifies design procedures for resource URIs and resource (state) representations (XML being only one option). Many examples use Ruby but one example does use the Restlet framework. Also looks at AJAX applications as REST clients. Leonard Richardson’s and Sam Ruby’s posts during the book promotion.

J2EE Web Services (2004) ISBN 0321146182 Bunkhouse Review Author’s Blog

Examines web service technology in a J2EE 1.4 context. Covers XML, XML Schema, SOAP 1.1, WSDL 1.1, WS-I Basic Profile 1.0a, UDDI 2.0 as general web service standards and the Java APIs using them: (the now dated) JAX-RPC (incl. EJB endpoints), JAXR (level 0), JAXP, SAAJ, SwA; deployment descriptors are also covered.

Designing Web Services with the J2EE™ 1.4 Platform (2004) ISBN 0321205219 On-line Version PDF Version

A more design/architecture oriented examination of web service technologies in a J2EE 1.4 context.

Service-Oriented Architecture: Concepts, Technology, and Design (2005) ISBN 0131858580 Web page

SOA with SOAP web services explained. Just don’t expect to see any code as this is a platform independent discussion of SOA with SOAP web services.

Service-Oriented Architecture: A Field Guide to Integrating XML and Web Services (2004) ISBN 0131428985 Web page

An examination of how XML technologies, SOAP, WSDL, UDDI, and various WS-* standards can be used to move towards a Service-Oriented Enterprise. No code as this is a platform independent exploration.

SOA Principles of Service Design (2007) ISBN 0132344823 Web page

Service-Orientation isn’t Object-Orientation. Discusses the service design principles needed to develop services that can operate successfully in a SOAP-based SOA.

SOA in Practice: The Art of Distributed System Design (2007) ISBN 0596529554 Web page

Need an SOA instead of a JaBoWS (Just another Bunch of Web Services)? While not specifically written for web service based SOAs but more towards large distributed systems in general this book presents some of the benefits that you can realize by adopting service-orientation and SOA practices. More importantly it reveals that large distributed systems can turn some common sense best practices established for smaller or component-based systems on their heads (example: the perceived need for a common business object model across the entire system). Interview

Java Web Services in a Nutshell

Building Web Services with Java: Making Sense of XML, SOAP, WSDL, and UDDI

Developing Web Services with Apache Axis

Developing Java Web Services: Architecting and Developing Secure Web Services Using Java

Java Web Services Architecture

File Transfer through Java Web Service

I was trying to do a java web service project which allows users to upload files through web service. After searching for several days, I realized that, this is not a good idea. In face, web service can transfer Image from end to end, but not for large regular files, such as pdf, doc, etc. The reason is that server will read file to byte array which consumes much memory. If many users use it at the same time, this may lead to scalability issue.

Continue »