private boolean saveRequestHeaders(SOAPMessageContext context) { Object[] headers = context.getHeaders(COMMON_HEADER_CONVERTER.getXmlRootElementName(), COMMON_HEADER_CONVERTER.getJaxbContext(), false); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Found " + headers.length + " headers: " + Arrays.toString(headers)); } if (headers.length == 1 && headers[0] instanceof JAXBElement<?> && ((JAXBElement<?>) headers[0]).getValue() instanceof CommonHeaderType) { CommonHeaderType nsiHeaders = (CommonHeaderType) ((JAXBElement<?>) headers[0]).getValue(); context.put(SAVED_HEADERS_PROPERTY, nsiHeaders); context.setScope(SAVED_HEADERS_PROPERTY, Scope.HANDLER); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Saving headers " + nsiHeaders + " to context"); } } else { LOGGER.info("No NSI headers present or headers did not match type: " + Arrays.toString(headers)); } return true; }
protected Map<String, Object> prepareRequest(Exchange camelExchange, org.apache.cxf.message.Exchange cxfExchange) throws Exception { // create invocation context WrappedMessageContext requestContext = new WrappedMessageContext( new HashMap<String, Object>(), null, Scope.APPLICATION); camelExchange.setProperty(Message.MTOM_ENABLED, String.valueOf(endpoint.isMtomEnabled())); // set data format mode in exchange DataFormat dataFormat = endpoint.getDataFormat(); camelExchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, dataFormat); LOG.trace("Set Camel Exchange property: {}={}", DataFormat.class.getName(), dataFormat); if (endpoint.getMergeProtocolHeaders()) { camelExchange.setProperty(CxfConstants.CAMEL_CXF_PROTOCOL_HEADERS_MERGED, Boolean.TRUE); } // set data format mode in the request context requestContext.put(DataFormat.class.getName(), dataFormat); // don't let CXF ClientImpl close the input stream if (dataFormat.dealias() == DataFormat.RAW) { cxfExchange.put(Client.KEEP_CONDUIT_ALIVE, true); LOG.trace("Set CXF Exchange property: {}={}", Client.KEEP_CONDUIT_ALIVE, true); } // bind the request CXF exchange endpoint.getCxfBinding().populateCxfRequestFromExchange(cxfExchange, camelExchange, requestContext); // Remove protocol headers from scopes. Otherwise, response headers can be // overwritten by request headers when SOAPHandlerInterceptor tries to create // a wrapped message context by the copyScoped() method. requestContext.getScopes().remove(Message.PROTOCOL_HEADERS); return requestContext.getWrappedMap(); }
@Override public boolean handleInbound(SOAPMessageContext msgContext) { log.info("handleRequest"); MAPBuilder builder = MAPBuilderFactory.getInstance().getBuilderInstance(); MAP addrProps = builder.inboundMap(msgContext); if (addrProps == null) throw new IllegalStateException("Cannot obtain AddressingProperties"); String clientid = null; MAPEndpoint replyTo = addrProps.getReplyTo(); for (Object obj :replyTo.getReferenceParameters()) { if (obj instanceof Element) { Element el = (Element)obj; QName qname = getElementQName(el); if (qname.equals(IDQN)) { clientid = getTextContent(el); } } else { log.warn("Unsupported reference parameter found: " + obj); } } if (clientid == null) throw new IllegalStateException("Cannot obtain client id"); // put the clientid in the message context msgContext.put("clientid", clientid); msgContext.setScope("clientid", Scope.APPLICATION); return true; }
@Override public boolean handleOutbound(SOAPMessageContext msgContext) { log.info("handleResponse"); MAPBuilder builder = MAPBuilderFactory.getInstance().getBuilderInstance(); MAP inProps = builder.inboundMap(msgContext); MAP outProps = builder.newMap(); outProps.initializeAsDestination(inProps.getReplyTo()); outProps.installOutboundMapOnServerSide(msgContext, outProps); msgContext.setScope(builder.newConstants().getServerAddressingPropertiesOutbound(), Scope.APPLICATION); return true; }
private static void setProperty(SOAPMessageContext context, String name, Object value, boolean logMessage) { context.put(name, value); context.setScope(name, Scope.APPLICATION); if (logMessage && log.isDebugEnabled()) { log.debug(name + " :" + value); } }
@Override public Object get(Object key) { // WARNING: there's no real guarantee that the reason a migrator is getting // a property is due to it being put on the MessageContext. // We would therefore be setting scope for a property that never actually makes // its way into the messageContext. Object obj = userMap.get(key); if (obj != null) { mepCtx.setScope((String)key, Scope.APPLICATION); } return obj; }
public Object next() { // WARNING: there's no real guarantee that the reason a migrator is iterating // over the properties is due to this being the source object for a putAll(source) // We would therefore be setting scope for a property that never actually makes // its way into the messageContext Map.Entry entry = (Map.Entry)containedIterator.next(); mepCtx.setScope((String)entry.getKey(), Scope.APPLICATION); return entry; }
@Override public Object put(String key, Object value) { // notice the logic here! We won't put a property on the userMap that is not APPLICATION scoped if (mepCtx.getScope(key) == Scope.APPLICATION) { return userMap.put(key, value); } return null; }
@Override public boolean containsKey(Object key) { if (mepCtx.getScope((String)key) == Scope.APPLICATION) { return userMap.containsKey(key); } return false; }
@Test public void shouldStartTransactionOnInboundMessage() { when(context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)).thenReturn(false); when(transactionManager.getTransaction(null)).thenReturn(transactionStatus); assertThat(subject.handleMessage(context), is(true)); verify(transactionManager).getTransaction(null); verify(context).put(TransactionSoapHandler.TRANSACTION_PROPERTY, transactionStatus); verify(context).setScope(TransactionSoapHandler.TRANSACTION_PROPERTY, Scope.HANDLER); }
@Override public void handleMessage(SoapMessage message) throws Fault { WrappedMessageContext ctx = new WrappedMessageContext(message, Scope.APPLICATION); WebServiceContextImpl.setMessageContext(ctx); }