@Override protected void initializeProvider(InterceptorProvider provider, Bus bus) { if (contraints == null) { return; } provider.getInInterceptors().add(CertConstraintsInterceptor.INSTANCE); provider.getInFaultInterceptors().add(CertConstraintsInterceptor.INSTANCE); }
private static boolean chainAlreadyContainsSAAJ(SoapMessage message) { ListIterator<Interceptor<? extends Message>> listIterator = message.getInterceptorChain().getIterator(); while (listIterator.hasNext()) { if (listIterator.next() instanceof SAAJOutInterceptor) { return true; } } return false; } }
private void initIntercepors(Client client, AbstractBasicInterceptorProvider clientFact) { client.getInInterceptors().addAll(clientFact.getInInterceptors()); client.getOutInterceptors().addAll(clientFact.getOutInterceptors()); client.getInFaultInterceptors().addAll(clientFact.getInFaultInterceptors()); client.getOutFaultInterceptors().addAll(clientFact.getOutFaultInterceptors()); }
private void write(Source source, Node n) { try { if (source instanceof DOMSource && ((DOMSource)source).getNode() == null) { return; } XMLStreamWriter writer = new W3CDOMStreamWriter((Element)n); StaxUtils.copy(source, writer); } catch (XMLStreamException e) { throw new Fault(e); } }
Exchange exchange = message.getExchange(); Exception ex = new Fault(exception); ic.reset(); ic.doIntercept(faultMessage); throw new Fault(e);
private Collection<Attachment> setupAttachmentOutput(SoapMessage message) { // We have attachments, so add the interceptor message.getInterceptorChain().add(attachOut); // We should probably come up with another property for this message.put(AttachmentOutInterceptor.WRITE_ATTACHMENTS, Boolean.TRUE); Collection<Attachment> atts = message.getAttachments(); if (atts == null) { atts = new ArrayList<>(); message.setAttachments(atts); } return atts; } }
private void handleAbort(Message message, W3CDOMStreamWriter writer) { message.getInterceptorChain().abort(); if (!message.getExchange().isOneWay()) { //server side inbound Endpoint e = message.getExchange().getEndpoint(); Message responseMsg = new MessageImpl(); responseMsg.setExchange(message.getExchange()); responseMsg = e.getBinding().createMessage(responseMsg); message.getExchange().setOutMessage(responseMsg); XMLStreamReader reader = message.getContent(XMLStreamReader.class); if (reader == null && writer != null) { reader = StaxUtils.createXMLStreamReader(writer.getDocument()); } InterceptorChain chain = OutgoingChainInterceptor .getOutInterceptorChain(message.getExchange()); responseMsg.setInterceptorChain(chain); responseMsg.put("LogicalHandlerInterceptor.INREADER", reader); chain.doIntercept(responseMsg); } }
message.getInterceptorChain().abort(); if (!getInvoker(message).isOutbound()) { message.getInterceptorChain().abort(); Endpoint e = message.getExchange().getEndpoint(); if (!message.getExchange().isOneWay()) { InterceptorChain chain = OutgoingChainInterceptor.getOutInterceptorChain(message .getExchange()); responseMsg.setInterceptorChain(chain); chain.doInterceptStartingAfter(responseMsg, SoapPreProtocolOutInterceptor.class.getName());
@Override public void handleFault(Message message) { Exception ex = message.getContent(Exception.class); if (ex instanceof AuthenticationException) { HttpServletResponse resp = (HttpServletResponse)message.getExchange() .getInMessage().get(AbstractHTTPDestination.HTTP_RESPONSE); resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED); resp.setHeader("WWW-Authenticate", authenticationType + " realm=\"" + realm + "\""); resp.setContentType("text/plain"); try { resp.getOutputStream().write(ex.getMessage().getBytes()); resp.getOutputStream().flush(); message.getInterceptorChain().setFaultObserver(null); //avoid return soap fault message.getInterceptorChain().abort(); } catch (IOException e) { // TODO } } }
private void handle401response(Message message, Endpoint e) { HttpServletResponse response = (HttpServletResponse)message.get("HTTP.RESPONSE"); response.setHeader(HEADER_WWW_AUTHENTICATE, AUTHENTICATION_SCHEME_BASIC + " realm=\"" + contextName + "\""); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setContentLength(0); message.getInterceptorChain().pause(); }
protected void updateMessageForSuspend() { inMessage.getExchange().getInMessage().getInterceptorChain().suspend(); } public void redispatch() {
/** * Add annotated Interceptors and Features to the Endpoint * @param ep */ protected void initializeAnnotationInterceptors(Endpoint ep, Class<?> ... cls) { Class<?> seiClass = ((JaxWsServiceFactoryBean)getServiceFactory()) .getJaxWsImplementorInfo().getSEIClass(); if (seiClass != null) { boolean found = false; for (Class<?> c : cls) { if (c.equals(seiClass)) { found = true; } } if (!found) { Class<?>[] cls2 = new Class<?>[cls.length + 1]; System.arraycopy(cls, 0, cls2, 0, cls.length); cls2[cls.length] = seiClass; cls = cls2; } } AnnotationInterceptors provider = new AnnotationInterceptors(cls); initializeAnnotationInterceptors(provider, ep); }
public void run() { try { handleResponseInternal(); } catch (Throwable e) { ((PhaseInterceptorChain)outMessage.getInterceptorChain()).abort(); outMessage.setContent(Exception.class, e); ((PhaseInterceptorChain)outMessage.getInterceptorChain()).unwind(outMessage); MessageObserver mo = outMessage.getInterceptorChain().getFaultObserver(); if (mo == null) { mo = outMessage.getExchange().get(MessageObserver.class); } mo.onMessage(outMessage); } } };
private BufferedImage convertToBufferedImage(Image image) throws IOException { if (image instanceof BufferedImage) { return (BufferedImage)image; } // Wait until the image is completely loaded MediaTracker tracker = new MediaTracker(new Component() { private static final long serialVersionUID = 6412221228374321325L; }); tracker.addImage(image, 0); try { tracker.waitForAll(); } catch (InterruptedException e) { throw new Fault(e); } // Create a BufferedImage so we can write it out later BufferedImage bufImage = new BufferedImage( image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics g = bufImage.createGraphics(); g.drawImage(image, 0, 0, null); return bufImage; }
public void handleMessage(SoapMessage message) { if (binding.getHandlerChain().isEmpty()) { return; } if (getInvoker(message).getProtocolHandlers().isEmpty()) { return; } checkUnderstoodHeaders(message); if (getInvoker(message).isOutbound()) { //The SOAPMessage might be set from the outchain, in this case, //we need to clean it up and create a new SOAPMessage dedicated to fault. message.setContent(SOAPMessage.class, null); SAAJ_OUT.handleMessage(message); message.getInterceptorChain().add(ending); } }
@Override protected void updateMessageForSuspend() { Message currentMessage = PhaseInterceptorChain.getCurrentMessage(); if (currentMessage.get(WriteListener.class) != null) { // CXF Continuation WriteListener will likely need to be introduced // for NIO supported with non-Servlet specific mechanisms getOutputStream().setWriteListener(currentMessage.get(WriteListener.class)); currentMessage.getInterceptorChain().suspend(); } else { inMessage.getExchange().getInMessage().getInterceptorChain().suspend(); } }
public void handleMessage(Message message) throws Fault { if (binding.getHandlerChain().isEmpty()) { return; } HandlerChainInvoker invoker = getInvoker(message); if (invoker.getLogicalHandlers().isEmpty()) { return; } XMLStreamWriter origWriter = message.getContent(XMLStreamWriter.class); Document doc = DOMUtils.newDocument(); message.setContent(Node.class, doc); W3CDOMStreamWriter writer = new W3CDOMStreamWriter(doc); // set up the namespace context try { writer.setNamespaceContext(origWriter.getNamespaceContext()); } catch (XMLStreamException ex) { // don't set the namespaceContext } // Replace stax writer with DomStreamWriter message.setContent(XMLStreamWriter.class, writer); message.put(ORIGINAL_WRITER, origWriter); message.getInterceptorChain().add(ending); }
private void validatePossibleFault(Message message, BindingOperationInfo bop, Node ds) { Element el = DOMUtils.getFirstElement(ds); if (!"Fault".equals(el.getLocalName())) { return; } message.put(Message.RESPONSE_CODE, 500); el = DOMUtils.getFirstElement(el); while (el != null && !"detail".equals(el.getLocalName())) { el = DOMUtils.getNextElement(el); } if (el != null) { Schema schema = EndpointReferenceUtils.getSchema(message.getExchange().getService() .getServiceInfos().get(0), message.getExchange().getBus()); try { validateFaultDetail(el, schema, bop); } catch (Exception e) { throw new Fault(e); } //We validated what we can from a fault standpoint message.put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.FALSE); } } private void validateFaultDetail(Element detail, Schema schema, BindingOperationInfo bop) throws Exception {
@Override public Boolean isWrapped(Method m) { // see if someone overrode the default value if (getServiceFactory().getWrapped() != null) { return getServiceFactory().getWrapped(); } m = getDeclaredMethod(m); SOAPBinding ann = m.getAnnotation(SOAPBinding.class); if (ann != null) { if (ann.style().equals(Style.RPC)) { Message message = new Message("SOAPBinding_MESSAGE_RPC", LOG, m.getName()); throw new Fault(new JaxWsConfigurationException(message)); } return !(ann.parameterStyle().equals(ParameterStyle.BARE)); } return isWrapped(); }