Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
261 additions
and 46 deletions.
- +4 −0 demo/.classpath
- +4 −1 demo/src/net/imgseek/server/demo/Iskdaemon_demo.gwt.xml
- +65 −25 demo/src/net/imgseek/server/demo/client/Iskdaemon_demo.java
- +29 −0 demo/src/net/imgseek/server/demo/server/IskDaemonClient.java
- +4 −18 demo/src/net/imgseek/server/demo/server/IskDemoServiceImpl.java
- +119 −0 demo/src/net/imgseek/server/demo/server/UploadServlet.java
- BIN demo/war/WEB-INF/lib/commons-fileupload-1.2.1.jar
- BIN demo/war/WEB-INF/lib/commons-io-1.4.jar
- BIN demo/war/WEB-INF/lib/gwtupload-0.6.4.jar
- BIN demo/war/WEB-INF/lib/log4j-1.2.13.jar
- +26 −0 demo/war/WEB-INF/web.xml
- +1 −1 src/core/imgdbapi.py
- +9 −1 src/imgSeekLib/ImageDB.py
@@ -0,0 +1,29 @@ | ||
package net.imgseek.server.demo.server; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
import org.apache.xmlrpc.client.XmlRpcClient; | ||
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; | ||
|
||
public class IskDaemonClient { | ||
public XmlRpcClient client; | ||
|
||
public IskDaemonClient() { | ||
|
||
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); | ||
try { | ||
config.setServerURL(new URL("http://127.0.0.1:31128/RPC")); | ||
} catch (MalformedURLException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} // isk-daemon | ||
// XML-RPC | ||
// endpoint | ||
// URL | ||
config.setEnabledForExtensions(true); | ||
this.client = new XmlRpcClient(); | ||
this.client.setConfig(config); | ||
|
||
} | ||
} |
@@ -0,0 +1,119 @@ | ||
package net.imgseek.server.demo.server; | ||
|
||
import gwtupload.server.UploadAction; | ||
import gwtupload.server.exceptions.UploadActionException; | ||
import gwtupload.shared.UConsts; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Hashtable; | ||
import java.util.List; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import net.imgseek.server.demo.shared.DbImageResult; | ||
|
||
import org.apache.commons.fileupload.FileItem; | ||
import org.apache.xmlrpc.XmlRpcException; | ||
|
||
/** | ||
* This class sends by email, all the fields and files received by GWTUpload | ||
* servlet. | ||
* | ||
* @author Manolo Carrasco Moñino | ||
* | ||
*/ | ||
public class UploadServlet extends UploadAction { | ||
private IskDaemonClient iskClient = new IskDaemonClient(); | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
Hashtable<String, String> receivedContentTypes = new Hashtable<String, String>(); | ||
/** | ||
* Maintain a list with received files and their content types. | ||
*/ | ||
Hashtable<String, File> receivedFiles = new Hashtable<String, File>(); | ||
|
||
private ImageDb imgIdDb = new ImageDb(); | ||
|
||
/** | ||
* Override executeAction to save the received files in a custom place and | ||
* delete this items from session. | ||
*/ | ||
@Override | ||
public String executeAction(HttpServletRequest request, | ||
List<FileItem> sessionFiles) throws UploadActionException { | ||
String response = ""; | ||
List<DbImageResult> dbImageList = new ArrayList<DbImageResult>(); | ||
int cont = 0; | ||
for (FileItem item : sessionFiles) { | ||
if (false == item.isFormField()) { | ||
cont++; | ||
try { | ||
// / Create a new file based on the remote file name in the | ||
// client | ||
// String saveName = | ||
// item.getName().replaceAll("[\\\\/><\\|\\s\"'{}()\\[\\]]+", | ||
// "_"); | ||
// File file =new File("/tmp/" + saveName); | ||
|
||
// / Create a temporary file placed in /tmp (only works in | ||
// unix) | ||
// File file = File.createTempFile("upload-", ".bin", new | ||
// File("/tmp")); | ||
|
||
// / Create a temporary file placed in the default system | ||
// temp folder | ||
byte[] data = item.get(); | ||
// searching by default on DB Space 1 | ||
Object[] params = new Object[] { 1, data, 12, false }; | ||
try { | ||
Object[] result = (Object[]) iskClient.client.execute( | ||
"queryImgBlob", params); | ||
for (Object res : result) { | ||
Object[] r = (Object[]) res; | ||
int rid = (Integer) r[0]; | ||
response += (rid + ";"); | ||
response += (r[1] + ";"); | ||
response += (this.imgIdDb.getUrlForImg(rid) + ";"); | ||
} | ||
|
||
// return ""; | ||
} catch (XmlRpcException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
|
||
} catch (Exception e) { | ||
throw new UploadActionException(e.getMessage()); | ||
} | ||
} | ||
} | ||
|
||
// / Remove files from session because we have a copy of them | ||
removeSessionFileItems(request); | ||
|
||
// / Send your customized message to the client. | ||
return response; | ||
} | ||
|
||
/** | ||
* Get the content of an uploaded file. | ||
*/ | ||
@Override | ||
public void getUploadedFile(HttpServletRequest request, | ||
HttpServletResponse response) throws IOException { | ||
String fieldName = request.getParameter(UConsts.PARAM_SHOW); | ||
File f = receivedFiles.get(fieldName); | ||
if (f != null) { | ||
response.setContentType(receivedContentTypes.get(fieldName)); | ||
FileInputStream is = new FileInputStream(f); | ||
copyFromInputStreamToOutputStream(is, response.getOutputStream()); | ||
} else { | ||
renderXmlResponse(request, response, XML_ERROR_ITEM_NOT_FOUND); | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.