From 97615af406688af816370f2a42d0c91a84abf88d Mon Sep 17 00:00:00 2001 From: theli Date: Tue, 26 Sep 2006 14:47:44 +0000 Subject: [PATCH] *) Restructuring of YaCy SOAP services - general functions moved to abstract service class - service class splitted into SearchService, CrawlService, StatusService *) Bugfix for SOAP search services - Attention: some xml tages where renamed See: http://www.yacy-forum.de/viewtopic.php?p=25877 *) New SOAP service function urlInfo to view the parsed content of an URL See: http://www.yacy-forum.de/viewtopic.php?p=25869 git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2660 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/ViewFile.soap | 24 ++ htroot/yacysearch.soap | 24 +- ...dSoapService.java => AbstractService.java} | 218 +++--------------- source/de/anomic/soap/httpdSoapHandler.java | 66 +++++- .../de/anomic/soap/services/CrawlService.java | 94 ++++++++ .../anomic/soap/services/SearchService.java | 208 +++++++++++++++++ .../anomic/soap/services/StatusService.java | 79 +++++++ 7 files changed, 520 insertions(+), 193 deletions(-) create mode 100644 htroot/ViewFile.soap rename source/de/anomic/soap/{httpdSoapService.java => AbstractService.java} (56%) create mode 100644 source/de/anomic/soap/services/CrawlService.java create mode 100644 source/de/anomic/soap/services/SearchService.java create mode 100644 source/de/anomic/soap/services/StatusService.java diff --git a/htroot/ViewFile.soap b/htroot/ViewFile.soap new file mode 100644 index 000000000..1e7339634 --- /dev/null +++ b/htroot/ViewFile.soap @@ -0,0 +1,24 @@ + + + + #(error)#::#[url]##(/error)# + #(error)#::#[hash]##(/error)# + #(error)#::#[wordCount]##(/error)# + #(error)#::#[desc]##(/error)# + #(error)#::#[size]##(/error)# + #(error)#::#[mimeType]##(/error)# + #(error)#0::1::2::3::4::5::6#(/error)# + + + #(viewMode)# + :: + + :: + + :: + #{sentences}# + + #{/sentences}# + #(/viewMode)# + + \ No newline at end of file diff --git a/htroot/yacysearch.soap b/htroot/yacysearch.soap index 6dc8b93ef..b1cabb187 100644 --- a/htroot/yacysearch.soap +++ b/htroot/yacysearch.soap @@ -1,26 +1,34 @@ - + Search for #[former]# Search for #[former]# #(type)# - #[totalcount]# - #[linkcount]# + #(num-results)#::::::::::#[totalcount]##(/num-results)# + #(num-results)#::::::::::#[linkcount]##(/num-results)# - + + #(excluded)#::#[stopwords]##(/excluded)# + + + #(combine)#:: - #{words}##[word]##{/words}# + #{words}##[word]##{/words}# #(/combine)# - + - #{results}# + + #{results}# #[description]# #[url]# + #[urlhash]# #[urlname]# - #[date]# + #[date]# #[size]# + YBR-#[ybr]# + #(snippet)#::#[text]##(/snippet)# #{/results}# :: diff --git a/source/de/anomic/soap/httpdSoapService.java b/source/de/anomic/soap/AbstractService.java similarity index 56% rename from source/de/anomic/soap/httpdSoapService.java rename to source/de/anomic/soap/AbstractService.java index 95cc7dc6e..16c761d38 100644 --- a/source/de/anomic/soap/httpdSoapService.java +++ b/source/de/anomic/soap/AbstractService.java @@ -1,4 +1,4 @@ -//httpdSoapService.java +//AbstractService.java //------------------------ //part of YaCy //(C) by Michael Peter Christen; mc@anomic.de @@ -45,15 +45,13 @@ package de.anomic.soap; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.io.StringReader; import java.lang.reflect.Method; -import java.util.Arrays; import java.util.HashMap; -import java.util.HashSet; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -64,7 +62,6 @@ import org.apache.axis.MessageContext; import org.apache.axis.message.SOAPEnvelope; import org.apache.axis.message.SOAPHeaderElement; import org.w3c.dom.Document; -import org.xml.sax.InputSource; import de.anomic.http.httpHeader; import de.anomic.http.httpTemplate; @@ -72,172 +69,35 @@ import de.anomic.server.serverClassLoader; import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch; -/** - * SOAP Service Class that will be invoked by the httpdSoapHandler - * - * @author Martin Thelian - */ -public class httpdSoapService -{ - /* ================================================================ - * Constants needed to set the template that should be used to - * fullfil the request - * ================================================================ */ - /** - * Constant: template for searching - */ - private static final String TEMPLATE_SEARCH = "yacysearch.soap"; - /** - * Constant: template for the network status page - */ - private static final String TEMPLATE_NETWORK_XML = "Network.xml"; - /** - * Constant: template for crawling - */ - private static final String TEMPLATE_CRAWLING = "IndexCreate_p.html"; - - /* ================================================================ - * Other Object fields - * ================================================================ */ - /** - * A hashset containing all templates that requires user authentication - */ - private static final HashSet SERVICE_NEEDS_AUTHENTICATION = new HashSet(Arrays.asList(new String[] - {TEMPLATE_CRAWLING})); - - private String rootPath; - private serverClassLoader provider; - private HashMap templates; - private serverSwitch switchboard; - private httpHeader requestHeader; - private MessageContext messageContext; - - - /** - * Constructor of this class - */ - public httpdSoapService() { - super(); - - // nothing special todo here at the moment - } - - /** - * Service for doing a simple search with the standard settings - * - * @param searchString the search string that should be used - * @return an rss document containing the search results. - * - * @throws AxisFault if the service could not be executed propery. - */ - public Document search( - String searchString, - String searchMode, - String searchOrder, - int maxSearchCount, - int maxSearchTime, - String urlMaskFilter - ) - throws AxisFault { - try { - // extracting the message context - extractMessageContext(); - - if ((searchMode == null) || !(searchMode.equalsIgnoreCase("global") || searchMode.equalsIgnoreCase("locale"))) { - searchMode = "global"; - } - - if (urlMaskFilter == null) urlMaskFilter = ".*"; - - // setting the searching properties - serverObjects args = new serverObjects(); - args.put("order","Quality-Date"); - args.put("Enter","Search"); - args.put("count",Integer.toString(maxSearchCount)); - args.put("resource","global"); - args.put("time",Integer.toString(maxSearchTime)); - args.put("urlmaskfilter",urlMaskFilter); - - args.put("search",searchString); - - // generating the template containing the search result - String result = writeTemplate(TEMPLATE_SEARCH, args); - - // sending back the result to the client - return this.convertContentToXML(result); - } catch (Exception e) { - throw new AxisFault(e.getMessage()); - } - } - - /** - * Service used to query the network properties - * @throws AxisFault if the service could not be executed propery. - */ - public String network() throws AxisFault { - try { - // extracting the message context - extractMessageContext(); - - // generating the template containing the network status information - String result = writeTemplate(TEMPLATE_NETWORK_XML, new serverObjects()); - - // sending back the result to the client - return result; - } catch (Exception e) { - throw new AxisFault(e.getMessage()); - } - } - - /** - * Service used start a new crawling job using the default settings for crawling - * - * @return returns the http status page containing the crawling properties to the user - * TODO: creating an extra xml template that can be send back to the client. - * - * @throws AxisFault if the service could not be executed propery. - */ - public String crawling(String crawlingURL) throws AxisFault { - try { - // extracting the message context - extractMessageContext(); - - // setting the crawling properties - serverObjects args = new serverObjects(); - args.put("crawlingQ","on"); - args.put("xsstopw","on"); - args.put("crawlOrder","on"); - args.put("crawlingstart","Start New Crawl"); - args.put("crawlingDepth","2"); - args.put("crawlingFilter",".*"); - args.put("storeHTCache","on"); - args.put("localIndexing","on"); - args.put("crawlingURL",crawlingURL); - - // triggering the crawling - String result = writeTemplate(TEMPLATE_CRAWLING, args); - - // sending back the crawling status page to the user - return result; - } catch (Exception e) { - throw new AxisFault(e.getMessage()); - } - } +public abstract class AbstractService { + protected String rootPath; + protected serverClassLoader provider; + protected HashMap templates; + protected serverSwitch switchboard; + protected httpHeader requestHeader; + protected MessageContext messageContext; /** * This function is called by the available service functions to * extract all needed informations from the SOAP message context. + * @throws AxisFault */ - private void extractMessageContext() { + protected void extractMessageContext(boolean authenticate) throws AxisFault { this.messageContext = MessageContext.getCurrentContext(); this.rootPath = (String) this.messageContext.getProperty(httpdSoapHandler.MESSAGE_CONTEXT_HTTP_ROOT_PATH); this.provider = (serverClassLoader) this.messageContext.getProperty(httpdSoapHandler.MESSAGE_CONTEXT_SERVER_CLASSLOADER); this.templates = (HashMap) this.messageContext.getProperty(httpdSoapHandler.MESSAGE_CONTEXT_TEMPLATES); this.switchboard = (serverSwitch) this.messageContext.getProperty(httpdSoapHandler.MESSAGE_CONTEXT_SERVER_SWITCH); - this.requestHeader = (httpHeader) this.messageContext.getProperty(httpdSoapHandler.MESSAGE_CONTEXT_HTTP_HEADER); + this.requestHeader = (httpHeader) this.messageContext.getProperty(httpdSoapHandler.MESSAGE_CONTEXT_HTTP_HEADER); + + if (authenticate) { + this.doAuthentication(); + } } + + /** * This function is called by the service functions to * invoke the desired server-internal method and to generate @@ -248,17 +108,13 @@ public class httpdSoapService * @return * @throws AxisFault */ - private String writeTemplate(String templateName, serverObjects args) + protected byte[] writeTemplate(String templateName, serverObjects args) throws AxisFault { try { // determining the proper class that should be invoked File file = new File(this.rootPath, templateName); File rc = rewriteClassFile(file); - if (SERVICE_NEEDS_AUTHENTICATION.contains(templateName)) { - this.doAuthentication(); - } - // invoke the desired method serverObjects tp = (serverObjects) rewriteMethod(rc).invoke(null, new Object[] {this.requestHeader, args, this.switchboard}); @@ -271,17 +127,18 @@ public class httpdSoapService // generating the output document ByteArrayOutputStream o = new ByteArrayOutputStream(); FileInputStream fis = new FileInputStream(file); - httpTemplate.writeTemplate(fis, o, tp, "-UNRESOLVED_PATTERN-".getBytes()); + httpTemplate.writeTemplate(fis, o, tp, "-UNRESOLVED_PATTERN-".getBytes("UTF-8")); o.close(); fis.close(); // convert it into a byte array and send it back as result byte[] result = o.toByteArray(); - return new String(result, "UTF-8"); + return result; } catch (Exception e) { throw new AxisFault(e.getMessage()); } - } + } + /** * This function is used to test if an invoked method requires authentication @@ -290,9 +147,7 @@ public class httpdSoapService * * @throws AxisFault if an authentication was required. */ - private void validateAuthentication(serverObjects tp) - throws AxisFault - { + protected void validateAuthentication(serverObjects tp) throws AxisFault { // check if the servlets requests authentification if (tp.containsKey("AUTHENTICATE")) { throw new AxisFault("log-in required"); @@ -305,8 +160,7 @@ public class httpdSoapService * * @throws AxisFault if the authentication could not be done successfully */ - private void doAuthentication() - throws AxisFault { + protected void doAuthentication() throws AxisFault { // accessing the SOAP request message Message message = this.messageContext.getRequestMessage(); @@ -334,7 +188,7 @@ public class httpdSoapService * @param template * @return */ - private File rewriteClassFile(File template) { + protected File rewriteClassFile(File template) { try { String f = template.getCanonicalPath(); int p = f.lastIndexOf("."); @@ -354,12 +208,12 @@ public class httpdSoapService * @param classFile * @return */ - private Method rewriteMethod(File classFile) { + protected Method rewriteMethod(File classFile) { Method m = null; // now make a class out of the stream try { //System.out.println("**DEBUG** loading class file " + classFile); - Class c = provider.loadClass(classFile); + Class c = this.provider.loadClass(classFile); Class[] params = new Class[] { Class.forName("de.anomic.http.httpHeader"), Class.forName("de.anomic.server.serverObjects"), @@ -374,22 +228,24 @@ public class httpdSoapService return m; } - private Document convertContentToXML(String contentString) - throws Exception - { + protected Document convertContentToXML(String contentString) throws Exception { + return convertContentToXML(contentString.getBytes("UTF-8")); + } + + protected Document convertContentToXML(byte[] content) throws Exception { Document doc = null; try { DocumentBuilderFactory newDocBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder newDocBuilder = newDocBuilderFactory.newDocumentBuilder(); - InputSource is = new InputSource(new StringReader(contentString)); - doc = newDocBuilder.parse(is); + ByteArrayInputStream byteIn = new ByteArrayInputStream(content); + doc = newDocBuilder.parse(byteIn); } catch (Exception e) { String errorMessage = "Unable to parse the search result XML data. " + e.getClass().getName() + ". " + e.getMessage(); throw new Exception(errorMessage); } return doc; - } - + } + } diff --git a/source/de/anomic/soap/httpdSoapHandler.java b/source/de/anomic/soap/httpdSoapHandler.java index 24bc555e3..280e14693 100644 --- a/source/de/anomic/soap/httpdSoapHandler.java +++ b/source/de/anomic/soap/httpdSoapHandler.java @@ -1,3 +1,48 @@ +//httpdSoapHandler.java +//------------------------ +//part of YaCy +//(C) by Michael Peter Christen; mc@anomic.de +//first published on http://www.anomic.de +//Frankfurt, Germany, 2005 +// +//this file was contributed by Martin Thelian +//last major change: $LastChangedDate$ by $LastChangedBy$ +//Revision: $LastChangedRevision$ +// +//This program is free software; you can redistribute it and/or modify +//it under the terms of the GNU General Public License as published by +//the Free Software Foundation; either version 2 of the License, or +//(at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +//Using this software in any meaning (reading, learning, copying, compiling, +//running) means that you agree that the Author(s) is (are) not responsible +//for cost, loss of data or any harm that may be caused directly or indirectly +//by usage of this softare or this documentation. The usage of this software +//is on your own risk. The installation and usage (starting/running) of this +//software may allow other people or application to access your computer and +//any attached devices and is highly dependent on the configuration of the +//software which must be done by the user of the software; the author(s) is +//(are) also not responsible for proper configuration and usage of the +//software, even if provoked by documentation provided together with +//the software. +// +//Any changes to this file according to the GPL as documented in the file +//gpl.txt aside this file in the shipment you received can be done to the +//lines that follows this copyright notice here, but changes must not be +//done inside the copyright notive above. A re-distribution must contain +//the intact and unchanged copyright notice. +//Contributions and changes to the program code must be marked as such. + + package de.anomic.soap; import java.io.ByteArrayInputStream; @@ -89,14 +134,20 @@ public final class httpdSoapHandler extends httpdAbstractHandler implements http "" - + "" + + "" + "" + "" - + "" + + "" + "" + "" + ""; + public static final String[] services = new String[] { + "search=de.anomic.soap.services.SearchService", + "crawl=de.anomic.soap.services.CrawlService", + "status=de.anomic.soap.services.StatusSevice" + }; + /* =============================================================== * Constants needed to set the SOAP message context * =============================================================== */ @@ -143,8 +194,15 @@ public final class httpdSoapHandler extends httpdAbstractHandler implements http // setting some options ... engine.setShouldSaveConfig(false); - // deploy the service - deployService(serviceDeploymentString,engine); + for (int i=0; i < services.length; i++) { + String[] nextService = services[i].split("="); + String deploymentStr = serviceDeploymentString + .replaceAll("@serviceName@", nextService[0]) + .replaceAll("@className@", nextService[1]); + + // deploy the service + deployService(deploymentStr,engine); + } } /** diff --git a/source/de/anomic/soap/services/CrawlService.java b/source/de/anomic/soap/services/CrawlService.java new file mode 100644 index 000000000..22ba53d85 --- /dev/null +++ b/source/de/anomic/soap/services/CrawlService.java @@ -0,0 +1,94 @@ +//CrawlService.java +//------------------------ +//part of YaCy +//(C) by Michael Peter Christen; mc@anomic.de +//first published on http://www.anomic.de +//Frankfurt, Germany, 2005 +// +//this file was contributed by Martin Thelian +//last major change: $LastChangedDate$ by $LastChangedBy$ +//Revision: $LastChangedRevision$ +// +//This program is free software; you can redistribute it and/or modify +//it under the terms of the GNU General Public License as published by +//the Free Software Foundation; either version 2 of the License, or +//(at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +//Using this software in any meaning (reading, learning, copying, compiling, +//running) means that you agree that the Author(s) is (are) not responsible +//for cost, loss of data or any harm that may be caused directly or indirectly +//by usage of this softare or this documentation. The usage of this software +//is on your own risk. The installation and usage (starting/running) of this +//software may allow other people or application to access your computer and +//any attached devices and is highly dependent on the configuration of the +//software which must be done by the user of the software; the author(s) is +//(are) also not responsible for proper configuration and usage of the +//software, even if provoked by documentation provided together with +//the software. +// +//Any changes to this file according to the GPL as documented in the file +//gpl.txt aside this file in the shipment you received can be done to the +//lines that follows this copyright notice here, but changes must not be +//done inside the copyright notive above. A re-distribution must contain +//the intact and unchanged copyright notice. +//Contributions and changes to the program code must be marked as such. + + +package de.anomic.soap.services; + +import org.apache.axis.AxisFault; + +import de.anomic.server.serverObjects; +import de.anomic.soap.AbstractService; + +public class CrawlService extends AbstractService { + + /** + * Constant: template for crawling + */ + private static final String TEMPLATE_CRAWLING = "IndexCreate_p.html"; + + /** + * Service used start a new crawling job using the default settings for crawling + * + * @return returns the http status page containing the crawling properties to the user + * TODO: creating an extra xml template that can be send back to the client. + * + * @throws AxisFault if the service could not be executed propery. + */ + public String crawling(String crawlingURL) throws AxisFault { + try { + // extracting the message context + extractMessageContext(true); + + // setting the crawling properties + serverObjects args = new serverObjects(); + args.put("crawlingQ","on"); + args.put("xsstopw","on"); + args.put("crawlOrder","on"); + args.put("crawlingstart","Start New Crawl"); + args.put("crawlingDepth","2"); + args.put("crawlingFilter",".*"); + args.put("storeHTCache","on"); + args.put("localIndexing","on"); + args.put("crawlingURL",crawlingURL); + + // triggering the crawling + byte[] result = writeTemplate(TEMPLATE_CRAWLING, args); + + // sending back the crawling status page to the user + return new String(result,"UTF-8"); + } catch (Exception e) { + throw new AxisFault(e.getMessage()); + } + } +} diff --git a/source/de/anomic/soap/services/SearchService.java b/source/de/anomic/soap/services/SearchService.java new file mode 100644 index 000000000..71913a9fa --- /dev/null +++ b/source/de/anomic/soap/services/SearchService.java @@ -0,0 +1,208 @@ +//httpdSoapService.java +//------------------------ +//part of YaCy +//(C) by Michael Peter Christen; mc@anomic.de +//first published on http://www.anomic.de +//Frankfurt, Germany, 2005 +// +//this file was contributed by Martin Thelian +//last major change: $LastChangedDate$ by $LastChangedBy$ +//Revision: $LastChangedRevision$ +// +//This program is free software; you can redistribute it and/or modify +//it under the terms of the GNU General Public License as published by +//the Free Software Foundation; either version 2 of the License, or +//(at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +//Using this software in any meaning (reading, learning, copying, compiling, +//running) means that you agree that the Author(s) is (are) not responsible +//for cost, loss of data or any harm that may be caused directly or indirectly +//by usage of this softare or this documentation. The usage of this software +//is on your own risk. The installation and usage (starting/running) of this +//software may allow other people or application to access your computer and +//any attached devices and is highly dependent on the configuration of the +//software which must be done by the user of the software; the author(s) is +//(are) also not responsible for proper configuration and usage of the +//software, even if provoked by documentation provided together with +//the software. +// +//Any changes to this file according to the GPL as documented in the file +//gpl.txt aside this file in the shipment you received can be done to the +//lines that follows this copyright notice here, but changes must not be +//done inside the copyright notive above. A re-distribution must contain +//the intact and unchanged copyright notice. +//Contributions and changes to the program code must be marked as such. + + +package de.anomic.soap.services; + +import org.apache.axis.AxisFault; +import org.w3c.dom.Document; + +import de.anomic.plasma.plasmaSearchPreOrder; +import de.anomic.server.serverObjects; +import de.anomic.soap.AbstractService; + +/** + * SOAP Service Class that will be invoked by the httpdSoapHandler + * + * @author Martin Thelian + */ +public class SearchService extends AbstractService +{ + /* ================================================================ + * Constants needed to set the template that should be used to + * fullfil the request + * ================================================================ */ + private static final String TEMPLATE_SEARCH = "yacysearch.soap"; + private static final String TEMPLATE_URLINFO = "ViewFile.soap"; + + + /** + * Constructor of this class + */ + public SearchService() { + super(); + // nothing special todo here at the moment + } + + /** + * Service for doing a simple search with the standard settings + * + * @param searchString the search string that should be used + * @param maxSearchCount the maximum amount of search result that should be returned + * @param searchOrder can be a combination of YBR, Date and Quality, e.g. YBR-Date-Quality or Date-Quality-YBR + * @param searchMode can be global or local + * @param searchMode the total amount of seconds to use for the search + * @param urlMask if the urlMaskfilter parameter should be used + * @param urlMaskfilter e.g. .* + * @param prefermaskfilter + * @param category can be image or href + * + * @return an xml document containing the search results. + * + * @throws AxisFault if the service could not be executed propery. + */ + public Document search( + String searchString, + int maxSearchCount, + String searchOrder, + String searchMode, + int maxSearchTime, + boolean urlMask, + String urlMaskfilter, + String prefermaskfilter, + String category + ) + throws AxisFault { + try { + // extracting the message context + extractMessageContext(false); + + if ((searchMode == null) || !(searchMode.equalsIgnoreCase("global") || searchMode.equalsIgnoreCase("locale"))) { + searchMode = "global"; + } + + if (maxSearchCount < 0) { + maxSearchCount = 10; + } + + if (searchOrder == null || searchOrder.length() == 0) { + searchOrder = plasmaSearchPreOrder.canUseYBR() ? "YBR-Date-Quality" : "Date-Quality-YBR"; + } + + if (maxSearchTime < 0) { + maxSearchTime = 10; + } + + if (urlMaskfilter == null) { + urlMaskfilter = ".*"; + } + + if (prefermaskfilter == null) { + prefermaskfilter = ""; + } + + if (category == null || category.length() == 0) { + category = "href"; + } + + // setting the searching properties + serverObjects args = new serverObjects(); + args.put("search",searchString); + args.put("count",Integer.toString(maxSearchCount)); + args.put("order",searchOrder); + args.put("resource",searchMode); + args.put("time",Integer.toString(maxSearchTime)); + args.put("urlmask",(!urlMask)?"no":"yes"); + args.put("urlmaskfilter",urlMaskfilter); + args.put("prefermaskfilter",prefermaskfilter); + args.put("cat",category); + + args.put("Enter","Search"); + + // generating the template containing the search result + byte[] result = writeTemplate(TEMPLATE_SEARCH, args); + + // sending back the result to the client + return this.convertContentToXML(result); + } catch (Exception e) { + throw new AxisFault(e.getMessage()); + } + } + + /** + * + * + * @param url the url + * @param viewMode one of (VIEW_MODE_AS_PLAIN_TEXT = 1, + * VIEW_MODE_AS_PARSED_TEXT = 2, + * VIEW_MODE_AS_PARSED_SENTENCES = 3) [Source: ViewFile.java] + * @return an xml document containing the url info. + * + * @throws AxisFault if the service could not be executed propery. + */ + public Document urlInfo(String urlHash, int viewMode) throws AxisFault { + try { + // extracting the message context + extractMessageContext(true); + + if (urlHash == null || urlHash.trim().equals("")) { + throw new AxisFault("No Url-hash provided."); + } + + if (viewMode < 1 || viewMode > 3) { + viewMode = 2; + } + + String viewModeStr = "sentences"; + if (viewMode == 1) viewModeStr = "plain"; + else if (viewMode == 2) viewModeStr = "parsed"; + else if (viewMode == 3) viewModeStr = "sentences"; + + + // setting the properties + final serverObjects args = new serverObjects(); + args.put("urlHash",urlHash); + args.put("viewMode",viewModeStr); + + // generating the template containing the url info + byte[] result = writeTemplate(TEMPLATE_URLINFO, args); + + // sending back the result to the client + return this.convertContentToXML(result); + } catch (Exception e) { + throw new AxisFault(e.getMessage()); + } + } + +} diff --git a/source/de/anomic/soap/services/StatusService.java b/source/de/anomic/soap/services/StatusService.java new file mode 100644 index 000000000..3c1d77761 --- /dev/null +++ b/source/de/anomic/soap/services/StatusService.java @@ -0,0 +1,79 @@ +//StatusService.java +//------------------------ +//part of YaCy +//(C) by Michael Peter Christen; mc@anomic.de +//first published on http://www.anomic.de +//Frankfurt, Germany, 2005 +// +//this file was contributed by Martin Thelian +//last major change: $LastChangedDate$ by $LastChangedBy$ +//Revision: $LastChangedRevision$ +// +//This program is free software; you can redistribute it and/or modify +//it under the terms of the GNU General Public License as published by +//the Free Software Foundation; either version 2 of the License, or +//(at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +//Using this software in any meaning (reading, learning, copying, compiling, +//running) means that you agree that the Author(s) is (are) not responsible +//for cost, loss of data or any harm that may be caused directly or indirectly +//by usage of this softare or this documentation. The usage of this software +//is on your own risk. The installation and usage (starting/running) of this +//software may allow other people or application to access your computer and +//any attached devices and is highly dependent on the configuration of the +//software which must be done by the user of the software; the author(s) is +//(are) also not responsible for proper configuration and usage of the +//software, even if provoked by documentation provided together with +//the software. +// +//Any changes to this file according to the GPL as documented in the file +//gpl.txt aside this file in the shipment you received can be done to the +//lines that follows this copyright notice here, but changes must not be +//done inside the copyright notive above. A re-distribution must contain +//the intact and unchanged copyright notice. +//Contributions and changes to the program code must be marked as such. + + +package de.anomic.soap.services; + +import org.apache.axis.AxisFault; +import org.w3c.dom.Document; + +import de.anomic.server.serverObjects; +import de.anomic.soap.AbstractService; + +public class StatusService extends AbstractService { + + /** + * Constant: template for the network status page + */ + private static final String TEMPLATE_NETWORK_XML = "Network.xml"; + + /** + * Service used to query the network properties + * @throws AxisFault if the service could not be executed propery. + */ + public Document network() throws AxisFault { + try { + // extracting the message context + extractMessageContext(false); + + // generating the template containing the network status information + byte[] result = writeTemplate(TEMPLATE_NETWORK_XML, new serverObjects()); + + // sending back the result to the client + return this.convertContentToXML(result); + } catch (Exception e) { + throw new AxisFault(e.getMessage()); + } + } +}