List of usage examples for javax.xml.soap SOAPEnvelope createName
public abstract Name createName(String localName, String prefix, String uri) throws SOAPException;
From source file:org.pentaho.platform.plugin.action.xmla.XMLABaseComponent.java
private SOAPElement getDiscoverRoot(final SOAPEnvelope envelope, final SOAPElement e) throws XMLAException, SOAPException { Name nRoot = envelope.createName("root", "", XMLABaseComponent.ROWS_URI); //$NON-NLS-1$ //$NON-NLS-2$ SOAPElement eRoot = selectSingleNode(e, nRoot); if (eRoot == null) { throw new XMLAException( Messages.getInstance().getString("XMLABaseComponent.ERROR_0026_NO_ROOT_DISCOVER_ELEMENT")); } //$NON-NLS-1$ return eRoot; }
From source file:org.pentaho.platform.plugin.action.xmla.XMLABaseComponent.java
private SOAPElement getDiscoverRow(final SOAPEnvelope envelope, final SOAPElement e) throws XMLAException, SOAPException { Name nRow = envelope.createName("row", "", XMLABaseComponent.ROWS_URI); //$NON-NLS-1$ //$NON-NLS-2$ SOAPElement eRow = selectSingleNode(e, nRow); if (eRow == null) { throw new XMLAException( Messages.getInstance().getString("XMLABaseComponent.ERROR_0027_NO_DISCOVER_ROW_ELEMENT")); } //$NON-NLS-1$ return eRow;// ww w.j a va 2 s . c om }
From source file:org.springframework.integration.sqs.AWSSecurityHandler.java
/** * {@inheritDoc}/*from w w w .j a va 2 s . c om*/ */ public boolean handleMessage(final SOAPMessageContext context) { logMessage(context); Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (!outboundProperty) { return true; } /* * Example SOAP header from * http://docs.amazonwebservices.com/AWSSimpleQueueService * /2008-01-01/SQSDeveloperGuide * /MakingRequests_MakingSOAPRequestsArticle.html * * <soapenv:Header * xmlns:aws="http://security.amazonaws.com/doc/2007-01-01/"> * <aws:AWSAccessKeyId>1D9FVRAYCP1VJS767E02EXAMPLE</aws:AWSAccessKeyId> * <aws:Timestamp>2008-02-10T23:59:59Z</aws:Timestamp> * <aws:Signature>SZf1CHmQ/nrZbsrC13hCZS061ywsEXAMPLE</aws:Signature> * </soapenv:Header> */ SOAPMessage aSOAPMessage = context.getMessage(); try { SOAPEnvelope aEnvelope = aSOAPMessage.getSOAPPart().getEnvelope(); SOAPHeader aHeader = aEnvelope.addHeader(); String aTimestampStr = this.getTimestamp(); // ADD AWS SECURITY HEADER ---------------------------------------- aHeader.addNamespaceDeclaration(NAMESPACE_AWS_PREFIX, NAMESPACE_AWS); // ADD ACCESS KEY ------------------------------------------------- Name aKeyName = aEnvelope.createName("AWSAccessKeyId", NAMESPACE_AWS_PREFIX, NAMESPACE_AWS); SOAPHeaderElement aKey = aHeader.addHeaderElement(aKeyName); aKey.addTextNode(s_key); // ADD TIMESTAMP -------------------------------------------------- Name aTimestampName = aEnvelope.createName("Timestamp", NAMESPACE_AWS_PREFIX, NAMESPACE_AWS); SOAPHeaderElement aTimestamp = aHeader.addHeaderElement(aTimestampName); aTimestamp.addTextNode(aTimestampStr); // ADD SIGNATURE -------------------------------------------------- Name aSignatureName = aEnvelope.createName("Signature", NAMESPACE_AWS_PREFIX, NAMESPACE_AWS); SOAPHeaderElement aSignature = aHeader.addHeaderElement(aSignatureName); SOAPBody aBody = aEnvelope.getBody(); Iterator<?> aChildren = aBody.getChildElements(); SOAPBodyElement aAction = (SOAPBodyElement) aChildren.next(); if (aChildren.hasNext()) { throw new IllegalStateException( "Unexpected number of actions in soap request. Cannot calculate signature."); } aSignature.addTextNode(this.calculateSignature(aAction.getLocalName(), aTimestampStr)); aSOAPMessage.saveChanges(); logMessage("Final out message: ", aSOAPMessage); } catch (Exception e) { throw new IllegalStateException("Failed to add aws headers!", e); } return true; }
From source file:org.springframework.ws.soap.saaj.support.SaajUtils.java
/** * Converts a {@link QName} to a {@link Name}. A {@link SOAPElement} is required to resolve namespaces. * * @param qName the <code>QName</code> to convert * @param resolveElement a <code>SOAPElement</code> used to resolve namespaces to prefixes * @return the converted SAAJ Name/* www .j a va 2 s .c om*/ * @throws SOAPException if conversion is unsuccessful * @throws IllegalArgumentException if <code>qName</code> is not fully qualified */ public static Name toName(QName qName, SOAPElement resolveElement) throws SOAPException { String qNamePrefix = QNameUtils.getPrefix(qName); SOAPEnvelope envelope = getEnvelope(resolveElement); if (StringUtils.hasLength(qName.getNamespaceURI()) && StringUtils.hasLength(qNamePrefix)) { return envelope.createName(qName.getLocalPart(), qNamePrefix, qName.getNamespaceURI()); } else if (StringUtils.hasLength(qName.getNamespaceURI())) { Iterator<?> prefixes; if (getSaajVersion(resolveElement) == SAAJ_11) { prefixes = resolveElement.getNamespacePrefixes(); } else { prefixes = resolveElement.getVisibleNamespacePrefixes(); } while (prefixes.hasNext()) { String prefix = (String) prefixes.next(); if (qName.getNamespaceURI().equals(resolveElement.getNamespaceURI(prefix))) { return envelope.createName(qName.getLocalPart(), prefix, qName.getNamespaceURI()); } } return envelope.createName(qName.getLocalPart(), "", qName.getNamespaceURI()); } else { return envelope.createName(qName.getLocalPart()); } }
From source file:org.wso2.carbon.identity.sso.saml.util.SAMLSOAPUtils.java
/** * * @param samlRes SAML Response// w w w .ja v a 2 s . c o m * @param acUrl Assertion Consumer URL * @return */ public static String createSOAPMessage(String samlRes, String acUrl) throws TransformerException, SOAPException { SOAPMessage soapMsg; MessageFactory factory = MessageFactory.newInstance(); soapMsg = factory.createMessage(); SOAPPart part = soapMsg.getSOAPPart(); SOAPEnvelope envelope = part.getEnvelope(); SOAPHeader header = envelope.getHeader(); SOAPHeaderElement soapHeaderElement = header.addHeaderElement( envelope.createName(SAMLECPConstants.SOAPECPHeaderElements.SOAP_ECP_HEADER_LOCAL_NAME, SAMLECPConstants.SOAPECPHeaderElements.SOAP_ECP_HEADER_PREFIX, SAMLECPConstants.SOAPECPHeaderElements.SOAP_ECP_HEADER_URI)); soapHeaderElement.setMustUnderstand(true); soapHeaderElement.setActor(SAMLECPConstants.SOAPHeaderElements.SOAP_HEADER_ELEMENT_ACTOR); soapHeaderElement.addAttribute(new QName(SAMLECPConstants.SOAPHeaderElements.SOAP_HEADER_ELEMENT_ACS_URL), acUrl); SOAPBody body = envelope.getBody(); String rawxml = "<![CDATA[" + samlRes + "]]>"; body.addTextNode(rawxml); return convertSOAPMsgToString(soapMsg).replace("<![CDATA[", "").replace("]]>", ""); }
From source file:test.saaj.TestAttachmentSerialization.java
public int saveMsgWithAttachments(OutputStream os) throws Exception { MessageFactory mf = MessageFactory.newInstance(); SOAPMessage msg = mf.createMessage(); SOAPPart sp = msg.getSOAPPart(); SOAPEnvelope envelope = sp.getEnvelope(); SOAPHeader header = envelope.getHeader(); SOAPBody body = envelope.getBody(); SOAPElement el = header.addHeaderElement(envelope.createName("field4", NS_PREFIX, NS_URI)); SOAPElement el2 = el.addChildElement("field4b", NS_PREFIX); SOAPElement el3 = el2.addTextNode("field4value"); el = body.addBodyElement(envelope.createName("bodyfield3", NS_PREFIX, NS_URI)); el2 = el.addChildElement("bodyfield3a", NS_PREFIX); el2.addTextNode("bodyvalue3a"); el2 = el.addChildElement("bodyfield3b", NS_PREFIX); el2.addTextNode("bodyvalue3b"); el2 = el.addChildElement("datefield", NS_PREFIX); AttachmentPart ap = msg.createAttachmentPart(); ap.setContent("some attachment text...", "text/plain"); msg.addAttachmentPart(ap);//w w w . j a v a 2s .com String jpgfilename = "docs/images/axis.jpg"; File myfile = new File(jpgfilename); FileDataSource fds = new FileDataSource(myfile); DataHandler dh = new DataHandler(fds); AttachmentPart ap2 = msg.createAttachmentPart(dh); ap2.setContentType("image/jpg"); msg.addAttachmentPart(ap2); // Test for Bug #17664 if (msg.saveRequired()) { msg.saveChanges(); } MimeHeaders headers = msg.getMimeHeaders(); assertTrue(headers != null); String[] contentType = headers.getHeader("Content-Type"); assertTrue(contentType != null); msg.writeTo(os); os.flush(); return msg.countAttachments(); }