List of usage examples for javax.xml.soap SOAPConstants SOAP_1_1_PROTOCOL
String SOAP_1_1_PROTOCOL
To view the source code for javax.xml.soap SOAPConstants SOAP_1_1_PROTOCOL.
Click Source Link
From source file:org.cerberus.service.soap.impl.SoapService.java
@Override public SOAPMessage createSoapRequest(String envelope, String method) throws SOAPException, IOException, SAXException, ParserConfigurationException { String unescapedEnvelope = StringEscapeUtils.unescapeXml(envelope); boolean is12SoapVersion = SOAP_1_2_NAMESPACE_PATTERN.matcher(unescapedEnvelope).matches(); MimeHeaders headers = new MimeHeaders(); headers.addHeader("SOAPAction", "\"" + method + "\""); headers.addHeader("Content-Type", is12SoapVersion ? SOAPConstants.SOAP_1_2_CONTENT_TYPE : SOAPConstants.SOAP_1_1_CONTENT_TYPE); InputStream input = new ByteArrayInputStream(unescapedEnvelope.getBytes("UTF-8")); MessageFactory messageFactory = MessageFactory .newInstance(is12SoapVersion ? SOAPConstants.SOAP_1_2_PROTOCOL : SOAPConstants.SOAP_1_1_PROTOCOL); return messageFactory.createMessage(headers, input); }
From source file:org.springframework.ws.soap.saaj.SaajSoapMessageFactory.java
public void setSoapVersion(SoapVersion version) { if (SaajUtils.getSaajVersion() >= SaajUtils.SAAJ_13) { if (SoapVersion.SOAP_11 == version) { messageFactoryProtocol = SOAPConstants.SOAP_1_1_PROTOCOL; } else if (SoapVersion.SOAP_12 == version) { messageFactoryProtocol = SOAPConstants.SOAP_1_2_PROTOCOL; } else {/*from w ww. j a va2 s . c o m*/ throw new IllegalArgumentException( "Invalid version [" + version + "]. Expected the SOAP_11 or SOAP_12 constant"); } } else if (SoapVersion.SOAP_11 != version) { throw new IllegalArgumentException("SAAJ 1.1 and 1.2 only support SOAP 1.1"); } }
From source file:org.springframework.ws.soap.saaj.SaajSoapMessageFactory.java
public void afterPropertiesSet() { if (messageFactory == null) { try {/*from ww w . j a v a 2s. com*/ if (SaajUtils.getSaajVersion() >= SaajUtils.SAAJ_13) { if (!StringUtils.hasLength(messageFactoryProtocol)) { messageFactoryProtocol = SOAPConstants.SOAP_1_1_PROTOCOL; } if (logger.isInfoEnabled()) { logger.info("Creating SAAJ 1.3 MessageFactory with " + messageFactoryProtocol); } messageFactory = MessageFactory.newInstance(messageFactoryProtocol); } else if (SaajUtils.getSaajVersion() == SaajUtils.SAAJ_12) { logger.info("Creating SAAJ 1.2 MessageFactory"); messageFactory = MessageFactory.newInstance(); } else if (SaajUtils.getSaajVersion() == SaajUtils.SAAJ_11) { logger.info("Creating SAAJ 1.1 MessageFactory"); messageFactory = MessageFactory.newInstance(); } else { throw new IllegalStateException( "SaajSoapMessageFactory requires SAAJ 1.1, which was not found on the classpath"); } } catch (NoSuchMethodError ex) { throw new SoapMessageCreationException( "Could not create SAAJ MessageFactory. Is the version of the SAAJ specification interfaces [" + SaajUtils.getSaajVersionString() + "] the same as the version supported by the application server?", ex); } catch (SOAPException ex) { throw new SoapMessageCreationException("Could not create SAAJ MessageFactory: " + ex.getMessage(), ex); } } if (logger.isDebugEnabled()) { logger.debug("Using MessageFactory class [" + messageFactory.getClass().getName() + "]"); } }
From source file:org.springframework.ws.soap.saaj.support.SaajUtils.java
private static boolean isSaaj13() { try {/*from w w w .j av a 2 s. c o m*/ ClassUtils.forName(SAAJ_13_CLASS_NAME, SaajUtils.class.getClassLoader()); MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); return true; } catch (ClassNotFoundException ex) { return false; } catch (NoSuchMethodError ex) { return false; } catch (SOAPException ex) { return false; } }
From source file:test.integ.be.agiv.security.Axis2Test.java
@Test public void testWSSecurityHandler() throws Exception { // setup//from w w w . j a v a 2 s . c o m WSSecurityHandler testedInstance = new WSSecurityHandler(); SOAPMessageContext mockContext = EasyMock.createMock(SOAPMessageContext.class); EasyMock.expect(mockContext.get("javax.xml.ws.handler.message.outbound")).andStubReturn(Boolean.TRUE); EasyMock.expect(mockContext.get("be.agiv.security.handler.WSSecurityHandler.token")).andStubReturn(null); String testUsername = "username-" + UUID.randomUUID().toString(); EasyMock.expect(mockContext.get("be.agiv.security.handler.WSSecurityHandler.username")) .andStubReturn(testUsername); EasyMock.expect(mockContext.get("be.agiv.security.handler.WSSecurityHandler.password")) .andStubReturn("password"); EasyMock.expect(mockContext.get("be.agiv.security.handler.WSSecurityHandler.key")).andStubReturn(null); EasyMock.expect(mockContext.get("be.agiv.security.handler.WSSecurityHandler.certificate")) .andStubReturn(null); SOAPMessage soapMessage = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL).createMessage(null, new ByteArrayInputStream( "<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\"><Body>test</Body></Envelope>" .getBytes())); LOG.debug("SOAP message: " + toString(soapMessage.getSOAPPart())); EasyMock.expect(mockContext.getMessage()).andStubReturn(soapMessage); // prepare EasyMock.replay(mockContext); // operate testedInstance.handleMessage(mockContext); // verify EasyMock.verify(mockContext); LOG.debug("SOAP message after handleMessage: " + toString(soapMessage.getSOAPPart())); }
From source file:test.integ.be.fedict.trust.WSSecurityTest.java
@Test public void testWSSecurity() throws Exception { // Setup/*from ww w .j av a 2 s.co m*/ KeyPair keyPair = TestUtils.generateKeyPair(); X509Certificate certificate = TestUtils.generateSelfSignedCertificate(keyPair, "CN=Test"); KeyPair fooKeyPair = TestUtils.generateKeyPair(); X509Certificate fooCertificate = TestUtils.generateSelfSignedCertificate(fooKeyPair, "CN=F00"); this.wsSecurityClientHandler.setServerCertificate(certificate); KeyStoreType keyStoreType = KeyStoreType.PKCS12; String keyStorePassword = "secret"; String keyEntryPassword = "secret"; String alias = "alias"; File tmpP12File = File.createTempFile("keystore-", ".p12"); tmpP12File.deleteOnExit(); TestUtils.persistInKeyStore(tmpP12File, "pkcs12", keyPair.getPrivate(), certificate, keyStorePassword, keyEntryPassword, alias); String keyStorePath = tmpP12File.getAbsolutePath(); MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); InputStream testSoapMessageInputStream = WSSecurityTest.class.getResourceAsStream("/test-soap-message.xml"); assertNotNull(testSoapMessageInputStream); SOAPMessage message = messageFactory.createMessage(null, testSoapMessageInputStream); SOAPMessageContext soapMessageContext = new TestSOAPMessageContext(message, true); soapMessageContext.put(MessageContext.SERVLET_CONTEXT, this.mockServletContext); // Expectations expect(this.mockServletContext.getAttribute(TrustService.class.getName())).andReturn(mockTrustService); expect(this.mockTrustService.getWsSecurityConfig()).andReturn(new WSSecurityConfigEntity("test", true, keyStoreType, keyStorePath, keyStorePassword, keyEntryPassword, alias)); // Replay replay(this.mockObjects); // Operate : Let WSSecurityServerHandler sign the SOAP message assertTrue(this.wsSecurityServerHandler.handleMessage(soapMessageContext)); // Verify message is signed verify(this.mockObjects); SOAPMessage resultMessage = soapMessageContext.getMessage(); SOAPPart resultSoapPart = resultMessage.getSOAPPart(); LOG.debug("signed SOAP part:" + TestUtils.domToString(resultSoapPart)); Element nsElement = resultSoapPart.createElement("nsElement"); nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:soap", "http://schemas.xmlsoap.org/soap/envelope/"); nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"); nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:ds", "http://www.w3.org/2000/09/xmldsig#"); nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"); Node resultNode = XPathAPI.selectSingleNode(resultSoapPart, "/soap:Envelope/soap:Header/wsse:Security[@soap:mustUnderstand = '1']", nsElement); assertNotNull(resultNode); assertNotNull("missing WS-Security timestamp", XPathAPI.selectSingleNode(resultSoapPart, "/soap:Envelope/soap:Header/wsse:Security/wsu:Timestamp/wsu:Created", nsElement)); assertEquals(2.0, XPathAPI.eval(resultSoapPart, "count(//ds:Reference)", nsElement).num()); // Setup soapMessageContext.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, false); // Operate : pass on signed message to WSSecurityClientHandler for // validation assertTrue(this.wsSecurityClientHandler.handleMessage(soapMessageContext)); // Operate : pass on signed message to WSSecurityClient handler // configured with wrong server certificate this.wsSecurityClientHandler.setServerCertificate(fooCertificate); try { this.wsSecurityClientHandler.handleMessage(soapMessageContext); fail(); } catch (SOAPFaultException e) { // expected LOG.debug("SOAPFaultException: " + e.getMessage()); } }
From source file:test.unit.be.agiv.security.handler.WSSecurityHandlerTest.java
@Test public void testUsernameToken() throws Exception { // setup/*from ww w . j ava2 s . c o m*/ WSSecurityHandler testedInstance = new WSSecurityHandler(); SOAPMessageContext mockContext = EasyMock.createMock(SOAPMessageContext.class); EasyMock.expect(mockContext.get("javax.xml.ws.handler.message.outbound")).andStubReturn(Boolean.TRUE); String testUsername = "username-" + UUID.randomUUID().toString(); testedInstance.setCredentials(testUsername, "password"); SOAPMessage soapMessage = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL).createMessage(null, new ByteArrayInputStream( "<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\"><Body>test</Body></Envelope>" .getBytes())); LOG.debug("SOAP message: " + toString(soapMessage.getSOAPPart())); EasyMock.expect(mockContext.getMessage()).andStubReturn(soapMessage); // prepare EasyMock.replay(mockContext); // operate testedInstance.handleMessage(mockContext); // verify EasyMock.verify(mockContext); LOG.debug("SOAP message after handleMessage: " + toString(soapMessage.getSOAPPart())); Element nsElement = getNSElement(soapMessage.getSOAPPart()); String resultUsername = XPathAPI.selectSingleNode(soapMessage.getSOAPPart(), "soap:Envelope/soap:Header/wsse:Security/wsse:UsernameToken/wsse:Username/text()", nsElement) .getNodeValue(); assertEquals(testUsername, resultUsername); }