import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; import java.net.*; import javax.wsdl.*; import org.apache.wsil.*; import org.apache.wsil.QName; import org.apache.wsil.WSILDocument; import org.apache.wsil.client.WSILProxy; import org.apache.wsil.WSILDocument; import com.ibm.uddi4j.wsdl.util.*; import org.apache.wsil.util.WSDLDocument; public class InspectionHandlerServlet extends HttpServlet { /** * JSP viewer * */ public final static String JSP_VIEWER = "wsdlTableGenerator.jsp"; /** * ServiceNames attribute * */ public final static String SERVICE_NAMES = "serviceNames"; /** * Locations attribute * */ public final static String LOCATIONS = "locations"; /** * Abstracts attribute * */ public final static String ABSTRACTS = "abstracts"; /** * Inspection input parameter * */ public final static String INSPECTION_URL = "inspectionDocURL"; /** * Error page * */ public final static String ERROR_PAGE = "/errorPage.jsp"; public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { doPost(req, res); } public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); try { WSDLDocument[] wsdlDocArray = null; WSILDocument wsilDoc = null; // Create WSIL proxy WSILProxy wsilProxy = new WSILProxy(req.getParameter(INSPECTION_URL)); // Create a new WSIL document wsilDoc = wsilProxy.getWSILDocument(); // Set service names req.setAttribute(SERVICE_NAMES, getAllWSDLServiceNames(wsilDoc)); // Set abstracts req.setAttribute(ABSTRACTS, getAllAbstracts(wsilDoc)); // Set locations req.setAttribute(LOCATIONS, getAllWSDLLocations(wsilDoc)); // Set WSIL URL req.setAttribute(INSPECTION_URL, req.getParameter(INSPECTION_URL)); // Transfer control RequestDispatcher rd = req.getRequestDispatcher(JSP_VIEWER); rd.forward(req, res); } catch (Throwable t) { req.setAttribute("javax.servlet.jsp.jspException", t); // Transfer control to Error page RequestDispatcher rd = getServletContext().getRequestDispatcher(ERROR_PAGE); rd.forward(req, res); } } /** * Returns the an array of WSIL Abstract entries. * * @param wsilDoc a <code>WSILDocument</code> value * @return a <code>String[]</code> value or null if no abstracts were found. * @exception WSILException if an error occurs */ public String[] getAllAbstracts(WSILDocument wsilDoc) throws WSILException { Vector abstractsVector = new Vector(); String[] abstractsArray = null; // Get service array org.apache.wsil.Service[] serviceArray = wsilDoc.getInspection().getServices(); for (int i = 0; i < serviceArray.length; i++) { WSILElementWithText[] textArray = textArray = serviceArray[i].getAbstracts(); if (textArray == null) continue; // Look up abstracts for (int j = 0; j < textArray.length; j++) abstractsVector.add(textArray[j].getText()); } // Create abstractsArray if (abstractsVector.size() != 0) { abstractsArray = new String[abstractsVector.size()]; abstractsVector.copyInto(abstractsArray); } return abstractsArray; } /** * Returns the an array of WSDL location entries. * * @param wsilDoc a <code>WSILDocument</code> value * @return a <code>String[]</code> value * @exception WSILException if an error occurs */ public String[] getAllWSDLLocations(WSILDocument wsilDoc) throws WSILException { Vector wsdlDocLocationVector = new Vector(); String[] wsdlDocLocationArray = null; // Get service array org.apache.wsil.Service[] serviceArray = wsilDoc.getInspection().getServices(); for (int i = 0; i < serviceArray.length; i++) { Description[] descriptionArray = serviceArray[i].getDescriptions(); String currentLocation = null; for (int k = 0; k < descriptionArray.length; k++) { String location = descriptionArray[k].getLocation(); if (location == null) continue; // Avoid duplicates if (currentLocation != null && currentLocation.equals(location)) continue; currentLocation = location; wsdlDocLocationVector.add(wsilDoc.resolveURL(location)); } } // Create wsdlDocLocationArray if (wsdlDocLocationVector.size() != 0) { wsdlDocLocationArray = new String[wsdlDocLocationVector.size()]; wsdlDocLocationVector.copyInto(wsdlDocLocationArray); } return wsdlDocLocationArray; } /** * Returns the an array of WSDL service names entries. * * @param wsilDoc a <code>WSILDocument</code> value * @return a <code>String[]</code> value * @exception WSILException if an error occurs */ public String[] getAllWSDLServiceNames(WSILDocument wsilDoc) throws WSILException { Vector wsdlDocServiceNameVector = new Vector(); String[] wsdlDocServiceNameArray = null; // Get service array org.apache.wsil.Service[] serviceArray = wsilDoc.getInspection().getServices(); for (int i = 0; i < serviceArray.length; i++) { ServiceName[] serviceNameArray = serviceArray[i].getServiceNames(); if (serviceNameArray != null && serviceNameArray.length != 0) { wsdlDocServiceNameVector.add(serviceNameArray[0].getText()); } } // Create wsdlDocServiceNameArray if (wsdlDocServiceNameVector.size() != 0) { wsdlDocServiceNameArray = new String[wsdlDocServiceNameVector.size()]; wsdlDocServiceNameVector.copyInto(wsdlDocServiceNameArray); } return wsdlDocServiceNameArray; } }