ctkDicomHostServerPrivate.cpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. // Qt includes
  16. #include <QHostAddress>
  17. // CTK includes
  18. #include "ctkDicomHostServerPrivate.h"
  19. #include <ctkDicomHostInterface.h>
  20. #include <ctkDicomAppHostingTypesHelper.h>
  21. #include <ctkExchangeSoapMessageProcessor.h>
  22. #include "ctkHostSoapMessageProcessor_p.h"
  23. // STD includes
  24. #include <stdexcept>
  25. //----------------------------------------------------------------------------
  26. ctkDicomHostServerPrivate::ctkDicomHostServerPrivate(ctkDicomHostInterface* hostInterface, int port, QString path) :
  27. Port(port), Path(path), HostInterface(hostInterface)
  28. {
  29. connect(&this->Server, SIGNAL(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)),
  30. this, SLOT(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)));
  31. connect(&this->Server, SIGNAL(incomingWSDLMessage(QString,QString*)),
  32. this, SLOT(incomingWSDLMessage(QString,QString*)));
  33. if (!this->Server.listen(QHostAddress::LocalHost, this->Port))
  34. {
  35. qCritical() << "Listening to 127.0.0.1:" << this->Port << " failed.";
  36. }
  37. ctkHostSoapMessageProcessor* hostProcessor = new ctkHostSoapMessageProcessor( hostInterface );
  38. this->Processors.push_back(hostProcessor);
  39. ctkExchangeSoapMessageProcessor* exchangeProcessor = new ctkExchangeSoapMessageProcessor( hostInterface );
  40. this->Processors.push_back(exchangeProcessor);
  41. }
  42. //----------------------------------------------------------------------------
  43. void ctkDicomHostServerPrivate::incomingWSDLMessage(
  44. const QString& message, QString* reply)
  45. {
  46. if (message == "?wsdl")
  47. {
  48. QFile wsdlfile(":/dah/HostService-20100825.wsdl");
  49. wsdlfile.open(QFile::ReadOnly | QFile::Text);
  50. if(wsdlfile.isOpen())
  51. {
  52. QTextStream textstream(&wsdlfile);
  53. *reply = textstream.readAll();
  54. QString actualURL="http://localhost:";
  55. //actualURL+=QString::number(this->Port)+"/HostInterface"; // FIXME: has to be replaced by url provided by host
  56. actualURL+=QString::number(this->Port)+Path;
  57. reply->replace("REPLACE_WITH_ACTUAL_URL",actualURL);
  58. reply->replace("HostService-20100825.xsd",actualURL+"?xsd=1");
  59. //reply->replace("<soap:body use=\"literal\"/>","<soap:body use=\"literal\"></soap:body>");
  60. }
  61. }
  62. else if (message == "?xsd=1")
  63. {
  64. QFile wsdlfile(":/dah/HostService-20100825.xsd");
  65. wsdlfile.open(QFile::ReadOnly | QFile::Text);
  66. if(wsdlfile.isOpen())
  67. {
  68. QTextStream textstream(&wsdlfile);
  69. *reply = textstream.readAll();
  70. }
  71. }
  72. }
  73. //----------------------------------------------------------------------------
  74. void ctkDicomHostServerPrivate::incomingSoapMessage(
  75. const QtSoapMessage& message, QtSoapMessage* reply)
  76. {
  77. this->Processors.process(message, reply);
  78. }