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: */
19: package org.apache.axis2.transport;
20:
21: import org.apache.axiom.om.OMOutputFormat;
22: import org.apache.axis2.AxisFault;
23: import org.apache.axis2.context.MessageContext;
24:
25: import java.io.OutputStream;
26: import java.net.URL;
27:
28: /**
29: * <p/>
30: * MessageFormatter implementations are used by Axis2 to support serialization
31: * of messages to different message formats. (Eg: JSON). Users can register
32: * MessageFormatter implementations against a message type using the axis2.xml.
33: * Message type for a message can be specified by setting the "messageType"
34: * property in the MessageContext. This can also be given as a parameter in the
35: * service.xml/axis2.xml for a per service based/engine wide configuration.
36: * </p>
37: * <p/>
38: * <messageFormatters>
39: * <messageFormatter contentType="application/soap+xml"
40: * class="org.apache.axis2.transport.http.SOAPMessageFormatter"/>
41: * </messageFormatters>
42: * </p>
43: */
44: public interface MessageFormatter {
45:
46: /**
47: * @return a byte array of the message formatted according to the given
48: * message format.
49: */
50: public byte[] getBytes(MessageContext messageContext,
51: OMOutputFormat format) throws AxisFault;
52:
53: /**
54: * To support deffered writing transports as in http chunking.. Axis2 was
55: * doing this for some time..
56: * <p/>
57: * Preserve flag can be used to preserve the envelope for later use. This is
58: * usefull when implementing authentication machnisms like NTLM.
59: *
60: * @param outputStream
61: * @param preserve :
62: * do not consume the OM when this is set..
63: */
64: public void writeTo(MessageContext messageContext,
65: OMOutputFormat format, OutputStream outputStream,
66: boolean preserve) throws AxisFault;
67:
68: /**
69: * Different message formats can set their own content types
70: * Eg: JSONFormatter can set the content type as application/json
71: *
72: * @param messageContext
73: * @param format
74: * @param soapAction
75: */
76: public String getContentType(MessageContext messageContext,
77: OMOutputFormat format, String soapAction);
78:
79: /**
80: * Some message formats may want to alter the target url.
81: *
82: * @return the target URL
83: */
84: public URL getTargetAddress(MessageContext messageContext,
85: OMOutputFormat format, URL targetURL) throws AxisFault;
86:
87: /**
88: * @return this only if you want set a transport header for SOAP Action
89: */
90: public String formatSOAPAction(MessageContext messageContext,
91: OMOutputFormat format, String soapAction);
92: }
|