private void registerUnderstoodHeaders(MessageContext request, List<Handler> handlerList) { if (handlerList != null && handlerList.size() > 0) { Set<QName> understoodHeaders = new HashSet<QName>(); // Add the headers from each of the SOAP handlers to the collection for (Handler handler : handlerList) { if(handler instanceof SOAPHandler){ SOAPHandler soapHandler = (SOAPHandler)handler; Set<QName> headers = soapHandler.getHeaders(); if (headers != null && headers.size() > 0) { understoodHeaders.addAll(headers); } } } // Put the understood header qnames on the request context where it can // be found during response processing. if (understoodHeaders != null && understoodHeaders.size() > 0) { if (log.isDebugEnabled()) { log.debug("Adding understood header QName collection to message context " + understoodHeaders); } request.setProperty("client.UnderstoodHeaders", understoodHeaders); } } }
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()); } }
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); } } }
/** * Add a message handler to a SOAP binding * @param binding binding to which we'll add the handler * @param handler the handler to be added */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static void addMessageHandler(Object binding, SOAPHandler<SOAPMessageContext> handler) { final Binding b = ((BindingProvider) binding).getBinding(); List handlerList = b.getHandlerChain(); if (handlerList == null) handlerList = new ArrayList(); handlerList.add(handler); b.setHandlerChain(handlerList); }
/** * Add a message handler to a SOAP binding * @param binding binding to which we'll add the handler * @param index position in the list of handlers * @param handler the handler to be added */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static void addMessageHandler(Object binding, int index, SOAPHandler<SOAPMessageContext> handler) { final Binding b = ((BindingProvider) binding).getBinding(); List handlerList = b.getHandlerChain(); if (handlerList == null) handlerList = new ArrayList(); handlerList.add(index, handler); b.setHandlerChain(handlerList); }
@Override public void setHandlerChain(List<Handler> list) { if (list != null) { for (Handler handler : list) { if (handler instanceof SOAPHandler) { throw new WebServiceException("Chain contains incompatibile handler"); } } } super.setHandlerChain(list); }
private void sortChain() throws WebServiceException { if (handlers.size() == 0) { logicalLength = 0; return; } ArrayList<Handler> logicalHandlers = new ArrayList<Handler>(); ArrayList<Handler> protocolHandlers = new ArrayList<Handler>(); Iterator handlerIterator = handlers.iterator(); while (handlerIterator.hasNext()) { // this is a safe cast since the handlerResolver and binding.setHandlerChain // and InvocationContext.setHandlerChain verifies it before we get here Handler handler = (Handler)handlerIterator.next(); // JAXWS 9.2.1.2 sort them by Logical, then SOAP if (LogicalHandler.class.isAssignableFrom(handler.getClass())) logicalHandlers.add((LogicalHandler) handler); else if (SOAPHandler.class.isAssignableFrom(handler.getClass())) // instanceof ProtocolHandler protocolHandlers.add((SOAPHandler) handler); else if (Handler.class.isAssignableFrom(handler.getClass())) { throw ExceptionFactory.makeWebServiceException(Messages .getMessage("handlerChainErr1", handler.getClass().getName())); } else { throw ExceptionFactory.makeWebServiceException(Messages .getMessage("handlerChainErr2", handler.getClass().getName())); } } logicalLength = logicalHandlers.size(); // JAXWS 9.2.1.2 sort them by Logical, then SOAP handlers.clear(); handlers.addAll(logicalHandlers); handlers.addAll(protocolHandlers); }
/** * registerHandlerHeaders will invoke getHeaders on SOAPHandlers and return a List of headers * that are Understood by the handlers. * @param msgContext * @param handlers */ public static List<QName> registerSOAPHandlerHeaders(MessageContext msgContext, List<Handler> handlers){ List<QName> understood = new ArrayList<QName>(); if(msgContext == null){ return understood; } for(Handler handler:handlers){ if(handler instanceof SOAPHandler){ SOAPHandler soapHandler = (SOAPHandler)handler; //Invoking getHeaders. if(log.isDebugEnabled()){ log.debug("Invoking getHeader() on SOAPHandler"); } Set<QName> headers = soapHandler.getHeaders(); if(headers!=null){ for(QName header:headers){ if(!understood.contains(header)){ if(log.isDebugEnabled()){ log.debug("Adding Header QName" + header + " to uderstoodHeaderQName List"); } //Adding this to understood header list. understood.add(header); } } } } } return understood; }
public static void registerHandlerHeaders(AxisService axisService, List<Handler> handlers) { if (handlers == null || axisService == null) { return; } ArrayList<QName> understoodHeaderQNames = new ArrayList<QName>(); for (Handler handler : handlers) { if (handler instanceof SOAPHandler) { SOAPHandler soapHandler = (SOAPHandler) handler; Set<QName> headers = soapHandler.getHeaders(); if (headers != null) { for (QName header : headers) { if (!understoodHeaderQNames.contains(header)) { understoodHeaderQNames.add(header); } } } } } if (!understoodHeaderQNames.isEmpty()) { Parameter headerQNParameter = new Parameter(EndpointDescription.HANDLER_PARAMETER_QNAMES, understoodHeaderQNames); try { axisService.addParameter(headerQNParameter); } catch (AxisFault e) { log.warn(Messages.getMessage("regHandlerHeadersErr",axisService.getName(),e.getMessage())); } } }
@Override public TraceeClientHandlerResolverBuilder add(SOAPHandler<SOAPMessageContext> handler) { if (handler != null) { this.handlerList.add(handler); } return this; }
@Override public TraceeClientHandlerResolverBuilder add(Class<? extends SOAPHandler<SOAPMessageContext>> handlerType) { if (handlerType != null) { try { SOAPHandler<SOAPMessageContext> handler = handlerType.newInstance(); this.handlerList.add(handler); } catch (Exception e) { logger.error("HandlerResolver of type '" + handlerType.getCanonicalName() + "' couldn't be added to HandlerResolver", e); } } return this; }
@Test public void shouldCreateHandlerResolverAndIgnoreNullValuedHandlerInstance() { HandlerResolver handlerResolver = TraceeClientHandlerResolver.buildHandlerResolver().add((SOAPHandler)null).build(); MatcherAssert.assertThat(handlerResolver, Matchers.notNullValue()); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo), Matchers.notNullValue()); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo).size(), Matchers.is(1)); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo).get(0).getClass(), Matchers.typeCompatibleWith(TraceeClientErrorLoggingHandler.class)); }
@Test public void shouldCreateHandlerResolverAndIgnoreNullValuedHandlerType() { HandlerResolver handlerResolver = TraceeClientHandlerResolver.buildHandlerResolver().add((Class<SOAPHandler<SOAPMessageContext>>)null).build(); MatcherAssert.assertThat(handlerResolver, Matchers.notNullValue()); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo), Matchers.notNullValue()); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo).size(), Matchers.is(1)); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo).get(0).getClass(), Matchers.typeCompatibleWith(TraceeClientErrorLoggingHandler.class)); }
private void setUpHandlersOnce() { handlers = new ArrayList<Handler>(); HandlerConfiguration handlerConfig = ((BindingImpl) binding).getHandlerConfig(); List<SOAPHandler> soapSnapShot= handlerConfig.getSoapHandlers(); if (!soapSnapShot.isEmpty()) { handlers.addAll(soapSnapShot); roles = new HashSet<String>(); roles.addAll(handlerConfig.getRoles()); } }
void setUpProcessor() { // 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) binding).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, binding, handlers); } }
public List<SOAPHandler> getSoapHandlers() { return soapHandlers; }
public SOAPConfigDelegateHandler(SOAPHandler<T> delegate, boolean isPre) { super(delegate, isPre); }
@Override public Set<QName> getHeaders() { return ((SOAPHandler<T>)delegate).getHeaders(); }
@SuppressWarnings({"rawtypes", "unchecked"}) private static List<Handler> convertToHandlers(List<UnifiedHandlerChainMetaData> handlerChains, String bindingID, boolean isPre) { List<Handler> handlers = new LinkedList<Handler>(); if (handlerChains != null && !handlerChains.isEmpty()) { final String protocolBinding = bindingIDs.get(bindingID); for (UnifiedHandlerChainMetaData handlerChain : handlerChains) { if (handlerChain.getPortNamePattern() != null || handlerChain.getServiceNamePattern() != null) { ROOT_LOGGER.filtersNotSupported(); } if (matchProtocolBinding(protocolBinding, handlerChain.getProtocolBindings())) { for (UnifiedHandlerMetaData uhmd : handlerChain.getHandlers()) { if (uhmd.getInitParams() != null && !uhmd.getInitParams().isEmpty()) { ROOT_LOGGER.initParamsNotSupported(); } Object h = newInstance(uhmd.getHandlerClass()); if (h != null) { if (h instanceof Handler) { if (h instanceof LogicalHandler) { handlers.add(new LogicalConfigDelegateHandler((LogicalHandler)h, isPre)); } else if (h instanceof SOAPHandler) { handlers.add(new SOAPConfigDelegateHandler((SOAPHandler)h, isPre)); } else { handlers.add(new ConfigDelegateHandler((Handler)h, isPre)); } } else { throw MESSAGES.notJAXWSHandler(uhmd.getHandlerClass()); } } } } } } return handlers; }
public List<Handler> getHandlerChain(PortInfo portinfo) { ArrayList<Handler> handlers = new ArrayList<Handler>(); Iterator it = handlerChainsType == null ? null : handlerChainsType.getHandlerChain().iterator(); while ((it != null) && (it.hasNext())) { HandlerChainType handlerChainType = ((HandlerChainType)it.next()); // if !match, continue (to next chain) if (!(chainResolvesToPort(handlerChainType, portinfo))) continue; List<HandlerType> handlerTypeList = handlerChainType.getHandler(); Iterator ht = handlerTypeList.iterator(); while (ht.hasNext()) { HandlerType handlerType = (HandlerType)ht.next(); // TODO must do better job comparing the handlerType with the PortInfo param // to see if the current iterator handler is intended for this service. // TODO review: need to check for null getHandlerClass() return? // or will schema not allow it? String portHandler = handlerType.getHandlerClass().getValue(); Handler handler = null; // instantiate portHandler class try { handler = createHandlerInstance(loadClass(portHandler)); } catch (Exception e) { // TODO: should we just ignore this problem? throw ExceptionFactory.makeWebServiceException(e); } if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) { log.debug("Successfully instantiated the class: " + handler.getClass()); } // 9.2.1.2 sort them by Logical, then SOAP if (LogicalHandler.class.isAssignableFrom(handler.getClass())) handlers.add((LogicalHandler) handler); else if (SOAPHandler.class.isAssignableFrom(handler.getClass())) // instanceof ProtocolHandler handlers.add((SOAPHandler) handler); else if (Handler.class.isAssignableFrom(handler.getClass())) { throw ExceptionFactory.makeWebServiceException(Messages .getMessage("handlerChainErr1", handler .getClass().getName())); } else { throw ExceptionFactory.makeWebServiceException(Messages .getMessage("handlerChainErr2", handler .getClass().getName())); } } } return handlers; }
/** * Adds a specific {@link Handler} to the handler chain * * @param handler */ public void addHandler(SOAPHandler<SOAPMessageContext> handler) { this.handlerChain.add(handler); }
/** * Adds an existing {@link javax.xml.ws.handler.soap.SOAPHandler} instance to the HandlerResolver. * @param handler the instance to add * @return this builder instance */ TraceeClientHandlerResolverBuilder add(final SOAPHandler<SOAPMessageContext> handler);