001 /*
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements. See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership. The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License. You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied. See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 *
020 */
021 package org.apache.qpid.management.servlet;
022
023 import java.io.IOException;
024 import java.io.PrintWriter;
025
026 import javax.servlet.ServletException;
027 import javax.servlet.http.HttpServlet;
028 import javax.servlet.http.HttpServletRequest;
029 import javax.servlet.http.HttpServletResponse;
030
031 import org.apache.muse.util.xml.XmlUtils;
032 import org.apache.qpid.management.Messages;
033 import org.apache.qpid.management.wsdm.muse.engine.WSDMAdapterIsolationLayer;
034 import org.apache.qpid.qman.debug.XmlDebugger;
035 import org.apache.qpid.transport.util.Logger;
036 import org.w3c.dom.Document;
037 import org.xml.sax.SAXException;
038
039 /**
040 * QMan Adapter facade.
041 * This is the main requestor entry point of the WS-DM connector / adapter.
042 * All WSDM requests will be handled (at higher level) by this servlet.
043 *
044 * @author Andrea Gazzarini
045 */
046 public class WSDMAdapter extends HttpServlet
047 {
048 private static final long serialVersionUID = 6149614872902682208L;
049 private final static Logger LOGGER = Logger.get(WSDMAdapter.class);
050 private WSDMAdapterIsolationLayer _isolationLayer;
051
052 @Override
053 public void init() throws ServletException {
054 LOGGER.debug(Messages.QMAN_000026_WSDM_ADAPTER_STARTS);
055
056 _isolationLayer = new WSDMAdapterIsolationLayer(getServletContext());
057 _isolationLayer.initialize();
058
059 LOGGER.debug(Messages.QMAN_000027_WSDM_ADAPTER_STARTED);
060
061 }
062
063 /**
064 * Accepts http requests containing a soap envelope (request) and therefore
065 * acts as the main entry point of whole WS process.
066 *
067 * @param request the http request.
068 * @param response the http response.
069 * @throws ServletException in case of application failure.
070 * @throws IOException in case of generic I/O failure.
071 */
072 @Override
073 protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
074 {
075 PrintWriter writer = response.getWriter();
076
077 Document soapEnvelopeRequest = null;
078 String soapEnvelopeResposeAsString = null;
079
080 try
081 {
082 soapEnvelopeRequest = XmlUtils.createDocument(request.getInputStream());
083
084 Document soapEnvelopeResponse = _isolationLayer.handleRequest(soapEnvelopeRequest);
085 soapEnvelopeResposeAsString = XmlUtils.toString(soapEnvelopeResponse,false,true);
086
087 response.setContentType("text/xml");
088
089 writer.write(soapEnvelopeResposeAsString);
090 } catch (SAXException exception)
091 {
092 LOGGER.error(
093 exception,
094 Messages.QMAN_100019_REQ_OR_RES_MALFORMED);
095 throw new ServletException(exception);
096 } finally {
097 writer.flush();
098
099 XmlDebugger.debug(soapEnvelopeRequest);
100 try {
101 XmlDebugger.debug(soapEnvelopeResposeAsString);
102 } catch(Exception exception) {
103 LOGGER.error(
104 exception,
105 Messages.QMAN_100019_REQ_OR_RES_MALFORMED);
106 }
107 }
108 }
109 }
|