perfsonar-dev - perfsonar: r2346 - branches/as/src/org/perfsonar/service/web
Subject: perfsonar development work
List archive
- From:
- To:
- Subject: perfsonar: r2346 - branches/as/src/org/perfsonar/service/web
- Date: Tue, 24 Apr 2007 04:47:08 -0400
Author: rodriguez
Date: 2007-04-24 04:47:08 -0400 (Tue, 24 Apr 2007)
New Revision: 2346
Modified:
branches/as/src/org/perfsonar/service/web/RequestHandler.java
Log:
Back to a old revision
Modified: branches/as/src/org/perfsonar/service/web/RequestHandler.java
===================================================================
--- branches/as/src/org/perfsonar/service/web/RequestHandler.java
2007-04-23 14:53:08 UTC (rev 2345)
+++ branches/as/src/org/perfsonar/service/web/RequestHandler.java
2007-04-24 08:47:08 UTC (rev 2346)
@@ -7,8 +7,6 @@
package org.perfsonar.service.web;
-import org.apache.axis.message.SOAPBodyElement;
-import org.apache.axis.message.SOAPEnvelope;
import org.ggf.ns.nmwg.base.v2_0.Message;
import org.perfsonar.commons.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.commons.auxiliary.ComponentNames;
@@ -22,201 +20,214 @@
import org.perfsonar.service.commons.util.ResultCodesUtil;
import org.w3c.dom.Document;
+
/**
* Class which handles web service requests.
- *
+ *
* @author Loukik
* @author Maciej Glowiak
*/
public class RequestHandler {
- // ----------------------------------------------------- constants
- private static final String INIT_SERVICE_MESSAGE_TYPE = "InitService";
- private static final String SAX_PARSER_CONFIG =
"service.sax_parser.config";
+ // ----------------------------------------------------- constants
- // -------------------------------------------- instance variables
- private ConfigurationComponent configuration = null;
- private LoggerComponent logger = null;
+ private static final String INIT_SERVICE_MESSAGE_TYPE = "InitService";
- // ---------------------------------- public methods
- public void acceptCall(SOAPEnvelope req, SOAPEnvelope resp) {
- /*
- *
- * The first invocation of
AuxiliaryComponentManager.getInstance()
- * creates the static instance of AuxiliaryComponentManager.
- *
- */
+ private static final String SAX_PARSER_CONFIG =
"service.sax_parser.config";
- try {
- configuration = (ConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
- if (configuration == null)
- throw new
PerfSONARException("error.common.no_configuration",
- "Cannot read configuration
file");
+ // -------------------------------------------- instance variables
- // get logger component
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
- if (logger == null)
- throw new
PerfSONARException("error.common.no_logger",
- "Cannot find logger
component");
+ private ConfigurationComponent configuration = null;
- logger.info("RequestHandler: Service received a
request");
- logger.debug("RequestHandler: "
- + "Calling on parser to parse the
request");
- logger
- .debug("void acceptCall(SOAPEnvelope
req, SOAPEnvelope resp)");
-
- SOAPBodyElement body = req.getFirstBody();
- Document reqDoc = body.getAsDocument();
- Document respDoc = acceptCall(reqDoc);
- resp.getBody().addDocument(respDoc);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
+ private LoggerComponent logger = null;
- // ---------------------------------- private methods
- /**
- * Accepts web service based calls and gives back responses
- *
- * @param request
- * org.w3c.dom.Document which contains the XML request
- *
- * @return org.w3c.dom.Document response provided by the service
- *
- * @throws Exception
- * If any fatal error occurred (but almost all errors are
being
- * catched and converted to PerfSONAR result codes
- */
- private Document acceptCall(Document request) {
- try {
- // convert input Document into Message -
requestMessage
+ // ---------------------------------- public methods
- Message requestMessage = null;
- try {
- requestMessage =
XMLUtils.convertToMessage(request,
-
configuration.getProperty(SAX_PARSER_CONFIG));
- } catch (Exception e) {
+ /**
+ * Accepts web service based calls and gives back responses
+ *
+ * @param request org.w3c.dom.Document which contains the XML request
+ *
+ * @return org.w3c.dom.Document response provided by the service
+ *
+ * @throws Exception If any fatal error occurred (but almost all errors
+ * are being catched and converted to PerfSONAR result codes
+ */
+ public Document acceptCall(Document request) {
- throw new
PerfSONARException("error.common.parse_error",
- "Parse/validation error, "
- + "Cannot
convert request to Message. "
- + "Nested
error messsage was " + e.getMessage());
+ /*
+ *
+ * The first invocation of AuxiliaryComponentManager.getInstance()
+ * creates the static instance of AuxiliaryComponentManager.
+ *
+ */
- }
+ try {
- // if parsed well
+ //get configuration component (and create Aux Comp Manager
- if (requestMessage != null) {
+ configuration =
(ConfigurationComponent)AuxiliaryComponentManager.
+ getInstance().getComponent(ComponentNames.CONFIG);
- logger.debug("RequestHandler: "
- + "Message object constructed
from request. "
- + "Request is of type: " +
requestMessage.getType());
+ if (configuration == null) throw new PerfSONARException(
+ "error.common.no_configuration",
+ "Cannot read configuration file");
- // Check if it is not InitService message only
- if
(INIT_SERVICE_MESSAGE_TYPE.equalsIgnoreCase(requestMessage
- .getType())) {
+ //get logger component
- // if so, response that service was
set up correctly
- throw new
PerfSONARException("service.common.success",
- "Service initialized
correctly");
+ logger = (LoggerComponent)AuxiliaryComponentManager.
+ getInstance().getComponent(ComponentNames.LOGGER);
- }
+ if (logger == null) throw new PerfSONARException(
+ "error.common.no_logger",
+ "Cannot find logger component");
- // Call on the MessageHandlerFactory to get
the appropriate
- // message handler for this type of message.
+ logger.info("RequestHandler: Service received a request");
+ logger.debug("RequestHandler: " +
+ "Calling on parser to parse the request");
- MessageHandler messageHandler =
MessageHandlerFactory
-
.getMessageHandler(requestMessage.getType());
+ //convert input Document into Message - requestMessage
- // Call on the mh to "execute" the message
and return
- // a response message.
- logger.debug("RequestHandler: " + "Calling on
MessageHandler ["
- + messageHandler.getClass() +
"] to satisfy request");
+ Message requestMessage = null;
+ try {
- // run proper message handler,
- // which will run ServiceEngine
- //
*****************************************************
+ requestMessage = XMLUtils.convertToMessage(
+ request,
+ configuration.getProperty(SAX_PARSER_CONFIG));
- Message responseMessage = messageHandler
- .execute(requestMessage);
+ } catch (Exception e) {
+
+ throw new PerfSONARException("error.common.parse_error",
+ "Parse/validation error, " +
+ "Cannot convert request to Message. " +
+ "Nested error messsage was "+e.getMessage());
- //
*****************************************************
+ }
- // convert response Message into Document
- Document responseDocument = XMLUtils
-
.convertMessageToDOM(responseMessage);
+ //if parsed well
- // if everything went fine, return response
document to Axis
+ if (requestMessage!=null) {
- logger
- .info("RequestHandler:
Service sent a successful response");
+ logger.debug("RequestHandler: " +
+ "Message object constructed from request. " +
+ "Request is of type: " +
+ requestMessage.getType());
- return responseDocument;
+ /*
+ * Check if it is not InitService message only
+ */
+ if (INIT_SERVICE_MESSAGE_TYPE.
+ equalsIgnoreCase(requestMessage.getType())) {
- } else {
+ //if so, response that service was set up correctly
+ throw new PerfSONARException("service.common.success",
+ "Service initialized correctly");
+
+ }
+
+
+ // Call on the MessageHandlerFactory to get the appropriate
+ // message handler for this type of message.
- // if anything went wrong with parsing, throw
exception
- logger.error("RequestHandler: "
- + "Message object constructed
as null from request");
+ MessageHandler messageHandler =
+ MessageHandlerFactory.getMessageHandler(
+ requestMessage.getType());
- throw new SystemException(
- "error.common.parse_error",
- "RequestHandler: "
- + "Server
could not construct a message object "
- + "from the
request due to unknown error. "
- + "Please
check request and try again");
- }
+ // Call on the mh to "execute" the message and return
+ // a response message.
+ logger.debug(
+ "RequestHandler: " +
+ "Calling on MessageHandler ["+
+ messageHandler.getClass()+"] to satisfy request");
- } catch (PerfSONARException pex) {
- /*
- * If any error occured response with result/error
code
- */
+ //run proper message handler,
+ //which will run ServiceEngine
+ //*****************************************************
- // create common result code
- Message responseMessage =
ResultCodesUtil.createResultCodeMetadata(
- null, pex);
+ Message responseMessage = messageHandler.execute(
+ requestMessage);
- // convert it into Document
- Document responseDocument = null;
- try {
+ //*****************************************************
- responseDocument = XMLUtils
-
.convertMessageToDOM(responseMessage);
+ // convert response Message into Document
+ Document responseDocument = XMLUtils.
+ convertMessageToDOM( responseMessage );
- } catch (PerfSONARException e) {
+ //if everything went fine, return response document to Axis
- // or send null if impossible
+ logger.info("RequestHandler: Service sent a successful
response");
- logger.fatal("RequestHandler: "
- + "Return null response -
neither can create "
- + "response message nor error
code message!");
+ return responseDocument;
- }
- logger.info("RequestHandler: Service sent a response "
- + "with error information");
+ } else {
- return responseDocument;
+ //if anything went wrong with parsing, throw exception
+ logger.error("RequestHandler: " +
+ "Message object constructed as null from request");
+
+ throw new SystemException("error.common.parse_error",
+ "RequestHandler: " +
+ "Server could not construct a message object " +
+ "from the request due to unknown error. " +
+ "Please check request and try again");
+ }
+
+
+ } catch (PerfSONARException pex) {
- }
+ /*
+ * If any error occured
+ * response with result/error code
+ */
- }
+ //create common result code
-} // RequestHandler
+ Message responseMessage =
+ ResultCodesUtil.createResultCodeMetadata(
+ null,
+ pex);
+
+ //convert it into Document
+ Document responseDocument = null;
+ try {
+
+ responseDocument = XMLUtils.convertMessageToDOM(
+ responseMessage);
+
+ } catch (PerfSONARException e) {
+
+ //or send null if impossible
+
+ logger.fatal("RequestHandler: " +
+ "Return null response - neither can create " +
+ "response message nor error code message!");
+
+ }
+
+ logger.info("RequestHandler: Service sent a response "
+ + "with error information");
+
+ return responseDocument;
+
+ }
+
+ }
+
+
+} //RequestHandler
- perfsonar: r2346 - branches/as/src/org/perfsonar/service/web, svnlog, 04/24/2007
Archive powered by MHonArc 2.6.16.