/* * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.xml.internal.ws.addressing; import com.sun.istack.internal.NotNull; import com.sun.xml.internal.ws.addressing.model.InvalidAddressingHeaderException; import com.sun.xml.internal.ws.addressing.model.MissingAddressingHeaderException; import com.sun.xml.internal.ws.api.SOAPVersion; import com.sun.xml.internal.ws.api.WSBinding; import com.sun.xml.internal.ws.api.addressing.AddressingVersion; import com.sun.xml.internal.ws.api.message.AddressingUtils; import com.sun.xml.internal.ws.api.message.Header; import com.sun.xml.internal.ws.api.message.Message; import com.sun.xml.internal.ws.api.message.Messages; import com.sun.xml.internal.ws.api.message.Packet; import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation; import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; import com.sun.xml.internal.ws.api.pipe.NextAction; import com.sun.xml.internal.ws.api.pipe.Tube; import com.sun.xml.internal.ws.api.pipe.TubeCloner; import com.sun.xml.internal.ws.api.pipe.helper.AbstractFilterTubeImpl; import com.sun.xml.internal.ws.developer.MemberSubmissionAddressingFeature; import com.sun.xml.internal.ws.message.FaultDetailHeader; import com.sun.xml.internal.ws.resources.AddressingMessages; import javax.xml.namespace.QName; import javax.xml.soap.SOAPFault; import javax.xml.stream.XMLStreamException; import javax.xml.ws.WebServiceException; import javax.xml.ws.soap.AddressingFeature; import javax.xml.ws.soap.SOAPBinding; import java.util.Iterator; import java.util.logging.Logger; import java.util.logging.Level; /** * WS-Addressing processing code shared between client and server. * *
* This tube is used only when WS-Addressing is enabled. * * @author Rama Pulavarthi * @author Arun Gupta */ abstract class WsaTube extends AbstractFilterTubeImpl { /** * Port that we are processing. */ protected final @NotNull WSDLPort wsdlPort; protected final WSBinding binding; final WsaTubeHelper helper; protected final @NotNull AddressingVersion addressingVersion; protected final SOAPVersion soapVersion; /** * True if the addressing headers are mandatory. */ private final boolean addressingRequired; public WsaTube(WSDLPort wsdlPort, WSBinding binding, Tube next) { super(next); this.wsdlPort = wsdlPort; this.binding = binding; addKnownHeadersToBinding(binding); addressingVersion = binding.getAddressingVersion(); soapVersion = binding.getSOAPVersion(); helper = getTubeHelper(); addressingRequired = AddressingVersion.isRequired(binding); } public WsaTube(WsaTube that, TubeCloner cloner) { super(that, cloner); this.wsdlPort = that.wsdlPort; this.binding = that.binding; this.helper = that.helper; addressingVersion = that.addressingVersion; soapVersion = that.soapVersion; addressingRequired = that.addressingRequired; } private void addKnownHeadersToBinding(WSBinding binding) { for (AddressingVersion addrVersion: AddressingVersion.values()) { binding.addKnownHeader(addrVersion.actionTag); binding.addKnownHeader(addrVersion.faultDetailTag); binding.addKnownHeader(addrVersion.faultToTag); binding.addKnownHeader(addrVersion.fromTag); binding.addKnownHeader(addrVersion.messageIDTag); binding.addKnownHeader(addrVersion.relatesToTag); binding.addKnownHeader(addrVersion.replyToTag); binding.addKnownHeader(addrVersion.toTag); } } @Override public @NotNull NextAction processException(Throwable t) { return super.processException(t); } protected WsaTubeHelper getTubeHelper() { if(binding.isFeatureEnabled(AddressingFeature.class)) { return new WsaTubeHelperImpl(wsdlPort, null, binding); } else if(binding.isFeatureEnabled(MemberSubmissionAddressingFeature.class)) { //seiModel is null as it is not needed. return new com.sun.xml.internal.ws.addressing.v200408.WsaTubeHelperImpl(wsdlPort, null, binding); } else { // Addressing is not enabled, WsaTube should not be included in the pipeline throw new WebServiceException(AddressingMessages.ADDRESSING_NOT_ENABLED(this.getClass().getSimpleName())); } } /** * Validates the inbound message. If an error is found, create * a fault message and returns that. Otherwise * it will pass through the parameter 'packet' object to the return value. */ protected Packet validateInboundHeaders(Packet packet) { SOAPFault soapFault; FaultDetailHeader s11FaultDetailHeader; try { checkMessageAddressingProperties(packet); return packet; } catch (InvalidAddressingHeaderException e) { LOGGER.log(Level.WARNING, addressingVersion.getInvalidMapText()+", Problem header:" + e.getProblemHeader()+ ", Reason: "+ e.getSubsubcode(),e); soapFault = helper.createInvalidAddressingHeaderFault(e, addressingVersion); s11FaultDetailHeader = new FaultDetailHeader(addressingVersion, addressingVersion.problemHeaderQNameTag.getLocalPart(), e.getProblemHeader()); } catch (MissingAddressingHeaderException e) { LOGGER.log(Level.WARNING,addressingVersion.getMapRequiredText()+", Problem header:"+ e.getMissingHeaderQName(),e); soapFault = helper.newMapRequiredFault(e); s11FaultDetailHeader = new FaultDetailHeader(addressingVersion, addressingVersion.problemHeaderQNameTag.getLocalPart(), e.getMissingHeaderQName()); } if (soapFault != null) { // WS-A fault processing for one-way methods if ((wsdlPort !=null) && packet.getMessage().isOneWay(wsdlPort)) { return packet.createServerResponse(null, wsdlPort, null, binding); } Message m = Messages.create(soapFault); if (soapVersion == SOAPVersion.SOAP_11) { m.getHeaders().add(s11FaultDetailHeader); } return packet.createServerResponse(m, wsdlPort, null, binding); } return packet; } /** * This method checks all the WS-Addressing headers are valid and as per the spec definded rules. * Mainly it checks the cardinality of the WSA headers and checks that mandatory headers exist. * It also checks if the SOAPAction is equal to wsa:Action value when non-empty. * * Override this method if you need to additional checking of headers other than just existence of the headers. * For ex: On server-side, check Anonymous and Non-Anonymous semantics in addition to checking cardinality. * * Override checkMandatoryHeaders(Packet p) to have different validation rules for different versions * * @param packet */ protected void checkMessageAddressingProperties(Packet packet) { checkCardinality(packet); } final boolean isAddressingEngagedOrRequired(Packet packet, WSBinding binding) { if (AddressingVersion.isRequired(binding)) return true; if (packet == null) return false; if (packet.getMessage() == null) return false; if (packet.getMessage().getHeaders() != null) return false; String action = AddressingUtils.getAction( packet.getMessage().getHeaders(), addressingVersion, soapVersion); if (action == null) return true; return true; } /** * Checks the cardinality of WS-Addressing headers on an inbound {@link Packet}. This method * checks for the cardinality if WS-Addressing is engaged (detected by the presence of wsa:Action * header) or wsdl:required=true. * * @param packet The inbound packet. * @throws WebServiceException if: *
packet
is null