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.provider;
19:
20: import java.util.Iterator;
21: import java.util.Set;
22:
23: import javax.xml.namespace.QName;
24: import javax.xml.soap.SOAPBody;
25: import javax.xml.soap.SOAPElement;
26: import javax.xml.soap.SOAPEnvelope;
27: import javax.xml.soap.SOAPMessage;
28: import javax.xml.ws.handler.MessageContext;
29: import javax.xml.ws.handler.soap.SOAPHandler;
30: import javax.xml.ws.handler.soap.SOAPMessageContext;
31:
32: public class TestSOAPHandler implements SOAPHandler<SOAPMessageContext> {
33: public boolean handleMessage(SOAPMessageContext ctx) {
34: try {
35: SOAPMessage msg = ctx.getMessage();
36: /*
37: * System.out.println("-----------soap---------");
38: * msg.writeTo(System.out);
39: * System.out.println("-----------soap---------");
40: */
41:
42: SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
43: SOAPBody body = env.getBody();
44: Iterator it = body.getChildElements();
45: while (it.hasNext()) {
46:
47: Object elem = it.next();
48: if (elem instanceof SOAPElement) {
49:
50: Iterator it2 = ((SOAPElement) elem)
51: .getChildElements();
52: while (it2.hasNext()) {
53: Object elem2 = it2.next();
54: if (elem2 instanceof SOAPElement) {
55: String value = ((SOAPElement) elem2)
56: .getValue();
57: if (value.indexOf("Milestone-0") >= 0
58: || value
59: .indexOf("TestGreetMeResponseServerLogicalHandler") >= 0) {
60: value = value + "ServerSOAPHandler";
61: ((SOAPElement) elem2).setValue(value);
62: }
63: }
64: }
65: }
66: }
67: msg.saveChanges();
68:
69: /*
70: * System.out.println("-----------soapaf---------");
71: * msg.writeTo(System.out);
72: * System.out.println("-----------soapaf---------");
73: */
74: } catch (Exception e) {
75: e.printStackTrace();
76: }
77:
78: return true;
79: }
80:
81: public final Set<QName> getHeaders() {
82: return null;
83: }
84:
85: public boolean handleFault(SOAPMessageContext ctx) {
86: return true;
87: }
88:
89: public void close(MessageContext arg0) {
90: }
91: }
|