cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [1/2] git commit: CXF-5923: Create sample to demonstrate usage of search extension with Lucene and Tika. Added error handling to UI component.
Date Tue, 09 Sep 2014 12:59:28 GMT
Repository: cxf
Updated Branches:
  refs/heads/master eba07e615 -> 0aaa2b574


CXF-5923: Create sample to demonstrate usage of search extension with Lucene and Tika. Added
error handling to UI component.


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/85c06fc4
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/85c06fc4
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/85c06fc4

Branch: refs/heads/master
Commit: 85c06fc4d6a642627434785a2d228d3c08d68768
Parents: eba07e6
Author: reta <drreta@gmail.com>
Authored: Tue Sep 9 08:48:27 2014 -0400
Committer: reta <drreta@gmail.com>
Committed: Tue Sep 9 08:48:27 2014 -0400

----------------------------------------------------------------------
 .../java/demo/jaxrs/search/server/Catalog.java  |  5 +++
 .../src/main/resources/browser/index.html       | 38 +++++++++++++++++---
 2 files changed, 38 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/85c06fc4/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java
b/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java
index d9cf249..7e52421 100644
--- a/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java
+++ b/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java
@@ -54,6 +54,7 @@ import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.core.StreamingOutput;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.ext.multipart.Attachment;
 import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
@@ -112,6 +113,10 @@ public class Catalog {
                     
                     if (handler != null) {
                         final String source = handler.getName();
+                        if (StringUtils.isEmpty(source)) {
+                            response.resume(Response.status(Status.BAD_REQUEST).build());
+                            return;
+                        }
                                                 
                         final LuceneDocumentMetadata metadata = new LuceneDocumentMetadata()
                             .withSource(source)

http://git-wip-us.apache.org/repos/asf/cxf/blob/85c06fc4/distribution/src/main/release/samples/jax_rs/search/src/main/resources/browser/index.html
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/search/src/main/resources/browser/index.html
b/distribution/src/main/release/samples/jax_rs/search/src/main/resources/browser/index.html
index 7ab4fd4..c61f55d 100644
--- a/distribution/src/main/release/samples/jax_rs/search/src/main/resources/browser/index.html
+++ b/distribution/src/main/release/samples/jax_rs/search/src/main/resources/browser/index.html
@@ -14,14 +14,18 @@
 
 <body>
 	<div class="container">
+		<div class="fluent-container" id="error">
+			<div class="alert alert-danger hide" role="alert" id="error-message"></div>
    	
+	    </div>
+	
 	    <form id="form" class="form-upload" role="form" enctype="multipart/form-data" method="post"
action="http://localhost:9000/catalog">
             <h2 class="form-upload-heading">Please select a PDF file</h2>
             <div class="form-group">
-                <input id="file" name="file" type="file" multiple=true class="file"></button>
+                <input id="file" name="file" type="file" multiple="true" class="file"></input>
             </div>
         </form>
         
-        <form id="from-search" role="search" method="get" action="http://localhost:9000/catalog/search">
+        <form id="form-search" role="search" method="get" action="http://localhost:9000/catalog/search">
             <h2 class="form-upload-heading">Query the Catalog</h2>
 		    <div class="input-group add-on">
 		        <input id="search-query" type="text" class="form-control" placeholder="Search">
	    
@@ -36,8 +40,25 @@
     </div> <!-- /container -->
     
     <script type="text/javascript">
+        function handleError(request, status, error, form) {
+			$( "#error-message" ).removeClass('hide');
+			
+			if ( request.status === undefined || request.status === 0 ) {
+				$( "#error-message" ).html( "Unable to send request to the server: " + $(form).attr("action")
);
+			} else {
+				if( request.status == 500 ) {
+					$( "#error-message" ).html( 'Internal server error.' );
+				} else if( request.status == 409 ) {
+					$( "#error-message" ).html( 'Document with such name already exists.' );
+				} else if( request.status == 400 ) {
+					$( "#error-message" ).html( 'No documents for upload, please select at least one.' );
+				}
+			}
+        };
+    
     	$( "#form" ).submit(function(e) {    		
-    		var formData = new FormData($(this)[0]);
+    		var formData = new FormData( $(this)[0] );
+    		$( "#error-message" ).addClass('hide');    		
 
     		$.ajax({
     			url:$(this).attr("action"),
@@ -47,6 +68,9 @@
     			success: function (data) {
     			    $('#file').fileinput('clear');
     			},
+    			error: function (request, status, error) {
+    				handleError(request, status, error, "#form");
+    			},
 	    		cache: false,
     			contentType: false,
     			processData: false
@@ -56,8 +80,9 @@
 	        return false;
 	    });
     	
-    	$( "#from-search" ).submit(function(e) {    		
+    	$( "#form-search" ).submit(function(e) {    		
     		var query = $( "#search-query" ).val();
+    		$( "#error-message" ).addClass('hide');
     		$( "#results" ).html("");
     		
     		if( query !== "" ) {
@@ -80,7 +105,7 @@
 	    				$.each(data, function (index, value) {
 	    					table += "\
 	    					<tr>\
-	    		               <td>" + value.source + "</td>\
+	    		                <td>" + value.source + "</td>\
 	    		                <td>" + value.score + "</td>\
 	    		                <td><a href='" + value.url + "'>Open</a></td>\
 	    		            </tr>";
@@ -93,6 +118,9 @@
 	    				$( "#results" ).html(table);
 	    		
 	    			},
+	    			error: function (request, status, error) {
+	    				handleError(request, status, error, "#form-search");
+	    			},
 		    		cache: false,
 	    			contentType: false,
 	    			processData: false


Mime
View raw message