perfsonar-dev - perfsonar: r2260 - branches/as/src/org/perfsonar/service/web
Subject: perfsonar development work
List archive
- From:
- To:
- Subject: perfsonar: r2260 - branches/as/src/org/perfsonar/service/web
- Date: Wed, 21 Mar 2007 05:09:40 -0400
Author: rodriguez
Date: 2007-03-21 05:09:40 -0400 (Wed, 21 Mar 2007)
New Revision: 2260
Modified:
branches/as/src/org/perfsonar/service/web/RequestHandler.java
Log:
It has the capacity to get soap headers
Modified: branches/as/src/org/perfsonar/service/web/RequestHandler.java
===================================================================
--- branches/as/src/org/perfsonar/service/web/RequestHandler.java
2007-03-20 13:49:04 UTC (rev 2259)
+++ branches/as/src/org/perfsonar/service/web/RequestHandler.java
2007-03-21 09:09:40 UTC (rev 2260)
@@ -7,6 +7,8 @@
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;
@@ -20,214 +22,201 @@
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";
- // ----------------------------------------------------- constants
+ private static final String SAX_PARSER_CONFIG =
"service.sax_parser.config";
+ // -------------------------------------------- instance variables
+ private ConfigurationComponent configuration = null;
- private static final String INIT_SERVICE_MESSAGE_TYPE = "InitService";
+ private LoggerComponent logger = null;
+ // ---------------------------------- public methods
- private static final String SAX_PARSER_CONFIG =
"service.sax_parser.config";
+ public void acceptCall(SOAPEnvelope req, SOAPEnvelope resp) {
+ /*
+ *
+ * The first invocation of
AuxiliaryComponentManager.getInstance()
+ * creates the static instance of AuxiliaryComponentManager.
+ *
+ */
+ try {
+ configuration = (ConfigurationComponent)
AuxiliaryComponentManager
+
.getInstance().getComponent(ComponentNames.CONFIG);
- // -------------------------------------------- instance variables
+ if (configuration == null)
+ throw new
PerfSONARException("error.common.no_configuration",
+ "Cannot read configuration
file");
+ // get logger component
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
+ .getComponent(ComponentNames.LOGGER);
- private ConfigurationComponent configuration = null;
+ if (logger == null)
+ throw new
PerfSONARException("error.common.no_logger",
+ "Cannot find logger
component");
- private LoggerComponent logger = 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 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) {
- // ---------------------------------- public methods
+ try {
+ // convert input Document into Message -
requestMessage
+ Message requestMessage = null;
+ try {
+ requestMessage =
XMLUtils.convertToMessage(request,
+
configuration.getProperty(SAX_PARSER_CONFIG));
- /**
- * 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) {
+ } catch (Exception e) {
- /*
- *
- * The first invocation of AuxiliaryComponentManager.getInstance()
- * creates the static instance of AuxiliaryComponentManager.
- *
- */
+ throw new
PerfSONARException("error.common.parse_error",
+ "Parse/validation error, "
+ + "Cannot
convert request to Message. "
+ + "Nested
error messsage was " + e.getMessage());
- try {
+ }
- //get configuration component (and create Aux Comp Manager
+ // if parsed well
- configuration =
(ConfigurationComponent)AuxiliaryComponentManager.
- getInstance().getComponent(ComponentNames.CONFIG);
+ if (requestMessage != null) {
- if (configuration == null) throw new PerfSONARException(
- "error.common.no_configuration",
- "Cannot read configuration file");
+ logger.debug("RequestHandler: "
+ + "Message object constructed
from request. "
+ + "Request is of type: " +
requestMessage.getType());
- //get logger component
+ // Check if it is not InitService message only
+ if
(INIT_SERVICE_MESSAGE_TYPE.equalsIgnoreCase(requestMessage
+ .getType())) {
- logger = (LoggerComponent)AuxiliaryComponentManager.
- getInstance().getComponent(ComponentNames.LOGGER);
+ // if so, response that service was
set up correctly
+ throw new
PerfSONARException("service.common.success",
+ "Service initialized
correctly");
- if (logger == null) throw new PerfSONARException(
- "error.common.no_logger",
- "Cannot find logger component");
+ }
- logger.info("RequestHandler: Service received a request");
- logger.debug("RequestHandler: " +
- "Calling on parser to parse the request");
+ // Call on the MessageHandlerFactory to get
the appropriate
+ // message handler for this type of message.
- //convert input Document into Message - requestMessage
+ MessageHandler messageHandler =
MessageHandlerFactory
+
.getMessageHandler(requestMessage.getType());
- Message requestMessage = null;
- try {
+ // Call on the mh to "execute" the message
and return
+ // a response message.
+ logger.debug("RequestHandler: " + "Calling on
MessageHandler ["
+ + messageHandler.getClass() +
"] to satisfy request");
- requestMessage = XMLUtils.convertToMessage(
- request,
- configuration.getProperty(SAX_PARSER_CONFIG));
+ // run proper message handler,
+ // which will run ServiceEngine
+ //
*****************************************************
- } catch (Exception e) {
-
- throw new PerfSONARException("error.common.parse_error",
- "Parse/validation error, " +
- "Cannot convert request to Message. " +
- "Nested error messsage was "+e.getMessage());
+ Message responseMessage = messageHandler
+ .execute(requestMessage);
- }
+ //
*****************************************************
- //if parsed well
+ // convert response Message into Document
+ Document responseDocument = XMLUtils
+
.convertMessageToDOM(responseMessage);
- if (requestMessage!=null) {
+ // if everything went fine, return response
document to Axis
- logger.debug("RequestHandler: " +
- "Message object constructed from request. " +
- "Request is of type: " +
- requestMessage.getType());
+ logger
+ .info("RequestHandler:
Service sent a successful response");
- /*
- * Check if it is not InitService message only
- */
- if (INIT_SERVICE_MESSAGE_TYPE.
- equalsIgnoreCase(requestMessage.getType())) {
+ return responseDocument;
- //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.
+ } else {
- MessageHandler messageHandler =
- MessageHandlerFactory.getMessageHandler(
- requestMessage.getType());
+ // if anything went wrong with parsing, throw
exception
+ logger.error("RequestHandler: "
+ + "Message object constructed
as null from request");
- // Call on the mh to "execute" the message and return
- // a response message.
- logger.debug(
- "RequestHandler: " +
- "Calling on MessageHandler ["+
- messageHandler.getClass()+"] to satisfy 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) {
- //run proper message handler,
- //which will run ServiceEngine
- //*****************************************************
+ /*
+ * If any error occured response with result/error
code
+ */
- Message responseMessage = messageHandler.execute(
- requestMessage);
+ // create common result code
+ Message responseMessage =
ResultCodesUtil.createResultCodeMetadata(
+ null, pex);
- //*****************************************************
+ // convert it into Document
+ Document responseDocument = null;
+ try {
- // convert response Message into Document
- Document responseDocument = XMLUtils.
- convertMessageToDOM( responseMessage );
+ responseDocument = XMLUtils
+
.convertMessageToDOM(responseMessage);
- //if everything went fine, return response document to Axis
+ } catch (PerfSONARException e) {
- logger.info("RequestHandler: Service sent a successful
response");
+ // or send null if impossible
- return responseDocument;
+ logger.fatal("RequestHandler: "
+ + "Return null response -
neither can create "
+ + "response message nor error
code message!");
+ }
- } else {
+ logger.info("RequestHandler: Service sent a response "
+ + "with error information");
- //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) {
+ return responseDocument;
- /*
- * If any error occured
- * response with result/error code
- */
+ }
- //create common result code
+ }
- 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
+} // RequestHandler
- perfsonar: r2260 - branches/as/src/org/perfsonar/service/web, svnlog, 03/21/2007
Archive powered by MHonArc 2.6.16.