All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opensaml.ws.soap.soap11.encoder.http.HTTPSOAP11Encoder Maven / Gradle / Ivy

Go to download

The OpenWS library provides a growing set of tools to work with web services at a low level. These tools include classes for creating and reading SOAP messages, transport-independent clients for connecting to web services, and various transports for use with those clients.

The newest version!
/*
 * Licensed to the University Corporation for Advanced Internet Development, 
 * Inc. (UCAID) under one or more contributor license agreements.  See the 
 * NOTICE file distributed with this work for additional information regarding
 * copyright ownership. The UCAID licenses this file to You under the Apache 
 * License, Version 2.0 (the "License"); you may not use this file except in 
 * compliance with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.opensaml.ws.soap.soap11.encoder.http;

import java.util.List;

import org.opensaml.ws.message.MessageContext;
import org.opensaml.ws.message.encoder.MessageEncodingException;
import org.opensaml.ws.soap.soap11.Envelope;
import org.opensaml.ws.soap.soap11.Header;
import org.opensaml.ws.soap.soap11.encoder.SOAP11Encoder;
import org.opensaml.ws.transport.http.HTTPOutTransport;
import org.opensaml.ws.transport.http.HTTPTransportUtils;
import org.opensaml.ws.wsaddressing.Action;
import org.opensaml.xml.XMLObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Basic SOAP 1.1 encoder for HTTP transport.
 */
public class HTTPSOAP11Encoder extends SOAP11Encoder {

    /** Class logger. */
    private final Logger log = LoggerFactory.getLogger(HTTPSOAP11Encoder.class);
    

    /** Constructor. */
    public HTTPSOAP11Encoder() {
        super();
    }

    /** {@inheritDoc} */
    protected void doEncode(MessageContext messageContext) throws MessageEncodingException {
        if (!(messageContext.getOutboundMessageTransport() instanceof HTTPOutTransport)) {
            log.error("Invalid outbound message transport type, this encoder only support HTTPOutTransport");
            throw new MessageEncodingException(
                    "Invalid outbound message transport type, this encoder only support HTTPOutTransport");
        }
        
        super.doEncode(messageContext);
    }
    
    /**
     * 

* This implementation performs the following actions on the context's {@link HTTPOutTransport}: *

    *
  1. Adds the HTTP header: "Cache-control: no-cache, no-store"
  2. *
  3. Adds the HTTP header: "Pragma: no-cache"
  4. *
  5. Sets the character encoding to: "UTF-8"
  6. *
  7. Sets the content type to: "text/xml"
  8. *
  9. Sets the SOAPAction HTTP header the value returned by {@link #getSOAPAction(MessageContext)}, if * that returns non-null.
  10. *
*

* *

* Subclasses should NOT set the SOAPAction HTTP header in this method. Instead, they should override * the method {@link #getSOAPAction(MessageContext)}. *

* * @param messageContext the current message context being processed * * @throws MessageEncodingException thrown if there is a problem preprocessing the transport */ protected void preprocessTransport(MessageContext messageContext) throws MessageEncodingException { HTTPOutTransport outTransport = (HTTPOutTransport) messageContext.getOutboundMessageTransport(); HTTPTransportUtils.addNoCacheHeaders(outTransport); HTTPTransportUtils.setUTF8Encoding(outTransport); HTTPTransportUtils.setContentType(outTransport, "text/xml"); String soapAction = getSOAPAction(messageContext); if (soapAction != null) { outTransport.setHeader("SOAPAction", soapAction); } else { outTransport.setHeader("SOAPAction", ""); } } /** * Determine the value of the SOAPAction HTTP header to send. * *

* The default behavior is to return the value of the SOAP Envelope's WS-Addressing Action header, * if present. *

* * @param messageContext the current message context being processed * @return a SOAPAction HTTP header URI value */ protected String getSOAPAction(MessageContext messageContext) { Envelope env = (Envelope) messageContext.getOutboundMessage(); Header header = env.getHeader(); if (header == null) { return null; } List objList = header.getUnknownXMLObjects(Action.ELEMENT_NAME); if (objList == null || objList.isEmpty()) { return null; } else { return ((Action)objList.get(0)).getValue(); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy