*) bugfix for blacklist remove (blacklist was not informed about remove)

*) adding new soap service class for blacklist management
*) new junit class to test soap blacklist service

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2841 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
theli 2006-10-22 08:32:55 +00:00
parent c5a5a9eb1c
commit ac13fa763a
11 changed files with 843 additions and 55 deletions

View File

@ -97,6 +97,7 @@
<taskdef resource="svnRevNrParser.properties" classpath="${lib}/svnRevNr.jar"/>
<!-- determine the revision number -->
<echo message="Trying to read Revision number from file ${svnEntriesFile}"/>
<svnrevnr file="${svnEntriesFile}" property="baseRevisionNr"/>
<!-- replacing the old with the new revision number -->

View File

@ -224,7 +224,7 @@ public class Blacklist_p {
}
for (int blTypes=0; blTypes < supportedBlacklistTypes.length; blTypes++) {
if (listManager.ListInListslist(supportedBlacklistTypes[blTypes] + ".BlackLists",blacklistToUse)) {
plasmaSwitchboard.urlBlacklist.add(supportedBlacklistTypes[blTypes],oldEntry.substring(0, pos), oldEntry.substring(pos + 1));
plasmaSwitchboard.urlBlacklist.remove(supportedBlacklistTypes[blTypes],oldEntry.substring(0, pos));
}
}

View File

@ -79,6 +79,10 @@ public abstract class AbstractService {
protected httpHeader requestHeader;
protected MessageContext messageContext;
protected static final boolean NO_AUTHENTICATION = false;
protected static final boolean AUTHENTICATION_NEEDED = true;
/**
* This function is called by the available service functions to
* extract all needed informations from the SOAP message context.
@ -167,6 +171,8 @@ public abstract class AbstractService {
} catch (Exception e) {
if (e instanceof AxisFault) throw (AxisFault) e;
e.printStackTrace();
// create a new AxisFault Object
throw new AxisFault(e.getMessage());
}

View File

@ -30,9 +30,10 @@
<pathelement location="${libx}/saaj.jar" />
<pathelement location="${libx}/wsdl4j.jar" />
<!-- optional libraries needed for soap attachments -->
<pathelement location="${libx}/gnumail.jar" />
<pathelement location="${libx}/activation.jar" />
<pathelement location="${libx}/inetlib.jar" />
</path>

View File

@ -149,7 +149,8 @@ public final class httpdSoapHandler extends httpdAbstractHandler implements http
"search=de.anomic.soap.services.SearchService",
"crawl=de.anomic.soap.services.CrawlService",
"status=de.anomic.soap.services.StatusService",
"admin=de.anomic.soap.services.AdminService"
"admin=de.anomic.soap.services.AdminService",
"blacklist=de.anomic.soap.services.BlacklistService"
};
/* ===============================================================

View File

@ -0,0 +1,443 @@
package de.anomic.soap.services;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import org.apache.axis.AxisFault;
import org.w3c.dom.Document;
import de.anomic.data.listManager;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverObjects;
import de.anomic.soap.AbstractService;
public class BlacklistService extends AbstractService {
private static final String LIST_MANAGER_LISTS_PATH = "listManager.listsPath";
private static final String BLACKLISTS = ".BlackLists";
private static final String BLACKLISTS_TYPES = "BlackLists.types";
private final static String BLACKLIST_SHARED = "BlackLists.Shared";
/* =====================================================================
* Used XML Templates
* ===================================================================== */
private static final String TEMPLATE_BLACKLIST_XML = "xml/blacklists_p.xml";
public Document getBlacklistList() throws Exception {
try {
// extracting the message context
extractMessageContext(AUTHENTICATION_NEEDED);
// generating the template containing the network status information
byte[] result = writeTemplate(TEMPLATE_BLACKLIST_XML, new serverObjects());
// sending back the result to the client
return this.convertContentToXML(result);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
public void createBlacklist(String blacklistName, boolean shareBlacklist, String[] activateForBlacklistTypes) throws IOException {
// Check for errors
if ((blacklistName == null)||(blacklistName.length() == 0))
throw new IllegalArgumentException("Blacklist name must not be null or empty.");
// check if we know all types passed to this function
checkForKnownBlacklistTypes(activateForBlacklistTypes);
if (blacklistName.indexOf("/") != -1)
throw new IllegalArgumentException("Blacklist name must not contain '/'.");
// extracting the message context
extractMessageContext(AUTHENTICATION_NEEDED);
// initialize the list manager
initBlacklistManager();
// check if the blacklist already exists
if (blacklistExists(blacklistName))
throw new AxisFault("Blacklist with name '" + blacklistName + "' already exist.");
// creating the new file
createBlacklistFile(blacklistName);
// share the newly created blacklist
if (shareBlacklist) doShareBlacklist(blacklistName);
// activate blacklist
this.activateBlacklistForTypes(blacklistName,activateForBlacklistTypes);
}
public void deleteBlacklist(String blacklistName) throws AxisFault {
// Check for errors
if ((blacklistName == null)||(blacklistName.length() == 0))
throw new IllegalArgumentException("Blacklist name must not be null or empty.");
// extracting the message context
extractMessageContext(AUTHENTICATION_NEEDED);
// initialize the list manager
initBlacklistManager();
// check if the blacklist exists
if (!blacklistExists(blacklistName))
throw new AxisFault("Blacklist with name '" + blacklistName + "' does not exist.");
// deactivate list
deativateBlacklistForAllTypes(blacklistName);
// unshare list
doUnshareBlacklist(blacklistName);
// delete the file
deleteBlacklistFile(blacklistName);
}
public void shareBlacklist(String blacklistName) throws AxisFault {
// Check for errors
if ((blacklistName == null)||(blacklistName.length() == 0))
throw new IllegalArgumentException("Blacklist name must not be null or empty.");
// extracting the message context
extractMessageContext(AUTHENTICATION_NEEDED);
// initialize the list manager
initBlacklistManager();
// check if the blacklist file exists
if (!blacklistExists(blacklistName))
throw new AxisFault("Blacklist with name '" + blacklistName + "' does not exist.");
// share blacklist
this.doShareBlacklist(blacklistName);
}
public void unshareBlacklist(String blacklistName) throws AxisFault {
// Check for errors
if ((blacklistName == null)||(blacklistName.length() == 0))
throw new IllegalArgumentException("Blacklist name must not be null or empty.");
// extracting the message context
extractMessageContext(AUTHENTICATION_NEEDED);
// initialize the list manager
initBlacklistManager();
// check if the blacklist file exists
if (!blacklistExists(blacklistName))
throw new AxisFault("Blacklist with name '" + blacklistName + "' does not exist.");
// share blacklist
this.doUnshareBlacklist(blacklistName);
}
public void activateBlacklist(String blacklistName, String[] activateForBlacklistTypes) throws AxisFault {
// Check for errors
if ((blacklistName == null)||(blacklistName.length() == 0))
throw new IllegalArgumentException("Blacklist name must not be null or empty.");
// extracting the message context
extractMessageContext(AUTHENTICATION_NEEDED);
// initialize the list manager
initBlacklistManager();
// check if the blacklist file exists
if (!blacklistExists(blacklistName))
throw new AxisFault("Blacklist with name '" + blacklistName + "' does not exist.");
// check if we know all types passed to this function
checkForKnownBlacklistTypes(activateForBlacklistTypes);
// activate blacklist
activateBlacklistForTypes(blacklistName, activateForBlacklistTypes);
}
public void deactivateBlacklist(String blacklistName, String[] deactivateForBlacklistTypes) throws AxisFault {
// Check for errors
if ((blacklistName == null)||(blacklistName.length() == 0))
throw new IllegalArgumentException("Blacklist name must not be null or empty.");
// extracting the message context
extractMessageContext(AUTHENTICATION_NEEDED);
// initialize the list manager
initBlacklistManager();
// check if the blacklist file exists
if (!blacklistExists(blacklistName))
throw new AxisFault("Blacklist with name '" + blacklistName + "' does not exist.");
// check if we know all types passed to this function
checkForKnownBlacklistTypes(deactivateForBlacklistTypes);
// activate blacklist
deactivateBlacklistForTypes(blacklistName, deactivateForBlacklistTypes);
}
public void addBlacklistItem(String blacklistName, String blacklistItem) throws AxisFault {
// Check for errors
if ((blacklistName == null)||(blacklistName.length() == 0))
throw new IllegalArgumentException("Blacklist name must not be null or empty.");
if ((blacklistItem == null)||(blacklistItem.length() == 0))
throw new IllegalArgumentException("Blacklist item must not be null or empty.");
// extracting the message context
extractMessageContext(AUTHENTICATION_NEEDED);
// initialize the list manager
initBlacklistManager();
// check if the blacklist file exists
if (!blacklistExists(blacklistName))
throw new AxisFault("Blacklist with name '" + blacklistName + "' does not exist.");
// prepare item
blacklistItem = prepareBlacklistItem(blacklistItem);
// TODO: check if the entry is already in there
// append the line to the file
addBlacklistItemToFile(blacklistItem, blacklistName);
// pass the entry to the blacklist engine
addBlacklistItemToBlacklist(blacklistItem, blacklistName);
}
public void removeBlacklistItem(String blacklistName, String blacklistItem) throws AxisFault {
// Check for errors
if ((blacklistName == null)||(blacklistName.length() == 0))
throw new IllegalArgumentException("Blacklist name must not be null or empty.");
if ((blacklistItem == null)||(blacklistItem.length() == 0))
throw new IllegalArgumentException("Blacklist item must not be null or empty.");
// extracting the message context
extractMessageContext(AUTHENTICATION_NEEDED);
// initialize the list manager
initBlacklistManager();
// check if the blacklist file exists
if (!blacklistExists(blacklistName))
throw new AxisFault("Blacklist with name '" + blacklistName + "' does not exist.");
// prepare item
blacklistItem = prepareBlacklistItem(blacklistItem);
// remove blacklist from file
removeBlacklistItemFromBlacklistFile(blacklistItem,blacklistName);
// remove it from the blacklist engine
removeBlacklistItemFromBlacklist(blacklistItem,blacklistName);
}
public String[] getBlacklistTypes() throws AxisFault {
// extracting the message context
extractMessageContext(AUTHENTICATION_NEEDED);
// return supported types
return getSupportedBlacklistTypeArray();
}
private void addBlacklistItemToBlacklist(String blacklistItem, String blacklistName) {
// split the item into host part and path
String[] itemParts = getBlacklistItemParts(blacklistItem);
// getting the supported blacklist types
String[] supportedBlacklistTypes = getSupportedBlacklistTypeArray();
// loop through the various types
for (int blTypes=0; blTypes < supportedBlacklistTypes.length; blTypes++) {
// if the current blacklist is activated for the type, add the item to the list
if (listManager.ListInListslist(supportedBlacklistTypes[blTypes] + BLACKLISTS,blacklistName)) {
plasmaSwitchboard.urlBlacklist.add(supportedBlacklistTypes[blTypes],itemParts[0], itemParts[1]);
}
}
}
private void addBlacklistItemToFile(String blacklistItem, String blacklistName) throws AxisFault {
PrintWriter pw = null;
try {
pw = new PrintWriter(new FileWriter(getBlacklistFile(blacklistName), true));
pw.println(blacklistItem);
pw.close();
} catch (IOException e) {
throw new AxisFault("Unable to append blacklist entry.",e);
} finally {
if (pw != null) try { pw.close(); } catch (Exception e){ /* */}
}
}
private void removeBlacklistItemFromBlacklistFile(String blacklistItem, String blacklistName) {
// load blacklist data from file
ArrayList list = listManager.getListArray(getBlacklistFile(blacklistName));
// delete the old entry from file
if (list != null) {
for (int i=0; i < list.size(); i++) {
if (((String)list.get(i)).equals(blacklistItem)) {
list.remove(i);
break;
}
}
listManager.writeList(getBlacklistFile(blacklistName), (String[])list.toArray(new String[list.size()]));
}
}
private void removeBlacklistItemFromBlacklist(String blacklistItem, String blacklistName) {
String[] itemParts = getBlacklistItemParts(blacklistItem);
// getting the supported blacklist types
String[] supportedBlacklistTypes = getSupportedBlacklistTypeArray();
// loop through the various types
for (int blTypes=0; blTypes < supportedBlacklistTypes.length; blTypes++) {
// if the current blacklist is activated for the type, remove the item from the list
if (listManager.ListInListslist(supportedBlacklistTypes[blTypes] + BLACKLISTS,blacklistName)) {
plasmaSwitchboard.urlBlacklist.remove(supportedBlacklistTypes[blTypes],itemParts[0]);
}
}
}
private String prepareBlacklistItem(String blacklistItem) {
if (blacklistItem == null) throw new NullPointerException("Item is null");
// cut of heading http://
if (blacklistItem.startsWith("http://") ){
blacklistItem = blacklistItem.substring("http://".length());
}
// adding missing parts
int pos = blacklistItem.indexOf("/");
if (pos < 0) {
// add default empty path pattern
blacklistItem = blacklistItem + "/.*";
}
return blacklistItem;
}
private String[] getBlacklistItemParts(String blacklistItem) {
if (blacklistItem == null) throw new NullPointerException("Item is null");
int pos = blacklistItem.indexOf("/");
if (pos == -1) throw new IllegalArgumentException("Item format is not correct.");
return new String[] {
blacklistItem.substring(0, pos),
blacklistItem.substring(pos + 1)
};
}
private String[] getSharedBlacklistArray() {
String sharedBlacklists = this.switchboard.getConfig(BLACKLIST_SHARED, "");
String[] supportedBlacklistTypeArray = sharedBlacklists.split(",");
return supportedBlacklistTypeArray;
}
private File getBlacklistFile(String blacklistName) {
File blacklistFile = new File(listManager.listsPath, blacklistName);
return blacklistFile;
}
private boolean blacklistExists(String blacklistName) {
File blacklistFile = getBlacklistFile(blacklistName);
return blacklistFile.exists();
}
private HashSet getSharedBlacklistSet() {
HashSet supportedTypesSet = new HashSet(Arrays.asList(getSharedBlacklistArray()));
return supportedTypesSet;
}
private String[] getSupportedBlacklistTypeArray() {
String supportedBlacklistTypesStr = this.switchboard.getConfig(BLACKLISTS_TYPES, "");
String[] supportedBlacklistTypeArray = supportedBlacklistTypesStr.split(",");
return supportedBlacklistTypeArray;
}
private void createBlacklistFile(String blacklistName) throws IOException {
File newFile = getBlacklistFile(blacklistName);
newFile.createNewFile();
}
private void deleteBlacklistFile(String blacklistName) {
File BlackListFile = new File(listManager.listsPath, blacklistName);
BlackListFile.delete();
}
private void doShareBlacklist(String blacklistName) {
listManager.addListToListslist(BLACKLIST_SHARED, blacklistName);
}
private void doUnshareBlacklist(String blacklistName) {
listManager.removeListFromListslist(BLACKLIST_SHARED, blacklistName);
}
private void initBlacklistManager() {
// init Manager properties
if (listManager.switchboard == null)
listManager.switchboard = (plasmaSwitchboard) this.switchboard;
if (listManager.listsPath == null)
listManager.listsPath = new File(listManager.switchboard.getRootPath(),listManager.switchboard.getConfig(LIST_MANAGER_LISTS_PATH, "DATA/LISTS"));
}
private void ativateBlacklistForAllTypes(String blacklistName) {
String[] supportedBlacklistTypes = getSupportedBlacklistTypeArray();
this.activateBlacklistForTypes(blacklistName,supportedBlacklistTypes);
}
private void activateBlacklistForTypes(String blacklistName, String[] activateForBlacklistTypes) {
if (activateForBlacklistTypes == null) return;
for (int blTypes=0; blTypes < activateForBlacklistTypes.length; blTypes++) {
listManager.addListToListslist(activateForBlacklistTypes[blTypes] + BLACKLISTS, blacklistName);
}
}
private void deativateBlacklistForAllTypes(String blacklistName) {
String[] supportedBlacklistTypes = getSupportedBlacklistTypeArray();
this.deactivateBlacklistForTypes(blacklistName,supportedBlacklistTypes);
}
private void deactivateBlacklistForTypes(String blacklistName, String[] deactivateForBlacklistTypes) {
if (deactivateForBlacklistTypes == null) return;
for (int blTypes=0; blTypes < deactivateForBlacklistTypes.length; blTypes++) {
listManager.removeListFromListslist(deactivateForBlacklistTypes[blTypes] + BLACKLISTS, blacklistName);
}
}
private HashSet getSupportedBlacklistTypeSet() {
HashSet supportedTypesSet = new HashSet(Arrays.asList(getSupportedBlacklistTypeArray()));
return supportedTypesSet;
}
private void checkForKnownBlacklistTypes(String[] types) throws AxisFault {
if (types == null) return;
// get kown blacklist types
HashSet supportedTypesSet = getSupportedBlacklistTypeSet();
// check if we know all types stored in the array
for (int i=0; i < types.length; i++) {
if (!supportedTypesSet.contains(types[i]))
throw new AxisFault("Unknown blaclist type '" + types[i] + "' at position " + i);
}
}
}

View File

@ -70,7 +70,7 @@ public class StatusService extends AbstractService {
public Document network() throws AxisFault {
try {
// extracting the message context
extractMessageContext(false);
extractMessageContext(NO_AUTHENTICATION);
// generating the template containing the network status information
byte[] result = writeTemplate(TEMPLATE_NETWORK_XML, new serverObjects());
@ -110,7 +110,7 @@ public class StatusService extends AbstractService {
Integer remotecrawlerqueueCount
) throws Exception {
// extracting the message context
extractMessageContext(true);
extractMessageContext(AUTHENTICATION_NEEDED);
// passing parameters to servlet
serverObjects input = new serverObjects();

View File

@ -0,0 +1,243 @@
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://yacy:8080/soap/blacklist" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://yacy:8080/soap/blacklist" xmlns:intf="http://yacy:8080/soap/blacklist" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><!--WSDL created by Apache Axis version: 1.2RC2
Built on Nov 16, 2004 (12:19:44 EST)--><wsdl:types><schema targetNamespace="http://yacy:8080/soap/blacklist" xmlns="http://www.w3.org/2001/XMLSchema"><import namespace="http://xml.apache.org/xml-soap"/><import namespace="http://schemas.xmlsoap.org/soap/encoding/"/><complexType name="ArrayOf_soapenc_string"><complexContent><restriction base="soapenc:Array"><attribute ref="soapenc:arrayType" wsdl:arrayType="soapenc:string[]"/></restriction></complexContent></complexType></schema></wsdl:types>
<wsdl:message name="unshareBlacklistResponse">
</wsdl:message>
<wsdl:message name="deactivateBlacklistResponse">
</wsdl:message>
<wsdl:message name="createNewXMLDocumentRequest">
<wsdl:part name="rootElementName" type="soapenc:string"/>
</wsdl:message>
<wsdl:message name="addBlacklistItemRequest">
<wsdl:part name="blacklistName" type="soapenc:string"/>
<wsdl:part name="blacklistItem" type="soapenc:string"/>
</wsdl:message>
<wsdl:message name="removeBlacklistItemResponse">
</wsdl:message>
<wsdl:message name="activateBlacklistResponse">
</wsdl:message>
<wsdl:message name="getBlacklistTypesResponse">
<wsdl:part name="getBlacklistTypesReturn" type="impl:ArrayOf_soapenc_string"/>
</wsdl:message>
<wsdl:message name="getBlacklistTypesRequest">
</wsdl:message>
<wsdl:message name="removeBlacklistItemRequest">
<wsdl:part name="blacklistName" type="soapenc:string"/>
<wsdl:part name="blacklistItem" type="soapenc:string"/>
</wsdl:message>
<wsdl:message name="addBlacklistItemResponse">
</wsdl:message>
<wsdl:message name="shareBlacklistResponse">
</wsdl:message>
<wsdl:message name="getBlacklistListResponse">
<wsdl:part name="getBlacklistListReturn" type="apachesoap:Document"/>
</wsdl:message>
<wsdl:message name="createBlacklistResponse">
</wsdl:message>
<wsdl:message name="getBlacklistListRequest">
</wsdl:message>
<wsdl:message name="unshareBlacklistRequest">
<wsdl:part name="blacklistName" type="soapenc:string"/>
</wsdl:message>
<wsdl:message name="shareBlacklistRequest">
<wsdl:part name="blacklistName" type="soapenc:string"/>
</wsdl:message>
<wsdl:message name="deleteBlacklistResponse">
</wsdl:message>
<wsdl:message name="activateBlacklistRequest">
<wsdl:part name="blacklistName" type="soapenc:string"/>
<wsdl:part name="activateForBlacklistTypes" type="impl:ArrayOf_soapenc_string"/>
</wsdl:message>
<wsdl:message name="createBlacklistRequest">
<wsdl:part name="blacklistName" type="soapenc:string"/>
<wsdl:part name="shareBlacklist" type="xsd:boolean"/>
<wsdl:part name="activateForBlacklistTypes" type="impl:ArrayOf_soapenc_string"/>
</wsdl:message>
<wsdl:message name="deleteBlacklistRequest">
<wsdl:part name="blacklistName" type="soapenc:string"/>
</wsdl:message>
<wsdl:message name="deactivateBlacklistRequest">
<wsdl:part name="blacklistName" type="soapenc:string"/>
<wsdl:part name="deactivateForBlacklistTypes" type="impl:ArrayOf_soapenc_string"/>
</wsdl:message>
<wsdl:message name="createNewXMLDocumentResponse">
<wsdl:part name="createNewXMLDocumentReturn" type="apachesoap:Document"/>
</wsdl:message>
<wsdl:portType name="BlacklistService">
<wsdl:operation name="getBlacklistList">
<wsdl:input message="impl:getBlacklistListRequest" name="getBlacklistListRequest"/>
<wsdl:output message="impl:getBlacklistListResponse" name="getBlacklistListResponse"/>
</wsdl:operation>
<wsdl:operation name="createBlacklist" parameterOrder="blacklistName shareBlacklist activateForBlacklistTypes">
<wsdl:input message="impl:createBlacklistRequest" name="createBlacklistRequest"/>
<wsdl:output message="impl:createBlacklistResponse" name="createBlacklistResponse"/>
</wsdl:operation>
<wsdl:operation name="shareBlacklist" parameterOrder="blacklistName">
<wsdl:input message="impl:shareBlacklistRequest" name="shareBlacklistRequest"/>
<wsdl:output message="impl:shareBlacklistResponse" name="shareBlacklistResponse"/>
</wsdl:operation>
<wsdl:operation name="deleteBlacklist" parameterOrder="blacklistName">
<wsdl:input message="impl:deleteBlacklistRequest" name="deleteBlacklistRequest"/>
<wsdl:output message="impl:deleteBlacklistResponse" name="deleteBlacklistResponse"/>
</wsdl:operation>
<wsdl:operation name="unshareBlacklist" parameterOrder="blacklistName">
<wsdl:input message="impl:unshareBlacklistRequest" name="unshareBlacklistRequest"/>
<wsdl:output message="impl:unshareBlacklistResponse" name="unshareBlacklistResponse"/>
</wsdl:operation>
<wsdl:operation name="activateBlacklist" parameterOrder="blacklistName activateForBlacklistTypes">
<wsdl:input message="impl:activateBlacklistRequest" name="activateBlacklistRequest"/>
<wsdl:output message="impl:activateBlacklistResponse" name="activateBlacklistResponse"/>
</wsdl:operation>
<wsdl:operation name="deactivateBlacklist" parameterOrder="blacklistName deactivateForBlacklistTypes">
<wsdl:input message="impl:deactivateBlacklistRequest" name="deactivateBlacklistRequest"/>
<wsdl:output message="impl:deactivateBlacklistResponse" name="deactivateBlacklistResponse"/>
</wsdl:operation>
<wsdl:operation name="addBlacklistItem" parameterOrder="blacklistName blacklistItem">
<wsdl:input message="impl:addBlacklistItemRequest" name="addBlacklistItemRequest"/>
<wsdl:output message="impl:addBlacklistItemResponse" name="addBlacklistItemResponse"/>
</wsdl:operation>
<wsdl:operation name="removeBlacklistItem" parameterOrder="blacklistName blacklistItem">
<wsdl:input message="impl:removeBlacklistItemRequest" name="removeBlacklistItemRequest"/>
<wsdl:output message="impl:removeBlacklistItemResponse" name="removeBlacklistItemResponse"/>
</wsdl:operation>
<wsdl:operation name="getBlacklistTypes">
<wsdl:input message="impl:getBlacklistTypesRequest" name="getBlacklistTypesRequest"/>
<wsdl:output message="impl:getBlacklistTypesResponse" name="getBlacklistTypesResponse"/>
</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="blacklistSoapBinding" type="impl:BlacklistService">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getBlacklistList">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getBlacklistListRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
</wsdl:input>
<wsdl:output name="getBlacklistListResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/blacklist" use="encoded"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="createBlacklist">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="createBlacklistRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
</wsdl:input>
<wsdl:output name="createBlacklistResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/blacklist" use="encoded"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="shareBlacklist">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="shareBlacklistRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
</wsdl:input>
<wsdl:output name="shareBlacklistResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/blacklist" use="encoded"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="deleteBlacklist">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="deleteBlacklistRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
</wsdl:input>
<wsdl:output name="deleteBlacklistResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/blacklist" use="encoded"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="unshareBlacklist">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="unshareBlacklistRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
</wsdl:input>
<wsdl:output name="unshareBlacklistResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/blacklist" use="encoded"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="activateBlacklist">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="activateBlacklistRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
</wsdl:input>
<wsdl:output name="activateBlacklistResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/blacklist" use="encoded"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="deactivateBlacklist">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="deactivateBlacklistRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
</wsdl:input>
<wsdl:output name="deactivateBlacklistResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/blacklist" use="encoded"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="addBlacklistItem">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="addBlacklistItemRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
</wsdl:input>
<wsdl:output name="addBlacklistItemResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/blacklist" use="encoded"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="removeBlacklistItem">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="removeBlacklistItemRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
</wsdl:input>
<wsdl:output name="removeBlacklistItemResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/blacklist" use="encoded"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getBlacklistTypes">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getBlacklistTypesRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.soap.anomic.de" use="encoded"/>
</wsdl:input>
<wsdl:output name="getBlacklistTypesResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://yacy:8080/soap/blacklist" 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/blacklist" use="encoded"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="BlacklistServiceService">
<wsdl:port binding="impl:blacklistSoapBinding" name="blacklist">
<wsdlsoap:address location="http://yacy:8080/soap/blacklist"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

View File

@ -0,0 +1,66 @@
package de.anomic.soap.services;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.rmi.Remote;
import java.util.Properties;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Stub;
import yacy.soap.status.StatusService;
import yacy.soap.status.StatusServiceServiceLocator;
import junit.framework.TestCase;
public abstract class AbstractServiceTest extends TestCase {
protected static final String SOAP_HEADER_NAMESPACE = "http://http.anomic.de/header";
protected static final String SOAP_HEADER_AUTHORIZATION = "Authorization";
protected static String authString;
protected static String peerPort;
protected static Remote service;
protected void setUp() throws Exception {
if (peerPort == null) this.loadConfigProperties();
super.setUp();
}
protected abstract void createServiceClass() throws ServiceException;
protected String getBaseServiceURL() {
return "http://localhost:" + peerPort + "/soap/";
}
protected void loadConfigProperties() throws Exception {
BufferedInputStream fileInput = null;
try {
File configFile = new File("DATA/SETTINGS/httpProxy.conf");
System.out.println("Reading config file: " + configFile.getAbsoluteFile().toString());
fileInput = new BufferedInputStream(new FileInputStream(configFile));
// load property list
Properties peerProperties = new Properties();
peerProperties.load(fileInput);
fileInput.close();
// getting admin account auth string
authString = peerProperties.getProperty("adminAccountBase64MD5");
if (authString == null) throw new Exception("Unable to find authentication information.");
peerPort = peerProperties.getProperty("port");
if (authString == null) throw new Exception("Unable to find peer port information.");
// creating the service class
createServiceClass();
// setting the authentication header
((Stub)service).setHeader(SOAP_HEADER_NAMESPACE,SOAP_HEADER_AUTHORIZATION,authString);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fileInput != null) try { fileInput.close(); } catch (Exception e){/* ignore this */}
}
}
}

View File

@ -0,0 +1,65 @@
package de.anomic.soap.services;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import org.apache.axis.utils.XMLUtils;
import org.w3c.dom.Document;
import yacy.soap.blacklist.BlacklistService;
import yacy.soap.blacklist.BlacklistServiceServiceLocator;
public class BlacklistServiceTest extends AbstractServiceTest {
protected void createServiceClass() throws ServiceException {
// construct Soap object
BlacklistServiceServiceLocator locator = new BlacklistServiceServiceLocator();
locator.setblacklistEndpointAddress(getBaseServiceURL() + "blacklist");
service = locator.getblacklist();
}
public void testGetBlacklistList() throws RemoteException {
Document xml = ((BlacklistService)service).getBlacklistList();
System.out.println(XMLUtils.DocumentToString(xml));
}
public void testBlacklist() throws RemoteException {
BlacklistService bl = ((BlacklistService)service);
// create new blacklist
String blacklistName = "junit_test_" + System.currentTimeMillis();
bl.createBlacklist(blacklistName,false,null);
// share blacklist
bl.shareBlacklist(blacklistName);
// getting supported blacklist Types
String[] blTypes = bl.getBlacklistTypes();
// activate blacklist
bl.activateBlacklist(blacklistName,blTypes);
// add blacklist item
String item = "http://www.yacy.net";
bl.addBlacklistItem(blacklistName,item);
// getting the blacklist list
Document xml = ((BlacklistService)service).getBlacklistList();
System.out.println(XMLUtils.DocumentToString(xml));
// remove blacklist item
bl.removeBlacklistItem(blacklistName,item);
// unshare
bl.unshareBlacklist(blacklistName);
// deactivate for proxy and dht
bl.deactivateBlacklist(blacklistName,new String[]{"proxy","dht"});
// delete blacklist
bl.deleteBlacklist(blacklistName);
}
}

View File

@ -1,70 +1,32 @@
package de.anomic.soap.services;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.rmi.RemoteException;
import java.util.Properties;
import junit.framework.TestCase;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Stub;
import org.apache.axis.utils.XMLUtils;
import org.w3c.dom.Document;
import yacy.soap.status.StatusService;
import yacy.soap.status.StatusServiceServiceLocator;
public class StatusServiceTest extends TestCase {
private static String authString;
private static String peerPort;
private static StatusService service;
protected void setUp() throws Exception {
if (peerPort == null) this.loadConfigProperties();
super.setUp();
}
private void loadConfigProperties() throws Exception {
BufferedInputStream fileInput = null;
try {
File configFile = new File("DATA/SETTINGS/httpProxy.conf");
System.out.println("Reading config file: " + configFile.getAbsoluteFile().toString());
fileInput = new BufferedInputStream(new FileInputStream(configFile));
// load property list
Properties peerProperties = new Properties();
peerProperties.load(fileInput);
fileInput.close();
// getting admin account auth string
authString = peerProperties.getProperty("adminAccountBase64MD5");
if (authString == null) throw new Exception("Unable to find authentication information.");
peerPort = peerProperties.getProperty("port");
if (authString == null) throw new Exception("Unable to find peer port information.");
// construct Soap object
StatusServiceServiceLocator locator = new StatusServiceServiceLocator();
locator.setstatusEndpointAddress("http://localhost:" + peerPort + "/soap/status");
service = locator.getstatus();
((Stub)service).setHeader("http://http.anomic.de/header","Authorization",authString);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fileInput != null) try { fileInput.close(); } catch (Exception e){/* ignore this */}
}
}
public class StatusServiceTest extends AbstractServiceTest {
protected void createServiceClass() throws ServiceException {
// construct Soap object
StatusServiceServiceLocator locator = new StatusServiceServiceLocator();
locator.setstatusEndpointAddress(getBaseServiceURL() + "status");
service = locator.getstatus();
}
public void testNetwork() throws RemoteException {
Document xml = service.network();
Document xml = ((StatusService)service).network();
System.out.println(XMLUtils.DocumentToString(xml));
}
public void testGetQueueStatus() throws RemoteException {
Document xml = service.getQueueStatus(null,null,null,null);
Document xml = ((StatusService)service).getQueueStatus(null,null,null,null);
System.out.println(XMLUtils.DocumentToString(xml));
}
}