Inserting and Retrieving Binary Data with MongoDB using JAX-RS RESTful Web Service

File Upload and Download using MongoDB

In this tutorial we are going to develop file upload and file download capability using RESTful web service using JAX-RS and Jersey storing the contents of files into MongoDB Database using a powerful feature in MongoDB for managing large files called GridFS. The bulk of the framework for this tutorial came from my previous tutorial on Inserting and Retrieving Binary Data using SQL Server using JAX-RS RESTful Web Service so you find many similarities between these two posts.

MongoDB manages all of its data as documents with an upper limit on file size of 16MB. So what do it do when your images, video, PDFs, PPT slides or Excel spreadsheets exceed this 16MB limit? MongoDB has actually built a specification called GridFS which is supported by all of its MongoDB drivers that manages large files by splitting them up into smaller parts or chunks and storing the data in separate documents in its collections. It can then reassemble these smaller chunks automatically into the original file when asked to retrieve the contents of that file.

This functionality makes MongoDB an excellent choice for things like a queryable document repository, or content management system, or image/video warehouse with all of the associated metadata being stored in a separate MongoDB collection and associated with the GridFS system by a unique id. Best of all, GridFS does not have limitations on file size or number of documents per directory or even file naming rules. You get a truly flexible solution that can be easily ported from one system to another using MongoDB.

mongodb gridfs structure

As you will see, our example will be able to save and load PDF files, Excel files, Word Document files, Powerpoint files, Image files, or any other type of file BLOB available us provided we have ample amount of storage space.

Getting Started

In order to run this tutorial yourself, you will need the following:

Required Libraries

Copy all of the following jars to WebContent->WEB-INF->lib folder.

asm-3.1.jar
jersey-client-1.18.jar
jersey-core-1.18.jar
jersey-json-1.18.jar
jersey-multipart-1.18.jar
jersey-server-1.18.jar
jersey-servlet-1.18.jar
jsr311-api-1.1.1.jar
log4j-1.2.17.jar
mimepull-1.6.jar
mongo-java-driver-2.11.3.jar

Complete Project Overview

I have added the project overview to give you a full view of the structure and show you all files contained in this sample project.

jax-rs mongodb proj

RESTful Web Service End Points

#URIMethodDescription
1/rest/files/uploadPOSTUses multipart/form-data encoding type. Because of this no characters are encoded. This value is required when you are using forms that have a file upload feature as you do not want to alter the binary files in any way.
2/rest/files/download/file/{id}GETDownloads the file from the database with id via the path parameter. This web service endpoint is typically used when URI path parameters are extracted from the request URI, and the parameter names correspond to the URI path template variable names.
3/rest/files/download/details/{id}GETProvides record details from the database based in the id passed via path parameter. Using this URI will allow you to verify the data stored in MongoDB for a particular record id.

Collections available in our Tutorial Database in MongoDB

As you can see below, our tutorial database holds a set of collections and these collections will hold our mongoDB documents which will store the form data (filestore), the file metadata (filestore.files) and file raw binary data (filestore.chunks).

> show collections
filestore
filestore.chunks
filestore.files
system.indexes
>

Implement our File Download Service Class using the JAX-RS API

Implementing a RESTful service requires nothing more than creating a POJO and annotating using the javax.ws.rs.* annotations. Additionally, you will need to ensure your class is under the package you defined in your web descriptor as Jersey will use this package to scan your classes for the existence RESTful resources.

Our upload method uploadFile, takes six parameters using @FormDataParam. In this method I am using @Consumes annotation with a media type of MediaType.MULTIPART_FORM_DATA this will allow us to consume multipart form data from our HTML page. The first two parameters are used for the file handling, the first one of @FormDataParam provides an InputStream to the file being uploaded and the other @FormDataParam provides content disposition header by using the FormDataContentDisposition object in the Jersey API. The next four parameters are used in the database for ID and metadata purposes to better describe details about the file we are planning to store in the database.

In the important method used in the RestFileStoreDBExample service class is the downloadFilebyID method. You will notice that I am using @Produces annotation with a media type of MediaType.APPLICATION_OCTET_STREAM. This allow us to download the file as a binary file and download it directly in your browser. This method uses the @PathParam annotation which binds the value of a URI template parameter or a path segment containing the template parameter to a resource method parameter.

mongodb url structure

http://localhost:8080/RestfulFileStoreMongoDBExample/rest/files/download/file/1001

The other point worth mentioning is the fact that we are performing some database checking by ensuring that the document actually exists in our MongoDB collection. If the document exists, we return it to the user and if the document is missing, we construct an appropriate error message and return it to the user in the HTML response.

Uploading a file to MongoDB Database

In this code snippet we will concentrate on the code responsible for saving the binary data to our MongoDB database by inserting the file details into our filestore collection and storing the actual binary data associated with the file in the GridFS collections called filestore.files and filestore.chunks. Using this code you will be able to store PDF files, Excel files, Image files, or any type of file available to you provided you have enough space available to MongoDB.

Using GridFSInputFile we create an object that is able to take the input stream coming the file we uploaded via our HTML page and save it to GridFS file structure in MongoDB.

In this code snippet, we accept multipart form data that has been submitted through the HTML form listed below and inject the data into the appropriate variables. We then open a connection to MongoDB instance and connect to our database called tutorial. Next, we get our collection called filestore which will be used to store the ID, description, file_year, department and filename. We perform a query using the id we passed in to ensure that a document with that ID does not exist in our collection. If it does not, we create a BasicDBObject document object and append all of the fields we require and insert that document into our collection. The last thing we do here is use the GridFS API to create the collection and store the associated file

We will be storing the actual binary data associated with the files in the GridFS file system. We set the ID in this collection, set the filename and save the contents of the file in the collection.

public Response uploadFile(
    @FormDataParam("file") InputStream fileInputStream,
    @FormDataParam("file") FormDataContentDisposition fileInputDetails,
    @FormDataParam("id") String  id,
    @FormDataParam("description") String  description,
    @FormDataParam("file_year") String file_year,
    @FormDataParam("department") String department) throws UnknownHostException {
 
  MongoClient mongoClient = new MongoClient("localhost", 27017);
  DB mongoDB = mongoClient.getDB("tutorial");
    
  //Let's store the standard data in regular collection
  DBCollection collection = mongoDB.getCollection("filestore");
  
  // Let's query to ensure ID does not already exist in Mongo
  // if it does, we will alert the user 
  BasicDBObject query = new BasicDBObject();
  query.put("_id", id);
  DBCursor cursor = collection.find(query);
    
  if (!cursor.hasNext()) {
    // Build our document and add all the fields
    BasicDBObject document = new BasicDBObject();
    document.append("_id", id);
    document.append("description", description);
    document.append("file_year", file_year);
    document.append("filename", fileInputDetails.getFileName());
    document.append("department", department);
      
    //insert the document into the collection 
    collection.insert(document);
      
    // Now let's store the binary file data using filestore GridFS  
    GridFS fileStore = new GridFS(mongoDB, "filestore");
    GridFSInputFile inputFile = fileStore.createFile(fileInputStream);
    inputFile.setId(id);
    inputFile.setFilename(fileInputDetails.getFileName());
    inputFile.save();

   ...   
  }
}

Downloading a file from MongoDB Database

In this code snippet you can see that the output we are expecting to produce is an APPLICATION_OCTET_STREAM which is essentially binary data. We will be obtaining the ID from the path parameter of the request URL. Using @PathParam annotation we will inject this id from the request URL into our String id variable which will be used as a parameter in our BasicDBObject query object to verify that our collection contains a document with that id in MongoDB database and retrieve the desired document.

Once we find the document in the collection using collection.findOne(query) with a matching ID we extract from the document we extract all the keys from the document and put them into our fields Hashmap. The core to retrieving the binary data from the GridFS filestore happens when we use gridFile.getInputStream(). Using this inputStream we will read in all of the bytes of streaming data and put it into our ByteArrayOutputStream which will be returned to the user as an HTTP response object.

Please note that we need to use the previously stored filename when building our response header via builder.header(“Content-Disposition”, “attachment; filename=” + filename);.

@GET
@Path("/download/file/{id}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response downloadFilebyID(@PathParam("id")  String id) throws IOException {
  
  Response response = null;
  MongoClient mongoClient = new MongoClient("localhost", 27017);
  DB mongoDB = mongoClient.getDB("tutorial");
  
  //Let's store the standard data in regular collection
  DBCollection collection = mongoDB.getCollection("filestore");
  
  logger.info("Inside downloadFilebyID...");
  logger.info("ID: " + id);

  BasicDBObject query = new BasicDBObject();
  query.put("_id", id);
  DBObject doc = collection.findOne(query);
  DBCursor cursor = collection.find(query);
      
  if (cursor.hasNext()) {
    Set<String> allKeys = doc.keySet();
    HashMap<String, String> fields = new HashMap<String,String>();
    for (String key: allKeys) {
      fields.put(key, doc.get(key).toString());
    }
        
    logger.info("description: " + fields.get("description"));
    logger.info("department: " + fields.get("department"));
    logger.info("file_year: " + fields.get("file_year"));
    logger.info("filename: " + fields.get("filename"));
       
    GridFS fileStore = new GridFS(mongoDB, "filestore");
    GridFSDBFile gridFile = fileStore.findOne(query);

    InputStream in = gridFile.getInputStream();
        
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    int data = in.read();
    while (data >= 0) {
      out.write((char) data);
      data = in.read();
    }
    out.flush();

    ResponseBuilder builder = Response.ok(out.toByteArray());
    builder.header("Content-Disposition", "attachment; filename=" + fields.get("filename"));
    response = builder.build();

    ...
  }
} 

Complete Program (RestFileStoreMongoDBExample.java)

package com.avaldes;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Set;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.gridfs.GridFS;
import com.mongodb.gridfs.GridFSDBFile;
import com.mongodb.gridfs.GridFSInputFile;
import com.sun.jersey.multipart.FormDataParam;

import org.apache.log4j.Logger;

import com.sun.jersey.core.header.FormDataContentDisposition;

@Path("/files")
public class RestFileStoreMongoDBExample {
  static Logger logger = Logger.getLogger(RestFileStoreMongoDBExample.class);
  
  @POST
  @Path("/upload")
  @Consumes(MediaType.MULTIPART_FORM_DATA)
  @Produces("text/html")
  public Response uploadFile(
      @FormDataParam("file") InputStream fileInputStream,
      @FormDataParam("file") FormDataContentDisposition fileInputDetails,
      @FormDataParam("id") String  id,
      @FormDataParam("description") String  description,
      @FormDataParam("file_year") String file_year,
      @FormDataParam("department") String department) throws UnknownHostException {
 
    MongoClient mongoClient = new MongoClient("localhost", 27017);
    DB mongoDB = mongoClient.getDB("tutorial");
    
    //Let's store the standard data in regular collection
    DBCollection collection = mongoDB.getCollection("filestore");
    
    // Let's query to ensure ID does not already exist in Mongo
    // if it does, we will alert the user 
    BasicDBObject query = new BasicDBObject();
    query.put("_id", id);
    DBCursor cursor = collection.find(query);
    
    if (!cursor.hasNext()) {
      // Build our document and add all the fields
      BasicDBObject document = new BasicDBObject();
      document.append("_id", id);
      document.append("description", description);
      document.append("file_year", file_year);
      document.append("filename", fileInputDetails.getFileName());
      document.append("department", department);
      
      //insert the document into the collection 
      collection.insert(document);
      
      // Now let's store the binary file data using filestore GridFS  
      GridFS fileStore = new GridFS(mongoDB, "filestore");
      GridFSInputFile inputFile = fileStore.createFile(fileInputStream);
      inputFile.setId(id);
      inputFile.setFilename(fileInputDetails.getFileName());
      inputFile.save();
          
      String status = "Upload has been successful";
    
      logger.info("ID: " + id);
      logger.info("description: " + description);
      logger.info("department: " + department);
      logger.info("file_year: : " + file_year);
      logger.info("fileInputDetails: " + fileInputDetails);
      
      return Response.status(200).entity(status).build();
    } else {
      String status = "Unable to insert record with ID: " + id +" as record already exists!!!";
      logger.info(status);
      return Response.status(200).entity(status).build();
    }
  }
  
  @GET
  @Path("/download/file/{id}")
  @Produces(MediaType.APPLICATION_OCTET_STREAM)
  public Response downloadFilebyID(@PathParam("id")  String id) throws IOException {
    
    Response response = null;
    MongoClient mongoClient = new MongoClient("localhost", 27017);
    DB mongoDB = mongoClient.getDB("tutorial");
    
    //Let's store the standard data in regular collection
    DBCollection collection = mongoDB.getCollection("filestore");
    
    logger.info("Inside downloadFilebyID...");
    logger.info("ID: " + id);

    BasicDBObject query = new BasicDBObject();
    query.put("_id", id);
    DBObject doc = collection.findOne(query);
    DBCursor cursor = collection.find(query);
        
    if (cursor.hasNext()) {
      Set<String> allKeys = doc.keySet();
      HashMap<String, String> fields = new HashMap<String,String>();
      for (String key: allKeys) {
        fields.put(key, doc.get(key).toString());
      }
          
      logger.info("description: " + fields.get("description"));
      logger.info("department: " + fields.get("department"));
      logger.info("file_year: " + fields.get("file_year"));
      logger.info("filename: " + fields.get("filename"));
         
      GridFS fileStore = new GridFS(mongoDB, "filestore");
      GridFSDBFile gridFile = fileStore.findOne(query);
  
      InputStream in = gridFile.getInputStream();
          
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      int data = in.read();
      while (data >= 0) {
        out.write((char) data);
        data = in.read();
      }
      out.flush();
  
      ResponseBuilder builder = Response.ok(out.toByteArray());
      builder.header("Content-Disposition", "attachment; filename=" + fields.get("filename"));
      response = builder.build();
    } else {
      response = Response.status(404).
          entity(" Unable to get file with ID: " + id).
          type("text/plain").
          build();
    }
        
    return response;
  }
  
  @GET
  @Path("/download/details/{id}")
  @Produces(MediaType.TEXT_HTML)
  public Response showFileStoreDetails(@PathParam("id")  String id) throws UnknownHostException {
    
    Response response = null;
    MongoClient mongoClient = new MongoClient("localhost", 27017);
    DB mongoDB = mongoClient.getDB("tutorial");
    
    //Let's store the standard data in regular collection
    DBCollection collection = mongoDB.getCollection("filestore");
    
    logger.info("Inside showFileStoreDetails...");
    logger.info("ID: " + id);

    BasicDBObject query = new BasicDBObject();
    query.put("_id", id);
    DBObject doc = collection.findOne(query);

    DBCursor cursor = collection.find(query);
        
    if (cursor.hasNext()) {
      Set<String> allKeys = doc.keySet();
      HashMap<String, String> fields = new HashMap<String,String>();
      for (String key: allKeys) {
        fields.put(key, doc.get(key).toString());
      }
          
     logger.info("description: " + fields.get("description"));
     logger.info("department: " + fields.get("department"));
     logger.info("file_year: " + fields.get("file_year"));
     logger.info("filename: " + fields.get("filename"));
     
     StringBuffer status = new StringBuffer("Inside showHeaders: <br/><br/>");
     status.append("description : ");
     status.append(fields.get("description"));
     status.append("<br/>");
     status.append("department : ");
     status.append(fields.get("department"));
     status.append("<br/>");
     status.append("file_year : ");
     status.append(fields.get("file_year"));
     status.append("<br/>");
     status.append("filename : ");
     status.append(fields.get("filename"));
     status.append("<br/>");
      
     response = Response.status(200).entity(status.toString()).build();
   } else {
     response = Response.status(404).
        entity(" Unable to get file with ID: " + id).
        type("text/plain").
        build();
   }
   return response;
 }

LOG4J Configuration File (log4j.xml)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

  <!-- Appenders -->
  <appender name="console" class="org.apache.log4j.ConsoleAppender">
  <param name="Target" value="System.out" />
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%-5p: %c - %m%n" />
    </layout>
  </appender>
  
  <!-- Application Loggers -->
  <logger name="com.avaldes">
    <level value="info" />
  </logger>

  <!-- Root Logger -->
  <root>
    <priority value="warn" />
    <appender-ref ref="console" />
  </root>
</log4j:configuration>

Simple HTML Web Page (index.html)

This page is very simple having only a few input fields of type text for the ID, Description, File Year and Department. The last field is of type file to allow the user to choose a file to upload to our RESTful web service. This HTML page will use the method of POST with an encoding type of enctype=”multipart/form-data” in the HTML form element.

<h1>RESTful Web Service - File Upload into MongoDB Example</h1>  
<form action="/RestfulFileStoreMongoDBExample/rest/files/upload" method="POST" enctype="multipart/form-data">
  <p>ID: <input type="text" name="id" size="10" /></p>
  <p>Description: <input type="text" name="description" size="50" /></p>
  <p>File Year: <input type="text" name="file_year" size="6" /></p>
  <p>Department: <input type="text" name="department" size="10" /></p>  
  <p>File Upload: <input type="file" name="file" size="60" /></p>  
  <input type="submit" value="Submit" />  
</form>

Web Deployment Descriptor (web.xml)

This is a pretty straight forward deployment descriptor file – only thing you need to add is the location of you java package in the Jersey ServletContainer entry as init-param. Please ensure you add it to the web.xml file as shown below.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>com.omega.rest</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  <servlet>
 
   <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>com.avaldes</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>
</web-app>

Testing out the Web Services

To test out the application, simply enter all the required fields into the input text fields and choose the file to upload using the file picker. Then click on the Submit button. This will insert the fields into our MongoDB database and store the file in the database as a Binary Large Object Block (BLOB).

Saving an Image in MongoDB using JAX-RS Web Service

Using our HTML web page we will use the POST method to submit all the form elements from our form to our RESTful web service. We will also perform a file upload of our photo.jpg file and save that file into MongoDB using the GridFS file system.

mongodb screen1

Querying the data in the filestore collection in MongoDB

> db.filestore.find().pretty()
{
	"_id" : "1001",
	"description" : "Jennifer Aniston Photo",
	"file_year" : "2009",
	"filename" : "photo.jpg",
	"department" : "MARKETING"
}
>
> db.filestore.files.find().pretty()
{
	"_id" : "1001",
	"chunkSize" : NumberLong(262144),
	"length" : NumberLong(19642),
	"md5" : "2ee6b6adec30c23c6d7bff6a835a956b",
	"filename" : "photo.jpg",
	"contentType" : null,
	"uploadDate" : ISODate("2013-11-04T19:54:49.782Z"),
	"aliases" : null
}
>

Downloading an Image from MongoDB using JAX-RS Web Service

http://localhost:8080/RestfulFileStoreMongoDBExample/rest/files/download/file/1001

mongodb screen2

Once are request is processed by the REST service the image file is returned to the use via the HTTP response object.

mongodb screen4

http://localhost:8080/RestfulFileStoreMongoDBExample/rest/files/download/details/1001

mongodb screen3

Download the Code

That’s It!

I hope you enjoyed this tutorial. It was certainly a lot of fun putting it together and testing it out. Please continue to share the love and like us so that we can continue bringing you quality tutorials. Happy Coding!!!

java jaxrs monfodb

Related JAX-RS Tutorial Posts

  • RESTful Web Services with AngularJS, Bootstrap and Java using JAX-RS and Jersey
    In this tutorial we will develop a full blown CRUD application using JAX-RS API and Jersey to implement RESTful web services. JAX-RS stands for Java API for RESTful Web Services and by using this powerful API developers can easily build REST services. Jersey RESTful Web Services is an open source framework for developing RESTful Web Services in Java that provides support for JAX-RS APIs.
  • JAX-RS Security using JSON Web Encryption(JWE) with AngularJS, Bootstrap, Grid-UI and MongoDB Example
    In this tutorial we will discuss how to use AngularJS, Bootstrap and Grid-UI to connect to secure JAX-RS RESTful web services using JWE/JWT/JWS for Authentication and Authorization. In our example implementation, we will be using Symmetric Encryption where the receiver and sender share a common key.
  • JAX-RS Security using JSON Web Encryption (JWE) with JWS/JWT for Authentication and Authorization
    In this tutorial we will discuss how to secure JAX-RS RESTful web services using JSON Web Encryption(JWE), JSON Web Key (JWK), JSON Web Signature(JWS), and JSON Web Tokens(JWT) for Authentication and Authorization. JSON Web Encryption (JWE) encrypted content using Javascript Object Notation (JSON) based structures.
  • JAX-RS Security using JSON Web Tokens (JWT) for Authentication and Authorization
    In this tutorial we will discuss how to secure JAX-RS RESTful web services using JSON Web Tokens Authentication and Authorization. This form of security is used for authenticating a client using a signed token which can be verified by application servers. This token-based form of security is a ideal candidate for Cross-domain (CORS) access and when server-side scalability is a prime motivation factor.
  • JAX-RS Security using API-KEY for Authorization
    In this tutorial we will discuss how to secure JAX-RS RESTful web services using API-KEY or Service Key for Authorization. This form of security is used to ensure that certain RESTful endpoints are protected against unauthorized use.
  • JAX-RS Security using Digest Authentication and Authorization
    In this JAX-RS Digest Authentication and Authorization tutorial we will discuss how to set up digest security for our RESTful web service. This form of access authentication is slightly more complex than the previously discussed JAX-RS Basic Authentication Tutorial.
  • JAX-RS Security using Basic Authentication and Authorization
    In this JAX-RS basic authentication and authorization tutorial we will discuss how to set up security for our RESTful web service. We will need to ensure that some of the URIs are protected and only clients that have been authenticated and authorized are able to gain access and make use of them.
  • Upload and Download Multiple Binary Files using MongoDB
    In this tutorial we are going to develop multiple file upload and file download capability using RESTful web service using JAX-RS and Jersey storing the contents of files into MongoDB Database using a powerful feature in MongoDB for managing large files called GridFS.
  • Inserting and Retrieving Binary Data with MongoDB using JAX-RS RESTful Web Service
    In this tutorial we are going to develop file upload and file download capability using RESTful web service using JAX-RS and Jersey storing the contents of files into MongoDB Database using a powerful feature in MongoDB for managing large files called GridFS. The bulk of the framework for this tutorial came from my previous tutorial so you find many similarities between the two posts.
  • Inserting and Retrieving Binary Data with SQL Server Database using JAX-RS RESTful Web Service
    In this tutorial we are going to develop file upload and file download capability using RESTful web service using JAX-RS and Jersey storing the contents of the file into SQL Server Database using BLOB. Our example will be able to store PDF files, Excel files, Word Document files, Powerpoint files, Image files, or any other type of file available us provided we have ample amount of storage space.
  • File Download Example Using RESTful Web Service with JAX-RS and Jersey
    In this example we are going to develop file download capability using RESTful web service using JAX-RS and Jersey. As you will see, downloading a File using Jersey is very easy as it uses the HTTP GET for the file operations. In our web service, we will be allowing you to download the file via two mechanisms. You will be able to download by HTTP query parameters via @QueryParam and also by using the path parameters via @PathParam.
  • JAX-RS Restful Web Services with JNDI Datasource for MySQL in Tomcat
    In this tutorial we will discuss how to set up JAX-RS RESTful web services and configure a JNDI Datasource with Connection Pooling in Tomcat and connect to MYSQL Database. JNDI (Java Naming and Directory Interface) provides and interface to multiple naming and directory services.
  • File Upload Example Using RESTful Web Service with JAX-RS and Jersey
    In this example we are going to develop file upload capability using RESTful web service using JAX-RS and Jersey. As you will see, uploading a File using Jersey is pretty straight forward as it uses HTTP POST with the encoding type of multipart/form-data for the file operations.
  • RESTful Web Services @FormParam Example using JAX-RS and Jersey
    In this example we are going to develop a simple RESTful web service using JAX-RS and Jersey to extract form parameters submitted by a form using @FormParam annotation.
  • RESTful Web Services @MatrixParam Example using JAX-RS and Jersey
    In this example we are going to develop a simple RESTful web service using JAX-RS and Jersey to extract matrix parameters from the request URL using the @MatrixParam annotations.
  • RESTful Web Services @QueryParam Example using JAX-RS and Jersey
    In this example we are going to develop a simple RESTful web service using JAX-RS and Jersey to extract query parameters from the request URL using the @QueryParam annotation.
  • RESTful Web Services @PathParam Example using JAX-RS and Jersey
    In this example we are going to develop a simple RESTful web service using JAX-RS and Jersey to extract path parameters from the request URL using the @PathParam annotation.

Please Share Us on Social Media

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *