feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,166 @@
/*
* Copyright (c) 1997, 2012, 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.handler;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.api.pipe.TubeCloner;
import com.sun.xml.internal.ws.api.pipe.Tube;
import com.sun.xml.internal.ws.api.pipe.helper.AbstractFilterTubeImpl;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
import com.sun.xml.internal.ws.api.model.SEIModel;
import com.sun.xml.internal.ws.binding.BindingImpl;
import com.sun.xml.internal.ws.model.AbstractSEIModelImpl;
import com.sun.xml.internal.ws.spi.db.BindingContext;
import javax.xml.ws.handler.LogicalHandler;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.Handler;
import javax.xml.ws.WebServiceException;
import java.util.List;
import java.util.ArrayList;
/**
*
* @author WS Development Team
*/
public class ClientLogicalHandlerTube extends HandlerTube {
private SEIModel seiModel;
/**
* Creates a new instance of LogicalHandlerTube
*/
public ClientLogicalHandlerTube(WSBinding binding, SEIModel seiModel, WSDLPort port, Tube next) {
super(next, port, binding);
this.seiModel = seiModel;
}
/**
* This constructor is used on client-side where, SOAPHandlerTube is created
* first and then a LogicalHandlerTube is created with a handler to that
* SOAPHandlerTube.
* With this handle, LogicalHandlerTube can call
* SOAPHandlerTube.closeHandlers()
*/
public ClientLogicalHandlerTube(WSBinding binding, SEIModel seiModel, Tube next, HandlerTube cousinTube) {
super(next, cousinTube, binding);
this.seiModel = seiModel;
}
/**
* Copy constructor for {@link com.sun.xml.internal.ws.api.pipe.Tube#copy(com.sun.xml.internal.ws.api.pipe.TubeCloner)}.
*/
private ClientLogicalHandlerTube(ClientLogicalHandlerTube that, TubeCloner cloner) {
super(that, cloner);
this.seiModel = that.seiModel;
}
//should be overridden by DriverHandlerTubes
@Override
protected void initiateClosing(MessageContext mc) {
close(mc);
super.initiateClosing(mc);
}
public AbstractFilterTubeImpl copy(TubeCloner cloner) {
return new ClientLogicalHandlerTube(this, cloner);
}
void setUpProcessor() {
if (handlers == null) {
// Take a snapshot, User may change chain after invocation, Same chain
// should be used for the entire MEP
handlers = new ArrayList<Handler>();
WSBinding binding = getBinding();
List<LogicalHandler> logicalSnapShot= ((BindingImpl) binding).getHandlerConfig().getLogicalHandlers();
if (!logicalSnapShot.isEmpty()) {
handlers.addAll(logicalSnapShot);
if (binding.getSOAPVersion() == null) {
processor = new XMLHandlerProcessor(this, binding,
handlers);
} else {
processor = new SOAPHandlerProcessor(true, this, binding,
handlers);
}
}
}
}
MessageUpdatableContext getContext(Packet packet) {
return new LogicalMessageContextImpl(getBinding(), getBindingContext(), packet);
}
private BindingContext getBindingContext() {
return (seiModel!= null && seiModel instanceof AbstractSEIModelImpl) ?
((AbstractSEIModelImpl)seiModel).getBindingContext() : null;
}
boolean callHandlersOnRequest(MessageUpdatableContext context, boolean isOneWay) {
boolean handlerResult;
try {
//CLIENT-SIDE
handlerResult = processor.callHandlersRequest(HandlerProcessor.Direction.OUTBOUND, context, !isOneWay);
} catch (WebServiceException wse) {
remedyActionTaken = true;
//no rewrapping
throw wse;
} catch (RuntimeException re) {
remedyActionTaken = true;
throw new WebServiceException(re);
}
if (!handlerResult) {
remedyActionTaken = true;
}
return handlerResult;
}
void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {
try {
//CLIENT-SIDE
processor.callHandlersResponse(HandlerProcessor.Direction.INBOUND, context, handleFault);
} catch (WebServiceException wse) {
//no rewrapping
throw wse;
} catch (RuntimeException re) {
throw new WebServiceException(re);
}
}
void closeHandlers(MessageContext mc) {
closeClientsideHandlers(mc);
}
}

View File

@@ -0,0 +1,152 @@
/*
* Copyright (c) 1997, 2012, 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.handler;
import com.sun.istack.internal.Nullable;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.handler.MessageHandler;
import com.sun.xml.internal.ws.api.message.Attachment;
import com.sun.xml.internal.ws.api.message.AttachmentSet;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.api.model.SEIModel;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
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.binding.BindingImpl;
import com.sun.xml.internal.ws.client.HandlerConfiguration;
import com.sun.xml.internal.ws.message.DataHandlerAttachment;
import javax.activation.DataHandler;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.Handler;
import java.util.*;
import java.util.Map.Entry;
/**
* @author Rama Pulavarthi
*/
public class ClientMessageHandlerTube extends HandlerTube {
private SEIModel seiModel;
private Set<String> roles;
/**
* Creates a new instance of MessageHandlerTube
*/
public ClientMessageHandlerTube(@Nullable SEIModel seiModel, WSBinding binding, WSDLPort port, Tube next) {
super(next, port, binding);
this.seiModel = seiModel;
}
/**
* Copy constructor for {@link com.sun.xml.internal.ws.api.pipe.Tube#copy(com.sun.xml.internal.ws.api.pipe.TubeCloner)}.
*/
private ClientMessageHandlerTube(ClientMessageHandlerTube that, TubeCloner cloner) {
super(that, cloner);
this.seiModel = that.seiModel;
}
public AbstractFilterTubeImpl copy(TubeCloner cloner) {
return new ClientMessageHandlerTube(this, cloner);
}
void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {
try {
//CLIENT-SIDE
processor.callHandlersResponse(HandlerProcessor.Direction.INBOUND, context, handleFault);
} catch (WebServiceException wse) {
//no rewrapping
throw wse;
} catch (RuntimeException re) {
throw new WebServiceException(re);
}
}
boolean callHandlersOnRequest(MessageUpdatableContext context, boolean isOneWay) {
boolean handlerResult;
//Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
AttachmentSet attSet = context.packet.getMessage().getAttachments();
for (Entry<String, DataHandler> entry : atts.entrySet()) {
String cid = entry.getKey();
if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
attSet.add(att);
}
}
try {
//CLIENT-SIDE
handlerResult = processor.callHandlersRequest(HandlerProcessor.Direction.OUTBOUND, context, !isOneWay);
} catch (WebServiceException wse) {
remedyActionTaken = true;
//no rewrapping
throw wse;
} catch (RuntimeException re) {
remedyActionTaken = true;
throw new WebServiceException(re);
}
if (!handlerResult) {
remedyActionTaken = true;
}
return handlerResult;
}
void closeHandlers(MessageContext mc) {
closeClientsideHandlers(mc);
}
void setUpProcessor() {
if (handlers == null) {
// Take a snapshot, User may change chain after invocation, Same chain
// should be used for the entire MEP
handlers = new ArrayList<Handler>();
HandlerConfiguration handlerConfig = ((BindingImpl) getBinding()).getHandlerConfig();
List<MessageHandler> msgHandlersSnapShot= handlerConfig.getMessageHandlers();
if (!msgHandlersSnapShot.isEmpty()) {
handlers.addAll(msgHandlersSnapShot);
roles = new HashSet<String>();
roles.addAll(handlerConfig.getRoles());
processor = new SOAPHandlerProcessor(true, this, getBinding(), handlers);
}
}
}
MessageUpdatableContext getContext(Packet p) {
MessageHandlerContextImpl context = new MessageHandlerContextImpl(seiModel, getBinding(), port, p, roles);
return context;
}
}

View File

@@ -0,0 +1,162 @@
/*
* Copyright (c) 1997, 2012, 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.handler;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.api.message.Attachment;
import com.sun.xml.internal.ws.api.message.AttachmentSet;
import com.sun.xml.internal.ws.api.pipe.TubeCloner;
import com.sun.xml.internal.ws.api.pipe.Tube;
import com.sun.xml.internal.ws.api.pipe.helper.AbstractFilterTubeImpl;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
import com.sun.xml.internal.ws.client.HandlerConfiguration;
import com.sun.xml.internal.ws.binding.BindingImpl;
import com.sun.xml.internal.ws.message.DataHandlerAttachment;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.Handler;
import javax.xml.ws.WebServiceException;
import javax.activation.DataHandler;
import java.util.*;
import java.util.Map.Entry;
/**
*
* @author WS Development Team
*/
public class ClientSOAPHandlerTube extends HandlerTube {
private Set<String> roles;
/**
* Creates a new instance of SOAPHandlerTube
*/
public ClientSOAPHandlerTube(WSBinding binding, WSDLPort port, Tube next) {
super(next, port, binding);
if (binding.getSOAPVersion() != null) {
// SOAPHandlerTube should n't be used for bindings other than SOAP.
// TODO: throw Exception
}
}
// Handle to LogicalHandlerTube means its used on SERVER-SIDE
/**
* This constructor is used on client-side where, LogicalHandlerTube is created
* first and then a SOAPHandlerTube is created with a handler to that
* LogicalHandlerTube.
* With this handle, SOAPHandlerTube can call LogicalHandlerTube.closeHandlers()
*/
public ClientSOAPHandlerTube(WSBinding binding, Tube next, HandlerTube cousinTube) {
super(next, cousinTube, binding);
}
/**
* Copy constructor for {@link com.sun.xml.internal.ws.api.pipe.Tube#copy(com.sun.xml.internal.ws.api.pipe.TubeCloner)}.
*/
private ClientSOAPHandlerTube(ClientSOAPHandlerTube that, TubeCloner cloner) {
super(that, cloner);
}
public AbstractFilterTubeImpl copy(TubeCloner cloner) {
return new ClientSOAPHandlerTube(this, cloner);
}
void setUpProcessor() {
if (handlers == null) {
// Take a snapshot, User may change chain after invocation, Same chain
// should be used for the entire MEP
handlers = new ArrayList<Handler>();
HandlerConfiguration handlerConfig = ((BindingImpl) getBinding()).getHandlerConfig();
List<SOAPHandler> soapSnapShot= handlerConfig.getSoapHandlers();
if (!soapSnapShot.isEmpty()) {
handlers.addAll(soapSnapShot);
roles = new HashSet<String>();
roles.addAll(handlerConfig.getRoles());
processor = new SOAPHandlerProcessor(true, this, getBinding(), handlers);
}
}
}
MessageUpdatableContext getContext(Packet packet) {
SOAPMessageContextImpl context = new SOAPMessageContextImpl(getBinding(), packet,roles);
return context;
}
boolean callHandlersOnRequest(MessageUpdatableContext context, boolean isOneWay) {
boolean handlerResult;
//Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
AttachmentSet attSet = context.packet.getMessage().getAttachments();
for (Entry<String, DataHandler> entry : atts.entrySet()) {
String cid = entry.getKey();
if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
attSet.add(att);
}
}
try {
//CLIENT-SIDE
handlerResult = processor.callHandlersRequest(HandlerProcessor.Direction.OUTBOUND, context, !isOneWay);
} catch (WebServiceException wse) {
remedyActionTaken = true;
//no rewrapping
throw wse;
} catch (RuntimeException re) {
remedyActionTaken = true;
throw new WebServiceException(re);
}
if (!handlerResult) {
remedyActionTaken = true;
}
return handlerResult;
}
void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {
try {
//CLIENT-SIDE
processor.callHandlersResponse(HandlerProcessor.Direction.INBOUND, context, handleFault);
} catch (WebServiceException wse) {
//no rewrapping
throw wse;
} catch (RuntimeException re) {
throw new WebServiceException(re);
}
}
void closeHandlers(MessageContext mc) {
closeClientsideHandlers(mc);
}
}

View File

@@ -0,0 +1,568 @@
/*
* Copyright (c) 1997, 2012, 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.handler;
import com.sun.xml.internal.ws.api.BindingID;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil;
import com.sun.xml.internal.ws.transport.http.DeploymentDescriptorParser;
import com.sun.xml.internal.ws.util.HandlerAnnotationInfo;
import com.sun.xml.internal.ws.util.JAXWSUtils;
import com.sun.xml.internal.ws.util.UtilException;
import javax.annotation.PostConstruct;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamReader;
import javax.xml.ws.handler.Handler;
import javax.xml.ws.handler.PortInfo;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.logging.Logger;
public class HandlerChainsModel {
private static final Logger logger = Logger.getLogger(
com.sun.xml.internal.ws.util.Constants.LoggingDomain + ".util");
private Class annotatedClass;
private List<HandlerChainType> handlerChains;
private String id;
/** Creates a new instance of HandlerChains */
private HandlerChainsModel(Class annotatedClass) {
this.annotatedClass = annotatedClass;
}
private List<HandlerChainType> getHandlerChain() {
if (handlerChains == null) {
handlerChains = new ArrayList<HandlerChainType>();
}
return handlerChains;
}
public String getId() {
return id;
}
public void setId(String value) {
this.id = value;
}
/**
* reader should be on <handler-chains> element
*/
public static HandlerChainsModel parseHandlerConfigFile(Class annotatedClass, XMLStreamReader reader) {
ensureProperName(reader,QNAME_HANDLER_CHAINS);
HandlerChainsModel handlerModel = new HandlerChainsModel(annotatedClass);
List<HandlerChainType> hChains = handlerModel.getHandlerChain();
XMLStreamReaderUtil.nextElementContent(reader);
while (reader.getName().equals(QNAME_HANDLER_CHAIN)) {
HandlerChainType hChain = new HandlerChainType();
XMLStreamReaderUtil.nextElementContent(reader);
if (reader.getName().equals(QNAME_CHAIN_PORT_PATTERN)) {
QName portNamePattern = XMLStreamReaderUtil.getElementQName(reader);
hChain.setPortNamePattern(portNamePattern);
XMLStreamReaderUtil.nextElementContent(reader);
} else if (reader.getName().equals(QNAME_CHAIN_PROTOCOL_BINDING)) {
String bindingList = XMLStreamReaderUtil.getElementText(reader);
StringTokenizer stk = new StringTokenizer(bindingList);
while(stk.hasMoreTokens()) {
String token = stk.nextToken();
// This will convert tokens into Binding URI
hChain.addProtocolBinding(token);
}
XMLStreamReaderUtil.nextElementContent(reader);
} else if (reader.getName().equals(QNAME_CHAIN_SERVICE_PATTERN)) {
QName serviceNamepattern = XMLStreamReaderUtil.getElementQName(reader);
hChain.setServiceNamePattern(serviceNamepattern);
XMLStreamReaderUtil.nextElementContent(reader);
}
List<HandlerType> handlers = hChain.getHandlers();
// process all <handler> elements
while (reader.getName().equals(QNAME_HANDLER)) {
HandlerType handler = new HandlerType();
XMLStreamReaderUtil.nextContent(reader);
if (reader.getName().equals(QNAME_HANDLER_NAME)) {
String handlerName =
XMLStreamReaderUtil.getElementText(reader).trim();
handler.setHandlerName(handlerName);
XMLStreamReaderUtil.nextContent(reader);
}
// handler class
ensureProperName(reader, QNAME_HANDLER_CLASS);
String handlerClass =
XMLStreamReaderUtil.getElementText(reader).trim();
handler.setHandlerClass(handlerClass);
XMLStreamReaderUtil.nextContent(reader);
// init params (ignored)
while (reader.getName().equals(QNAME_HANDLER_PARAM)) {
skipInitParamElement(reader);
}
// headers (ignored)
while (reader.getName().equals(QNAME_HANDLER_HEADER)) {
skipTextElement(reader);
}
// roles (not stored per handler)
while (reader.getName().equals(QNAME_HANDLER_ROLE)) {
List<String> soapRoles = handler.getSoapRoles();
soapRoles.add(XMLStreamReaderUtil.getElementText(reader));
XMLStreamReaderUtil.nextContent(reader);
}
handlers.add(handler);
// move past </handler>
ensureProperName(reader, QNAME_HANDLER);
XMLStreamReaderUtil.nextContent(reader);
}
// move past </handler-chain>
ensureProperName(reader, QNAME_HANDLER_CHAIN);
hChains.add(hChain);
XMLStreamReaderUtil.nextContent(reader);
}
return handlerModel;
}
/**
* <p>This method is called internally by HandlerAnnotationProcessor,
* and by
* {@link com.sun.xml.internal.ws.transport.http.DeploymentDescriptorParser}
* directly when it reaches the handler chains element in the
* descriptor file it is parsing.
* @param reader should be on <handler-chains> element
* @return A HandlerAnnotationInfo object that stores the
* handlers and roles.
*/
public static HandlerAnnotationInfo parseHandlerFile(XMLStreamReader reader,
ClassLoader classLoader, QName serviceName, QName portName,
WSBinding wsbinding) {
ensureProperName(reader,QNAME_HANDLER_CHAINS);
String bindingId = wsbinding.getBindingId().toString();
HandlerAnnotationInfo info = new HandlerAnnotationInfo();
XMLStreamReaderUtil.nextElementContent(reader);
List<Handler> handlerChain = new ArrayList<Handler>();
Set<String> roles = new HashSet<String>();
while (reader.getName().equals(QNAME_HANDLER_CHAIN)) {
XMLStreamReaderUtil.nextElementContent(reader);
if (reader.getName().equals(QNAME_CHAIN_PORT_PATTERN)) {
if (portName == null) {
logger.warning("handler chain sepcified for port " +
"but port QName passed to parser is null");
}
boolean parseChain = JAXWSUtils.matchQNames(portName,
XMLStreamReaderUtil.getElementQName(reader));
if (!parseChain) {
skipChain(reader);
continue;
}
XMLStreamReaderUtil.nextElementContent(reader);
} else if (reader.getName().equals(QNAME_CHAIN_PROTOCOL_BINDING)) {
if (bindingId == null) {
logger.warning("handler chain sepcified for bindingId " +
"but bindingId passed to parser is null");
}
String bindingConstraint = XMLStreamReaderUtil.getElementText(reader);
boolean skipThisChain = true;
StringTokenizer stk = new StringTokenizer(bindingConstraint);
List<String> bindingList = new ArrayList<String>();
while(stk.hasMoreTokens()) {
String tokenOrURI = stk.nextToken();
/*
Convert short-form tokens to API's binding ids
Unknown token, Put it as it is
*/
tokenOrURI = DeploymentDescriptorParser.getBindingIdForToken(tokenOrURI);
String binding = BindingID.parse(tokenOrURI).toString();
bindingList.add(binding);
}
if(bindingList.contains(bindingId)){
skipThisChain = false;
}
if (skipThisChain) {
skipChain(reader);
continue;
}
XMLStreamReaderUtil.nextElementContent(reader);
} else if (reader.getName().equals(QNAME_CHAIN_SERVICE_PATTERN)) {
if (serviceName == null) {
logger.warning("handler chain sepcified for service " +
"but service QName passed to parser is null");
}
boolean parseChain = JAXWSUtils.matchQNames(
serviceName,
XMLStreamReaderUtil.getElementQName(reader));
if (!parseChain) {
skipChain(reader);
continue;
}
XMLStreamReaderUtil.nextElementContent(reader);
}
// process all <handler> elements
while (reader.getName().equals(QNAME_HANDLER)) {
Handler handler;
XMLStreamReaderUtil.nextContent(reader);
if (reader.getName().equals(QNAME_HANDLER_NAME)) {
skipTextElement(reader);
}
// handler class
ensureProperName(reader, QNAME_HANDLER_CLASS);
try {
handler = (Handler) loadClass(classLoader,
XMLStreamReaderUtil.getElementText(reader).trim()).newInstance();
} catch (InstantiationException ie){
throw new RuntimeException(ie);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
XMLStreamReaderUtil.nextContent(reader);
// init params (ignored)
while (reader.getName().equals(QNAME_HANDLER_PARAM)) {
skipInitParamElement(reader);
}
// headers (ignored)
while (reader.getName().equals(QNAME_HANDLER_HEADER)) {
skipTextElement(reader);
}
// roles (not stored per handler)
while (reader.getName().equals(QNAME_HANDLER_ROLE)) {
roles.add(XMLStreamReaderUtil.getElementText(reader));
XMLStreamReaderUtil.nextContent(reader);
}
// call @PostConstruct method on handler if present
for (Method method : handler.getClass().getMethods()) {
if (method.getAnnotation(PostConstruct.class) == null) {
continue;
}
try {
method.invoke(handler, new Object [0]);
break;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
handlerChain.add(handler);
// move past </handler>
ensureProperName(reader, QNAME_HANDLER);
XMLStreamReaderUtil.nextContent(reader);
}
// move past </handler-chain>
ensureProperName(reader, QNAME_HANDLER_CHAIN);
XMLStreamReaderUtil.nextContent(reader);
}
info.setHandlers(handlerChain);
info.setRoles(roles);
return info;
}
public HandlerAnnotationInfo getHandlersForPortInfo(PortInfo info){
HandlerAnnotationInfo handlerInfo = new HandlerAnnotationInfo();
List<Handler> handlerClassList = new ArrayList<Handler>();
Set<String> roles = new HashSet<String>();
for(HandlerChainType hchain : handlerChains) {
boolean hchainMatched = false;
if((!hchain.isConstraintSet()) ||
JAXWSUtils.matchQNames(info.getServiceName(), hchain.getServiceNamePattern()) ||
JAXWSUtils.matchQNames(info.getPortName(), hchain.getPortNamePattern()) ||
hchain.getProtocolBindings().contains(info.getBindingID()) ){
hchainMatched = true;
}
if(hchainMatched) {
for(HandlerType handler : hchain.getHandlers()) {
try {
Handler handlerClass = (Handler) loadClass(annotatedClass.getClassLoader(),
handler.getHandlerClass()).newInstance();
callHandlerPostConstruct(handlerClass);
handlerClassList.add(handlerClass);
} catch (InstantiationException ie){
throw new RuntimeException(ie);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
roles.addAll(handler.getSoapRoles());
}
}
}
handlerInfo.setHandlers(handlerClassList);
handlerInfo.setRoles(roles);
return handlerInfo;
}
private static Class loadClass(ClassLoader loader, String name) {
try {
return Class.forName(name, true, loader);
} catch (ClassNotFoundException e) {
throw new UtilException(
"util.handler.class.not.found",
name);
}
}
private static void callHandlerPostConstruct(Object handlerClass) {
// call @PostConstruct method on handler if present
for (Method method : handlerClass.getClass().getMethods()) {
if (method.getAnnotation(PostConstruct.class) == null) {
continue;
}
try {
method.invoke(handlerClass, new Object [0]);
break;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
private static void skipChain(XMLStreamReader reader) {
while (XMLStreamReaderUtil.nextContent(reader) !=
XMLStreamConstants.END_ELEMENT ||
!reader.getName().equals(QNAME_HANDLER_CHAIN)) {}
XMLStreamReaderUtil.nextElementContent(reader);
}
private static void skipTextElement(XMLStreamReader reader) {
XMLStreamReaderUtil.nextContent(reader);
XMLStreamReaderUtil.nextElementContent(reader);
XMLStreamReaderUtil.nextElementContent(reader);
}
private static void skipInitParamElement(XMLStreamReader reader) {
int state;
do {
state = XMLStreamReaderUtil.nextContent(reader);
} while (state != XMLStreamReader.END_ELEMENT ||
!reader.getName().equals(QNAME_HANDLER_PARAM));
XMLStreamReaderUtil.nextElementContent(reader);
}
private static void ensureProperName(XMLStreamReader reader,
QName expectedName) {
if (!reader.getName().equals(expectedName)) {
failWithLocalName("util.parser.wrong.element", reader,
expectedName.getLocalPart());
}
}
static void ensureProperName(XMLStreamReader reader, String expectedName) {
if (!reader.getLocalName().equals(expectedName)) {
failWithLocalName("util.parser.wrong.element", reader,
expectedName);
}
}
private static void failWithLocalName(String key,
XMLStreamReader reader, String arg) {
throw new UtilException(key,
Integer.toString(reader.getLocation().getLineNumber()),
reader.getLocalName(),
arg );
}
public static final String PROTOCOL_SOAP11_TOKEN = "##SOAP11_HTTP";
public static final String PROTOCOL_SOAP12_TOKEN = "##SOAP12_HTTP";
public static final String PROTOCOL_XML_TOKEN = "##XML_HTTP";
public static final String NS_109 =
"http://java.sun.com/xml/ns/javaee";
public static final QName QNAME_CHAIN_PORT_PATTERN =
new QName(NS_109, "port-name-pattern");
public static final QName QNAME_CHAIN_PROTOCOL_BINDING =
new QName(NS_109, "protocol-bindings");
public static final QName QNAME_CHAIN_SERVICE_PATTERN =
new QName(NS_109, "service-name-pattern");
public static final QName QNAME_HANDLER_CHAIN =
new QName(NS_109, "handler-chain");
public static final QName QNAME_HANDLER_CHAINS =
new QName(NS_109, "handler-chains");
public static final QName QNAME_HANDLER =
new QName(NS_109, "handler");
public static final QName QNAME_HANDLER_NAME =
new QName(NS_109, "handler-name");
public static final QName QNAME_HANDLER_CLASS =
new QName(NS_109, "handler-class");
public static final QName QNAME_HANDLER_PARAM =
new QName(NS_109, "init-param");
public static final QName QNAME_HANDLER_PARAM_NAME =
new QName(NS_109, "param-name");
public static final QName QNAME_HANDLER_PARAM_VALUE =
new QName(NS_109, "param-value");
public static final QName QNAME_HANDLER_HEADER =
new QName(NS_109, "soap-header");
public static final QName QNAME_HANDLER_ROLE =
new QName(NS_109, "soap-role");
static class HandlerChainType {
//constraints
QName serviceNamePattern;
QName portNamePattern;
List<String> protocolBindings;
// This flag is set if one of the above constraint is set on handler chain
boolean constraintSet = false;
List<HandlerType> handlers;
String id;
/** Creates a new instance of HandlerChain */
public HandlerChainType() {
protocolBindings = new ArrayList<String>();
}
public void setServiceNamePattern(QName value) {
this.serviceNamePattern = value;
constraintSet = true;
}
public QName getServiceNamePattern() {
return serviceNamePattern;
}
public void setPortNamePattern(QName value) {
this.portNamePattern = value;
constraintSet = true;
}
public QName getPortNamePattern() {
return portNamePattern;
}
public List<java.lang.String> getProtocolBindings() {
return this.protocolBindings;
}
public void addProtocolBinding(String tokenOrURI){
/*
Convert short-form tokens to API's binding ids
Unknown token, Put it as it is
*/
tokenOrURI = DeploymentDescriptorParser.getBindingIdForToken(tokenOrURI);
String binding = BindingID.parse(tokenOrURI).toString();
protocolBindings.add(binding);
constraintSet = true;
}
public boolean isConstraintSet() {
return constraintSet || !protocolBindings.isEmpty();
}
public java.lang.String getId() {
return id;
}
public void setId(java.lang.String value) {
this.id = value;
}
public List<HandlerType> getHandlers() {
if (handlers == null) {
handlers = new ArrayList<HandlerType>();
}
return this.handlers;
}
}
static class HandlerType {
String handlerName;
String handlerClass;
List<String> soapRoles;
java.lang.String id;
/** Creates a new instance of HandlerComponent */
public HandlerType() {
}
public String getHandlerName() {
return handlerName;
}
public void setHandlerName(String value) {
this.handlerName = value;
}
public String getHandlerClass() {
return handlerClass;
}
public void setHandlerClass(String value) {
this.handlerClass = value;
}
public java.lang.String getId() {
return id;
}
public void setId(java.lang.String value) {
this.id = value;
}
public List<String> getSoapRoles() {
if (soapRoles == null) {
soapRoles = new ArrayList<String>();
}
return this.soapRoles;
}
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 1997, 2012, 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.handler;
import com.sun.istack.internal.localization.Localizable;
import com.sun.xml.internal.ws.util.exception.JAXWSExceptionBase;
/**
* Exception thrown by handler-related code. Extends
* {@link com.sun.xml.internal.ws.util.exception.JAXWSExceptionBase}
* using the appropriate resource bundle.
*
* @see com.sun.xml.internal.ws.util.exception.JAXWSExceptionBase
*
* @author WS Development Team
*/
public class HandlerException extends JAXWSExceptionBase {
public HandlerException(String key, Object... args) {
super(key, args);
}
public HandlerException(Throwable throwable) {
super(throwable);
}
public HandlerException(Localizable arg) {
super("handler.nestedError", arg);
}
public String getDefaultResourceBundleName() {
return "com.sun.xml.internal.ws.resources.handler";
}
}

View File

@@ -0,0 +1,412 @@
/*
* Copyright (c) 1997, 2012, 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.handler;
import com.sun.xml.internal.ws.api.WSBinding;
import javax.xml.ws.ProtocolException;
import javax.xml.ws.handler.Handler;
import javax.xml.ws.handler.MessageContext;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* @author WS Development Team
*/
abstract class HandlerProcessor<C extends MessageUpdatableContext> {
boolean isClient;
static final Logger logger = Logger.getLogger(
com.sun.xml.internal.ws.util.Constants.LoggingDomain + ".handler");
// need request or response for Handle interface
public enum RequestOrResponse {
REQUEST, RESPONSE }
public enum Direction {
OUTBOUND, INBOUND }
private List<? extends Handler> handlers; // may be logical/soap mixed
WSBinding binding;
private int index = -1;
private HandlerTube owner;
/**
* The handlers that are passed in will be sorted into
* logical and soap handlers. During this sorting, the
* understood headers are also obtained from any soap
* handlers.
*
* @param chain A list of handler objects, which can
* be protocol or logical handlers.
*/
protected HandlerProcessor(HandlerTube owner, WSBinding binding, List<? extends Handler> chain) {
this.owner = owner;
if (chain == null) { // should only happen in testing
chain = new ArrayList<Handler>();
}
handlers = chain;
this.binding = binding;
}
/**
* Gives index of the handler in the chain to know what handlers in the chain
* are invoked
*/
int getIndex() {
return index;
}
/**
* This is called when a handler returns false or throws a RuntimeException
*/
void setIndex(int i) {
index = i;
}
/**
* TODO: Just putting thoughts,
* Current contract: This is Called during Request Processing.
* return true, if all handlers in the chain return true
* Current Pipe can call nextPipe.process();
* return false, One of the handlers has returned false or thrown a
* RuntimeException. Remedy Actions taken:
* 1) In this case, The processor will setIndex()to track what
* handlers are invoked until that point.
* 2) Previously invoked handlers are again invoked (handleMessage()
* or handleFault()) to take remedy action.
* CurrentPipe should NOT call nextPipe.process()
* While closing handlers, check getIndex() to get the invoked
* handlers.
* @throws RuntimeException this happens when a RuntimeException occurs during
* handleMessage during Request processing or
* during remedy action 2)
* CurrentPipe should NOT call nextPipe.process() and throw the
* exception to the previous Pipe
* While closing handlers, check getIndex() to get the invoked
* handlers.
*/
public boolean callHandlersRequest(Direction direction,
C context,
boolean responseExpected) {
setDirection(direction, context);
boolean result;
// call handlers
try {
if (direction == Direction.OUTBOUND) {
result = callHandleMessage(context, 0, handlers.size() - 1);
} else {
result = callHandleMessage(context, handlers.size() - 1, 0);
}
} catch (ProtocolException pe) {
logger.log(Level.FINER, "exception in handler chain", pe);
if (responseExpected) {
//insert fault message if its not a fault message
insertFaultMessage(context, pe);
// reverse direction
reverseDirection(direction, context);
//Set handleFault so that cousinTube is aware of fault
setHandleFaultProperty();
// call handle fault
if (direction == Direction.OUTBOUND) {
callHandleFault(context, getIndex() - 1, 0);
} else {
callHandleFault(context, getIndex() + 1, handlers.size() - 1);
}
return false;
}
throw pe;
} catch (RuntimeException re) {
logger.log(Level.FINER, "exception in handler chain", re);
throw re;
}
if (!result) {
if (responseExpected) {
// reverse direction
reverseDirection(direction, context);
// call handle message
if (direction == Direction.OUTBOUND) {
callHandleMessageReverse(context, getIndex() - 1, 0);
} else {
callHandleMessageReverse(context, getIndex() + 1, handlers.size() - 1);
}
} else {
// Set handleFalse so that cousinTube is aware of false processing
// Oneway, dispatch the message
// cousinTube should n't call handleMessage() anymore.
setHandleFalseProperty();
}
return false;
}
return result;
}
/**
* TODO: Just putting thoughts,
* Current contract: This is Called during Response Processing.
* Runs all handlers until handle returns false or throws a RuntimeException
* CurrentPipe should close all the handlers in the chain.
* throw RuntimeException, this happens when a RuntimeException occurs during
* normal Response processing or remedy action 2) taken
* during callHandlersRequest().
* CurrentPipe should close all the handlers in the chain. *
*/
public void callHandlersResponse(Direction direction,
C context, boolean isFault) {
setDirection(direction, context);
try {
if (isFault) {
// call handleFault on handlers
if (direction == Direction.OUTBOUND) {
callHandleFault(context, 0, handlers.size() - 1);
} else {
callHandleFault(context, handlers.size() - 1, 0);
}
} else {
// call handleMessage on handlers
if (direction == Direction.OUTBOUND) {
callHandleMessageReverse(context, 0, handlers.size() - 1);
} else {
callHandleMessageReverse(context, handlers.size() - 1, 0);
}
}
} catch (RuntimeException re) {
logger.log(Level.FINER, "exception in handler chain", re);
throw re;
}
}
/**
* Reverses the Message Direction.
* MessageContext.MESSAGE_OUTBOUND_PROPERTY is changed.
*/
private void reverseDirection(Direction origDirection, C context) {
if (origDirection == Direction.OUTBOUND) {
context.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, false);
} else {
context.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, true);
}
}
/**
* Sets the Message Direction.
* MessageContext.MESSAGE_OUTBOUND_PROPERTY is changed.
*/
private void setDirection(Direction direction, C context) {
if (direction == Direction.OUTBOUND) {
context.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, true);
} else {
context.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, false);
}
}
/**
* When this property is set HandlerPipes can call handleFault() on the
* message
*/
private void setHandleFaultProperty() {
owner.setHandleFault();
}
/**
* When this property is set HandlerPipes will not call
* handleMessage() during Response processing.
*/
private void setHandleFalseProperty() {
owner.setHandleFalse();
}
/**
* When a ProtocolException is thrown, this is called.
* If it's XML/HTTP Binding, clear the the message
* If its SOAP/HTTP Binding, put right SOAP Fault version
*/
abstract void insertFaultMessage(C context,
ProtocolException exception);
/*
* Calls handleMessage on the handlers. Indices are
* inclusive. Exceptions get passed up the chain, and an
* exception or return of 'false' ends processing.
*/
private boolean callHandleMessage(C context, int start, int end) {
/* Do we need this check?
if (handlers.isEmpty() ||
start == -1 ||
start == handlers.size()) {
return false;
}
*/
int i = start;
try {
if (start > end) {
while (i >= end) {
if (!handlers.get(i).handleMessage(context)) {
setIndex(i);
return false;
}
i--;
}
} else {
while (i <= end) {
if (!handlers.get(i).handleMessage(context)) {
setIndex(i);
return false;
}
i++;
}
}
} catch (RuntimeException e) {
setIndex(i);
throw e;
}
return true;
}
/*
* Calls handleMessage on the handlers. Indices are
* inclusive. Exceptions get passed up the chain, and an
* exception (or)
* return of 'false' calls addHandleFalseProperty(context) and
* ends processing.
* setIndex() is not called.
*
*/
private boolean callHandleMessageReverse(C context, int start, int end) {
if (handlers.isEmpty() ||
start == -1 ||
start == handlers.size()) {
return false;
}
int i = start;
if (start > end) {
while (i >= end) {
if (!handlers.get(i).handleMessage(context)) {
// Set handleFalse so that cousinTube is aware of false processing
setHandleFalseProperty();
return false;
}
i--;
}
} else {
while (i <= end) {
if (!handlers.get(i).handleMessage(context)) {
// Set handleFalse so that cousinTube is aware of false processing
setHandleFalseProperty();
return false;
}
i++;
}
}
return true;
}
/*
* Calls handleFault on the handlers. Indices are
* inclusive. Exceptions get passed up the chain, and an
* exception or return of 'false' ends processing.
*/
private boolean callHandleFault(C context, int start, int end) {
if (handlers.isEmpty() ||
start == -1 ||
start == handlers.size()) {
return false;
}
int i = start;
if (start > end) {
try {
while (i >= end) {
if (!handlers.get(i).handleFault(context)) {
return false;
}
i--;
}
} catch (RuntimeException re) {
logger.log(Level.FINER,
"exception in handler chain", re);
throw re;
}
} else {
try {
while (i <= end) {
if (!handlers.get(i).handleFault(context)) {
return false;
}
i++;
}
} catch (RuntimeException re) {
logger.log(Level.FINER,
"exception in handler chain", re);
throw re;
}
}
return true;
}
/**
* Calls close on the handlers from the starting
* index through the ending index (inclusive). Made indices
* inclusive to allow both directions more easily.
*/
void closeHandlers(MessageContext context, int start, int end) {
if (handlers.isEmpty() ||
start == -1) {
return;
}
if (start > end) {
for (int i = start; i >= end; i--) {
try {
handlers.get(i).close(context);
} catch (RuntimeException re) {
logger.log(Level.INFO,
"Exception ignored during close", re);
}
}
} else {
for (int i = start; i <= end; i++) {
try {
handlers.get(i).close(context);
} catch (RuntimeException re) {
logger.log(Level.INFO,
"Exception ignored during close", re);
}
}
}
}
}

View File

@@ -0,0 +1,384 @@
/*
* Copyright (c) 1997, 2012, 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.handler;
import com.sun.istack.internal.Nullable;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
import com.sun.xml.internal.ws.api.pipe.*;
import com.sun.xml.internal.ws.api.pipe.helper.AbstractFilterTubeImpl;
import com.sun.xml.internal.ws.binding.BindingImpl;
import com.sun.xml.internal.ws.client.HandlerConfiguration;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.Handler;
import java.util.List;
/**
* @author WS Development team
*/
public abstract class HandlerTube extends AbstractFilterTubeImpl {
/**
* handle hold reference to other Tube for inter-tube communication
*/
HandlerTube cousinTube;
protected List<Handler> handlers;
HandlerProcessor processor;
boolean remedyActionTaken = false;
protected final @Nullable WSDLPort port;
// flag used to decide whether to call close on cousinTube
boolean requestProcessingSucessful = false;
private WSBinding binding;
private HandlerConfiguration hc;
public HandlerTube(Tube next, WSDLPort port, WSBinding binding) {
super(next);
this.port = port;
this.binding = binding;
}
public HandlerTube(Tube next, HandlerTube cousinTube, WSBinding binding) {
super(next);
this.cousinTube = cousinTube;
this.binding = binding;
if(cousinTube != null) {
this.port = cousinTube.port;
} else {
this.port = null;
}
}
/**
* Copy constructor for {@link Tube#copy(TubeCloner)}.
*/
protected HandlerTube(HandlerTube that, TubeCloner cloner) {
super(that,cloner);
if(that.cousinTube != null) {
this.cousinTube = cloner.copy(that.cousinTube);
}
this.port = that.port;
this.binding = that.binding;
}
protected WSBinding getBinding() {
return binding;
}
@Override
public NextAction processRequest(Packet request) {
setupExchange();
// This check is done to cover handler returning false in Oneway request
if (isHandleFalse()) {
// Cousin HandlerTube returned false during Oneway Request processing.
// Don't call handlers and dispatch the message.
remedyActionTaken = true;
return doInvoke(super.next, request);
}
// This is done here instead of the constructor, since User can change
// the roles and handlerchain after a stub/proxy is created.
setUpProcessorInternal();
MessageUpdatableContext context = getContext(request);
boolean isOneWay = checkOneWay(request);
try {
if (!isHandlerChainEmpty()) {
// Call handlers on Request
boolean handlerResult = callHandlersOnRequest(context, isOneWay);
//Update Packet with user modifications
context.updatePacket();
// two-way case where no message is sent
if (!isOneWay && !handlerResult) {
return doReturnWith(request);
}
}
requestProcessingSucessful = true;
// Call next Tube
return doInvoke(super.next, request);
} catch (RuntimeException re) {
if(isOneWay) {
//Eat the exception, its already logged and close the transportBackChannel
if(request.transportBackChannel != null ) {
request.transportBackChannel.close();
}
request.setMessage(null);
return doReturnWith(request);
} else
throw re;
} finally {
if(!requestProcessingSucessful) {
initiateClosing(context.getMessageContext());
}
}
}
@Override
public NextAction processResponse(Packet response) {
setupExchange();
MessageUpdatableContext context = getContext(response);
try {
if (isHandleFalse() || (response.getMessage() == null)) {
// Cousin HandlerTube returned false during Response processing.
// or it is oneway request
// or handler chain is empty
// Don't call handlers.
return doReturnWith(response);
}
setUpProcessorInternal();
boolean isFault = isHandleFault(response);
if (!isHandlerChainEmpty()) {
// Call handlers on Response
callHandlersOnResponse(context, isFault);
}
} finally {
initiateClosing(context.getMessageContext());
}
//Update Packet with user modifications
context.updatePacket();
return doReturnWith(response);
}
@Override
public NextAction processException(Throwable t) {
try {
return doThrow(t);
} finally {
Packet packet = Fiber.current().getPacket();
MessageUpdatableContext context = getContext(packet);
initiateClosing(context.getMessageContext());
/* TODO revisit: commented this out as the modified packet is no longer used
In future if the message is propagated even when an exception
occurs, then uncomment context.updatePacket();
*/
//Update Packet with user modifications
//context.updatePacket();
}
}
/**
* Must be overridden by HandlerTube that drives other handler tubes for processing a message.
* On Client-side: ClientLogicalHandlerTube drives the Handler Processing.
* On Server-side: In case SOAP Binding, ServerMessageHandlerTube drives the Handler Processing.
* In case XML/HTTP Binding, ServerLogicalHandlerTube drives the Handler Processing.
*
*
* If its a top HandlerTube, should override by calling #close(MessaggeContext);
*
*/
protected void initiateClosing(MessageContext mc) {
// Do nothing
}
/**
* Calls close on previously invoked handlers.
* Also, Cleans up any state left over in the Tube instance from the current
* invocation, as Tube instances can be reused after the completion of MEP.
*
* On Client, SOAPHandlers are closed first and then LogicalHandlers
* On Server, LogicalHandlers are closed first and then SOAPHandlers
*/
final public void close(MessageContext msgContext) {
//assuming cousinTube is called if requestProcessingSucessful is true
if (requestProcessingSucessful) {
if (cousinTube != null) {
cousinTube.close(msgContext);
}
}
if (processor != null)
closeHandlers(msgContext);
// Clean up the exchange for next invocation.
exchange = null;
requestProcessingSucessful = false;
}
/**
* On Client, Override by calling #closeClientHandlers(MessageContext mc)
* On Server, Override by calling #closeServerHandlers(MessageContext mc)
* The difference is the order in which they are closed.
* @param mc
*/
abstract void closeHandlers(MessageContext mc);
/**
* Called by close(MessageContext mc) in a Client Handlertube
*/
protected void closeClientsideHandlers(MessageContext msgContext) {
if (processor == null)
return;
if (remedyActionTaken) {
//Close only invoked handlers in the chain
//CLIENT-SIDE
processor.closeHandlers(msgContext, processor.getIndex(), 0);
processor.setIndex(-1);
//reset remedyActionTaken
remedyActionTaken = false;
} else {
//Close all handlers in the chain
//CLIENT-SIDE
processor.closeHandlers(msgContext, handlers.size() - 1, 0);
}
}
/**
* Called by close(MessageContext mc) in a Server Handlertube
*/
protected void closeServersideHandlers(MessageContext msgContext) {
if (processor == null)
return;
if (remedyActionTaken) {
//Close only invoked handlers in the chain
//SERVER-SIDE
processor.closeHandlers(msgContext, processor.getIndex(), handlers.size() - 1);
processor.setIndex(-1);
//reset remedyActionTaken
remedyActionTaken = false;
} else {
//Close all handlers in the chain
//SERVER-SIDE
processor.closeHandlers(msgContext, 0, handlers.size() - 1);
}
}
abstract void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault);
abstract boolean callHandlersOnRequest(MessageUpdatableContext context, boolean oneWay);
private boolean checkOneWay(Packet packet) {
if (port != null) {
/* we can determine this value from WSDL */
return packet.getMessage().isOneWay(port);
} else {
/*
otherwise use this value as an approximation, since this carries
the application's intention --- whether it was invokeOneway vs invoke,etc.
*/
return !(packet.expectReply != null && packet.expectReply);
}
}
private void setUpProcessorInternal() {
HandlerConfiguration hc = ((BindingImpl) binding).getHandlerConfig();
if (hc != this.hc)
resetProcessor();
this.hc = hc;
setUpProcessor();
}
abstract void setUpProcessor();
protected void resetProcessor() {
handlers = null;
}
final public boolean isHandlerChainEmpty() {
return handlers.isEmpty();
}
abstract MessageUpdatableContext getContext(Packet p);
private boolean isHandleFault(Packet packet) {
if (cousinTube != null) {
return exchange.isHandleFault();
} else {
boolean isFault = packet.getMessage().isFault();
exchange.setHandleFault(isFault);
return isFault;
}
}
final void setHandleFault() {
exchange.setHandleFault(true);
}
private boolean isHandleFalse() {
return exchange.isHandleFalse();
}
final void setHandleFalse() {
exchange.setHandleFalse();
}
private void setupExchange() {
if(exchange == null) {
exchange = new HandlerTubeExchange();
if(cousinTube != null) {
cousinTube.exchange = exchange;
}
} else {
if(cousinTube != null) {
cousinTube.exchange = exchange;
}
}
}
private HandlerTubeExchange exchange;
/**
* This class is used primarily to exchange information or status between
* LogicalHandlerTube and SOAPHandlerTube
*/
static final class HandlerTubeExchange {
private boolean handleFalse;
private boolean handleFault;
boolean isHandleFault() {
return handleFault;
}
void setHandleFault(boolean isFault) {
this.handleFault = isFault;
}
public boolean isHandleFalse() {
return handleFalse;
}
void setHandleFalse() {
this.handleFalse = true;
}
}
}

View File

@@ -0,0 +1,86 @@
/*
* 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.handler;
import com.sun.xml.internal.ws.api.message.Message;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.spi.db.BindingContext;
import javax.xml.ws.LogicalMessage;
import javax.xml.ws.handler.LogicalMessageContext;
/**
* Implementation of LogicalMessageContext. This class is used at runtime
* to pass to the handlers for processing logical messages.
*
* <p>This Class delegates most of the fuctionality to Packet
*
* @see Packet
*
* @author WS Development Team
*/
class LogicalMessageContextImpl extends MessageUpdatableContext implements LogicalMessageContext {
private LogicalMessageImpl lm;
private WSBinding binding;
// private JAXBContext defaultJaxbContext;
private BindingContext defaultJaxbContext;
public LogicalMessageContextImpl(WSBinding binding, BindingContext defaultJAXBContext, Packet packet) {
super(packet);
this.binding = binding;
this.defaultJaxbContext = defaultJAXBContext;
}
public LogicalMessage getMessage() {
if(lm == null)
lm = new LogicalMessageImpl(defaultJaxbContext, packet);
return lm;
}
void setPacketMessage(Message newMessage){
if(newMessage != null) {
packet.setMessage(newMessage);
lm = null;
}
}
protected void updateMessage() {
//If LogicalMessage is not acccessed, its not modified.
if(lm != null) {
//Check if LogicalMessageImpl has changed, if so construct new one
// Packet are handled through MessageContext
if(lm.isPayloadModifed()){
Message msg = packet.getMessage();
Message updatedMsg = lm.getMessage(msg.getHeaders(),msg.getAttachments(),binding);
packet.setMessage(updatedMsg);
}
lm = null;
}
}
}

View File

@@ -0,0 +1,364 @@
/*
* 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.handler;
import com.sun.xml.internal.ws.api.message.MessageHeaders;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.api.message.Message;
import com.sun.xml.internal.ws.api.message.AttachmentSet;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.spi.db.BindingContext;
import com.sun.xml.internal.ws.spi.db.BindingContextFactory;
import com.sun.xml.internal.ws.util.xml.XmlUtil;
import com.sun.xml.internal.ws.message.EmptyMessageImpl;
import com.sun.xml.internal.ws.message.DOMMessage;
import com.sun.xml.internal.ws.message.jaxb.JAXBMessage;
import com.sun.xml.internal.ws.message.source.PayloadSourceMessage;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.util.JAXBSource;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.ws.LogicalMessage;
import javax.xml.ws.WebServiceException;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Document;
/**
* Implementation of {@link LogicalMessage}. This class implements the methods
* used by LogicalHandlers to get/set the request or response either
* as a JAXB object or as javax.xml.transform.Source.
* <p/>
* <p>The {@link Message} that is passed into the constructor
* is used to retrieve the payload of the request or response.
*
* @author WS Development Team
* @see Message
* @see LogicalMessageContextImpl
*/
class LogicalMessageImpl implements LogicalMessage {
private Packet packet;
// protected JAXBContext defaultJaxbContext;
protected BindingContext defaultJaxbContext;
private ImmutableLM lm = null;
public LogicalMessageImpl(BindingContext defaultJaxbContext, Packet
packet) {
// don't create extract payload until Users wants it.
this.packet = packet;
this.defaultJaxbContext = defaultJaxbContext;
}
public Source getPayload() {
if (lm == null) {
Source payload = packet.getMessage().copy().readPayloadAsSource();
if (payload instanceof DOMSource) {
lm = createLogicalMessageImpl(payload);
}
return payload;
} else {
return lm.getPayload();
}
}
public void setPayload(Source payload) {
lm = createLogicalMessageImpl(payload);
}
private ImmutableLM createLogicalMessageImpl(Source payload) {
if (payload == null) {
lm = new EmptyLogicalMessageImpl();
} else if (payload instanceof DOMSource) {
lm = new DOMLogicalMessageImpl((DOMSource) payload);
} else {
lm = new SourceLogicalMessageImpl(payload);
}
return lm;
}
public Object getPayload(BindingContext context) {
if (context == null) {
context = defaultJaxbContext;
}
if (context == null)
throw new WebServiceException("JAXBContext parameter cannot be null");
Object o;
if (lm == null) {
try {
o = packet.getMessage().copy().readPayloadAsJAXB(context.createUnmarshaller());
} catch (JAXBException e) {
throw new WebServiceException(e);
}
} else {
o = lm.getPayload(context);
lm = new JAXBLogicalMessageImpl(context.getJAXBContext(), o);
}
return o;
}
public Object getPayload(JAXBContext context) {
if (context == null) {
return getPayload(defaultJaxbContext);
}
if (context == null)
throw new WebServiceException("JAXBContext parameter cannot be null");
Object o;
if (lm == null) {
try {
o = packet.getMessage().copy().readPayloadAsJAXB(context.createUnmarshaller());
} catch (JAXBException e) {
throw new WebServiceException(e);
}
} else {
o = lm.getPayload(context);
lm = new JAXBLogicalMessageImpl(context, o);
}
return o;
}
public void setPayload(Object payload, BindingContext context) {
if (context == null) {
context = defaultJaxbContext;
}
if (payload == null) {
lm = new EmptyLogicalMessageImpl();
} else {
lm = new JAXBLogicalMessageImpl(context.getJAXBContext(), payload);
}
}
public void setPayload(Object payload, JAXBContext context) {
if (context == null) {
setPayload(payload, defaultJaxbContext);
}
if (payload == null) {
lm = new EmptyLogicalMessageImpl();
} else {
lm = new JAXBLogicalMessageImpl(context, payload);
}
}
public boolean isPayloadModifed() {
return (lm != null);
}
/**
* This should be called by first checking if the payload is modified.
*
* @param headers
* @param attachments
* @param binding
* @return
*/
public Message getMessage(MessageHeaders headers, AttachmentSet attachments, WSBinding binding) {
assert isPayloadModifed();
if(isPayloadModifed()) {
return lm.getMessage(headers,attachments,binding);
} else {
return packet.getMessage();
}
}
private abstract class ImmutableLM {
public abstract Source getPayload();
public abstract Object getPayload(BindingContext context);
public abstract Object getPayload(JAXBContext context);
public abstract Message getMessage(MessageHeaders headers, AttachmentSet attachments, WSBinding binding);
}
private class DOMLogicalMessageImpl extends SourceLogicalMessageImpl {
private DOMSource dom;
public DOMLogicalMessageImpl(DOMSource dom) {
super(dom);
this.dom = dom;
}
@Override
public Source getPayload() {
return dom;
}
public Message getMessage(MessageHeaders headers, AttachmentSet attachments, WSBinding binding) {
Node n = dom.getNode();
if(n.getNodeType()== Node.DOCUMENT_NODE) {
n = ((Document)n).getDocumentElement();
}
return new DOMMessage(binding.getSOAPVersion(), headers, (Element)n, attachments);
}
}
private class EmptyLogicalMessageImpl extends ImmutableLM {
public EmptyLogicalMessageImpl() {
}
@Override
public Source getPayload() {
return null;
}
@Override
public Object getPayload(JAXBContext context) {
return null;
}
@Override
public Object getPayload(BindingContext context) {
return null;
}
public Message getMessage(MessageHeaders headers, AttachmentSet attachments, WSBinding binding) {
return new EmptyMessageImpl(headers,attachments,binding.getSOAPVersion());
}
}
private class JAXBLogicalMessageImpl extends ImmutableLM {
private JAXBContext ctxt;
private Object o;
public JAXBLogicalMessageImpl(JAXBContext ctxt, Object o) {
this.ctxt = ctxt;
this.o = o;
}
@Override
public Source getPayload() {
JAXBContext context = ctxt;
if (context == null) {
context = defaultJaxbContext.getJAXBContext();
}
try {
return new JAXBSource(context, o);
} catch (JAXBException e) {
throw new WebServiceException(e);
}
}
@Override
public Object getPayload(JAXBContext context) {
// if(context == ctxt) {
// return o;
// }
try {
Source payloadSrc = getPayload();
if (payloadSrc == null)
return null;
Unmarshaller unmarshaller = context.createUnmarshaller();
return unmarshaller.unmarshal(payloadSrc);
} catch (JAXBException e) {
throw new WebServiceException(e);
}
}
public Object getPayload(BindingContext context) {
// if(context == ctxt) {
// return o;
// }
try {
Source payloadSrc = getPayload();
if (payloadSrc == null)
return null;
Unmarshaller unmarshaller = context.createUnmarshaller();
return unmarshaller.unmarshal(payloadSrc);
} catch (JAXBException e) {
throw new WebServiceException(e);
}
}
public Message getMessage(MessageHeaders headers, AttachmentSet attachments, WSBinding binding) {
return JAXBMessage.create(BindingContextFactory.create(ctxt), o,binding.getSOAPVersion(), headers,attachments);
}
}
private class SourceLogicalMessageImpl extends ImmutableLM {
private Source payloadSrc;
public SourceLogicalMessageImpl(Source source) {
this.payloadSrc = source;
}
public Source getPayload() {
assert (!(payloadSrc instanceof DOMSource));
try {
Transformer transformer = XmlUtil.newTransformer();
DOMResult domResult = new DOMResult();
transformer.transform(payloadSrc, domResult);
DOMSource dom = new DOMSource(domResult.getNode());
lm = new DOMLogicalMessageImpl((DOMSource) dom);
payloadSrc = null;
return dom;
} catch (TransformerException te) {
throw new WebServiceException(te);
}
}
public Object getPayload(JAXBContext context) {
try {
Source payloadSrc = getPayload();
if (payloadSrc == null)
return null;
Unmarshaller unmarshaller = context.createUnmarshaller();
return unmarshaller.unmarshal(payloadSrc);
} catch (JAXBException e) {
throw new WebServiceException(e);
}
}
public Object getPayload(BindingContext context) {
try {
Source payloadSrc = getPayload();
if (payloadSrc == null)
return null;
Unmarshaller unmarshaller = context.createUnmarshaller();
return unmarshaller.unmarshal(payloadSrc);
} catch (JAXBException e) {
throw new WebServiceException(e);
}
}
public Message getMessage(MessageHeaders headers, AttachmentSet attachments, WSBinding binding) {
assert (payloadSrc!=null);
return new PayloadSourceMessage(headers, payloadSrc, attachments,binding.getSOAPVersion());
}
}
}

View File

@@ -0,0 +1,159 @@
/*
* 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.handler;
import com.sun.xml.internal.ws.api.message.Attachment;
import com.sun.xml.internal.ws.api.message.AttachmentSet;
import com.sun.xml.internal.ws.api.message.Packet;
import javax.activation.DataHandler;
import javax.xml.ws.handler.MessageContext;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
*
* @author WS Development Team
*/
class MessageContextImpl implements MessageContext {
private final Set<String> handlerScopeProps;
private final Packet packet;
private final Map<String, Object> asMapIncludingInvocationProperties;
/** Creates a new instance of MessageContextImpl */
public MessageContextImpl(Packet packet) {
this.packet = packet;
this.asMapIncludingInvocationProperties = packet.asMapIncludingInvocationProperties();
this.handlerScopeProps = packet.getHandlerScopePropertyNames(false);
}
protected void updatePacket() {
throw new UnsupportedOperationException("wrong call");
}
public void setScope(String name, Scope scope) {
if(!containsKey(name))
throw new IllegalArgumentException("Property " + name + " does not exist.");
if(scope == Scope.APPLICATION) {
handlerScopeProps.remove(name);
} else {
handlerScopeProps.add(name);
}
}
public Scope getScope(String name) {
if(!containsKey(name))
throw new IllegalArgumentException("Property " + name + " does not exist.");
if(handlerScopeProps.contains(name)) {
return Scope.HANDLER;
} else {
return Scope.APPLICATION;
}
}
public int size() {
return asMapIncludingInvocationProperties.size();
}
public boolean isEmpty() {
return asMapIncludingInvocationProperties.isEmpty();
}
public boolean containsKey(Object key) {
return asMapIncludingInvocationProperties.containsKey(key);
}
public boolean containsValue(Object value) {
return asMapIncludingInvocationProperties.containsValue(value);
}
public Object put(String key, Object value) {
if (!asMapIncludingInvocationProperties.containsKey(key)) {
//new property, default to Scope.HANDLER
handlerScopeProps.add(key);
}
return asMapIncludingInvocationProperties.put(key, value);
}
public Object get(Object key) {
if(key == null)
return null;
Object value = asMapIncludingInvocationProperties.get(key);
//add the attachments from the Message to the corresponding attachment property
if(key.equals(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS) ||
key.equals(MessageContext.INBOUND_MESSAGE_ATTACHMENTS)){
Map<String, DataHandler> atts = (Map<String, DataHandler>) value;
if(atts == null)
atts = new HashMap<String, DataHandler>();
AttachmentSet attSet = packet.getMessage().getAttachments();
for(Attachment att : attSet){
String cid = att.getContentId();
if (cid.indexOf("@jaxws.sun.com") == -1) {
Object a = atts.get(cid);
if (a == null) {
a = atts.get("<" + cid + ">");
if (a == null) atts.put(att.getContentId(), att.asDataHandler());
}
} else {
atts.put(att.getContentId(), att.asDataHandler());
}
}
return atts;
}
return value;
}
public void putAll(Map<? extends String, ? extends Object> t) {
for(String key: t.keySet()) {
if(!asMapIncludingInvocationProperties.containsKey(key)) {
//new property, default to Scope.HANDLER
handlerScopeProps.add(key);
}
}
asMapIncludingInvocationProperties.putAll(t);
}
public void clear() {
asMapIncludingInvocationProperties.clear();
}
public Object remove(Object key){
handlerScopeProps.remove(key);
return asMapIncludingInvocationProperties.remove(key);
}
public Set<String> keySet() {
return asMapIncludingInvocationProperties.keySet();
}
public Set<Map.Entry<String, Object>> entrySet(){
return asMapIncludingInvocationProperties.entrySet();
}
public Collection<Object> values() {
return asMapIncludingInvocationProperties.values();
}
}

View File

@@ -0,0 +1,85 @@
/*
* Copyright (c) 1997, 2012, 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.handler;
import com.sun.istack.internal.Nullable;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.handler.MessageHandlerContext;
import com.sun.xml.internal.ws.api.message.Message;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.api.model.SEIModel;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
import java.util.Set;
/**
* @author Rama Pulavarthi
*/
public class MessageHandlerContextImpl extends MessageUpdatableContext implements MessageHandlerContext {
private @Nullable SEIModel seiModel;
private Set<String> roles;
private WSBinding binding;
private @Nullable WSDLPort wsdlModel;
public MessageHandlerContextImpl(@Nullable SEIModel seiModel, WSBinding binding, @Nullable WSDLPort wsdlModel, Packet packet, Set<String> roles) {
super(packet);
this.seiModel = seiModel;
this.binding = binding;
this.wsdlModel = wsdlModel;
this.roles = roles;
}
public Message getMessage() {
return packet.getMessage();
}
public void setMessage(Message message) {
packet.setMessage(message);
}
public Set<String> getRoles() {
return roles;
}
public WSBinding getWSBinding() {
return binding;
}
public @Nullable SEIModel getSEIModel() {
return seiModel;
}
public @Nullable WSDLPort getPort() {
return wsdlModel;
}
void updateMessage() {
// Do Nothing
}
void setPacketMessage(Message newMessage) {
setMessage(newMessage);
}
}

View File

@@ -0,0 +1,140 @@
/*
* 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.handler;
import com.sun.xml.internal.ws.api.message.Message;
import com.sun.xml.internal.ws.api.message.Packet;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import javax.xml.ws.handler.MessageContext;
/**
* The class represents a MessageContext(Properties) and also allows the Message to be modified.
* This is extended by SOAPMessageContextImpl and LogicalMessageContextImpl.
*
* @author WS Development Team
*/
public abstract class MessageUpdatableContext implements MessageContext {
final Packet packet;
private MessageContextImpl ctxt;
/** Creates a new instance of MessageUpdatableContext */
public MessageUpdatableContext(Packet packet) {
ctxt = new MessageContextImpl(packet);
this.packet = packet;
}
/**
* Updates Message in the packet with user modifications
*/
abstract void updateMessage();
/**
* Updates Message in the packet with user modifications
* returns the new packet's message
*/
Message getPacketMessage(){
updateMessage();
return packet.getMessage();
}
/**
* Sets Message in the packet
* Any user modifications done on previous Message are lost.
*/
abstract void setPacketMessage(Message newMessage);
/**
* Updates the complete packet with user modfications to the message and
* properties cahnges in MessageContext
*/
public final void updatePacket() {
updateMessage();
}
MessageContextImpl getMessageContext() {
return ctxt;
}
public void setScope(String name, Scope scope) {
ctxt.setScope(name, scope);
}
public Scope getScope(String name) {
return ctxt.getScope(name);
}
/* java.util.Map methods below here */
public void clear() {
ctxt.clear();
}
public boolean containsKey(Object obj) {
return ctxt.containsKey(obj);
}
public boolean containsValue(Object obj) {
return ctxt.containsValue(obj);
}
public Set<Entry<String, Object>> entrySet() {
return ctxt.entrySet();
}
public Object get(Object obj) {
return ctxt.get(obj);
}
public boolean isEmpty() {
return ctxt.isEmpty();
}
public Set<String> keySet() {
return ctxt.keySet();
}
public Object put(String str, Object obj) {
return ctxt.put(str, obj);
}
public void putAll(Map<? extends String, ? extends Object> map) {
ctxt.putAll(map);
}
public Object remove(Object obj) {
return ctxt.remove(obj);
}
public int size() {
return ctxt.size();
}
public Collection<Object> values() {
return ctxt.values();
}
}

View File

@@ -0,0 +1,123 @@
/*
* Copyright (c) 1997, 2012, 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.handler;
import com.sun.xml.internal.ws.api.BindingID;
import com.sun.xml.internal.ws.client.WSServiceDelegate;
import javax.xml.namespace.QName;
import javax.xml.ws.handler.PortInfo;
/**
* <p>Implementation of the PortInfo interface. This is just a simple
* class used to hold the info necessary to uniquely identify a port,
* including the port name, service name, and binding ID. This class
* is only used on the client side.
*
* <p>An instance is created by
* {@link WSServiceDelegate} when used to
* place a handler chain into the HandlerResolver map. Another is
* created later by
* {@link com.sun.xml.internal.ws.client.WSServiceDelegate} to retrieve the
* necessary handler chain to set on a binding instance.
*
* @see WSServiceDelegate
* @see com.sun.xml.internal.ws.client.HandlerResolverImpl
*
* @author WS Development Team
*/
public class PortInfoImpl implements PortInfo {
private BindingID bindingId;
private QName portName;
private QName serviceName;
/**
* The class is constructed with the information needed to identify
* a port. This information cannot be changed later.
*
* @param bindingId The binding ID string.
* @param portName The QName of the port.
* @param serviceName The QName of the service.
*/
public PortInfoImpl(BindingID bindingId, QName portName, QName serviceName) {
if (bindingId == null) {
throw new RuntimeException("bindingId cannot be null");
}
if (portName == null) {
throw new RuntimeException("portName cannot be null");
}
if (serviceName == null) {
throw new RuntimeException("serviceName cannot be null");
}
this.bindingId = bindingId;
this.portName = portName;
this.serviceName = serviceName;
}
public String getBindingID() {
return bindingId.toString();
}
public QName getPortName() {
return portName;
}
public QName getServiceName() {
return serviceName;
}
/**
* Object.equals is overridden here so that PortInfo objects
* can be compared when using them as keys in the map in
* HandlerResolverImpl. This method relies on the equals()
* methods of java.lang.String and javax.xml.namespace.QName.
*
* @param obj The PortInfo object to test for equality.
* @return True if they match, and false if they do not or
* if the object passed in is not a PortInfo.
*/
public boolean equals(Object obj) {
if (obj instanceof PortInfo) {
PortInfo info = (PortInfo) obj;
if (bindingId.toString().equals(info.getBindingID()) &&
portName.equals(info.getPortName()) &&
serviceName.equals(info.getServiceName())) {
return true;
}
}
return false;
}
/**
* Needed so PortInfoImpl can be used as a key in a map. This
* method just delegates to the hashCode method of java.lang.String.
*/
public int hashCode() {
return bindingId.hashCode();
}
}

View File

@@ -0,0 +1,101 @@
/*
* Copyright (c) 1997, 2012, 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.
*/
/*
* SOAPHandlerProcessor.java
*
* Created on February 8, 2006, 5:43 PM
*
*
*/
package com.sun.xml.internal.ws.handler;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.SOAPVersion;
import com.sun.xml.internal.ws.api.message.Message;
import com.sun.xml.internal.ws.api.message.Messages;
import com.sun.xml.internal.ws.encoding.soap.SOAP12Constants;
import com.sun.xml.internal.ws.encoding.soap.SOAPConstants;
import java.util.List;
import java.util.logging.Level;
import javax.xml.namespace.QName;
import javax.xml.ws.ProtocolException;
import javax.xml.ws.handler.Handler;
/**
*
* @author WS Development Team
*/
final class SOAPHandlerProcessor<C extends MessageUpdatableContext> extends HandlerProcessor<C> {
/**
* Creates a new instance of SOAPHandlerProcessor
*/
public SOAPHandlerProcessor(boolean isClient, HandlerTube owner, WSBinding binding, List<? extends Handler> chain) {
super(owner, binding, chain);
this.isClient = isClient;
}
/**
* Replace the message in the given message context with a
* fault message. If the context already contains a fault
* message, then return without changing it.
*
* <p>This method should only be called during a request,
* because during a response an exception from a handler
* is dispatched rather than replacing the message with
* a fault. So this method can use the MESSAGE_OUTBOUND_PROPERTY
* to determine whether it is being called on the client
* or the server side. If this changes in the spec, then
* something else will need to be passed to the method
* to determine whether the fault code is client or server.
*/
final void insertFaultMessage(C context,
ProtocolException exception) {
try {
if(!context.getPacketMessage().isFault()) {
Message faultMessage = Messages.create(binding.getSOAPVersion(),
exception,determineFaultCode(binding.getSOAPVersion()));
context.setPacketMessage(faultMessage);
}
} catch (Exception e) {
// severe since this is from runtime and not handler
logger.log(Level.SEVERE,
"exception while creating fault message in handler chain", e);
throw new RuntimeException(e);
}
}
/**
* <p>Figure out if the fault code local part is client,
* server, sender, receiver, etc. This is called by
* insertFaultMessage.
*/
private QName determineFaultCode(SOAPVersion soapVersion) {
return isClient ? soapVersion.faultCodeClient : soapVersion.faultCodeServer;
}
}

View File

@@ -0,0 +1,131 @@
/*
* 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.handler;
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.Packet;
import com.sun.xml.internal.ws.api.message.saaj.SAAJFactory;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.SOAPVersion;
import javax.xml.bind.JAXBContext;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.handler.soap.SOAPMessageContext;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
* Implementation of {@link SOAPMessageContext}. This class is used at runtime
* to pass to the handlers for processing soap messages.
*
* @see MessageContextImpl
*
* @author WS Development Team
*/
public class SOAPMessageContextImpl extends MessageUpdatableContext implements SOAPMessageContext {
private Set<String> roles;
private SOAPMessage soapMsg = null;
private WSBinding binding;
public SOAPMessageContextImpl(WSBinding binding, Packet packet,Set<String> roles) {
super(packet);
this.binding = binding;
this.roles = roles;
}
public SOAPMessage getMessage() {
if(soapMsg == null) {
try {
Message m = packet.getMessage();
soapMsg = m != null ? m.readAsSOAPMessage() : null;
} catch (SOAPException e) {
throw new WebServiceException(e);
}
}
return soapMsg;
}
public void setMessage(SOAPMessage soapMsg) {
try {
this.soapMsg = soapMsg;
} catch(Exception e) {
throw new WebServiceException(e);
}
}
void setPacketMessage(Message newMessage){
if(newMessage != null) {
packet.setMessage(newMessage);
soapMsg = null;
}
}
protected void updateMessage() {
//Check if SOAPMessage has changed, if so construct new one,
// Packet are handled through MessageContext
if(soapMsg != null) {
packet.setMessage(SAAJFactory.create(soapMsg));
soapMsg = null;
}
}
public Object[] getHeaders(QName header, JAXBContext jaxbContext, boolean allRoles) {
SOAPVersion soapVersion = binding.getSOAPVersion();
List<Object> beanList = new ArrayList<Object>();
try {
Iterator<Header> itr = packet.getMessage().getHeaders().getHeaders(header,false);
if(allRoles) {
while(itr.hasNext()) {
beanList.add(itr.next().readAsJAXB(jaxbContext.createUnmarshaller()));
}
} else {
while(itr.hasNext()) {
Header soapHeader = itr.next();
//Check if the role is one of the roles on this Binding
String role = soapHeader.getRole(soapVersion);
if(getRoles().contains(role)) {
beanList.add(soapHeader.readAsJAXB(jaxbContext.createUnmarshaller()));
}
}
}
return beanList.toArray();
} catch(Exception e) {
throw new WebServiceException(e);
}
}
public Set<String> getRoles() {
return roles;
}
}

View File

@@ -0,0 +1,182 @@
/*
* Copyright (c) 1997, 2012, 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.handler;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.api.message.AttachmentSet;
import com.sun.xml.internal.ws.api.message.Attachment;
import com.sun.xml.internal.ws.api.pipe.TubeCloner;
import com.sun.xml.internal.ws.api.pipe.Tube;
import com.sun.xml.internal.ws.api.pipe.helper.AbstractFilterTubeImpl;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
import com.sun.xml.internal.ws.api.model.SEIModel;
import com.sun.xml.internal.ws.binding.BindingImpl;
import com.sun.xml.internal.ws.message.DataHandlerAttachment;
import com.sun.xml.internal.ws.model.AbstractSEIModelImpl;
import com.sun.xml.internal.ws.spi.db.BindingContext;
import javax.xml.ws.handler.LogicalHandler;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.Handler;
import javax.xml.ws.WebServiceException;
import javax.activation.DataHandler;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.Map.Entry;
/**
*
* @author WS Development Team
*/
public class ServerLogicalHandlerTube extends HandlerTube {
private SEIModel seiModel;
/**
* Creates a new instance of LogicalHandlerTube
*/
public ServerLogicalHandlerTube(WSBinding binding, SEIModel seiModel, WSDLPort port, Tube next) {
super(next, port, binding);
this.seiModel = seiModel;
setUpHandlersOnce();
}
/**
* This constructor is used on client-side where, SOAPHandlerTube is created
* first and then a LogicalHandlerTube is created with a handler to that
* SOAPHandlerTube.
* With this handle, LogicalHandlerTube can call
* SOAPHandlerTube.closeHandlers()
*/
public ServerLogicalHandlerTube(WSBinding binding, SEIModel seiModel, Tube next, HandlerTube cousinTube) {
super(next, cousinTube, binding);
this.seiModel = seiModel;
setUpHandlersOnce();
}
/**
* Copy constructor for {@link com.sun.xml.internal.ws.api.pipe.Tube#copy(com.sun.xml.internal.ws.api.pipe.TubeCloner)}.
*/
private ServerLogicalHandlerTube(ServerLogicalHandlerTube that, TubeCloner cloner) {
super(that, cloner);
this.seiModel = that.seiModel;
this.handlers = that.handlers;
}
//should be overridden by DriverHandlerTubes
@Override
protected void initiateClosing(MessageContext mc) {
if (getBinding().getSOAPVersion() != null) {
super.initiateClosing(mc);
} else {
close(mc);
super.initiateClosing(mc);
}
}
public AbstractFilterTubeImpl copy(TubeCloner cloner) {
return new ServerLogicalHandlerTube(this, cloner);
}
private void setUpHandlersOnce() {
handlers = new ArrayList<Handler>();
List<LogicalHandler> logicalSnapShot= ((BindingImpl) getBinding()).getHandlerConfig().getLogicalHandlers();
if (!logicalSnapShot.isEmpty()) {
handlers.addAll(logicalSnapShot);
}
}
protected void resetProcessor() {
processor = null;
}
void setUpProcessor() {
if (!handlers.isEmpty() && processor == null) {
if (getBinding().getSOAPVersion() == null) {
processor = new XMLHandlerProcessor(this, getBinding(),
handlers);
} else {
processor = new SOAPHandlerProcessor(false, this, getBinding(), handlers);
}
}
}
MessageUpdatableContext getContext(Packet packet) {
return new LogicalMessageContextImpl(getBinding(), getBindingContext(), packet);
}
private BindingContext getBindingContext() {
return (seiModel!= null && seiModel instanceof AbstractSEIModelImpl) ?
((AbstractSEIModelImpl)seiModel).getBindingContext() : null;
}
boolean callHandlersOnRequest(MessageUpdatableContext context, boolean isOneWay) {
boolean handlerResult;
try {
//SERVER-SIDE
handlerResult = processor.callHandlersRequest(HandlerProcessor.Direction.INBOUND, context, !isOneWay);
} catch (RuntimeException re) {
remedyActionTaken = true;
throw re;
}
if (!handlerResult) {
remedyActionTaken = true;
}
return handlerResult;
}
void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {
//Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
AttachmentSet attSet = context.packet.getMessage().getAttachments();
for (Entry<String, DataHandler> entry : atts.entrySet()) {
String cid = entry.getKey();
Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
attSet.add(att);
}
try {
//SERVER-SIDE
processor.callHandlersResponse(HandlerProcessor.Direction.OUTBOUND, context, handleFault);
} catch (WebServiceException wse) {
//no rewrapping
throw wse;
} catch (RuntimeException re) {
throw re;
}
}
void closeHandlers(MessageContext mc) {
closeServersideHandlers(mc);
}
}

View File

@@ -0,0 +1,153 @@
/*
* Copyright (c) 1997, 2012, 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.handler;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.handler.MessageHandler;
import com.sun.xml.internal.ws.api.message.Attachment;
import com.sun.xml.internal.ws.api.message.AttachmentSet;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.api.model.SEIModel;
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.binding.BindingImpl;
import com.sun.xml.internal.ws.client.HandlerConfiguration;
import com.sun.xml.internal.ws.message.DataHandlerAttachment;
import javax.activation.DataHandler;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.Handler;
import java.util.*;
import java.util.Map.Entry;
/**
* @author Rama Pulavarthi
*/
public class ServerMessageHandlerTube extends HandlerTube{
private SEIModel seiModel;
private Set<String> roles;
public ServerMessageHandlerTube(SEIModel seiModel, WSBinding binding, Tube next, HandlerTube cousinTube) {
super(next, cousinTube, binding);
this.seiModel = seiModel;
setUpHandlersOnce();
}
/**
* Copy constructor for {@link com.sun.xml.internal.ws.api.pipe.Tube#copy(com.sun.xml.internal.ws.api.pipe.TubeCloner)}.
*/
private ServerMessageHandlerTube(ServerMessageHandlerTube that, TubeCloner cloner) {
super(that, cloner);
this.seiModel = that.seiModel;
this.handlers = that.handlers;
this.roles = that.roles;
}
private void setUpHandlersOnce() {
handlers = new ArrayList<Handler>();
HandlerConfiguration handlerConfig = ((BindingImpl) getBinding()).getHandlerConfig();
List<MessageHandler> msgHandlersSnapShot= handlerConfig.getMessageHandlers();
if (!msgHandlersSnapShot.isEmpty()) {
handlers.addAll(msgHandlersSnapShot);
roles = new HashSet<String>();
roles.addAll(handlerConfig.getRoles());
}
}
void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {
//Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
AttachmentSet attSet = context.packet.getMessage().getAttachments();
for (Entry<String, DataHandler> entry : atts.entrySet()) {
String cid = entry.getKey();
if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
attSet.add(att);
}
}
try {
//SERVER-SIDE
processor.callHandlersResponse(HandlerProcessor.Direction.OUTBOUND, context, handleFault);
} catch (WebServiceException wse) {
//no rewrapping
throw wse;
} catch (RuntimeException re) {
throw re;
}
}
boolean callHandlersOnRequest(MessageUpdatableContext context, boolean isOneWay) {
boolean handlerResult;
try {
//SERVER-SIDE
handlerResult = processor.callHandlersRequest(HandlerProcessor.Direction.INBOUND, context, !isOneWay);
} catch (RuntimeException re) {
remedyActionTaken = true;
throw re;
}
if (!handlerResult) {
remedyActionTaken = true;
}
return handlerResult;
}
protected void resetProcessor() {
processor = null;
}
void setUpProcessor() {
if(!handlers.isEmpty() && processor == null) {
processor = new SOAPHandlerProcessor(false, this, getBinding(), handlers);
}
}
void closeHandlers(MessageContext mc) {
closeServersideHandlers(mc);
}
MessageUpdatableContext getContext(Packet packet) {
MessageHandlerContextImpl context = new MessageHandlerContextImpl(seiModel, getBinding(), port, packet, roles);
return context;
}
//should be overridden by DriverHandlerTubes
@Override
protected void initiateClosing(MessageContext mc) {
close(mc);
super.initiateClosing(mc);
}
public AbstractFilterTubeImpl copy(TubeCloner cloner) {
return new ServerMessageHandlerTube(this, cloner);
}
}

View File

@@ -0,0 +1,166 @@
/*
* Copyright (c) 1997, 2012, 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.handler;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.api.message.AttachmentSet;
import com.sun.xml.internal.ws.api.message.Attachment;
import com.sun.xml.internal.ws.api.pipe.TubeCloner;
import com.sun.xml.internal.ws.api.pipe.Tube;
import com.sun.xml.internal.ws.api.pipe.helper.AbstractFilterTubeImpl;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
import com.sun.xml.internal.ws.client.HandlerConfiguration;
import com.sun.xml.internal.ws.binding.BindingImpl;
import com.sun.xml.internal.ws.message.DataHandlerAttachment;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.Handler;
import javax.xml.ws.WebServiceException;
import javax.activation.DataHandler;
import java.util.*;
/**
*
* @author WS Development Team
*/
public class ServerSOAPHandlerTube extends HandlerTube {
private Set<String> roles;
/**
* Creates a new instance of SOAPHandlerTube
*/
public ServerSOAPHandlerTube(WSBinding binding, WSDLPort port, Tube next) {
super(next, port, binding);
if (binding.getSOAPVersion() != null) {
// SOAPHandlerTube should n't be used for bindings other than SOAP.
// TODO: throw Exception
}
setUpHandlersOnce();
}
// Handle to LogicalHandlerTube means its used on SERVER-SIDE
/**
* This constructor is used on client-side where, LogicalHandlerTube is created
* first and then a SOAPHandlerTube is created with a handler to that
* LogicalHandlerTube.
* With this handle, SOAPHandlerTube can call LogicalHandlerTube.closeHandlers()
*/
public ServerSOAPHandlerTube(WSBinding binding, Tube next, HandlerTube cousinTube) {
super(next, cousinTube, binding);
setUpHandlersOnce();
}
/**
* Copy constructor for {@link com.sun.xml.internal.ws.api.pipe.Tube#copy(com.sun.xml.internal.ws.api.pipe.TubeCloner)}.
*/
private ServerSOAPHandlerTube(ServerSOAPHandlerTube that, TubeCloner cloner) {
super(that, cloner);
this.handlers = that.handlers;
this.roles = that.roles;
}
public AbstractFilterTubeImpl copy(TubeCloner cloner) {
return new ServerSOAPHandlerTube(this, cloner);
}
private void setUpHandlersOnce() {
handlers = new ArrayList<Handler>();
HandlerConfiguration handlerConfig = ((BindingImpl) getBinding()).getHandlerConfig();
List<SOAPHandler> soapSnapShot= handlerConfig.getSoapHandlers();
if (!soapSnapShot.isEmpty()) {
handlers.addAll(soapSnapShot);
roles = new HashSet<String>();
roles.addAll(handlerConfig.getRoles());
}
}
protected void resetProcessor() {
processor = null;
}
void setUpProcessor() {
if(!handlers.isEmpty() && processor == null)
processor = new SOAPHandlerProcessor(false, this, getBinding(), handlers);
}
MessageUpdatableContext getContext(Packet packet) {
SOAPMessageContextImpl context = new SOAPMessageContextImpl(getBinding(), packet,roles);
return context;
}
boolean callHandlersOnRequest(MessageUpdatableContext context, boolean isOneWay) {
boolean handlerResult;
try {
//SERVER-SIDE
handlerResult = processor.callHandlersRequest(HandlerProcessor.Direction.INBOUND, context, !isOneWay);
} catch (RuntimeException re) {
remedyActionTaken = true;
throw re;
}
if (!handlerResult) {
remedyActionTaken = true;
}
return handlerResult;
}
void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {
//Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
AttachmentSet attSet = context.packet.getMessage().getAttachments();
for (Map.Entry<String, DataHandler> entry : atts.entrySet()) {
String cid = entry.getKey();
if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
attSet.add(att);
}
}
try {
//SERVER-SIDE
processor.callHandlersResponse(HandlerProcessor.Direction.OUTBOUND, context, handleFault);
} catch (WebServiceException wse) {
//no rewrapping
throw wse;
} catch (RuntimeException re) {
throw re;
}
}
void closeHandlers(MessageContext mc) {
closeServersideHandlers(mc);
}
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 1997, 2012, 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.
*/
/*
* LogicalHandlerProcessor.java
*
* Created on February 8, 2006, 5:40 PM
*
*/
package com.sun.xml.internal.ws.handler;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.message.Messages;
import java.util.List;
import javax.xml.ws.ProtocolException;
import javax.xml.ws.handler.Handler;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.http.HTTPException;
/**
* This is used only for XML/HTTP binding
* @author WS Development Team
*/
final class XMLHandlerProcessor<C extends MessageUpdatableContext> extends HandlerProcessor<C> {
/**
* Creates a new instance of LogicalHandlerProcessor
*/
public XMLHandlerProcessor(HandlerTube owner, WSBinding binding, List<? extends Handler> chain) {
super(owner, binding, chain);
}
/*
* TODO: This is valid only for XML/HTTP binding
* Empty the XML message
*/
final void insertFaultMessage(C context,
ProtocolException exception) {
if(exception instanceof HTTPException) {
context.put(MessageContext.HTTP_RESPONSE_CODE,((HTTPException)exception).getStatusCode());
}
if (context != null) {
// non-soap case
context.setPacketMessage(Messages.createEmpty(binding.getSOAPVersion()));
}
}
}