Skip to content

Commit

Permalink
*) new soap function to display log
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2902 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
theli committed Nov 3, 2006
1 parent ad248d6 commit 5e57e08
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 62 deletions.
22 changes: 12 additions & 10 deletions source/de/anomic/server/logging/GuiHandler.java
Expand Up @@ -45,6 +45,7 @@
package de.anomic.server.logging;

import java.util.ArrayList;
import java.util.Date;
import java.util.logging.ErrorManager;
import java.util.logging.Filter;
import java.util.logging.Formatter;
Expand Down Expand Up @@ -143,23 +144,24 @@ public synchronized void publish(LogRecord record) {
this.start++;
}
}

/**
* Push any buffered output to the target <tt>Handler</tt>.
* <p>
* The buffer is then cleared.
*/

public synchronized LogRecord[] getLogArray() {

LogRecord[] tempBuffer = new LogRecord[this.count];
return this.getLogArray(null);
}


public synchronized LogRecord[] getLogArray(Long sequenceNumberStart) {
ArrayList tempBuffer = new ArrayList(this.count);

for (int i = 0; i < this.count; i++) {
int ix = (this.start+i)%this.buffer.length;
LogRecord record = this.buffer[ix];
tempBuffer[i] = record;
if ((sequenceNumberStart == null) || (record.getSequenceNumber() >= sequenceNumberStart.longValue())) {
tempBuffer.add(record);
}
}

return tempBuffer;
return (LogRecord[]) tempBuffer.toArray(new LogRecord[tempBuffer.size()]);
}

public synchronized String getLog(boolean reversed, int lineCount) {
Expand Down
8 changes: 7 additions & 1 deletion source/de/anomic/soap/AbstractService.java
Expand Up @@ -292,7 +292,13 @@ protected Document convertContentToXML(byte[] content) throws Exception {
Document doc = null;
try {
DocumentBuilderFactory newDocBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder newDocBuilder = newDocBuilderFactory.newDocumentBuilder();

// disable dtd validation
newDocBuilderFactory.setValidating(false);
newDocBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
newDocBuilderFactory.setFeature("http://xml.org/sax/features/validation", false);

DocumentBuilder newDocBuilder = newDocBuilderFactory.newDocumentBuilder();

ByteArrayInputStream byteIn = new ByteArrayInputStream(content);
doc = newDocBuilder.parse(byteIn);
Expand Down
26 changes: 19 additions & 7 deletions source/de/anomic/soap/httpdSoapHandler.java
Expand Up @@ -118,6 +118,8 @@
*/
public final class httpdSoapHandler extends httpdAbstractHandler implements httpdHandler
{
public static final String SOAP_HANDLER_VERSION = "YaCySOAP V0.1";


/* ===============================================================
* Constants needed to set some SOAP properties
Expand Down Expand Up @@ -216,12 +218,12 @@ public final class httpdSoapHandler extends httpdAbstractHandler implements http

/**
* Constructor of this class
* @param switchboard
* @param theSwitchboard
*/
public httpdSoapHandler(serverSwitch switchboard) {
public httpdSoapHandler(serverSwitch theSwitchboard) {
super();

this.switchboard = switchboard;
this.switchboard = theSwitchboard;
this.theLogger = new serverLog("SOAP");

// create a htRootPath: system pages
Expand All @@ -231,7 +233,7 @@ public httpdSoapHandler(serverSwitch switchboard) {
}

if (this.htTemplatePath == null) {
this.htTemplatePath = new File(switchboard.getRootPath(), switchboard.getConfig("htTemplatePath","htroot/env/templates"));
this.htTemplatePath = new File(theSwitchboard.getRootPath(), theSwitchboard.getConfig("htTemplatePath","htroot/env/templates"));
// if (!(this.htTemplatePath.exists())) this.htTemplatePath.mkdir();
}

Expand All @@ -246,11 +248,11 @@ public httpdSoapHandler(serverSwitch switchboard) {
additionalServices = new Properties();

// getting the property filename containing the file list
String fileName = switchboard.getConfig("soap.serviceDeploymentList","");
String fileName = theSwitchboard.getConfig("soap.serviceDeploymentList","");
if (fileName.length() > 0) {
BufferedInputStream fileInput = null;
try {
File deploymentFile = new File(switchboard.getRootPath(),fileName);
File deploymentFile = new File(theSwitchboard.getRootPath(),fileName);
fileInput = new BufferedInputStream(new FileInputStream(deploymentFile));

// load property list
Expand Down Expand Up @@ -384,6 +386,8 @@ public void doGet(Properties conProp, httpHeader requestHeader, OutputStream res
Document doc = generateWSDL(msgContext);

if (doc != null) {
// TODO: what about doc.getInputEncoding()?
// TODO: what about getXmlEncoding?
// Converting the the wsdl document into a byte-array
String responseDoc = XMLUtils.DocumentToString(doc);
byte[] result = responseDoc.getBytes("UTF-8");
Expand Down Expand Up @@ -481,6 +485,7 @@ private void handleException(Properties conProp, httpHeader requestHeader, Messa
sendMessage(conProp,requestHeader,response,soapEx.getStatusCode(),soapEx.getStatusText(),soapErrorMsg);
} else {
this.theLogger.logSevere("Unexpected Exception while sending data to client",e);

}
} catch (Exception ex) {
// the http response header was already send. Just log the error
Expand Down Expand Up @@ -644,6 +649,10 @@ private static HashMap loadTemplates(File path) {
return result;
}

/**
* TODO: handle accept-charset http header
* TODO: what about content-encoding, transfer-encoding here?
*/
protected void sendMessage(Properties conProp, httpHeader requestHeader, OutputStream out, int statusCode, String statusText, String contentType, byte[] MessageBody) throws IOException {
// write out the response header
respondHeader(conProp, out, statusCode, statusText, (MessageBody==null)?null:contentType, (MessageBody==null)?-1:MessageBody.length, null, null);
Expand All @@ -653,6 +662,9 @@ protected void sendMessage(Properties conProp, httpHeader requestHeader, OutputS
out.flush();
}

/**
* TODO: handle accept-charset http header
*/
protected void sendMessage(Properties conProp, httpHeader requestHeader, OutputStream out, int statusCode, String statusText, Message soapMessage) throws IOException, SOAPException {
httpChunkedOutputStream chunkedOut = null;
GZIPOutputStream gzipOut = null;
Expand Down Expand Up @@ -717,7 +729,7 @@ protected void respondHeader(
String transferEncoding
) throws IOException {
httpHeader outgoingHeader = new httpHeader();
outgoingHeader.put(httpHeader.SERVER,"AnomicHTTPD (www.anomic.de)");
outgoingHeader.put(httpHeader.SERVER, SOAP_HANDLER_VERSION);
if (conttype != null) outgoingHeader.put(httpHeader.CONTENT_TYPE,conttype);
if (contlength != -1) outgoingHeader.put(httpHeader.CONTENT_LENGTH, Long.toString(contlength));
if (contentEncoding != null) outgoingHeader.put(httpHeader.CONTENT_ENCODING, contentEncoding);
Expand Down
61 changes: 53 additions & 8 deletions source/de/anomic/soap/services/AdminService.java
Expand Up @@ -46,6 +46,10 @@
package de.anomic.soap.services;

import java.util.ArrayList;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.logging.XMLFormatter;

import javax.xml.parsers.ParserConfigurationException;

Expand All @@ -58,6 +62,7 @@
import de.anomic.server.serverCore;
import de.anomic.server.serverObjects;
import de.anomic.server.serverThread;
import de.anomic.server.logging.GuiHandler;
import de.anomic.soap.AbstractService;
import de.anomic.yacy.yacyCore;
import de.anomic.yacy.yacySeed;
Expand Down Expand Up @@ -514,13 +519,14 @@ public Document getTransferProperties() throws AxisFault, ParserConfigurationExc
}

/**
* Function to configure the message forwarding settings of a peer.
* @see <a href="http://localhost:8080/Settings_p.html?page=messageForwarding">Peer Configuration - Message Forwarding</a>
*
* @param enableForwarding
* @param forwardingCommand
* @param forwardingTo
* @throws AxisFault
* @param enableForwarding specifies if forwarding should be enabled
* @param forwardingCommand the forwarding command to use. e.g. <code>/usr/sbin/sendmail</code>
* @param forwardingTo the delivery destination. e.g. <code>root@localhost</code>
*
* @link <a href="http://localhost:8080/Settings_p.html?page=messageForwarding">Peer Configuration - Message Forwarding</a>
* @throws AxisFault if authentication failed
*/
public void setMessageForwarding(
Boolean enableForwarding,
Expand All @@ -545,6 +551,8 @@ public void setMessageForwarding(
}

/**
* Function to query the current message forwarding configuration of a peer.
* @see <a href="http://localhost:8080/Settings_p.html?page=messageForwarding">Peer Configuration - Message Forwarding</a>
*
* @return a XML document of the following format
* <pre>
Expand All @@ -555,10 +563,9 @@ public void setMessageForwarding(
* &lt;msgForwardingTo&gt;root@localhost&lt;/msgForwardingTo&gt;
* &lt;/msgForwarding&gt;
* </pre>
* @throws AxisFault
* @throws ParserConfigurationException
*
* @link <a href="http://localhost:8080/Settings_p.html?page=messageForwarding">Peer Configuration - Message Forwarding</a>
* @throws AxisFault if authentication failed
* @throws ParserConfigurationException on XML parser errors
*/
public Document getMessageForwarding() throws AxisFault, ParserConfigurationException {
// extracting the message context
Expand All @@ -583,4 +590,42 @@ public Document getMessageForwarding() throws AxisFault, ParserConfigurationExce

return xmlDoc;
}

public Document getServerLog(Long sequenceNumber) throws Exception {
// extracting the message context
extractMessageContext(AUTHENTICATION_NEEDED);

Handler logHandler = null;
LogRecord[] log = null;

// getting the root handler
Logger logger = Logger.getLogger("");

// take a look for the GuiHandler
Handler[] handlers = logger.getHandlers();
for (int i=0; i<handlers.length; i++) {
if (handlers[i] instanceof GuiHandler) {
// getting the log records
logHandler = handlers[i];
log = ((GuiHandler)logHandler).getLogArray(sequenceNumber);
break;
}
}

StringBuffer buffer = new StringBuffer();

// format them into xml
XMLFormatter formatter = new XMLFormatter();
buffer.append(formatter.getHead(logHandler));

// format the logging entries
for (int i=0; i < log.length; i++) {
buffer.append(formatter.format(log[i]));
}

buffer.append(formatter.getTail(logHandler));

// convert into dom
return convertContentToXML(buffer.toString());
}
}

0 comments on commit 5e57e08

Please sign in to comment.