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,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.transport.http;
021:
022: import org.apache.axis2.AxisFault;
023: import org.apache.axis2.context.ConfigurationContext;
024: import org.apache.axis2.description.AxisOperation;
025: import org.apache.axis2.description.AxisService;
026: import org.apache.axis2.engine.AxisConfiguration;
027:
028: import java.util.Collection;
029: import java.util.Enumeration;
030: import java.util.HashMap;
031: import java.util.Hashtable;
032: import java.util.Iterator;
033: import java.util.Map;
034:
035: /**
036: * Class HTTPTransportReceiver
037: */
038: public class HTTPTransportReceiver {
039: public static Map getGetRequestParameters(String requestURI) {
040:
041: Map map = new HashMap();
042: if (requestURI == null || "".equals(requestURI)) {
043: return map;
044: }
045: char[] chars = requestURI.toCharArray();
046: final int NOT_BEGUN = 1500;
047: final int INSIDE_NAME = 1501;
048: final int INSIDE_VALUE = 1502;
049: int state = NOT_BEGUN;
050: StringBuffer name = new StringBuffer();
051: StringBuffer value = new StringBuffer();
052:
053: for (int index = 0; index < chars.length; index++) {
054: if (state == NOT_BEGUN) {
055: if (chars[index] == '?') {
056: state = INSIDE_NAME;
057: }
058: } else if (state == INSIDE_NAME) {
059: if (chars[index] == '=') {
060: state = INSIDE_VALUE;
061: } else {
062: name.append(chars[index]);
063: }
064: } else if (state == INSIDE_VALUE) {
065: if (chars[index] == ',') {
066: state = INSIDE_NAME;
067: map.put(name.toString(), value.toString());
068: name.delete(0, name.length());
069: value.delete(0, value.length());
070: } else {
071: value.append(chars[index]);
072: }
073: }
074: }
075:
076: if (name.length() + value.length() > 0) {
077: map.put(name.toString(), value.toString());
078: }
079:
080: return map;
081: }
082:
083: /**
084: * Returns the HTML text for the list of services deployed.
085: * This can be delegated to another Class as well
086: * where it will handle more options of GET messages.
087: *
088: * @return Returns String.
089: */
090: public static String getServicesHTML(
091: ConfigurationContext configurationContext) {
092: String temp = "";
093: Map services = configurationContext.getAxisConfiguration()
094: .getServices();
095: Hashtable erroneousServices = configurationContext
096: .getAxisConfiguration().getFaultyServices();
097: boolean status = false;
098:
099: if ((services != null) && !services.isEmpty()) {
100: status = true;
101:
102: Collection serviceCollection = services.values();
103:
104: temp += "<h2>" + "Deployed services" + "</h2>";
105:
106: for (Iterator it = serviceCollection.iterator(); it
107: .hasNext();) {
108:
109: AxisService axisService = (AxisService) it.next();
110:
111: Iterator iterator = axisService.getOperations();
112:
113: temp += "<h3><a href=\"" + axisService.getName()
114: + "?wsdl\">" + axisService.getName()
115: + "</a></h3>";
116:
117: if (iterator.hasNext()) {
118: temp += "Available operations <ul>";
119:
120: for (; iterator.hasNext();) {
121: AxisOperation axisOperation = (AxisOperation) iterator
122: .next();
123:
124: temp += "<li>"
125: + axisOperation.getName()
126: .getLocalPart() + "</li>";
127: }
128:
129: temp += "</ul>";
130: } else {
131: temp += "No operations specified for this service";
132: }
133: }
134: }
135:
136: if ((erroneousServices != null) && !erroneousServices.isEmpty()) {
137: temp += "<hr><h2><font color=\"blue\">Faulty Services</font></h2>";
138: status = true;
139:
140: Enumeration faultyservices = erroneousServices.keys();
141:
142: while (faultyservices.hasMoreElements()) {
143: String faultyserviceName = (String) faultyservices
144: .nextElement();
145:
146: temp += "<h3><font color=\"blue\">" + faultyserviceName
147: + "</font></h3>";
148: }
149: }
150:
151: if (!status) {
152: temp = "<h2>There are no services deployed</h2>";
153: }
154:
155: temp = "<html><head><title>Axis2: Services</title></head>"
156: + "<body>" + temp + "</body></html>";
157:
158: return temp;
159: }
160:
161: public static String printServiceHTML(String serviceName,
162: ConfigurationContext configurationContext) {
163: String temp = "";
164: try {
165: AxisConfiguration axisConfig = configurationContext
166: .getAxisConfiguration();
167: AxisService axisService = axisConfig
168: .getService(serviceName);
169: Iterator iterator = axisService.getOperations();
170: temp += "<h3>" + axisService.getName() + "</h3>";
171: temp += "<a href=\"" + axisService.getName()
172: + "?wsdl\">wsdl</a> <br/> ";
173: temp += "<i>Service Description : "
174: + axisService.getServiceDescription()
175: + "</i><br/><br/>";
176: if (iterator.hasNext()) {
177: temp += "Available operations <ul>";
178: for (; iterator.hasNext();) {
179: AxisOperation axisOperation = (AxisOperation) iterator
180: .next();
181: temp += "<li>"
182: + axisOperation.getName().getLocalPart()
183: + "</li>";
184: }
185: temp += "</ul>";
186: } else {
187: temp += "No operations specified for this service";
188: }
189: temp = "<html><head><title>Axis2: Services</title></head>"
190: + "<body>" + temp + "</body></html>";
191: } catch (AxisFault axisFault) {
192: temp = "<html><head><title>Service has a fualt</title></head>"
193: + "<body>"
194: + "<hr><h2><font color=\"blue\">"
195: + axisFault.getMessage()
196: + "</font></h2></body></html>";
197: }
198: return temp;
199: }
200: }
|