1 18 package org.apache.axis2.transport.http; 19 20 import org.apache.axis2.Constants; 21 import org.apache.axis2.context.ConfigurationContext; 22 import org.apache.axis2.deployment.util.DeploymentData; 23 import org.apache.axis2.description.OperationDescription; 24 import org.apache.axis2.description.ServiceDescription; 25 import org.apache.axis2.engine.AxisConfigurationImpl; 26 import org.apache.axis2.engine.AxisFault; 27 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 import javax.xml.namespace.QName ; 31 import java.io.IOException ; 32 import java.io.StringWriter ; 33 import java.io.OutputStream ; 34 import java.io.PrintWriter ; 35 import java.util.ArrayList ; 36 import java.util.Collection ; 37 import java.util.HashMap ; 38 39 public class ListingAgent { 40 41 44 private static final String LIST_MULTIPLE_SERVICE_JSP_NAME = "listServices.jsp"; 45 46 private static final String LIST_SRVICES_JSP_NAME = "listService.jsp"; 47 48 private static final String SELECT_SERVICE_JSP_NAME = "SelectService.jsp"; 49 50 private static final String ADMIN_JSP_NAME = "admin.jsp"; 51 52 private static final String LIST_AVAILABLE_MODULES_JSP_NAME = "listModules.jsp"; 53 54 private static final String LIST_GLOABLLY_ENGAGED_MODULES_JSP_NAME = "globalModules.jsp"; 55 56 private static final String LIST_PHASES_JSP_NAME = "viewphases.jsp"; 57 58 private static final String ENGAGING_MODULE_GLOBALLY_JSP_NAME = "engagingglobally.jsp"; 59 60 private static final String ENGAGING_MODULE_TO_SERVICE_JSP_NAME = "engagingtoaservice.jsp"; 61 62 65 private static final String LIST_SINGLE_SERVICE_JSP_NAME = "listSingleService.jsp"; 66 private static final String VIEW_GLOBAL_HANDLERS_JSP_NAME = "ViewGlobalHandlers.jsp"; 67 private static final String VIEW_SERVICE_HANDLERS_JSP_NAME = "ViewServiceHandlers.jsp"; 68 69 private static final String ENGAGE_TO_OPERATION_JSP_NAME = "enaggingtoanopeartion.jsp"; 70 71 public ListingAgent(ConfigurationContext configContext) { 72 this.configContext = configContext; 73 } 74 75 private ConfigurationContext configContext; 76 79 private final boolean allowListServices = true; 80 81 84 private final boolean allowListSingleService = true; 85 private OutputStream out = null; 86 87 public void handle( 88 HttpServletRequest httpServletRequest, 89 HttpServletResponse httpServletResponse,OutputStream out) 90 throws IOException { 91 this.out = out; 92 String filePart = httpServletRequest.getRequestURL().toString(); 93 if ((filePart != null) && filePart.endsWith(Constants.ADMIN_LISTSERVICES)) { 94 listAdminServices(httpServletRequest, httpServletResponse); 95 return; 96 } else if ((filePart != null) && filePart.endsWith(Constants.LIST_MODULES)) { 97 listModules(httpServletRequest, httpServletResponse); 98 return; 99 } else if ( 100 (filePart != null) && filePart.endsWith(Constants.LIST_GLOABLLY_ENGAGED_MODULES)) { 101 listGloballyModules(httpServletRequest, httpServletResponse); 102 return; 103 } else if ((filePart != null) && filePart.endsWith(Constants.LIST_PHASES)) { 104 listPhases(httpServletRequest, httpServletResponse); 105 return; 106 } else if ((filePart != null) && filePart.endsWith(Constants.ENGAGE_GLOBAL_MODULE)) { 107 engageModulesGlobally(httpServletRequest, httpServletResponse); 108 return; 109 } else if ((filePart != null) && filePart.endsWith(Constants.ENGAGE_MODULE_TO_SERVICE)) { 110 engageModulesToService(httpServletRequest, httpServletResponse); 111 return; 112 } else if ((filePart != null) && filePart.endsWith(Constants.ADMIN_LOGGING)) { 113 adminLogging(httpServletRequest, httpServletResponse); 114 return; 115 } else if ((filePart != null) && filePart.endsWith(Constants.VIEW_GLOBAL_HANDLERS)) { 116 viewGlobalHandlers(httpServletRequest, httpServletResponse); 117 return; 118 } else if ((filePart != null) && filePart.endsWith(Constants.SELECT_SERVICE)) { 119 selectService(httpServletRequest, httpServletResponse); 120 return; 121 } else if ((filePart != null) && filePart.endsWith(Constants.VIEW_SERVICE_HANDLERS)) { 122 viewServiceHandlers(httpServletRequest, httpServletResponse); 123 return; 124 } else if ( 125 (filePart != null) && filePart.endsWith(Constants.LIST_SERVICE_FOR_MODULE_ENGAMNET)) { 126 lsitServiceformodules(httpServletRequest, httpServletResponse); 127 return; 128 } else if ( 129 (filePart != null) && filePart.endsWith(Constants.LIST_OPERATIONS_FOR_THE_SERVICE)) { 130 engageModulesToOpeartion(httpServletRequest, httpServletResponse); 131 return; 132 } 133 134 if (allowListServices && (filePart != null) && filePart.endsWith(Constants.LISTSERVICES)) { 135 listServices(httpServletRequest, httpServletResponse); 136 return; 137 } else { 138 if (allowListSingleService) { 139 listService(httpServletRequest, httpServletResponse, filePart); 140 return; 141 } 142 } 143 } 144 145 152 private void listServices(HttpServletRequest req, HttpServletResponse res) throws IOException { 153 HashMap services = configContext.getAxisConfiguration().getServices(); 154 req.getSession().setAttribute(Constants.SERVICE_MAP, services); 155 req.getSession().setAttribute( 156 Constants.ERROR_SERVICE_MAP, 157 configContext.getAxisConfiguration().getFaulytServices()); 158 res.sendRedirect(LIST_MULTIPLE_SERVICE_JSP_NAME); 159 } 160 161 167 private void listAdminServices(HttpServletRequest req, HttpServletResponse res) 168 throws IOException { 169 HashMap services = configContext.getAxisConfiguration().getServices(); 170 req.getSession().setAttribute(Constants.SERVICE_MAP, services); 171 req.getSession().setAttribute( 172 Constants.ERROR_SERVICE_MAP, 173 configContext.getAxisConfiguration().getFaulytServices()); 174 res.sendRedirect(LIST_SRVICES_JSP_NAME); 175 } 176 177 private void selectService(HttpServletRequest req, HttpServletResponse res) 178 throws IOException { 179 HashMap services = configContext.getAxisConfiguration().getServices(); 180 req.getSession().setAttribute(Constants.SERVICE_MAP, services); 181 req.getSession().setAttribute(Constants.MODULE_ENGAMENT, null); 182 res.sendRedirect(SELECT_SERVICE_JSP_NAME); 183 } 184 private void adminLogging(HttpServletRequest req, HttpServletResponse res) throws IOException { 185 String username = req.getParameter("userName"); 186 String password = req.getParameter("password"); 187 if (username == null 188 || password == null 189 || username.trim().equals("") 190 || password.trim().equals("")) { 191 throw new AxisFault("invalid user name"); 192 } 193 String adminUserName = 194 (String ) ((AxisConfigurationImpl) configContext.getAxisConfiguration()) 195 .getParameter(Constants.USER_NAME) 196 .getValue(); 197 String adminPassword = 198 (String ) ((AxisConfigurationImpl) configContext.getAxisConfiguration()) 199 .getParameter(Constants.PASSWORD) 200 .getValue(); 201 if (username != null 202 && password != null 203 && username.equals(adminUserName) 204 && password.equals(adminPassword)) { 205 req.getSession().setAttribute(Constants.LOGGED, "Yes"); 206 res.sendRedirect(ADMIN_JSP_NAME); 207 } else { 208 throw new AxisFault("invalid user name"); 209 } 210 } 211 212 private void listModules(HttpServletRequest req, HttpServletResponse res) throws IOException { 213 HashMap modules = 214 ((AxisConfigurationImpl) configContext.getAxisConfiguration()).getModules(); 215 req.getSession().setAttribute(Constants.MODULE_MAP, modules); 216 req.getSession().setAttribute( 217 Constants.ERROR_MODULE_MAP, 218 configContext.getAxisConfiguration().getFaulytModules()); 219 res.sendRedirect(LIST_AVAILABLE_MODULES_JSP_NAME); 220 } 221 222 private void engageModulesGlobally(HttpServletRequest req, HttpServletResponse res) 223 throws IOException { 224 HashMap modules = 225 ((AxisConfigurationImpl) configContext.getAxisConfiguration()).getModules(); 226 req.getSession().setAttribute(Constants.MODULE_MAP, modules); 227 String moduleName = (String ) req.getParameter("modules"); 228 req.getSession().setAttribute(Constants.ENGAGE_STATUS, null); 229 if (moduleName != null) { 230 try { 231 configContext.getAxisConfiguration().engageModule(new QName (moduleName)); 232 req.getSession().setAttribute( 233 Constants.ENGAGE_STATUS, 234 moduleName + " module engaged globally Successfully"); 235 } catch (AxisFault axisFault) { 236 req.getSession().setAttribute(Constants.ENGAGE_STATUS, axisFault.getMessage()); 237 } 238 } 239 req.getSession().setAttribute("modules", null); 240 res.sendRedirect(ENGAGING_MODULE_GLOBALLY_JSP_NAME); 241 } 242 243 private void engageModulesToOpeartion(HttpServletRequest req, HttpServletResponse res) 244 throws IOException { 245 HashMap modules = 246 ((AxisConfigurationImpl) configContext.getAxisConfiguration()).getModules(); 247 req.getSession().setAttribute(Constants.MODULE_MAP, modules); 248 String moduleName = (String ) req.getParameter("modules"); 249 250 req.getSession().setAttribute(Constants.ENGAGE_STATUS, null); 251 req.getSession().setAttribute("modules", null); 252 253 String serviceName = (String ) req.getParameter("service"); 254 if (serviceName != null) { 255 req.getSession().setAttribute("service", serviceName); 256 } else { 257 serviceName = (String ) req.getSession().getAttribute("service"); 258 } 259 req.getSession().setAttribute( 260 Constants.OPEARTION_MAP, 261 configContext 262 .getAxisConfiguration() 263 .getService(new QName (serviceName)) 264 .getOperations()); 265 req.getSession().setAttribute(Constants.ENGAGE_STATUS, null); 266 String operationName = (String ) req.getParameter("operation"); 267 if (serviceName != null && moduleName != null && operationName != null) { 268 try { 269 OperationDescription od = 270 configContext.getAxisConfiguration().getService( 271 new QName (serviceName)).getOperation( 272 new QName (operationName)); 273 od.engageModule( 274 configContext.getAxisConfiguration().getModule(new QName (moduleName))); 275 req.getSession().setAttribute( 276 Constants.ENGAGE_STATUS, 277 moduleName + " module engaged to the operation Successfully"); 278 } catch (AxisFault axisFault) { 279 req.getSession().setAttribute(Constants.ENGAGE_STATUS, axisFault.getMessage()); 280 } 281 } 282 req.getSession().setAttribute("operation", null); 283 res.sendRedirect(ENGAGE_TO_OPERATION_JSP_NAME); 284 } 285 private void engageModulesToService(HttpServletRequest req, HttpServletResponse res) 286 throws IOException { 287 HashMap modules = 288 ((AxisConfigurationImpl) configContext.getAxisConfiguration()).getModules(); 289 req.getSession().setAttribute(Constants.MODULE_MAP, modules); 290 HashMap services = configContext.getAxisConfiguration().getServices(); 291 req.getSession().setAttribute(Constants.SERVICE_MAP, services); 292 String moduleName = (String ) req.getParameter("modules"); 293 req.getSession().setAttribute(Constants.ENGAGE_STATUS, null); 294 req.getSession().setAttribute("modules", null); 295 String serviceName = (String ) req.getParameter("service"); 296 req.getSession().setAttribute(Constants.ENGAGE_STATUS, null); 297 if (serviceName != null && moduleName != null) { 298 try { 299 300 configContext.getAxisConfiguration().getService( 301 new QName (serviceName)).engageModule( 302 configContext.getAxisConfiguration().getModule(new QName (moduleName))); 303 req.getSession().setAttribute( 304 Constants.ENGAGE_STATUS, 305 moduleName + " module engaged to the service Successfully"); 306 } catch (AxisFault axisFault) { 307 req.getSession().setAttribute(Constants.ENGAGE_STATUS, axisFault.getMessage()); 308 } 309 } 310 req.getSession().setAttribute("service", null); 311 res.sendRedirect(ENGAGING_MODULE_TO_SERVICE_JSP_NAME); 312 } 313 314 private void listGloballyModules(HttpServletRequest req, HttpServletResponse res) 315 throws IOException { 316 Collection modules = 317 ((AxisConfigurationImpl) configContext.getAxisConfiguration()).getEngadgedModules(); 318 req.getSession().setAttribute(Constants.MODULE_MAP, modules); 319 res.sendRedirect(LIST_GLOABLLY_ENGAGED_MODULES_JSP_NAME); 320 } 321 322 private void lsitServiceformodules(HttpServletRequest req, HttpServletResponse res) 323 throws IOException { 324 HashMap services = configContext.getAxisConfiguration().getServices(); 325 req.getSession().setAttribute(Constants.SERVICE_MAP, services); 326 req.getSession().setAttribute(Constants.MODULE_ENGAMENT, "Yes"); 327 res.sendRedirect(SELECT_SERVICE_JSP_NAME); 328 } 329 330 private void viewGlobalHandlers(HttpServletRequest req, HttpServletResponse res) 331 throws IOException { 332 req.getSession().setAttribute( 333 Constants.GLOBAL_HANDLERS, 334 configContext.getAxisConfiguration()); 335 res.sendRedirect(VIEW_GLOBAL_HANDLERS_JSP_NAME); 336 } 337 338 private void viewServiceHandlers(HttpServletRequest req, HttpServletResponse res) 339 throws IOException { 340 String service = (String ) req.getParameter("service"); 341 if (service != null) { 342 req.getSession().setAttribute( 343 Constants.SERVICE_HANDLERS, 344 configContext.getAxisConfiguration().getService(new QName (service))); 345 } 346 res.sendRedirect(VIEW_SERVICE_HANDLERS_JSP_NAME); 347 } 348 349 private void listPhases(HttpServletRequest req, HttpServletResponse res) throws IOException { 350 ArrayList phaselist = new ArrayList (); 351 DeploymentData depdata = DeploymentData.getInstance(); 352 phaselist.add(depdata.getINPhases()); 353 phaselist.add(depdata.getIN_FaultPhases()); 354 phaselist.add(depdata.getOUTPhases()); 355 phaselist.add(depdata.getOUT_FaultPhases()); 356 357 phaselist.add(depdata.getOperationInPhases()); 358 phaselist.add(depdata.getOperationInFaultPhases()); 359 phaselist.add(depdata.getOperationOutPhases()); 360 phaselist.add(depdata.getOperationOutFaultPhases()); 361 362 req.getSession().setAttribute(Constants.PHASE_LIST, phaselist); 363 res.sendRedirect(LIST_PHASES_JSP_NAME); 364 } 365 366 374 private void listService(HttpServletRequest req, HttpServletResponse res, String filePart) 375 throws IOException { 376 String serviceName = filePart.substring(filePart.lastIndexOf("/") + 1, filePart.length()); 377 HashMap services = configContext.getAxisConfiguration().getServices(); 378 String wsdl = req.getParameter("wsdl"); 379 if ((services != null) && !services.isEmpty()) { 380 Object serviceObj = services.get(new QName (serviceName)); 381 if (serviceObj != null) { 382 if(wsdl != null){ 383 res.setContentType("text/xml"); 385 PrintWriter out_writer = new PrintWriter (out); 386 ((ServiceDescription)serviceObj).printWSDL(out_writer,filePart); 387 392 out.flush(); 397 out.close(); 398 wsdl = null; 399 return; 400 } else { 401 req.getSession().setAttribute(Constants.SINGLE_SERVICE, serviceObj); 402 } 403 } 404 } 405 String URI = req.getRequestURI(); 406 URI = URI.substring(0, URI.indexOf("services")); 407 res.sendRedirect(URI + LIST_SINGLE_SERVICE_JSP_NAME); 408 } 409 410 } 411 | Popular Tags |