| 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 |
|
| 17 |
package samples.userguide.example4; |
| 18 |
|
| 19 |
import org.apache.axis.AxisFault; |
| 20 |
import org.apache.axis.Handler; |
| 21 |
import org.apache.axis.MessageContext; |
| 22 |
import org.apache.axis.handlers.BasicHandler; |
| 23 |
|
| 24 |
import java.io.FileOutputStream; |
| 25 |
import java.io.PrintWriter; |
| 26 |
import java.util.Date; |
| 27 |
|
| 28 |
public class LogHandler extends BasicHandler { |
| 29 |
public void invoke(MessageContext msgContext) throws AxisFault |
| 30 |
{ |
| 31 |
/** Log an access each time we get invoked. |
| 32 |
*/ |
| 33 |
try { |
| 34 |
Handler serviceHandler = msgContext.getService(); |
| 35 |
String filename = (String)getOption("filename"); |
| 36 |
if ((filename == null) || (filename.equals(""))) |
| 37 |
throw new AxisFault("Server.NoLogFile", |
| 38 |
"No log file configured for the LogHandler!", |
| 39 |
null, null); |
| 40 |
FileOutputStream fos = new FileOutputStream(filename, true); |
| 41 |
|
| 42 |
PrintWriter writer = new PrintWriter(fos); |
| 43 |
|
| 44 |
Integer numAccesses = |
| 45 |
(Integer)serviceHandler.getOption("accesses"); |
| 46 |
if (numAccesses == null) |
| 47 |
numAccesses = new Integer(0); |
| 48 |
|
| 49 |
numAccesses = new Integer(numAccesses.intValue() + 1); |
| 50 |
|
| 51 |
Date date = new Date(); |
| 52 |
String result = date + ": service " + |
| 53 |
msgContext.getTargetService() + |
| 54 |
" accessed " + numAccesses + " time(s)."; |
| 55 |
serviceHandler.setOption("accesses", numAccesses); |
| 56 |
|
| 57 |
writer.println(result); |
| 58 |
|
| 59 |
writer.close(); |
| 60 |
} catch (Exception e) { |
| 61 |
throw AxisFault.makeFault(e); |
| 62 |
} |
| 63 |
} |
| 64 |
} |