List of usage examples for javax.xml.soap SOAPMessage getSOAPPart
public abstract SOAPPart getSOAPPart();
From source file:it.cnr.icar.eric.common.soap.SOAPSender.java
/** * * Creates a SOAPMessage with bodyDoc as only child. *///from ww w. j av a 2 s. c o m public SOAPMessage createSOAPMessage(Document bodyDoc) throws JAXRException { SOAPMessage msg = null; try { MessageFactory factory = MessageFactory.newInstance(); msg = factory.createMessage(); SOAPPart sp = msg.getSOAPPart(); SOAPEnvelope se = sp.getEnvelope(); //SOAPHeader sh = se.getHeader(); SOAPBody sb = se.getBody(); sb.addDocument(bodyDoc); msg.saveChanges(); } catch (SOAPException e) { e.printStackTrace(); throw new JAXRException(resourceBundle.getString("message.URLNotFound"), e); } return msg; }
From source file:be.fedict.eid.idp.sp.protocol.saml2.artifact.ArtifactServiceClientHandler.java
/** * {@inheritDoc}/*from w ww . j a v a 2 s.co m*/ */ public boolean handleMessage(SOAPMessageContext soapMessageContext) { Boolean outbound = (Boolean) soapMessageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); SOAPMessage soapMessage = soapMessageContext.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); if (outbound) { handleOutboundDocument(soapPart); } else { handleInboundDocument(soapPart); } return true; }
From source file:be.e_contract.dssp.client.WSSecuritySOAPHandler.java
private void handleOutboundMessage(SOAPMessageContext context) throws WSSecurityException, SOAPException { if (null == this.session && null == this.username) { return;/*w w w . j a va 2 s . c om*/ } SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPHeader soapHeader; try { soapHeader = soapMessage.getSOAPHeader(); } catch (SOAPException e) { // WebSphere 8.5.5.1 work-around. soapHeader = null; } if (null == soapHeader) { /* * Work-around for Axis2. */ SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); soapHeader = soapEnvelope.addHeader(); } WSSecHeader wsSecHeader = new WSSecHeader(); Element securityElement = wsSecHeader.insertSecurityHeader(soapPart); if (null != this.session) { securityElement.appendChild( securityElement.getOwnerDocument().importNode(this.session.getSecurityTokenElement(), true)); } WSSecTimestamp wsSecTimeStamp = new WSSecTimestamp(); wsSecTimeStamp.setTimeToLive(60); wsSecTimeStamp.build(soapPart, wsSecHeader); if (null != this.username) { WSSecUsernameToken usernameToken = new WSSecUsernameToken(); usernameToken.setUserInfo(this.username, this.password); usernameToken.setPasswordType(WSConstants.PASSWORD_TEXT); usernameToken.prepare(soapPart); usernameToken.prependToHeader(wsSecHeader); } if (null != this.session) { // work-around for WebSphere WSSConfig wssConfig = new WSSConfig(); wssConfig.setWsiBSPCompliant(false); WSSecSignature wsSecSignature = new WSSecSignature(wssConfig); wsSecSignature.setSignatureAlgorithm(WSConstants.HMAC_SHA1); wsSecSignature.setKeyIdentifierType(WSConstants.CUSTOM_SYMM_SIGNING); wsSecSignature.setCustomTokenId(this.session.getSecurityTokenElement().getAttributeNS( "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "Id")); wsSecSignature.setSecretKey(this.session.getKey()); wsSecSignature.prepare(soapPart, null, wsSecHeader); Vector<WSEncryptionPart> signParts = new Vector<WSEncryptionPart>(); SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(soapPart.getDocumentElement()); signParts.add(new WSEncryptionPart(soapConstants.getBodyQName().getLocalPart(), soapConstants.getEnvelopeURI(), "Content")); signParts.add(new WSEncryptionPart(wsSecTimeStamp.getId())); List<Reference> referenceList = wsSecSignature.addReferencesToSign(signParts, wsSecHeader); wsSecSignature.computeSignature(referenceList, false, null); } /* * Really needs to be at the end for Axis2 to work. Axiom bug? */ appendSecurityHeader(soapHeader, securityElement); }
From source file:com.googlecode.ddom.saaj.SOAPPartTest.java
/** * Tests the behavior of {@link SOAPPart#getContent()} for a plain SOAP message created from an * input stream.//from www. ja v a 2s . c om * * @throws Exception * * @see SOAPMessageTest#testWriteTo() */ @Validated @Test public void testGetContent() throws Exception { MimeHeaders headers = new MimeHeaders(); headers.addHeader("Content-Type", "text/xml; charset=utf-8"); InputStream in = MessageSet.SOAP11.getTestMessage("message.xml"); byte[] orgContent = IOUtils.toByteArray(in); SOAPMessage message = factory.createMessage(headers, new ByteArrayInputStream(orgContent)); // Get the content before accessing the SOAP part Source source1 = message.getSOAPPart().getContent(); assertTrue(source1 instanceof StreamSource); byte[] content1 = IOUtils.toByteArray(((StreamSource) source1).getInputStream()); assertTrue(Arrays.equals(orgContent, content1)); // Now access the SOAP part and get the content again message.getSOAPPart().getEnvelope(); // Note that the fact that we can still access the SOAP part (although we have consumed // the input stream returned by getContent) means that the SAAJ implementation has // copied the content of the stream. Source source2 = message.getSOAPPart().getContent(); // The source is now a DOMSource. assertTrue(source2 instanceof DOMSource); }
From source file:be.e_contract.mycarenet.xkms2.KeyBindingAuthenticationSignatureSOAPHandler.java
@Override public boolean handleMessage(SOAPMessageContext context) { Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (false == outboundProperty) { return true; }/*from ww w . j a va 2s . co m*/ LOG.debug("adding key binding authentication signature"); SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); String requestElementName; if (null != this.prototypeKeyBindingId) { requestElementName = "RegisterRequest"; this.referenceUri = "#" + this.prototypeKeyBindingId; } else if (null != this.revokeKeyBindingId) { requestElementName = "RevokeRequest"; this.referenceUri = "#" + this.revokeKeyBindingId; } else { LOG.error("missing key binding id"); return false; } NodeList requestNodeList = soapPart.getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, requestElementName); Element requestElement = (Element) requestNodeList.item(0); if (null == requestElement) { LOG.error("request element not present"); return false; } Document xkmsDocument; try { xkmsDocument = copyDocument(requestElement); } catch (ParserConfigurationException e) { LOG.error("error copying XKMS request: " + e.getMessage(), e); return false; } NodeList keyBindingAuthenticationNodeList = xkmsDocument .getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, "KeyBindingAuthentication"); Element keyBindingAuthenticationElement = (Element) keyBindingAuthenticationNodeList.item(0); try { prepareDocument(xkmsDocument); addSignature(keyBindingAuthenticationElement); } catch (Exception e) { LOG.error("error adding authn signature: " + e.getMessage(), e); return false; } Node signatureNode = soapPart.importNode(keyBindingAuthenticationElement.getFirstChild(), true); keyBindingAuthenticationNodeList = soapPart.getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, "KeyBindingAuthentication"); keyBindingAuthenticationElement = (Element) keyBindingAuthenticationNodeList.item(0); keyBindingAuthenticationElement.appendChild(signatureNode); return true; }
From source file:com.wandrell.example.swss.test.integration.endpoint.password.plain.wss4j.ITEntityEndpointPasswordPlainWss4j.java
/** * Tests that a message with a wrong password returns a fault. * * @throws Exception//from www . j a v a 2 s .c o m * never, this is a required declaration */ @Test public final void testEndpoint_InvalidPassword_ReturnsFault() throws Exception { final SOAPMessage message; // Response message message = callWebService( SecureSoapMessages.getPlainPasswordMessage(pathValid, username, password + "abc123")); Assert.assertNotNull(message.getSOAPPart().getEnvelope().getBody().getFault()); }
From source file:com.wandrell.example.swss.test.integration.endpoint.password.plain.wss4j.ITEntityEndpointPasswordPlainWss4j.java
/** * Tests that a message with a wrong user returns a fault. * * @throws Exception/*ww w . j a v a2 s . c o m*/ * never, this is a required declaration */ @Test public final void testEndpoint_InvalidUser_ReturnsFault() throws Exception { final SOAPMessage message; // Response message message = callWebService( SecureSoapMessages.getPlainPasswordMessage(pathValid, username + "abc123", password)); Assert.assertNotNull(message.getSOAPPart().getEnvelope().getBody().getFault()); }
From source file:be.fedict.trust.xkms2.WSSecurityServerHandler.java
/** * {@inheritDoc}/* w w w . j a va 2 s. co m*/ */ public boolean handleMessage(SOAPMessageContext soapMessageContext) { LOG.debug("handle message"); Boolean outboundProperty = (Boolean) soapMessageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); SOAPMessage soapMessage = soapMessageContext.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); if (true == outboundProperty.booleanValue()) { handleOutboundDocument(soapPart, soapMessageContext); } else { handleInboundDocument(soapPart, soapMessageContext); } return true; }
From source file:com.wandrell.example.swss.test.integration.endpoint.password.digest.wss4j.ITEntityEndpointPasswordDigestWss4j.java
/** * Tests that a message with a wrong password returns a fault. * * @throws Exception//from ww w. j a va 2 s . c o m * never, this is a required declaration */ @Test public final void testEndpoint_InvalidPassword_ReturnsFault() throws Exception { final SOAPMessage message; // Response message message = callWebService( SecureSoapMessages.getDigestedPasswordMessage(pathValid, username, password + "abc123")); Assert.assertNotNull(message.getSOAPPart().getEnvelope().getBody().getFault()); }
From source file:com.wandrell.example.swss.test.integration.endpoint.password.digest.wss4j.ITEntityEndpointPasswordDigestWss4j.java
/** * Tests that a message with a wrong user returns a fault. * * @throws Exception//from ww w .ja va2s . c om * never, this is a required declaration */ @Test public final void testEndpoint_InvalidUser_ReturnsFault() throws Exception { final SOAPMessage message; // Response message message = callWebService( SecureSoapMessages.getDigestedPasswordMessage(pathValid, username + "abc123", password)); Assert.assertNotNull(message.getSOAPPart().getEnvelope().getBody().getFault()); }