source: other-projects/tipple-android/i-greenstone-server-files/greenstone/webapps/greenstone3/EchoHeaders.jws@ 26899

Last change on this file since 26899 was 26899, checked in by davidb, 11 years ago

Tipple reborn after Chris's Summer of Code 2013

File size: 2.7 KB
Line 
1/*
2 * Copyright 2002,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import org.apache.axis.AxisFault;
18import org.apache.axis.MessageContext;
19import org.apache.axis.transport.http.HTTPConstants;
20
21import javax.servlet.http.HttpServletRequest;
22import java.util.Enumeration;
23import java.util.ArrayList;
24import java.util.Iterator;
25
26/**
27 * class to list headers sent in request as a string array
28 */
29public class EchoHeaders {
30
31 /**
32 * demo message context stuff
33 * @return list of request headers
34 */
35 public String[] list() {
36 HttpServletRequest request = getRequest();
37 Enumeration headers=request.getHeaderNames();
38 ArrayList list=new ArrayList();
39 while (headers.hasMoreElements()) {
40 String h = (String) headers.nextElement();
41 String header=h+':'+request.getHeader(h);
42 list.add(header);
43 }
44 String[] results=new String[list.size()];
45 for(int i=0;i<list.size();i++) {
46 results[i]=(String) list.get(i);
47 }
48 return results;
49 }
50
51 /**
52 * get the caller; may involve reverse DNS
53 * @return
54 */
55 public String whoami() {
56 HttpServletRequest request = getRequest();
57 String remote=request.getRemoteHost();
58 return "Hello caller from "+remote;
59 }
60
61 /**
62 * very simple method to echo the param.
63 * @param param
64 * @return
65 */
66 public String echo(String param) {
67 return param;
68 }
69
70 /**
71 * throw an axis fault with the text included
72 */
73 public void throwAxisFault(String param) throws AxisFault {
74 throw new AxisFault(param);
75 }
76
77 public void throwException(String param) throws Exception {
78 throw new Exception(param);
79 }
80
81 /**
82 * thow a runtime exception
83 */
84 public void throwRuntimeException(String param) {
85 throw new RuntimeException(param);
86 }
87
88 /**
89 * helper
90 * @return
91 */
92 private HttpServletRequest getRequest() {
93 MessageContext context = MessageContext.getCurrentContext();
94 HttpServletRequest req = (HttpServletRequest) context.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
95 return req;
96 }
97
98}
Note: See TracBrowser for help on using the repository browser.