001: /*
002: * Copyright 2005-2007 WSO2, Inc. (http://wso2.com)
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.wso2.esb.transport.util;
018:
019: import org.apache.axis2.context.ConfigurationContext;
020: import org.apache.axis2.description.AxisService;
021: import org.wso2.esb.transport.HttpGetRequestProcessor;
022:
023: import javax.servlet.http.HttpServletRequest;
024: import javax.servlet.http.HttpServletResponse;
025: import java.io.IOException;
026: import java.io.OutputStream;
027:
028: /**
029: *
030: */
031: public abstract class AbstractWsdlProcessor implements
032: HttpGetRequestProcessor {
033:
034: protected void printWSDL(ConfigurationContext configurationContext,
035: HttpServletRequest request, HttpServletResponse response,
036: WSDLPrinter wsdlPrinter) throws IOException {
037: String requestURI = request.getRequestURI();
038: String serviceName = requestURI.substring(requestURI
039: .lastIndexOf("/") + 1);
040: AxisService axisService = configurationContext
041: .getAxisConfiguration().getServiceForActivation(
042: serviceName);
043:
044: OutputStream outputStream = response.getOutputStream();
045: if (axisService != null) {
046: if (!axisService.isActive()) {
047: response.setContentType("text/html");
048: outputStream
049: .write(("<h4>Service " + serviceName + " is inactive. Cannot display WSDL document.</h4>")
050: .getBytes());
051: outputStream.flush();
052: } else {
053: response.setContentType("text/xml");
054: wsdlPrinter.printWSDL(axisService);
055: }
056: } else {
057: response.setContentType("text/html");
058: outputStream
059: .write(("<h4>Service " + serviceName + " not found. Cannot display WSDL document.</h4>")
060: .getBytes());
061: outputStream.flush();
062: }
063: }
064:
065: /**
066: * This method check for annotation=true query param. If it is available
067: * this method return true, otherwise false.
068: *
069: * @param request
070: * @return boolean
071: */
072: protected boolean checkForAnnotation(HttpServletRequest request) {
073: String parameter = request.getParameter("annotation");
074: if (parameter != null && parameter.length() != 0) {
075: if (parameter.equals("true")) {
076: return true;
077: }
078: }
079:
080: return false;
081: }
082:
083: /**
084: * This method will return the value of the parameter
085: *
086: * @param request
087: * @param paramName
088: * @return String
089: */
090: protected String getImportedWSDL(HttpServletRequest request,
091: String paramName) {
092: String paramValue = request.getParameter(paramName);
093:
094: if (paramValue != null && paramValue.length() != 0) {
095: return paramValue;
096: }
097: return "";
098:
099: }
100:
101: interface WSDLPrinter {
102: void printWSDL(AxisService axisService) throws IOException;
103: }
104: }
|