001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019package org.apache.oozie.servlet; 020 021import javax.servlet.http.HttpServletResponse; 022 023import org.apache.oozie.ErrorCode; 024 025public class ServletUtilities { 026 027 /** 028 * accessory static method to check the app path parameter for the request 029 * used only for job-related request and only one of them should exist 030 * 031 * @param wfPath workflow app path 032 * @param coordPath coordinator app path 033 * @throws XServletException if either path is not valid 034 */ 035 protected static void ValidateAppPath(String wfPath, String coordPath) throws XServletException { 036 if (wfPath != null && coordPath != null) { 037 throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0302, 038 "multiple app paths specified, only one is allowed"); 039 } 040 else { 041 if (wfPath == null && coordPath == null) { 042 throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0302, 043 "a workflow or coordinator app path is required"); 044 } 045 } 046 } 047 048 /** 049 * accessory static method to check the app path parameter for the request 050 * used only for job-related request and only one of them should exist 051 * bundle appPath is also checked 052 * 053 * @param wfPath workflow app path 054 * @param coordPath coordinator app path 055 * @param bundlePath bundle app path 056 * @throws XServletException if either path is not valid 057 */ 058 protected static void ValidateAppPath(String wfPath, String coordPath, String bundlePath) throws XServletException { 059 int n = 0; 060 061 if (wfPath != null) { 062 n ++; 063 } 064 065 if (coordPath != null) { 066 n ++; 067 } 068 069 if (bundlePath != null) { 070 n ++; 071 } 072 073 if (n == 0) { 074 throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0302, "a workflow, coordinator, or bundle app path is required"); 075 } 076 077 if (n != 1) { 078 throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0302, "Multiple app paths specified, only one is allowed"); 079 } 080 } 081 082 /** 083 * accessory static method to check the lib path parameter for the request 084 * 085 * @param libPath lib path 086 * @throws XServletException if either path is not valid 087 */ 088 protected static void ValidateLibPath(String libPath) throws XServletException { 089 if (libPath == null) { 090 throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0302, "a lib path is required"); 091 } 092 } 093}