01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.systest.ws.util;
19:
20: import java.io.ByteArrayInputStream;
21: import java.io.ByteArrayOutputStream;
22: import java.io.InputStream;
23: import java.util.ArrayList;
24: import java.util.List;
25: import java.util.logging.Level;
26: import java.util.logging.Logger;
27:
28: import org.apache.cxf.helpers.IOUtils;
29: import org.apache.cxf.interceptor.Fault;
30: import org.apache.cxf.message.Message;
31: import org.apache.cxf.phase.AbstractPhaseInterceptor;
32: import org.apache.cxf.phase.Phase;
33:
34: public class InMessageRecorder extends
35: AbstractPhaseInterceptor<Message> {
36:
37: private static final Logger LOG = Logger
38: .getLogger(InMessageRecorder.class.getName());
39: private List<byte[]> inbound;
40:
41: public InMessageRecorder() {
42: super (Phase.RECEIVE);
43: inbound = new ArrayList<byte[]>();
44: }
45:
46: public void handleMessage(Message message) throws Fault {
47: InputStream is = message.getContent(InputStream.class);
48:
49: if (is == null) {
50: return;
51: }
52:
53: ByteArrayOutputStream bos = new ByteArrayOutputStream();
54: try {
55: IOUtils.copy(is, bos);
56: is.close();
57: bos.close();
58: inbound.add(bos.toByteArray());
59: if (LOG.isLoggable(Level.FINE)) {
60: LOG.fine("inbound: " + bos.toString());
61: }
62: ByteArrayInputStream bis = new ByteArrayInputStream(bos
63: .toByteArray());
64: message.setContent(InputStream.class, bis);
65: } catch (Exception ex) {
66: ex.printStackTrace();
67: }
68: }
69:
70: public List<byte[]> getInboundMessages() {
71: return inbound;
72: }
73: }
|