1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.ws.extensions.wsrm.jaxws;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.addressing.JAXWSAConstants;
import javax.xml.ws.addressing.soap.SOAPAddressingProperties;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.MessageContext.Scope;
import javax.xml.ws.handler.soap.SOAPMessageContext;
import org.jboss.ws.core.CommonMessageContext;
import org.jboss.ws.extensions.wsrm.RMConstant;
import org.jboss.ws.extensions.wsrm.RMSequence;
import org.jboss.ws.extensions.wsrm.api.RMException;
import org.jboss.ws.extensions.wsrm.spi.RMConstants;
import org.jboss.ws.extensions.wsrm.spi.RMProvider;
import org.jboss.ws.extensions.wsrm.spi.protocol.RMSerializable;
/**
* Server WS-RM JAX-WS handler
*
* @author richard.opalka@jboss.com
*
* @since Dec 12, 2007
*/
public final class RMServerHandler extends RMHandlerAbstractBase
{
private static final RMConstants rmConstants = RMProvider.get().getConstants();
protected final boolean handleOutbound(MessageContext msgContext)
{
log.debug("handling outbound message");
CommonMessageContext commonMsgContext = (CommonMessageContext)msgContext;
SOAPAddressingProperties addrProps = (SOAPAddressingProperties)commonMsgContext.get(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_OUTBOUND);
Map<String, Object> rmOutboundContext = (Map<String, Object>)commonMsgContext.get(RMConstant.RESPONSE_CONTEXT);
List<QName> outMsgs = (List<QName>)rmOutboundContext.get(RMConstant.PROTOCOL_MESSAGES);
Map<QName, RMSerializable> data = new HashMap<QName, RMSerializable>();
String optionalMessageId = (addrProps.getMessageID() != null) ? addrProps.getMessageID().getURI().toString() : null;
rmOutboundContext.put(RMConstant.WSA_MESSAGE_ID, optionalMessageId);
rmOutboundContext.put(RMConstant.PROTOCOL_MESSAGES_MAPPING, data);
SOAPMessage soapMessage = ((SOAPMessageContext)commonMsgContext).getMessage();
RMSequence sequenceImpl = (RMSequence)rmOutboundContext.get(RMConstant.SEQUENCE_REFERENCE);
// try to serialize CreateSequenceResponse to message
serialize(rmConstants.getCreateSequenceResponseQName(), outMsgs, data, soapMessage, sequenceImpl);
// try to serialize Sequence to message
serialize(rmConstants.getSequenceQName(), outMsgs, data, soapMessage, sequenceImpl);
// try to serialize AckRequested to message
serialize(rmConstants.getAckRequestedQName(), outMsgs, data, soapMessage, sequenceImpl);
// try to serialize CloseSequenceResponse to message
serialize(rmConstants.getCloseSequenceResponseQName(), outMsgs, data, soapMessage, sequenceImpl);
// try to serialize TerminateSequenceResponse to message
serialize(rmConstants.getTerminateSequenceResponseQName(), outMsgs, data, soapMessage, sequenceImpl);
// try to serialize SequenceAcknowledgement to message
serialize(rmConstants.getSequenceAcknowledgementQName(), outMsgs, data, soapMessage, sequenceImpl);
if ((outMsgs.size() != 0) && (data.size() == 0))
throw new RMException("RM handler have not serialized WS-RM message to the payload");
// TODO: implement SequenceFault serialization
return true;
}
protected final boolean handleInbound(MessageContext msgContext)
{
log.debug("handling inbound message");
SOAPMessage soapMessage = ((SOAPMessageContext)msgContext).getMessage();
// initialize RM response context
Map<String, Object> rmResponseContext = new HashMap<String, Object>();
List<QName> messages = new LinkedList<QName>();
rmResponseContext.put(RMConstant.PROTOCOL_MESSAGES, messages);
Map<QName, RMSerializable> data = new HashMap<QName, RMSerializable>();
rmResponseContext.put(RMConstant.PROTOCOL_MESSAGES_MAPPING, data);
// try to read CreateSequence from message
deserialize(rmConstants.getCreateSequenceQName(), soapMessage, messages, data);
// try to read AckRequested from message
deserialize(rmConstants.getAckRequestedQName(), soapMessage, messages, data);
// try to read Sequence from message
deserialize(rmConstants.getSequenceQName(), soapMessage, messages, data);
// try to read SequenceAcknowledgement from message
deserialize(rmConstants.getSequenceAcknowledgementQName(), soapMessage, messages, data);
// try to read CloseSequence from message
deserialize(rmConstants.getCloseSequenceQName(), soapMessage, messages, data);
// try to read TerminateSequence from message
deserialize(rmConstants.getTerminateSequenceQName(), soapMessage, messages, data);
if (data.size() == 0)
throw new RMException("RM handler was not able to find WS-RM message in the payload");
// propagate RM response context to higher layers
msgContext.put(RMConstant.REQUEST_CONTEXT, rmResponseContext);
msgContext.setScope(RMConstant.REQUEST_CONTEXT, Scope.APPLICATION);
return true;
}
}
|