Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

*) adding soap function to import yacy bookmarks from xml or html (transfered via soap attachments) *) soapHandler: code cleanup for service deployment

thelif37e2041e8b2
diff --git a/source/de/anomic/data/bookmarksDB.java b/source/de/anomic/data/bookmarksDB.java
index f89dfd917..85c0dbf2f 100644
--- a/source/de/anomic/data/bookmarksDB.java
+++ b/source/de/anomic/data/bookmarksDB.java
@@ -44,6 +44,9 @@ package de.anomic.data;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -433,58 +436,92 @@ public class bookmarksDB {
public void addBookmark(String url, String title, ArrayList tags){
}
- public void importFromBookmarks(URL baseURL, String input, String tag, boolean importPublic){
- HashMap links=new HashMap();
- Iterator it;
- String url,title;
- Bookmark bm;
- HashSet tags=listManager.string2hashset(tag); //this allow multiple default tags
- try {
- //load the links
- htmlFilterContentScraper scraper = new htmlFilterContentScraper(baseURL);
- //OutputStream os = new htmlFilterOutputStream(null, scraper, null, false);
- Writer writer= new htmlFilterWriter(null,null,scraper, null, false);
- serverFileUtils.write(input,writer);
- writer.close();
- links = (HashMap) scraper.getAnchors();
- } catch (IOException e) {}
- it=links.keySet().iterator();
- while(it.hasNext()){
- url=(String) it.next();
- title=(String) links.get(url);
- if(title.equals("")){//cannot be displayed
- title=url;
- }
- bm=new Bookmark(url);
- bm.setProperty(Bookmark.BOOKMARK_TITLE, title);
- bm.setTags(tags);
- bm.setPublic(importPublic);
- saveBookmark(bm);
- }
- flushBookmarkCache();
- flushTagCache();
+
+ public int importFromBookmarks(URL baseURL, String input, String tag, boolean importPublic){
+ try {
+ // convert string to inputstream
+ ByteArrayInputStream byteIn = new ByteArrayInputStream(input.getBytes("UTF-8"));
+ InputStreamReader reader = new InputStreamReader(byteIn,"UTF-8");
+
+ // import stream
+ return this.importFromBookmarks(baseURL,reader,tag,importPublic);
+ } catch (UnsupportedEncodingException e) {
+ return 0;
+ }
+ }
+ public int importFromBookmarks(URL baseURL, InputStreamReader input, String tag, boolean importPublic){
+ int importCount = 0;
+
+ HashMap links=new HashMap();
+ Iterator it;
+ String url,title;
+ Bookmark bm;
+ HashSet tags=listManager.string2hashset(tag); //this allow multiple default tags
+ try {
+ //load the links
+ htmlFilterContentScraper scraper = new htmlFilterContentScraper(baseURL);
+ //OutputStream os = new htmlFilterOutputStream(null, scraper, null, false);
+ Writer writer= new htmlFilterWriter(null,null,scraper, null, false);
+ serverFileUtils.copy(input,writer);
+ writer.close();
+ links = (HashMap) scraper.getAnchors();
+ } catch (IOException e) {}
+ it=links.keySet().iterator();
+ while(it.hasNext()){
+ url=(String) it.next();
+ title=(String) links.get(url);
+ if(title.equals("")){//cannot be displayed
+ title=url;
+ }
+ bm=new Bookmark(url);
+ bm.setProperty(Bookmark.BOOKMARK_TITLE, title);
+ bm.setTags(tags);
+ bm.setPublic(importPublic);
+ saveBookmark(bm);
+
+ importCount++;
+ }
+ flushBookmarkCache();
+ flushTagCache();
+
+ return importCount;
}
- public void importFromXML(String input, boolean importPublic){
- DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
- factory.setValidating(false);
- factory.setNamespaceAware(false);
- DocumentBuilder builder;
- try {
- builder = factory.newDocumentBuilder();
- Document doc=builder.parse(new ByteArrayInputStream(input.getBytes()));
- parseXMLimport(doc, importPublic);
- } catch (ParserConfigurationException e) {
- } catch (SAXException e) {
- } catch (IOException e) {
- }
-
+
+ public int importFromXML(String input, boolean importPublic){
+ try {
+ // convert string to inputstream
+ ByteArrayInputStream byteIn = new ByteArrayInputStream(input.getBytes("UTF-8"));
+
+ // import stream
+ return this.importFromXML(byteIn,importPublic);
+ } catch (UnsupportedEncodingException e) {
+ return 0;
+ }
}
- public void parseXMLimport(Node doc, boolean importPublic){
+
+ public int importFromXML(InputStream input, boolean importPublic){
+ DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ factory.setNamespaceAware(false);
+ DocumentBuilder builder;
+ try {
+ builder = factory.newDocumentBuilder();
+ Document doc=builder.parse(input);
+ return parseXMLimport(doc, importPublic);
+ } catch (ParserConfigurationException e) {
+ } catch (SAXException e) {
+ } catch (IOException e) {
+ }
+ return 0;
+
+ }
+ public int parseXMLimport(Node doc, boolean importPublic){
+ int importCount = 0;
if(doc.getNodeName()=="post"){
NamedNodeMap attributes = doc.getAttributes();
String url=attributes.getNamedItem("href").getNodeValue();
if(url.equals("")){
- return;
+ return 0;
}
Bookmark bm=new Bookmark(url);
String tagsString="";
@@ -520,15 +557,19 @@ public class bookmarksDB {
}
bm.setPublic(importPublic);
saveBookmark(bm);
+
+ importCount++;
}
NodeList children=doc.getChildNodes();
if(children != null){
for (int i=0; i<children.getLength(); i++) {
- parseXMLimport(children.item(i), importPublic);
+ importCount += parseXMLimport(children.item(i), importPublic);
}
}
flushBookmarkCache();
flushTagCache();
+
+ return importCount;
}
/**
* Subclass, which stores an Tag
diff --git a/source/de/anomic/soap/httpdSoapHandler.java b/source/de/anomic/soap/httpdSoapHandler.java
index 1a1bcf08f..f15715644 100644
--- a/source/de/anomic/soap/httpdSoapHandler.java
+++ b/source/de/anomic/soap/httpdSoapHandler.java
@@ -181,7 +181,9 @@ public final class httpdSoapHandler extends httpdAbstractHandler implements http
/* ===============================================================
* Other object fields
- * =============================================================== */
+ * =============================================================== */
+ private static final Object initSync = new Object();
+
private serverClassLoader provider = null;
private HashMap templates;
private serverSwitch switchboard;
@@ -191,32 +193,7 @@ public final class httpdSoapHandler extends httpdAbstractHandler implements http
private File htTemplatePath;
private static Properties additionalServices = null;
-
- /*
- * Creating and configuring an apache Axis server.
- * This is only needed once.
- */
- static {
- // create an Axis server
- serverLog.logInfo("SOAP","Init soap engine ...");
- engine = new AxisServer();
-
- // setting some options ...
- engine.setShouldSaveConfig(false);
-
- serverLog.logInfo("SOAP","Deploying default services ...");
- for (int i=0; i < defaultServices.length; i++) {
- String[] nextService = defaultServices[i].split("=");
- serverLog.logInfo("SOAP","Deploying service " + nextService[0] + ":" + nextService[1]);
- String deploymentStr = serviceDeploymentString
- .replaceAll("@serviceName@", nextService[0])
- .replaceAll("@className@", nextService[1]);
- // deploy the service
- deployService(deploymentStr,engine);
- }
- }
-
/**
* Constructor of this class
* @param theSwitchboard
@@ -242,50 +219,76 @@ public final class httpdSoapHandler extends httpdAbstractHandler implements http
this.provider = new serverClassLoader(/*this.getClass().getClassLoader()*/);
}
- if (this.templates == null) this.templates = loadTemplates(this.htTemplatePath);
-
- synchronized (engine) {
- if (additionalServices == null) {
- additionalServices = new Properties();
-
- // getting the property filename containing the file list
- String fileName = theSwitchboard.getConfig("soap.serviceDeploymentList","");
- if (fileName.length() > 0) {
- BufferedInputStream fileInput = null;
- try {
- File deploymentFile = new File(theSwitchboard.getRootPath(),fileName);
- fileInput = new BufferedInputStream(new FileInputStream(deploymentFile));
-
- // load property list
- additionalServices.load(fileInput);
- fileInput.close();
-
- // loop through and deploy services
- if (additionalServices.size() > 0) {
- Enumeration serviceNameEnum = additionalServices.keys();
- while (serviceNameEnum.hasMoreElements()) {
- String serviceName = (String) serviceNameEnum.nextElement();
- String className = additionalServices.getProperty(serviceName);
-
- String deploymentStr = serviceDeploymentString
- .replaceAll("@serviceName@", serviceName)
- .replaceAll("@className@", className);
-
- // deploy the service
- deployService(deploymentStr,engine);
- }
- }
- } catch (Exception e) {
- this.theLogger.logSevere("Unable to deploy additional services: " + e.getMessage(), e);
- } finally {
- if (fileInput != null) try { fileInput.close(); } catch (Exception e){/* ignore this */}
- }
- }
- }
+ if (this.templates == null) {
+ this.templates = loadTemplates(this.htTemplatePath);
+ }
- }
+ // deploy default soap services
+ if (engine == null) synchronized (initSync) { deployDefaultServices(); }
+
+ // init additional soap services
+ if (additionalServices == null) synchronized (initSync) { deployAdditionalServices(); }
}
+ private void deployDefaultServices() {
+ // create an Axis server
+ this.theLogger.logInfo("Init soap engine ...");
+ engine = new AxisServer();
+
+ // setting some options ...
+ engine.setShouldSaveConfig(false);
+
+ this.theLogger.logInfo("Deploying default services ...");
+ for (int i=0; i < defaultServices.length; i++) {
+ String[] nextService = defaultServices[i].split("=");
+ this.theLogger.logInfo("Deploying service " + nextService[0] + ": " + nextService[1]);
+ String deploymentStr = serviceDeploymentString
+ .replaceAll("@serviceName@", nextService[0])
+ .replaceAll("@className@", nextService[1]);
+
+ // deploy the service
+ deployService(deploymentStr,engine);
+ }
+ }
+
+ private void deployAdditionalServices() {
+ additionalServices = new Properties();
+
+ // getting the property filename containing the file list
+ String fileName = this.switchboard.getConfig("soap.serviceDeploymentList","");
+ if (fileName.length() > 0) {
+ BufferedInputStream fileInput = null;
+ try {
+ File deploymentFile = new File(this.switchboard.getRootPath(),fileName);
+ fileInput = new BufferedInputStream(new FileInputStream(deploymentFile));
+
+ // load property list
+ additionalServices.load(fileInput);
+ fileInput.close();
+
+ // loop through and deploy services
+ if (additionalServices.size() > 0) {
+ Enumeration serviceNameEnum = additionalServices.keys();
+ while (serviceNameEnum.hasMoreElements()) {
+ String serviceName = (String) serviceNameEnum.nextElement();
+ String className = additionalServices.getProperty(serviceName);
+
+ String deploymentStr = serviceDeploymentString
+ .replaceAll("@serviceName@", serviceName)
+ .replaceAll("@className@", className);
+
+ // deploy the service
+ deployService(deploymentStr,engine);
+ }
+ }
+ } catch (Exception e) {
+ this.theLogger.logSevere("Unable to deploy additional services: " + e.getMessage(), e);
+ } finally {
+ if (fileInput != null) try { fileInput.close(); } catch (Exception e){/* ignore this */}
+ }
+ }
+ }
+
private InputStream getBodyInputStream(httpHeader requestHeader, PushbackInputStream body) throws SoapException{
InputStream input;
diff --git a/source/de/anomic/soap/services/BookmarkService.java b/source/de/anomic/soap/services/BookmarkService.java
index f826f2d21..8b6a8d2e0 100644
--- a/source/de/anomic/soap/services/BookmarkService.java
+++ b/source/de/anomic/soap/services/BookmarkService.java
@@ -46,14 +46,25 @@
package de.anomic.soap.services;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
+import javax.activation.DataHandler;
+import javax.xml.soap.SOAPException;
+
import org.apache.axis.AxisFault;
+import org.apache.axis.Message;
+import org.apache.axis.MessageContext;
+import org.apache.axis.attachments.AttachmentPart;
+import org.apache.axis.attachments.Attachments;
import org.w3c.dom.Document;
import de.anomic.data.bookmarksDB;
import de.anomic.index.indexURL;
+import de.anomic.net.URL;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverObjects;
import de.anomic.soap.AbstractService;
@@ -67,12 +78,58 @@ public class BookmarkService extends AbstractService {
private static final String TEMPLATE_BOOKMARK_LIST_XML = "xml/bookmarks/posts/get.xml";
private static final String TEMPLATE_BOOKMARK_TAGS_XML = "xml/bookmarks/tags/get.xml";
+ /**
+ * @return a handler to the YaCy Bookmark DB
+ */
+ private bookmarksDB getBookmarkDB() {
+ assert (this.switchboard != null) : "Switchboard object is null";
+ assert (this.switchboard instanceof plasmaSwitchboard) : "Incorrect switchboard object";
+ assert (((plasmaSwitchboard)this.switchboard).bookmarksDB != null) : "Bookmark DB is null";
+
+ return ((plasmaSwitchboard)this.switchboard).bookmarksDB;
+ }
+
+ /**
+ * @return returns the input stream of a soap attachment
+ * @throws AxisFault if no attachment was found or attachments are not supported
+ * @throws SOAPException if attachment decoding didn't work
+ * @throws IOException on attachment read errors
+ */
+ private InputStream getAttachmentInputstream() throws AxisFault, SOAPException, IOException {
+ // get the current message context
+ MessageContext msgContext = MessageContext.getCurrentContext();
+
+ // getting the request message
+ Message reqMsg = msgContext.getRequestMessage();
+
+ // getting the attachment implementation
+ Attachments messageAttachments = reqMsg.getAttachmentsImpl();
+ if (messageAttachments == null) {
+ throw new AxisFault("Attachments not supported");
+ }
+
+ int attachmentCount= messageAttachments.getAttachmentCount();
+ if (attachmentCount == 0)
+ throw new AxisFault("No attachment found");
+ else if (attachmentCount != 1)
+ throw new AxisFault("Too many attachments as expected.");
+
+ // getting the attachments
+ AttachmentPart[] attachments = (AttachmentPart[])messageAttachments.getAttachments().toArray(new AttachmentPart[attachmentCount]);
+
+ // getting the content of the attachment
+ DataHandler dh = attachments[0].getDataHandler();
+
+ // return the input stream
+ return dh.getInputStream();
+ }
+
/**
* Converts an array of tags into a HashSet
* @param tagArray the array of tags
* @return the HashSet
*/
- private HashSet stringArrayToHashSet(String[] tagArray) {
+ private HashSet tagArrayToHashSet(String[] tagArray) {
HashSet tagSet = new HashSet();
if (tagArray == null) return tagSet;
@@ -84,6 +141,25 @@ public class BookmarkService extends AbstractService {
return tagSet;
}
+ /**
+ * Converts the tag array into a space separated list
+ * @param tagArray the tag array
+ * @return space separated list of tags
+ */
+ private String tagArrayToSepString(String[] tagArray, String sep) {
+ StringBuffer buffer = new StringBuffer();
+
+ for (int i=0; i < tagArray.length; i++) {
+ String nextTag = tagArray[i].trim();
+ if (nextTag.length() > 0) {
+ if (i > 0) buffer.append(sep);
+ buffer.append(nextTag);
+ }
+ }
+
+ return buffer.toString();
+ }
+
/**
* To publish a YaCy news message that a new bookmark was added.
* This is only done for public bookmarks
@@ -98,14 +174,14 @@ public class BookmarkService extends AbstractService {
if (tags == null || tags.length == 0) tags = new String[]{"unsorted"};
// convert tag array into hashset
- HashSet tagSet = stringArrayToHashSet(tags);
+ String tagString = tagArrayToSepString(tags," ");
// create a news message
HashMap map = new HashMap();
map.put("url", url.replace(',', '|'));
map.put("title", title.replace(',', ' '));
map.put("description", description.replace(',', ' '));
- map.put("tags", tagSet.toString().replace(',', ' '));
+ map.put("tags", tagString);
yacyCore.newsPool.publishMyNews(new yacyNewsRecord("bkmrkadd", map));
}
@@ -132,7 +208,7 @@ public class BookmarkService extends AbstractService {
// convert tag array into hashset
HashSet tagSet = null;
- if (tags != null) tagSet = stringArrayToHashSet(tags);
+ if (tags != null) tagSet = tagArrayToHashSet(tags);
// set properties
if (url != null) bookmark.setProperty(bookmarksDB.Bookmark.BOOKMARK_URL, url);
@@ -167,7 +243,7 @@ public class BookmarkService extends AbstractService {
if (url == null || url.length()==0) throw new IllegalArgumentException("The url must not be null or empty");
// create new bookmark object
- bookmarksDB.Bookmark bookmark = ((plasmaSwitchboard)this.switchboard).bookmarksDB.createBookmark(url);
+ bookmarksDB.Bookmark bookmark = getBookmarkDB().createBookmark(url);
// set bookmark properties
if(bookmark != null){
@@ -176,7 +252,7 @@ public class BookmarkService extends AbstractService {
// create a news message
publisNewBookmarkNews(url,title,description,tags);
}
- ((plasmaSwitchboard)this.switchboard).bookmarksDB.saveBookmark(bookmark);
+ getBookmarkDB().saveBookmark(bookmark);
} else {
throw new AxisFault("Unable to create bookmark. Unknown reason.");
}
@@ -197,7 +273,21 @@ public class BookmarkService extends AbstractService {
if (urlHash == null || urlHash.length()==0) throw new IllegalArgumentException("The url hash must not be null or empty");
// delete bookmark
- ((plasmaSwitchboard)this.switchboard).bookmarksDB.removeBookmark(urlHash);
+ getBookmarkDB().removeBookmark(urlHash);
+ }
+
+ public void deleteBookmarksByHash(String[] urlHashs) throws AxisFault {
+ // extracting the message context
+ extractMessageContext(AUTHENTICATION_NEEDED);
+ if (urlHashs == null || urlHashs.length==0) throw new IllegalArgumentException("The url hash array must not be null or empty");
+
+ for (int i=0; i < urlHashs.length; i++) {
+ String urlHash = urlHashs[i];
+ if (urlHash == null || urlHash.length()==0) throw new IllegalArgumentException("The url hash at position " + i + " is null or empty.");
+
+ // delete bookmark
+ getBookmarkDB().removeBookmark(urlHash);
+ }
}
public void deleteBookmark(String url) throws AxisFault {
@@ -210,6 +300,22 @@ public class BookmarkService extends AbstractService {
this.deleteBookmarkByHash(hash);
}
+ public void deleteBookmarks(String[] urls) throws AxisFault {
+ if (urls == null || urls.length==0) throw new IllegalArgumentException("The url array must not be null or empty");
+
+ String[] hashs = new String[urls.length];
+ for (int i=0; i < urls.length; i++) {
+ String url = urls[i];
+ if (url == null || url.length()==0) throw new IllegalArgumentException("The url at position " + i + " is null or empty");
+
+ // generating the url hash
+ hashs[i] = indexURL.urlHash(url);
+ }
+
+ // delete url
+ this.deleteBookmarksByHash(hashs);
+ }
+
/**
* Function to change the properties of a bookmark stored in the YaCy Bookmark DB
*
@@ -238,7 +344,7 @@ public class BookmarkService extends AbstractService {
if (urlHash == null || urlHash.length()==0) throw new IllegalArgumentException("The url hash must not be null or empty");
// getting the bookmark
- bookmarksDB.Bookmark bookmark = ((plasmaSwitchboard)this.switchboard).bookmarksDB.getBookmark(urlHash);
+ bookmarksDB.Bookmark bookmark = getBookmarkDB().getBookmark(urlHash);
if (bookmark == null) throw new AxisFault("Bookmark with hash " + urlHash + " could not be found");
// edit values
@@ -261,7 +367,7 @@ public class BookmarkService extends AbstractService {
if (oldTagName == null || oldTagName.length()==0) throw new IllegalArgumentException("The old tag name not be null or empty");
if (newTagName == null || newTagName.length()==0) throw new IllegalArgumentException("The nwe tag name not be null or empty");
- boolean success = ((plasmaSwitchboard)this.switchboard).bookmarksDB.renameTag(oldTagName,newTagName);
+ boolean success = getBookmarkDB().renameTag(oldTagName,newTagName);
if (!success) throw new AxisFault("Unable to rename tag. Unknown reason.");
}
@@ -324,4 +430,60 @@ public class BookmarkService extends AbstractService {
// sending back the result to the client
return this.convertContentToXML(result);
}
+
+ /**
+ * Function to import YaCy from XML (transfered via SOAP Attachment).<br>
+ * This function expects a xml document in the same format as returned by
+ * function {@link #getBookmarkList(String, String)}.
+ * @param isPublic specifies if the imported bookmarks are public or local
+ * @return the amount of imported bookmarks
+ *
+ * @throws SOAPException if there is no data in the attachment
+ * @throws IOException if authentication failed or the attachment could not be read
+ */
+ public int importBookmarkXML(boolean isPublic) throws SOAPException, IOException {
+
+ // extracting the message context
+ extractMessageContext(AUTHENTICATION_NEEDED);
+
+ // getting the attachment input stream
+ InputStream xmlIn = getAttachmentInputstream();
+
+ // import bookmarks
+ int importCount = getBookmarkDB().importFromXML(xmlIn, isPublic);
+
+ // return amount of imported bookmarks
+ return importCount;
+ }
+
+ /**
+ * Function to import YaCy from a html document (transfered via SOAP Attachment).<br>
+ * This function expects a well formed html document.
+ *
+ * @param baseURL the base url. This is needed to generate absolut URLs from relative URLs
+ * @param tags a list of bookmarks tags that should be assigned to the new bookmarks
+ * @param isPublic specifies if the imported bookmarks are public or local
+ * @return the amount of imported bookmarks
+ *
+ * @throws SOAPException if there is no data in the attachment
+ * @throws IOException if authentication failed or the attachment could not be read
+ */
+ public int importHtmlBookmarkFile(String baseURL, String[] tags, boolean isPublic) throws SOAPException, IOException {
+ if (tags == null || tags.length == 0) tags = new String[]{"unsorted"};
+
+ // extracting the message context
+ extractMessageContext(AUTHENTICATION_NEEDED);
+
+ // getting the attachment input stream
+ InputStream htmlIn = getAttachmentInputstream();
+ InputStreamReader htmlReader = new InputStreamReader(htmlIn,"UTF-8");
+
+ // import bookmarks
+ URL theBaseURL = new URL(baseURL);
+ String tagList = tagArrayToSepString(tags,",");
+ int importCount = getBookmarkDB().importFromBookmarks(theBaseURL,htmlReader, tagList,isPublic);
+
+ // return amount of imported bookmarks
+ return importCount;
+ }
}
diff --git a/source/de/anomic/soap/services/bookmarks.wsdl b/source/de/anomic/soap/services/bookmarks.wsdl
index 336abf2e9..fdd701b40 100644
--- a/source/de/anomic/soap/services/bookmarks.wsdl
+++ b/source/de/anomic/soap/services/bookmarks.wsdl
@@ -4,187 +4,272 @@ Built on Apr 22, 2006 (06:55:48 PDT)--><wsdl:types><schema targetNamespace="http
<wsdl:message name="addBookmarkResponse">
<wsdl:part name="addBookmarkReturn" type="xsd:string"/>
</wsdl:message>
+ <wsdl:message name="importHtmlBookmarkFileRequest">
+ <wsdl:part name="baseURL" type="xsd:string"/>
+ <wsdl:part name="tags" type="impl:ArrayOf_xsd_string"/>
+ <wsdl:part name="isPublic" type="xsd:boolean"/>
+ </wsdl:message>
+
<wsdl:message name="getBookmarkTagListResponse">
<wsdl:part name="getBookmarkTagListReturn" type="apachesoap:Document"/>
</wsdl:message>
<wsdl:message name="getBookmarkTagListRequest">
</wsdl:message>
-
<wsdl:message name="deleteBookmarkByHashRequest">
<wsdl:part name="urlHash" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="createNewXMLDocumentResponse">
+
<wsdl:part name="createNewXMLDocumentReturn" type="apachesoap:Document"/>
</wsdl:message>
<wsdl:message name="getBookmarkListResponse">
<wsdl:part name="getBookmarkListReturn" type="apachesoap:Document"/>
</wsdl:message>
+ <wsdl:message name="deleteBookmarksRequest">
+ <wsdl:part name="urls" type="impl:ArrayOf_xsd_string"/>
+ </wsdl:message>
+ <wsdl:message name="deleteBookmarksByHashResponse">
+ </wsdl:message>
+ <wsdl:message name="deleteBookmarksResponse">
+ </wsdl:message>
<wsdl:message name="renameTagRequest">
<wsdl:part name="oldTagName" type="xsd:string"/>
<wsdl:part name="newTagName" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="deleteBookmarkRequest">
<wsdl:part name="url" type="xsd:string"/>
+
</wsdl:message>
<wsdl:message name="editBookmarkRequest">
<wsdl:part name="urlHash" type="xsd:string"/>
-
<wsdl:part name="url" type="xsd:string"/>
<wsdl:part name="title" type="xsd:string"/>
<wsdl:part name="description" type="xsd:string"/>
<wsdl:part name="tags" type="impl:ArrayOf_xsd_string"/>
<wsdl:part name="isPublic" type="xsd:boolean"/>
</wsdl:message>
+
+ <wsdl:message name="importBookmarkXMLResponse">
+ <wsdl:part name="importBookmarkXMLReturn" type="xsd:int"/>
+ </wsdl:message>
+ <wsdl:message name="importBookmarkXMLRequest">
+ <wsdl:part name="isPublic" type="xsd:boolean"/>
+ </wsdl:message>
<wsdl:message name="createNewXMLDocumentRequest">
<wsdl:part name="rootElementName" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="renameTagResponse">
</wsdl:message>
+ <wsdl:message name="importHtmlBookmarkFileResponse">
+ <wsdl:part name="importHtmlBookmarkFileReturn" type="xsd:int"/>
+ </wsdl:message>
<wsdl:message name="addBookmarkRequest">
<wsdl:part name="url" type="xsd:string"/>
<wsdl:part name="title" type="xsd:string"/>
<wsdl:part name="description" type="xsd:string"/>
+
<wsdl:part name="tags" type="impl:ArrayOf_xsd_string"/>
<wsdl:part name="isPublic" type="xsd:boolean"/>
</wsdl:message>
-
+ <wsdl:message name="deleteBookmarksByHashRequest">
+ <wsdl:part name="urlHashs" type="impl:ArrayOf_xsd_string"/>
+ </wsdl:message>
<wsdl:message name="getBookmarkListRequest">
<wsdl:part name="tag" type="xsd:string"/>
<wsdl:part name="date" type="xsd:string"/>
+
</wsdl:message>
<wsdl:message name="editBookmarkResponse">
<wsdl:part name="editBookmarkReturn" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="deleteBookmarkResponse">
</wsdl:message>
-
<wsdl:message name="deleteBookmarkByHashResponse">
</wsdl:message>
<wsdl:portType name="BookmarkService">
+
<wsdl:operation name="renameTag" parameterOrder="oldTagName newTagName">
<wsdl:input message="impl:renameTagRequest" name="renameTagRequest"/>
<wsdl:output message="impl:renameTagResponse" name="renameTagResponse"/>
</wsdl:operation>
<wsdl:operation name="addBookmark" parameterOrder="url title description tags isPublic">
<wsdl:input message="impl:addBookmarkRequest" name="addBookmarkRequest"/>
-
<wsdl:output message="impl:addBookmarkResponse" name="addBookmarkResponse"/>
</wsdl:operation>
<wsdl:operation name="deleteBookmarkByHash" parameterOrder="urlHash">
+
<wsdl:input message="impl:deleteBookmarkByHashRequest" name="deleteBookmarkByHashRequest"/>
<wsdl:output message="impl:deleteBookmarkByHashResponse" name="deleteBookmarkByHashResponse"/>
</wsdl:operation>
+ <wsdl:operation name="deleteBookmarksByHash" parameterOrder="urlHashs">
+ <wsdl:input message="impl:deleteBookmarksByHashRequest" name="deleteBookmarksByHashRequest"/>
+ <wsdl:output message="impl:deleteBookmarksByHashResponse" name="deleteBookmarksByHashResponse"/>
+ </wsdl:operation>
<wsdl:operation name="deleteBookmark" parameterOrder="url">
<wsdl:input message="impl:deleteBookmarkRequest" name="deleteBookmarkRequest"/>
- <wsdl:output message="impl:deleteBookmarkResponse" name="deleteBookmarkResponse"/>
+ <wsdl:output message="impl:deleteBookmarkResponse" name="deleteBookmarkResponse"/>
+ </wsdl:operation>
+ <wsdl:operation name="deleteBookmarks" parameterOrder="urls">
+ <wsdl:input message="impl:deleteBookmarksRequest" name="deleteBookmarksRequest"/>
+ <wsdl:output message="impl:deleteBookmarksResponse" name="deleteBookmarksResponse"/>
</wsdl:operation>
<wsdl:operation name="editBookmark" parameterOrder="urlHash url title description tags isPublic">
<wsdl:input message="impl:editBookmarkRequest" name="editBookmarkRequest"/>
<wsdl:output message="impl:editBookmarkResponse" name="editBookmarkResponse"/>
+
</wsdl:operation>
<wsdl:operation name="getBookmarkList" parameterOrder="tag date">
<wsdl:input message="impl:getBookmarkListRequest" name="getBookmarkListRequest"/>
<wsdl:output message="impl:getBookmarkListResponse" name="getBookmarkListResponse"/>
</wsdl:operation>
-
<wsdl:operation name="getBookmarkTagList">
<wsdl:input message="impl:getBookmarkTagListRequest" name="getBookmarkTagListRequest"/>
<wsdl:output message="impl:getBookmarkTagListResponse" name="getBookmarkTagListResponse"/>
</wsdl:operation>
+
+ <wsdl:operation name="importBookmarkXML" parameterOrder="isPublic">
+ <wsdl:input message="impl:importBookmarkXMLRequest" name="importBookmarkXMLRequest"/>
+ <wsdl:output message="impl:importBookmarkXMLResponse" name="importBookmarkXMLResponse"/>
+ </wsdl:operation>
+ <wsdl:operation name="importHtmlBookmarkFile" parameterOrder="baseURL tags isPublic">
+ <wsdl:input message="impl:importHtmlBookmarkFileRequest" name="importHtmlBookmarkFileRequest"/>
+ <wsdl:output message="impl:importHtmlBookmarkFileResponse" name="importHtmlBookmarkFileResponse"/>
+ </wsdl:operation>
<wsdl:operation name="createNewXMLDocument" parameterOrder="rootElementName">
+
<wsdl:input message="impl:createNewXMLDocumentRequest" name="createNewXMLDocumentRequest"/>
<wsdl:output message="impl:createNewXMLDocumentResponse" name="createNewXMLDocumentResponse"/>
</wsdl:operation>
</wsdl:portType>
-
<wsdl:binding name="bookmarksSoapBinding" type="impl:BookmarkService">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="renameTag">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="renameTagRequest">
+
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
</wsdl:input>
<wsdl:output name="renameTagResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/bookmarks" use="encoded"/>
-
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="addBookmark">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="addBookmarkRequest">
+
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
</wsdl:input>
<wsdl:output name="addBookmarkResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/bookmarks" use="encoded"/>
-
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="deleteBookmarkByHash">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="deleteBookmarkByHashRequest">
+
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
</wsdl:input>
<wsdl:output name="deleteBookmarkByHashResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/bookmarks" use="encoded"/>
+ </wsdl:output>
+ </wsdl:operation>
+ <wsdl:operation name="deleteBookmarksByHash">
+ <wsdlsoap:operation soapAction=""/>
+ <wsdl:input name="deleteBookmarksByHashRequest">
+ <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
+ </wsdl:input>
+ <wsdl:output name="deleteBookmarksByHashResponse">
+ <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/bookmarks" use="encoded"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="deleteBookmark">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="deleteBookmarkRequest">
+
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
</wsdl:input>
<wsdl:output name="deleteBookmarkResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/bookmarks" use="encoded"/>
+ </wsdl:output>
+ </wsdl:operation>
+ <wsdl:operation name="deleteBookmarks">
+ <wsdlsoap:operation soapAction=""/>
+ <wsdl:input name="deleteBookmarksRequest">
+ <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
+ </wsdl:input>
+ <wsdl:output name="deleteBookmarksResponse">
+ <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/bookmarks" use="encoded"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="editBookmark">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="editBookmarkRequest">
+
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
</wsdl:input>
<wsdl:output name="editBookmarkResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/bookmarks" use="encoded"/>
-
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getBookmarkList">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getBookmarkListRequest">
+
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
</wsdl:input>
<wsdl:output name="getBookmarkListResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/bookmarks" use="encoded"/>
-
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getBookmarkTagList">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getBookmarkTagListRequest">
+
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
</wsdl:input>
<wsdl:output name="getBookmarkTagListResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/bookmarks" use="encoded"/>
+ </wsdl:output>
+ </wsdl:operation>
+ <wsdl:operation name="importBookmarkXML">
+ <wsdlsoap:operation soapAction=""/>
+ <wsdl:input name="importBookmarkXMLRequest">
+
+ <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
+ </wsdl:input>
+ <wsdl:output name="importBookmarkXMLResponse">
+ <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/bookmarks" use="encoded"/>
+ </wsdl:output>
+ </wsdl:operation>
+ <wsdl:operation name="importHtmlBookmarkFile">
+ <wsdlsoap:operation soapAction=""/>
+ <wsdl:input name="importHtmlBookmarkFileRequest">
+ <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
+ </wsdl:input>
+ <wsdl:output name="importHtmlBookmarkFileResponse">
+ <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/bookmarks" use="encoded"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="createNewXMLDocument">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="createNewXMLDocumentRequest">
+
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://soap.anomic.de" use="encoded"/>
</wsdl:input>
<wsdl:output name="createNewXMLDocumentResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/bookmarks" use="encoded"/>
-
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="BookmarkServiceService">
<wsdl:port binding="impl:bookmarksSoapBinding" name="bookmarks">
+
<wsdlsoap:address location="http://yacy:8080/soap/bookmarks"/>
</wsdl:port>
</wsdl:service>
diff --git a/test/de/anomic/soap/services/AdminServiceTest.java b/test/de/anomic/soap/services/AdminServiceTest.java
index 52167542a..e98e58d76 100644
--- a/test/de/anomic/soap/services/AdminServiceTest.java
+++ b/test/de/anomic/soap/services/AdminServiceTest.java
@@ -27,9 +27,9 @@ public class AdminServiceTest extends AbstractServiceTest {
private HashMap getMessageForwardingProperties(Document xml) throws DOMException, TransformerException {
HashMap result = new HashMap();
- result.put("msgForwardingEnabled",Boolean.valueOf(XPathAPI.selectSingleNode(xml,"/msgForwarding/msgForwardingEnabled").getTextContent()));
- result.put("msgForwardingCmd",XPathAPI.selectSingleNode(xml,"/msgForwarding/msgForwardingCmd").getTextContent());
- result.put("msgForwardingTo",XPathAPI.selectSingleNode(xml,"/msgForwarding/msgForwardingTo").getTextContent());
+ result.put("msgForwardingEnabled",Boolean.valueOf(XPathAPI.selectSingleNode(xml,"/msgForwarding/msgForwardingEnabled").getFirstChild().getNodeValue()));
+ result.put("msgForwardingCmd",XPathAPI.selectSingleNode(xml,"/msgForwarding/msgForwardingCmd").getFirstChild().getNodeValue());
+ result.put("msgForwardingTo",XPathAPI.selectSingleNode(xml,"/msgForwarding/msgForwardingTo").getFirstChild().getNodeValue());
return result;
}
@@ -48,9 +48,9 @@ public class AdminServiceTest extends AbstractServiceTest {
Document xml = ((AdminService)service).getMessageForwarding();
// check if values are equal
- assertEquals(msgEnabled,Boolean.valueOf(XPathAPI.selectSingleNode(xml,"/msgForwarding/msgForwardingEnabled").getTextContent()));
- assertEquals(msgCmd,XPathAPI.selectSingleNode(xml,"/msgForwarding/msgForwardingCmd").getTextContent());
- assertEquals(msgTo,XPathAPI.selectSingleNode(xml,"/msgForwarding/msgForwardingTo").getTextContent());
+ assertEquals(msgEnabled,Boolean.valueOf(XPathAPI.selectSingleNode(xml,"/msgForwarding/msgForwardingEnabled").getFirstChild().getNodeValue()));
+ assertEquals(msgCmd,XPathAPI.selectSingleNode(xml,"/msgForwarding/msgForwardingCmd").getFirstChild().getNodeValue());
+ assertEquals(msgTo,XPathAPI.selectSingleNode(xml,"/msgForwarding/msgForwardingTo").getFirstChild().getNodeValue());
// print it out
System.out.println(XMLUtils.DocumentToString(xml));
diff --git a/test/de/anomic/soap/services/BookmarkServiceTest.java b/test/de/anomic/soap/services/BookmarkServiceTest.java
index 9badee2c8..0fdfce40e 100644
--- a/test/de/anomic/soap/services/BookmarkServiceTest.java
+++ b/test/de/anomic/soap/services/BookmarkServiceTest.java
@@ -1,15 +1,24 @@
package de.anomic.soap.services;
+import java.net.MalformedURLException;
+import java.rmi.RemoteException;
import java.util.Date;
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
import javax.xml.rpc.ServiceException;
+import org.apache.axis.attachments.AttachmentPart;
+import org.apache.axis.attachments.PlainTextDataSource;
+import org.apache.axis.client.Stub;
import org.apache.axis.utils.XMLUtils;
import org.w3c.dom.Document;
import yacy.soap.bookmarks.BookmarkService;
import yacy.soap.bookmarks.BookmarkServiceServiceLocator;
import de.anomic.data.bookmarksDB;
+import de.anomic.index.indexURL;
+import de.anomic.net.URL;
public class BookmarkServiceTest extends AbstractServiceTest {
@@ -47,5 +56,98 @@ public class BookmarkServiceTest extends AbstractServiceTest {
// delete tag
bm.deleteBookmarkByHash(urlHash);
}
+
+ public void testImportHtmlBookmarklist() throws RemoteException {
+ BookmarkService bm = ((BookmarkService)service);
+ String[] hashs = new String[5];
+
+ // generate the html file
+ StringBuffer xmlStr = new StringBuffer();
+ xmlStr.append("<html><body>");
+ for (int i=0; i < hashs.length; i++) {
+ String url = "/testxmlimport" + i;
+ String title = "YaCy Bookmark XML Import " + i;
+ String hash = indexURL.urlHash("http://www.yacy.de"+ url);
+
+ xmlStr.append("\t<a href=\"").append(url).append("\">").append(title).append("</a>\r\n");
+
+ hashs[i] = hash;
+ }
+ xmlStr.append("</body></html>");
+
+ // create datasource to hold the attachment content
+ DataSource data = new PlainTextDataSource("bookmarks.html",xmlStr.toString());
+ DataHandler attachmentFile = new DataHandler(data);
+
+ // creating attachment part
+ AttachmentPart part = new AttachmentPart();
+ part.setDataHandler(attachmentFile);
+
+ // setting the attachment format that should be used
+ ((Stub)service)._setProperty(org.apache.axis.client.Call.ATTACHMENT_ENCAPSULATION_FORMAT,org.apache.axis.client.Call.ATTACHMENT_ENCAPSULATION_FORMAT_MIME);
+ ((Stub)service).addAttachment(part);
+
+ // import xml
+ int importCount = bm.importHtmlBookmarkFile("http://www.yacy.de/",new String[]{"yacy","bookmarks","htmlimport"},false);
+ assertEquals(hashs.length,importCount);
+
+ // query imported documents
+ Document xml = bm.getBookmarkList("htmlimport",null);
+ System.out.println(XMLUtils.DocumentToString(xml));
+
+ // delete imported URLS
+ bm.deleteBookmarksByHash(hashs);
+ }
+
+ public void testImportXML() throws MalformedURLException, RemoteException {
+ BookmarkService bm = ((BookmarkService)service);
+
+ String dateString = bookmarksDB.dateToiso8601(new Date(System.currentTimeMillis()));
+ String[] hashs = new String[5];
+
+ // generate xml document to import
+ StringBuffer xmlStr = new StringBuffer();
+ xmlStr.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n")
+ .append("<posts>\r\n");
+
+ for (int i=0; i < hashs.length; i++) {
+ URL url = new URL("http://www.yacy.de/testxmlimport" + i);
+ String title = "YaCy Bookmark XML Import " + i;
+ String description = "YaCy Bookmarkx XML Import junit test with url " + i;
+ String hash = indexURL.urlHash(url);
+ String tags = "yacy bookmarks xmlimport";
+
+ xmlStr.append("\t<post description=\"").append(title).append("\" extended=\"")
+ .append(description).append("\" hash=\"").append(hash).append("\" href=\"")
+ .append(url).append("\" tag=\"").append(tags).append("\" time=\"").append(dateString).append("\"/>\r\n");
+
+ hashs[i] = hash;
+ }
+
+ xmlStr.append("</posts>");
+
+ // create datasource to hold the attachment content
+ DataSource data = new PlainTextDataSource("bookmarks.xml",xmlStr.toString());
+ DataHandler attachmentFile = new DataHandler(data);
+
+ // creating attachment part
+ AttachmentPart part = new AttachmentPart();
+ part.setDataHandler(attachmentFile);
+
+ // setting the attachment format that should be used
+ ((Stub)service)._setProperty(org.apache.axis.client.Call.ATTACHMENT_ENCAPSULATION_FORMAT,org.apache.axis.client.Call.ATTACHMENT_ENCAPSULATION_FORMAT_MIME);
+ ((Stub)service).addAttachment(part);
+
+ // import xml
+ int importCount = bm.importBookmarkXML(false);
+ assertEquals(hashs.length,importCount);
+
+ // query imported documents
+ Document xml = bm.getBookmarkList("xmlimport",dateString);
+ System.out.println(XMLUtils.DocumentToString(xml));
+
+ // delete imported URLS
+ bm.deleteBookmarksByHash(hashs);
+ }
}
diff --git a/test/de/anomic/soap/services/ServiceTests.java b/test/de/anomic/soap/services/ServiceTests.java
index 5b155267b..05a1f752a 100644
--- a/test/de/anomic/soap/services/ServiceTests.java
+++ b/test/de/anomic/soap/services/ServiceTests.java
@@ -12,6 +12,7 @@ public class ServiceTests {
suite.addTestSuite(ShareServiceTest.class);
suite.addTestSuite(StatusServiceTest.class);
suite.addTestSuite(BlacklistServiceTest.class);
+ suite.addTestSuite(BookmarkServiceTest.class);
//$JUnit-END$
return suite;
}