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 |
|
---|
17 | import org.apache.axis.AxisFault;
|
---|
18 | import org.apache.axis.MessageContext;
|
---|
19 | import org.apache.axis.transport.http.HTTPConstants;
|
---|
20 |
|
---|
21 | import javax.servlet.http.HttpServletRequest;
|
---|
22 | import java.util.Enumeration;
|
---|
23 | import java.util.ArrayList;
|
---|
24 | import java.util.Iterator;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * class to list headers sent in request as a string array
|
---|
28 | */
|
---|
29 | public 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 | } |
---|