001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.transport.nhttp;
020:
021: import org.apache.axis2.addressing.EndpointReference;
022: import org.apache.axis2.addressing.AddressingConstants;
023: import org.apache.axis2.context.MessageContext;
024: import org.apache.axis2.context.OperationContext;
025: import org.apache.axis2.Constants;
026: import org.apache.axis2.transport.http.HTTPTransportUtils;
027: import org.apache.axis2.transport.http.HTTPConstants;
028: import org.apache.axiom.om.OMOutputFormat;
029:
030: public class Util {
031:
032: /**
033: * Get the EPR for the message passed in
034: * @param msgContext the message context
035: * @return the destination EPR
036: */
037: public static EndpointReference getDestinationEPR(
038: MessageContext msgContext) {
039:
040: // Trasnport URL can be different from the WSA-To
041: String transportURL = (String) msgContext
042: .getProperty(Constants.Configuration.TRANSPORT_URL);
043:
044: if (transportURL != null) {
045: return new EndpointReference(transportURL);
046: } else if ((msgContext.getTo() != null)
047: && !AddressingConstants.Submission.WSA_ANONYMOUS_URL
048: .equals(msgContext.getTo().getAddress())
049: && !AddressingConstants.Final.WSA_ANONYMOUS_URL
050: .equals(msgContext.getTo().getAddress())) {
051: return msgContext.getTo();
052: }
053: return null;
054: }
055:
056: /**
057: * Retirn the OMOutputFormat to be used for the message context passed in
058: * @param msgContext the message context
059: * @return the OMOutputFormat to be used
060: */
061: public static OMOutputFormat getOMOutputFormat(
062: MessageContext msgContext) {
063:
064: OMOutputFormat format = new OMOutputFormat();
065: msgContext.setDoingMTOM(HTTPTransportUtils
066: .doWriteMTOM(msgContext));
067: msgContext.setDoingSwA(HTTPTransportUtils
068: .doWriteSwA(msgContext));
069: msgContext.setDoingREST(HTTPTransportUtils
070: .isDoingREST(msgContext));
071: format.setSOAP11(msgContext.isSOAP11());
072: format.setDoOptimize(msgContext.isDoingMTOM());
073: format.setDoingSWA(msgContext.isDoingSwA());
074:
075: format.setCharSetEncoding(HTTPTransportUtils
076: .getCharSetEncoding(msgContext));
077: Object mimeBoundaryProperty = msgContext
078: .getProperty(Constants.Configuration.MIME_BOUNDARY);
079: if (mimeBoundaryProperty != null) {
080: format.setMimeBoundary((String) mimeBoundaryProperty);
081: }
082:
083: return format;
084: }
085:
086: /**
087: * Get the content type for the message passed in
088: * @param msgContext the message
089: * @return content type of the message
090: */
091: public static String getContentType(MessageContext msgContext) {
092: Object contentTypeObject = msgContext
093: .getProperty(Constants.Configuration.CONTENT_TYPE);
094: if (contentTypeObject != null) {
095: return (String) contentTypeObject;
096: } else if (msgContext.isDoingREST()) {
097: return HTTPConstants.MEDIA_TYPE_APPLICATION_XML;
098: } else {
099: return getOMOutputFormat(msgContext).getContentType();
100: }
101: }
102:
103: }
|