protected void processAttachments(SoapMessage message, SoapBodyInfo sbi) { Collection<Attachment> atts = setupAttachmentOutput(message); List<Object> outObjects = CastUtils.cast(message.getContent(List.class)); String partName = mpi.getConcreteName().getLocalPart(); String ct = (String) mpi.getProperty(Message.CONTENT_TYPE); throw new Fault(new org.apache.cxf.common.i18n.Message("ATTACHMENT_NOT_SUPPORTED", LOG, o.getClass()));
public void handleMessage(SoapMessage message) throws Fault { MessageContentsList list = (MessageContentsList)message.getContent(List.class); Object o = list.remove(0); SOAPMessage soapMessage = null; soapMessage = (SOAPMessage)o; if (soapMessage.countAttachments() > 0) { message.put("write.attachments", Boolean.TRUE); message.getVersion().getSender()); BindingOperationInfo bop = message.getExchange().getBindingOperationInfo(); DocumentFragment frag = soapMessage.getSOAPPart().createDocumentFragment(); try { while (nd != null) { if (nd instanceof SOAPFault) { message.put(Message.RESPONSE_CODE, 500); validateFault(message, (SOAPFault)nd, bop); message.setContent(SOAPMessage.class, soapMessage); if (!message.containsKey(SAAJOutInterceptor.ORIGINAL_XML_WRITER)) { XMLStreamWriter origWriter = message.getContent(XMLStreamWriter.class); message.put(SAAJOutInterceptor.ORIGINAL_XML_WRITER, origWriter); message.setContent(XMLStreamWriter.class, writer); message.setContent(SOAPMessage.class, soapMessage); .getContextualProperty(AbstractOutDatabindingInterceptor.OUT_BUFFERING);
protected void updateHeader(Exchange exchange, MessageContext ctx) { if (ctx.containsKey(Header.HEADER_LIST) && ctx.get(Header.HEADER_LIST) instanceof List<?>) { List<?> list = (List<?>) ctx.get(Header.HEADER_LIST); if (list != null && !list.isEmpty()) { SoapMessage sm = (SoapMessage) createResponseMessage(exchange); if (sm != null) { Iterator<?> iter = list.iterator(); while (iter.hasNext()) { Header header = (Header) iter.next(); if (header.getDirection() != Header.Direction.DIRECTION_IN && !header.getName().getNamespaceURI(). equals("http://docs.oasis-open.org/wss/2004/01/" + "oasis-200401-wss-wssecurity-secext-1.0.xsd") && !header.getName().getNamespaceURI(). equals("http://docs.oasis-open.org/" + "wss/oasis-wss-wssecurity-secext-1.1.xsd")) { //don't copy over security header, out interceptor chain will take care of it. sm.getHeaders().add(header); } } } } } }
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 validateFault(SoapMessage message, SOAPFault fault, BindingOperationInfo bop) { if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.OUT, message)) { Schema schema = EndpointReferenceUtils.getSchema(message.getExchange().getService() .getServiceInfos().get(0), message.getExchange().getBus()); Detail d = fault.getDetail(); try { validateFaultDetail(d, schema, bop); } catch (Exception e) { throw new SoapFault(e.getMessage(), e, message.getVersion().getReceiver()); } //We validated what we can from a fault standpoint message.put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.FALSE); } }
message.getInterceptorChain().abort(); MessageObserver observer = message.getExchange().get(MessageObserver.class); if (!message.getExchange().isOneWay() && observer != null) { Endpoint e = message.getExchange().getEndpoint(); Message responseMsg = new MessageImpl(); responseMsg.setExchange(message.getExchange()); responseMsg = e.getBinding().createMessage(responseMsg); message.getExchange().setInMessage(responseMsg); SOAPMessage soapMessage = ((SOAPMessageContext)context).getMessage(); responseMsg.put(InterceptorChain.STARTING_AT_INTERCEPTOR_ID, if (!getInvoker(message).isOutbound()) { message.getInterceptorChain().abort(); Endpoint e = message.getExchange().getEndpoint(); if (!message.getExchange().isOneWay()) { Message responseMsg = new MessageImpl(); responseMsg.setExchange(message.getExchange()); responseMsg = e.getBinding().createMessage(responseMsg); message.getExchange().setOutMessage(responseMsg); SOAPMessage soapMessage = ((SOAPMessageContext)context).getMessage(); .getExchange()); responseMsg.setInterceptorChain(chain);
SoapVersion soapVersion = ((SoapMessage)message).getVersion(); if (element != null) { Element bodyElement = (Element)element.getElementsByTagNameNS( element.getNamespaceURI(), soapVersion.getBody() .getLocalPart()).item(0); if (bodyElement != null) { element = (Element)bodyElement.getFirstChild(); QName opeName = new QName(element.getNamespaceURI(), element.getLocalName()); SoapBindingInfo binding = (SoapBindingInfo)soapBindingServer.getEndpoint().getEndpointInfo() .getBinding(); for (BindingOperationInfo op : binding.getOperations()) { if (op.getName().getLocalPart().equals(opeName.getLocalPart())) { return new QName(getPojoService().getNamespaceURI(), opeName.getLocalPart()); throw new Fault(new Exception("Operation must bound on this MessageExchange if use rpc mode")); throw new Fault(new Exception("Operation not bound on this MessageExchange"));
protected Header findSecurityHeader(SoapMessage message, boolean create) { for (Header h : message.getHeaders()) { QName n = h.getName(); if ("Security".equals(n.getLocalPart()) && (n.getNamespaceURI().equals(WSS4JConstants.WSSE_NS) || n.getNamespaceURI().equals(WSS4JConstants.WSSE11_NS))) { return h; } } if (!create) { return null; } Document doc = DOMUtils.getEmptyDocument(); Element el = doc.createElementNS(WSS4JConstants.WSSE_NS, "wsse:Security"); el.setAttributeNS(WSS4JConstants.XMLNS_NS, "xmlns:wsse", WSS4JConstants.WSSE_NS); SoapHeader sh = new SoapHeader(new QName(WSS4JConstants.WSSE_NS, "Security"), el); sh.setMustUnderstand(true); message.getHeaders().add(sh); return sh; }
public void handleMessage(SoapMessage message) { if (message.getContent(Exception.class) != null) { return; SoapVersion soapVersion = message.getVersion(); if (useSOAPEnvelope) { Element soapEnv = DomUtil.createElement(document, new QName( soapVersion.getEnvelope().getNamespaceURI(), soapVersion .getEnvelope().getLocalPart(), "soap")); Element soapBody = DomUtil.createElement(soapEnv, new QName( soapVersion.getBody().getNamespaceURI(), soapVersion .getBody().getLocalPart(), "soap")); setExtraPrefix(message, soapEnv); soapEnv.appendChild(soapBody); Element body = getBodyElement(message); message.setContent(Source.class, new DOMSource(document)); } else { try { XMLStreamReader reader = new StaxJbiWrapper(message); message.setContent(Source.class, new StaxSource(reader)); } catch (UnsupportedOperationException e) { document = createDOMWrapper(message); if (document != null) { message.setContent(Source.class, new DOMSource(document));
private void addPartialResponseHeader(SoapMessage message) { try { // add piggybacked wsa:From header to partial response List<Header> header = message.getHeaders(); Document doc = DOMUtils.getEmptyDocument(); SoapVersion ver = message.getVersion(); Element hdr = doc.createElementNS(ver.getHeader().getNamespaceURI(), ver.getHeader().getLocalPart()); hdr.setPrefix(ver.getHeader().getPrefix()); marshallFrom("urn:piggyback_responder", hdr, getMarshaller()); Element elem = DOMUtils.getFirstElement(hdr); while (elem != null) { Header holder = new Header( new QName(elem.getNamespaceURI(), elem.getLocalName()), elem, null); header.add(holder); elem = DOMUtils.getNextElement(elem); } } catch (Exception e) { verificationCache.put("SOAP header addition failed: " + e); e.printStackTrace(); } }
if (o instanceof Element || o instanceof JAXBElement) { if (header == null) { header = getHeaderFactory().getHeader(msg.getVersion()); Node importedNode = header.getOwnerDocument().importNode(e, true); header.appendChild(importedNode); } else { jaxbEl = (JAXBElement<?>) o; Element lastAdded = (Element)header.getLastChild(); header.removeChild(lastAdded); addIsReferenceParameterMarkerAttribute(lastAdded, maps.getNamespaceURI()); Header holder = new Header(new QName(lastAdded.getNamespaceURI(), lastAdded.getLocalName()), lastAdded); msg.getHeaders().add(holder); } else { LOG.log(Level.WARNING, "IGNORE_NON_ELEMENT_REF_PARAM_MSG", o);
if (partWrapper != null) { if (!JbiConstants.WSDL11_WRAPPER_NAMESPACE.equals(element .getNamespaceURI()) || !JbiConstants.WSDL11_WRAPPER_PART_LOCALNAME .equals(partWrapper.getLocalName())) { throw new Fault(new Exception( "Unexpected part wrapper element '" + QNameUtil.toString(element) + "' expected '{" + "}part'")); NodeList nodes = partWrapper.getChildNodes(); partsContent.add(nodes); List<Header> headerList = message.getHeaders(); List<SoapHeaderInfo> headers = msg.getExtensors(SoapHeaderInfo.class); for (SoapHeaderInfo header : headers) { if (header.getPart().getConcreteName().getNamespaceURI().equals( nl.item(0).getNamespaceURI()) && header.getPart().getConcreteName().getLocalPart() .equals(nl.item(0).getLocalName())) { headerList.add(new Header(header.getPart().getConcreteName(),
Bus b = message.getExchange() == null ? null : message.getExchange().getBus(); HeaderProcessor p = null; if (b != null && b.getExtension(HeaderManager.class) != null) { p = b.getExtension(HeaderManager.class).getHeaderProcessor(elem.getNamespaceURI()); obj = p.getDataBinding().createReader(Node.class).read(elem); SoapHeader shead = new SoapHeader(new QName(elem.getNamespaceURI(), elem.getLocalName()), obj, dataBinding); shead.setDirection(SoapHeader.Direction.DIRECTION_IN); String mu = elem.getAttributeNS(message.getVersion().getNamespace(), message.getVersion().getAttrNameMustUnderstand()); String act = elem.getAttributeNS(message.getVersion().getNamespace(), message.getVersion().getAttrNameRole()); Header oldHdr = message.getHeader( new QName(elem.getNamespaceURI(), elem.getLocalName())); if (oldHdr != null) { message.getHeaders().remove(oldHdr); message.getHeaders().add(shead);
private void readHeaders(XMLStreamReader xmlReader, SoapMessage message) throws XMLStreamException { SoapVersion version = message.getVersion(); XMLStreamReader filteredReader = new PartialXMLStreamReader(xmlReader, version.getBody()); Node nd = message.getContent(Node.class); W3CDOMStreamWriter writer = message.get(W3CDOMStreamWriter.class); Document doc = null; if (writer != null) { StaxUtils.copy(filteredReader, writer); doc = writer.getDocument(); } else if (nd instanceof Document) { doc = (Document)nd; StaxUtils.readDocElements(doc, doc, filteredReader, false, false); } else { doc = StaxUtils.read(filteredReader); message.setContent(Node.class, doc); QName header = version.getHeader(); List<Element> elemList = DOMUtils.findAllElementsByTagNameNS(element, header.getNamespaceURI(), header.getLocalPart()); for (Element elem : elemList) { while (hel != null) { SoapHeader sheader = new SoapHeader(DOMUtils.getElementQName(hel), hel); message.getHeaders().add(sheader); hel = DOMUtils.getNextElement(hel);
protected void prepareStackTrace(SoapMessage message, SoapFault fault) throws Exception { boolean config = MessageUtils.getContextualBoolean(message, Message.FAULT_STACKTRACE_ENABLED, false); if (config && fault.getCause() != null) { StringBuilder sb = new StringBuilder(); String soapNamespace = message.getVersion().getNamespace(); if (detail == null) { Document doc = DOMUtils.getEmptyDocument(); Element stackTrace = doc.createElementNS( Fault.STACKTRACE_NAMESPACE, Fault.STACKTRACE); stackTrace.setTextContent(sb.toString()); detail = doc.createElementNS( soapNamespace, "detail"); fault.setDetail(detail); detail.appendChild(stackTrace); } else { Element stackTrace = detail.getOwnerDocument().createElementNS(Fault.STACKTRACE_NAMESPACE, Fault.STACKTRACE); stackTrace.setTextContent(sb.toString());
@Override public Object getServiceObject(Exchange exchange) { Message inMessage = exchange.getInMessage(); if (inMessage instanceof SoapMessage) { SoapMessage soapMessage = (SoapMessage) inMessage; Header header = soapMessage.getHeader(new QName("uri:org.bimserver.shared", "token")); String token = null; if (header != null) { token = (String) exchange.getSession().get("token"); try { PublicInterface newService = serviceFactory.get(AccessMethod.SOAP).get(interfaceClass); exchange.getSession().put("token", token); return newService; } catch (UserException e) {
private void setFaultMessage(MessageContext mc, Exception exception) { Message msg = ((WrappedMessageContext)mc).getWrappedMessage(); msg.setContent(Exception.class, exception); msg.removeContent(XMLStreamReader.class); msg.removeContent(Source.class); version = ((SoapMessage)msg).getVersion(); SoapFault sf = SoapFault.createFault((Fault)exception, ((SoapMessage)msg).getVersion()); soapFault.setFaultString(sf.getReason()); SAAJUtils.setFaultCode(soapFault, sf.getFaultCode()); new QName("http://cxf.apache.org/faultcode", "HandlerFault")); soapFault.setFaultString(exception.getMessage());
SOAPMessage originalMsg = message.getContent(SOAPMessage.class); SOAPBody body = originalMsg.getSOAPPart().getEnvelope().getBody(); body.removeContents(); .getVersion()); soapFault.setFaultString(sf.getReason()); SAAJUtils.setFaultCode(soapFault, sf.getFaultCode()); soapFault.setFaultString(exception.getMessage()); SAAJUtils.setFaultCode(soapFault, new QName("http://cxf.apache.org/faultcode", "HandleFault"));
public void handleMessage(SoapMessage message) throws Fault { BindingOperationInfo bop = message.getExchange().getBindingOperationInfo(); if (bop == null) { return; String partName = mpi.getConcreteName().getLocalPart(); for (Attachment a : message.getAttachments()) { if (a.getId().startsWith(start)) { DataHandler dh = a.getDataHandler(); throw new Fault(e); o = IOUtils.readBytesFromStream(dh.getInputStream()); } catch (IOException e) { throw new Fault(e); o = ImageIO.read(dh.getInputStream()); } catch (IOException e) { throw new Fault(e);
public void handleMessage(SoapMessage message) throws Fault { List<Header> headers = message.getHeaders(); Header h2 = null; for (Header h : headers) { if ("RelatesTo".equals(h.getName().getLocalPart())) { h2 = h; } } headers.remove(h2); } }