WsdmRmdPerspectiveAction.java
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.web.action;
022 
023 import java.io.IOException;
024 import java.net.URI;
025 
026 import javax.management.ObjectName;
027 import javax.servlet.RequestDispatcher;
028 import javax.servlet.ServletException;
029 import javax.servlet.http.HttpServlet;
030 import javax.servlet.http.HttpServletRequest;
031 import javax.servlet.http.HttpServletResponse;
032 import javax.xml.namespace.QName;
033 
034 import org.apache.muse.core.proxy.ProxyHandler;
035 import org.apache.muse.core.proxy.ReflectionProxyHandler;
036 import org.apache.muse.util.xml.XmlUtils;
037 import org.apache.muse.ws.addressing.EndpointReference;
038 import org.apache.muse.ws.resource.remote.WsResourceClient;
039 import org.apache.qpid.management.Names;
040 import org.w3c.dom.Element;
041 
042 public class WsdmRmdPerspectiveAction extends HttpServlet
043 {
044   private static final long serialVersionUID = -2411413147821629363L;
045   private static final Object [] DIALECT = new Object[]{"http://docs.oasis-open.org/wsrf/rmd-1"};
046   
047   private ProxyHandler proxyHandler;
048   
049   private URI resourceUri;
050     
051   @Override
052   public void init() throws ServletException
053   {
054     proxyHandler  = new ReflectionProxyHandler();
055     proxyHandler.setAction("http://schemas.xmlsoap.org/ws/2004/09/mex/GetMetadata");
056     proxyHandler.setRequestName(new QName("http://schemas.xmlsoap.org/ws/2004/09/mex""GetMetadata", Names.PREFIX));
057     proxyHandler.setRequestParameterNames(new QName[]{new QName("http://schemas.xmlsoap.org/ws/2004/09/mex""Dialect", Names.PREFIX)});
058     proxyHandler.setResponseName(new QName("http://schemas.xmlsoap.org/ws/2004/09/mex""Metadata", Names.PREFIX));
059     proxyHandler.setReturnType(Element[].class);
060   }
061   
062   @SuppressWarnings("unchecked")
063   @Override
064   protected void service(HttpServletRequest request, HttpServletResponse responsethrows ServletException, IOException
065   {
066     try 
067     {
068 //      String resourceId = request.getParameter("resourceId");
069 //      ObjectName objectName = new ObjectName(resourceId);
070 //      
071 //      String wsresourceid = objectName.getKeyProperty(Names.OBJECT_ID);
072 //      EndpointReference resourceEndpointReference = new EndpointReference(getURI(request));
073 //      resourceEndpointReference.addParameter(
074 //          Names.RESOURCE_ID_QNAME, 
075 //          wsresourceid);
076 //      
077 //      WsResourceClient resourceClient = new WsResourceClient(resourceEndpointReference);
078 //      Element rmd = ((Element[])resourceClient.invoke(proxyHandler,DIALECT))[0];
079 //                        
080 //          String output = XmlUtils.toString(rmd);
081 //          
082 //      String [] keyProperties = objectName.getKeyPropertyListString().split(",");
083 //      
084 //      request.setAttribute("resourceId", objectName);
085 //      request.setAttribute("nameAttributes",keyProperties);
086 //      request.setAttribute("rmd",output);
087       RequestDispatcher dispatcher = request.getRequestDispatcher("/tbd.jsp");
088       dispatcher.forward(request,response)
089     catch(Exception exception)
090     {
091       request.setAttribute("errorMessage","Unable to detect the exact cause Please look at the reported stack trace below.");
092       request.setAttribute("exception",exception);
093       RequestDispatcher dispatcher = request.getRequestDispatcher("/error_page.jsp");
094       dispatcher.forward(request,response);      
095     }
096   }
097 
098   private URI getURI(HttpServletRequest request)
099   {
100     if (resourceUri == null)
101     {
102       StringBuilder builder = new StringBuilder();
103       builder
104         .append("http://")
105         .append(request.getServerName())
106         .append(":")
107         .append(request.getServerPort())
108         .append("/qman/services/QManWsResource");
109       resourceUri = URI.create(builder.toString());
110     }
111     return resourceUri;
112   }
113 }