| 1 |
/* |
| 2 |
* Copyright 2001-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 |
package test; |
| 17 |
|
| 18 |
import org.apache.axis.AxisFault; |
| 19 |
import org.apache.axis.Message; |
| 20 |
import org.apache.axis.MessageContext; |
| 21 |
import org.apache.axis.handlers.BasicHandler; |
| 22 |
|
| 23 |
import java.io.FileInputStream; |
| 24 |
import java.io.FileNotFoundException; |
| 25 |
|
| 26 |
/** |
| 27 |
* A trivial service which simply echoes back a desired SOAP message. This |
| 28 |
* is useful for testing, as we can simulate responses from particular packages, |
| 29 |
* bugs, etc. This should be deployed with provider="Handler". |
| 30 |
* |
| 31 |
* @author Glen Daniels ([email protected]) |
| 32 |
*/ |
| 33 |
public class PlaybackService extends BasicHandler { |
| 34 |
/** |
| 35 |
* Get the filename which contains the response message. Looks in |
| 36 |
* the MessageContext/service/engine for a "responseFile" property, and |
| 37 |
* if found simply returns that value. Otherwise defaults to |
| 38 |
* "response.xml" in the current directory of the server. |
| 39 |
* |
| 40 |
* This mechanism can be configured in two ways. First, anyone can set |
| 41 |
* the "responseFile" property based on the message contents, etc. As long |
| 42 |
* as this happens earlier in the handler chain, the value will be picked |
| 43 |
* up and used here. Second, this class can be subclassed and this |
| 44 |
* method overriden to do the right thing. |
| 45 |
* |
| 46 |
* @param context the current MessageContext |
| 47 |
* @return the filename containing the canned response |
| 48 |
*/ |
| 49 |
protected String getFilename(MessageContext context) { |
| 50 |
String filename = context.getStrProp("responseFile"); |
| 51 |
if (filename == null) { |
| 52 |
filename = "response.xml"; |
| 53 |
} |
| 54 |
return filename; |
| 55 |
} |
| 56 |
|
| 57 |
public void invoke(MessageContext context) throws AxisFault { |
| 58 |
try { |
| 59 |
FileInputStream stream = new FileInputStream(getFilename(context)); |
| 60 |
context.setResponseMessage(new Message(stream)); |
| 61 |
} catch (FileNotFoundException e) { |
| 62 |
throw AxisFault.makeFault(e); |
| 63 |
} |
| 64 |
} |
| 65 |
} |