01: /*
02: * Copyright 2004,2005 The Apache Software Foundation.
03: * Copyright 2007 International Business Machines Corp.
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.axis2.jaxws.provider.soapmsgmu;
18:
19: import javax.xml.ws.Provider;
20: import javax.xml.ws.ServiceMode;
21: import javax.xml.ws.Service;
22: import javax.xml.ws.WebServiceProvider;
23: import javax.xml.ws.BindingType;
24: import javax.xml.ws.soap.SOAPBinding;
25: import javax.xml.soap.SOAPMessage;
26:
27: import org.apache.axis2.jaxws.provider.AttachmentUtil;
28:
29: /**
30: * This class provides the server side implementation for JAX-WS Provider<MESSAGE>
31: * for SOAP11 Binding with Mode = MESSAGE.
32: *
33: * The receiving message and the sending back message
34: * must have the headers defined in wsdl.
35: */
36:
37: @WebServiceProvider()
38: @ServiceMode(value=Service.Mode.MESSAGE)
39: @BindingType(SOAPBinding.SOAP11HTTP_BINDING)
40: public class SoapMessageMUProvider implements Provider<SOAPMessage> {
41: /**
42: * This service receives soap message and return it back to client as is
43: * or add a soap mustUnderstand attribute header and then return it back to client
44: *
45: * @param SOAPMessage object sent by the client
46: * @return the SOAPMessage
47: */
48: public SOAPMessage invoke(SOAPMessage request) {
49: System.out
50: .println("----------------------------------------------");
51: System.out
52: .println("SoapMessageMUProvider:Invoke: Request received");
53: SOAPMessage response = null;
54:
55: try {
56: String string = AttachmentUtil.toString(request);
57: if (string != null) {
58: System.out.println("invoke: ---Received message= "
59: + string);
60: if (string.contains(new StringBuffer(
61: AttachmentUtil.UNDERSTOOD_MU_TEXT))) {
62: String responseStr = AttachmentUtil.msgEnvMU_understood
63: .replaceAll(
64: AttachmentUtil.MUHEADER_CLIENT_UNDERSTOOD,
65: AttachmentUtil.MUHEADER_SERVER_UNDERSTOOD);
66: response = AttachmentUtil
67: .toSOAPMessage(responseStr);
68: System.out.println("invoke: ---Response message= "
69: + AttachmentUtil.toString(response));
70: } else if (string.contains(new StringBuffer(
71: AttachmentUtil.MU_TEXT))) {
72: String responseStr = AttachmentUtil.msgEnvMU
73: .replaceAll(AttachmentUtil.MUHEADER_CLIENT,
74: AttachmentUtil.MUHEADER_SERVER);
75: response = AttachmentUtil
76: .toSOAPMessage(responseStr);
77: System.out.println("invoke: ---Response message= "
78: + AttachmentUtil.toString(response));
79: } else {
80: response = request;
81: }
82: } else {
83: String badResult = "***ERROR at Service Endpoint: Received message is NULL.";
84: throw new NullPointerException(badResult);
85: }
86: } catch (Exception e) {
87: System.out
88: .println("SoapMessageMUProviderService: Failed with exception.");
89: e.printStackTrace();
90: }
91: return response;
92: }
93: }
|