KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > receivers > AbstractInOutSyncMessageReceiver


1 /*
2  * Copyright 2004,2005 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 org.apache.axis2.receivers;
17
18 import org.apache.axis2.addressing.AddressingConstants;
19 import org.apache.axis2.addressing.MessageInformationHeadersCollection;
20 import org.apache.axis2.addressing.miheaders.RelatesTo;
21 import org.apache.axis2.context.MessageContext;
22 import org.apache.axis2.engine.AxisEngine;
23 import org.apache.axis2.engine.AxisFault;
24 import org.apache.axis2.transport.http.HTTPConstants;
25
26 /**
27  * This is the Absract IN-OUT MEP MessageReciver. The
28  * protected abstract methods are only for the sake of breaking down the logic
29  */

30 public abstract class AbstractInOutSyncMessageReceiver extends AbstractMessageReceiver {
31     public abstract void invokeBusinessLogic(
32         MessageContext inMessage,
33         MessageContext outMessage)
34         throws AxisFault;
35
36     public final void recieve(MessageContext messgeCtx) throws AxisFault {
37         MessageContext newmsgCtx =
38             new MessageContext(messgeCtx.getSystemContext(),
39                 messgeCtx.getSessionContext(),
40                 messgeCtx.getTransportIn(),
41                 messgeCtx.getTransportOut());
42
43         newmsgCtx.setMessageInformationHeaders(new MessageInformationHeadersCollection());
44         MessageInformationHeadersCollection oldMessageInfoHeaders =
45         messgeCtx.getMessageInformationHeaders();
46         MessageInformationHeadersCollection messageInformationHeaders =
47             new MessageInformationHeadersCollection();
48         messageInformationHeaders.setTo(oldMessageInfoHeaders.getReplyTo());
49         messageInformationHeaders.setFaultTo(oldMessageInfoHeaders.getFaultTo());
50         messageInformationHeaders.setFrom(oldMessageInfoHeaders.getTo());
51         messageInformationHeaders.setRelatesTo(
52             new RelatesTo(
53                 oldMessageInfoHeaders.getMessageId(),
54                 AddressingConstants.Submission.WSA_RELATES_TO_RELATIONSHIP_TYPE_DEFAULT_VALUE));
55         newmsgCtx.setMessageInformationHeaders(messageInformationHeaders);
56         newmsgCtx.setOperationContext(messgeCtx.getOperationContext());
57         newmsgCtx.setServiceContext(messgeCtx.getServiceContext());
58         newmsgCtx.setProperty(MessageContext.TRANSPORT_OUT,messgeCtx.getProperty(MessageContext.TRANSPORT_OUT));
59         newmsgCtx.setProperty(HTTPConstants.HTTPOutTransportInfo,messgeCtx.getProperty(HTTPConstants.HTTPOutTransportInfo));
60         newmsgCtx.setDoingREST(messgeCtx.isDoingREST());
61         newmsgCtx.setDoingMTOM(messgeCtx.isDoingMTOM());
62         
63         invokeBusinessLogic(messgeCtx,newmsgCtx);
64
65         AxisEngine engine =
66             new AxisEngine(
67                 messgeCtx.getOperationContext().getServiceContext().getEngineContext());
68         engine.send(newmsgCtx);
69     }
70 }
71
Popular Tags