Explorar el Código

added macros for soap message logging

ivowolf hace 14 años
padre
commit
394a58a68d

+ 14 - 10
Plugins/org.commontk.dah.core/ctkSimpleSoapClient.cpp

@@ -21,6 +21,7 @@
 
 
 #include "ctkSimpleSoapClient.h"
 #include "ctkSimpleSoapClient.h"
 #include "ctkDicomAppHostingTypes.h"
 #include "ctkDicomAppHostingTypes.h"
+#include "ctkSoapLog.h"
 
 
 #include <QApplication>
 #include <QApplication>
 #include <QCursor>
 #include <QCursor>
@@ -80,7 +81,9 @@ const QtSoapType & ctkSimpleSoapClient::submitSoapRequest(const QString& methodN
   action.append("\"");
   action.append("\"");
   d->http.setAction(action);
   d->http.setAction(action);
 
 
-  qDebug() << "Submitting action " << action << " method " << methodName << " to path " << d->path;
+  CTK_SOAP_LOG( << "Submitting action " << action
+                << " method " << methodName
+                << " to path " << d->path );
 
 
   QtSoapMessage request;
   QtSoapMessage request;
   request.setMethod(QtSoapQName(methodName,"http://wg23.dicom.nema.org/"));
   request.setMethod(QtSoapQName(methodName,"http://wg23.dicom.nema.org/"));
@@ -90,14 +93,15 @@ const QtSoapType & ctkSimpleSoapClient::submitSoapRequest(const QString& methodN
          it < soapTypes.constEnd(); it++)
          it < soapTypes.constEnd(); it++)
     {
     {
       request.addMethodArgument(*it);
       request.addMethodArgument(*it);
-      qDebug() << "  Argument type added " << (*it)->typeName() << ". Argument name is " << (*it)->name().name();;
+      CTK_SOAP_LOG( << "  Argument type added " << (*it)->typeName() << ". "
+                    << " Argument name is " << (*it)->name().name() );
     }
     }
   }
   }
-  qDebug() << request.toXmlString();
+  CTK_SOAP_LOG_LOWLEVEL( << request.toXmlString());
 
 
   d->http.submitRequest(request, d->path);;
   d->http.submitRequest(request, d->path);;
 
 
-  qDebug() << "Submitted request " << methodName ;
+  CTK_SOAP_LOG_LOWLEVEL( << "Submitted request " << methodName);
 
 
   QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
   QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
 
 
@@ -112,19 +116,19 @@ const QtSoapType & ctkSimpleSoapClient::submitSoapRequest(const QString& methodN
   if (response.isFault())
   if (response.isFault())
   {
   {
     qCritical() << "ctkSimpleSoapClient: server error (response.IsFault())";
     qCritical() << "ctkSimpleSoapClient: server error (response.IsFault())";
-    qDebug() << response.faultString().toString().toLatin1().constData() << endl;
-    qDebug() << response.toXmlString();
+    CTK_SOAP_LOG_LOWLEVEL( << response.faultString().toString().toLatin1().constData() << endl );
+    CTK_SOAP_LOG_LOWLEVEL( << response.toXmlString() );
     return response.returnValue();
     return response.returnValue();
     //    throw std::runtime_error("ctkSimpleSoapClient: server error (response.IsFault())");
     //    throw std::runtime_error("ctkSimpleSoapClient: server error (response.IsFault())");
   }
   }
 
 
-  qDebug() << "Response: " << response.toXmlString();
+  CTK_SOAP_LOG_LOWLEVEL( << "Response: " << response.toXmlString() );
 
 
   const QtSoapType &returnValue = response.returnValue();
   const QtSoapType &returnValue = response.returnValue();
 
 
-  qDebug() << " Is returnValue valid:" << returnValue.isValid();
-  qDebug() << " Name of returnValue:" << returnValue.name().name();
-  qDebug() << " Value of returnValue:" << returnValue.value().toString();
+  CTK_SOAP_LOG( << "  ReturnValue valid:" << returnValue.isValid() << "     "
+                << "Name: " << returnValue.name().name() << "     "
+                << "Value:" << returnValue.value().toString() );
 
 
   return returnValue;
   return returnValue;
 }
 }

+ 9 - 8
Plugins/org.commontk.dah.core/ctkSoapConnectionRunnable.cpp

@@ -21,6 +21,7 @@
 
 
 
 
 #include "ctkSoapConnectionRunnable_p.h"
 #include "ctkSoapConnectionRunnable_p.h"
+#include "ctkSoapLog.h"
 
 
 #include <QTcpSocket>
 #include <QTcpSocket>
 
 
@@ -61,7 +62,7 @@ void ctkSoapConnectionRunnable::readClient(QTcpSocket& socket)
   //qDebug() << socket->readAll();
   //qDebug() << socket->readAll();
   while (socket.canReadLine()) {
   while (socket.canReadLine()) {
     QString line = socket.readLine();
     QString line = socket.readLine();
-    qDebug() << line;
+    CTK_SOAP_LOG_LOWLEVEL( << line );
     if(line.contains("?wsdl HTTP"))
     if(line.contains("?wsdl HTTP"))
     {
     {
       requestType = "?wsdl";
       requestType = "?wsdl";
@@ -94,13 +95,13 @@ void ctkSoapConnectionRunnable::readClient(QTcpSocket& socket)
         while(body.size() < contentLength)
         while(body.size() < contentLength)
         {
         {
           QByteArray bodyPart = socket.read(contentLength);
           QByteArray bodyPart = socket.read(contentLength);
-          qDebug() << bodyPart;
+          CTK_SOAP_LOG_LOWLEVEL( << bodyPart );
           bytesRead += bodyPart.size();
           bytesRead += bodyPart.size();
           body.append(bodyPart);
           body.append(bodyPart);
-          qDebug() << " Expected content-length: " << contentLength << ". Bytes read so far: " << body.size();
+          CTK_SOAP_LOG_LOWLEVEL( << " Expected content-length: " << contentLength << ". Bytes read so far: " << body.size() );
           if (body.size()<contentLength)
           if (body.size()<contentLength)
           {
           {
-            qDebug() << " Message body too small. Trying to read more.";
+            qCritical() << " Message body too small. Trying to read more.";
             socket.waitForReadyRead(-1);
             socket.waitForReadyRead(-1);
           }
           }
         }
         }
@@ -109,7 +110,7 @@ void ctkSoapConnectionRunnable::readClient(QTcpSocket& socket)
           QtSoapMessage msg;
           QtSoapMessage msg;
           if (!msg.setContent(body))
           if (!msg.setContent(body))
           {
           {
-            qDebug() << "QtSoap import failed:" << msg.errorString();
+            qCritical() << "QtSoap import failed:" << msg.errorString();
             return;
             return;
           }
           }
 
 
@@ -118,11 +119,11 @@ void ctkSoapConnectionRunnable::readClient(QTcpSocket& socket)
 
 
           if (reply.isFault())
           if (reply.isFault())
           {
           {
-            qDebug() << "QtSoap reply faulty";
+            qCritical() << "QtSoap reply faulty";
             return;
             return;
           }
           }
 
 
-          qDebug() << "SOAP reply:";
+          CTK_SOAP_LOG_LOWLEVEL( << "SOAP reply:" );
 
 
           content = reply.toXmlString();
           content = reply.toXmlString();
         }
         }
@@ -136,7 +137,7 @@ void ctkSoapConnectionRunnable::readClient(QTcpSocket& socket)
 
 
       block.append(content);
       block.append(content);
 
 
-      qDebug() << block;
+      CTK_SOAP_LOG_LOWLEVEL( << block );
 
 
       socket.write(block);
       socket.write(block);
 
 

+ 31 - 0
Plugins/org.commontk.dah.core/ctkSoapLog.h

@@ -0,0 +1,31 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+#ifndef CTKSOAPLOG_H
+#define CTKSOAPLOG_H
+
+//#define CTK_SOAP_LOG_LOWLEVEL(msg) qDebug() msg;
+#define CTK_SOAP_LOG_LOWLEVEL(msg) 
+
+//#define CTK_SOAP_LOG(msg) qDebug() msg;
+#define CTK_SOAP_LOG(msg) 
+
+#endif // CTKSOAPLOG_H