List of usage examples for javax.xml.soap SOAPMessage getSOAPBody
public SOAPBody getSOAPBody() throws SOAPException
From source file:org.wso2.carbon.identity.provisioning.connector.UserUpdation.java
/** * Method for create SOAP connection/*from w ww . jav a 2 s . co m*/ */ public static boolean invokeSOAP(String userId, String serviceId, String loginId, String login, String firstName, String name, String mail, String phone, String status, String role, String extraFields) throws IdentityProvisioningException { try { SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapConnection = soapConnectionFactory.createConnection(); String url = InweboConnectorConstants.INWEBO_URL; SOAPMessage soapResponse = soapConnection.call(createUserObject(userId, serviceId, loginId, login, firstName, name, mail, phone, status, role, extraFields), url); String updationStatus = soapResponse.getSOAPBody().getElementsByTagName("loginUpdateReturn").item(0) .getTextContent().toString(); soapConnection.close(); boolean processStatus = StringUtils.equals("OK", updationStatus); if (!processStatus) { String error = soapResponse.getSOAPBody().getElementsByTagName("loginUpdateReturn").item(0) .getTextContent().toString(); throw new IdentityProvisioningException( "Error occurred while updating the user in InWebo:" + error); } return processStatus; } catch (SOAPException e) { throw new IdentityProvisioningException("Error occurred while sending SOAP Request to Server", e); } catch (IdentityProvisioningException e) { throw new IdentityProvisioningException("Error occurred while sending SOAP Request to Server", e); } }
From source file:org.wso2.carbon.identity.sso.saml.servlet.SAMLArtifactResolveServlet.java
/** * All requests are handled by this handleRequest method. Request should come with a soap envelop that * wraps an ArtifactResolve object. First we try to extract resolve object and if successful, call * handle artifact method.//from w w w . j a v a 2 s . c om * * @param req HttpServletRequest object received. * @param resp HttpServletResponse object to be sent. * @throws ServletException * @throws IOException */ private void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { ArtifactResolve artifactResolve = null; try { MessageFactory messageFactory = MessageFactory.newInstance(); InputStream inStream = req.getInputStream(); SOAPMessage soapMessage = messageFactory.createMessage(new MimeHeaders(), inStream); if (log.isDebugEnabled()) { OutputStream outputStream = new ByteArrayOutputStream(); soapMessage.writeTo(outputStream); log.debug("SAML2 Artifact Resolve request received: " + outputStream.toString()); } SOAPBody soapBody = soapMessage.getSOAPBody(); Iterator iterator = soapBody.getChildElements(); while (iterator.hasNext()) { SOAPBodyElement artifactResolveElement = (SOAPBodyElement) iterator.next(); if (StringUtils.equals(SAMLConstants.SAML20P_NS, artifactResolveElement.getNamespaceURI()) && StringUtils.equals(ArtifactResolve.DEFAULT_ELEMENT_LOCAL_NAME, artifactResolveElement.getLocalName())) { DOMSource source = new DOMSource(artifactResolveElement); StringWriter stringResult = new StringWriter(); TransformerFactory.newInstance().newTransformer().transform(source, new StreamResult(stringResult)); artifactResolve = (ArtifactResolve) SAMLSSOUtil.unmarshall(stringResult.toString()); } } } catch (SOAPException e) { throw new ServletException("Error while extracting SOAP body from the request.", e); } catch (TransformerException e) { throw new ServletException("Error while extracting ArtifactResponse from the request.", e); } catch (IdentityException e) { throw new ServletException("Error while unmarshalling ArtifactResponse from the request.", e); } if (artifactResolve != null) { handleArtifact(req, resp, artifactResolve); } else { log.error("Invalid SAML Artifact Resolve request received."); } } finally { SAMLSSOUtil.removeSaaSApplicationThreaLocal(); SAMLSSOUtil.removeUserTenantDomainThreaLocal(); SAMLSSOUtil.removeTenantDomainFromThreadLocal(); } }
From source file:ru.codeinside.gws.core.cproto.ExportChargeITest.java
@Test public void testParseSampleRequest() throws Exception { SOAPMessage soapResource = R.getSoapResource("gmp/export_charge/sample_request.xml"); ClientResponse response = new ClientResponse(); response.action = new QName("http://roskazna.ru/SmevUnifoService/", "UnifoTransferMsg"); response.verifyResult = new VerifyResult(null, null, null); response.appData = (Element) soapResource.getSOAPBody() .getElementsByTagNameNS("http://smev.gosuslugi.ru/rev111111", "AppData").item(0); assertNotNull(response.appData);/*from w w w .j ava 2s. c om*/ DummyContext context = createContext(); client.processClientResponse(response, context); assertNotNull(context.getVariable("BillDate_1")); }
From source file:ru.codeinside.gws.core.cproto.ExportPaymentITest.java
@Test @Ignore//from ww w . j a va 2s .c om public void testParseSampleRequest() throws Exception { SOAPMessage soapResource = R.getSoapResource("gmp/export_charge/sample_request.xml"); ClientResponse response = new ClientResponse(); response.action = new QName("http://roskazna.ru/SmevUnifoService/", "UnifoTransferMsg"); response.verifyResult = new VerifyResult(null, null, null); response.appData = (Element) soapResource.getSOAPBody() .getElementsByTagNameNS("http://smev.gosuslugi.ru/rev111111", "AppData").item(0); assertNotNull(response.appData); DummyContext context = createContext(); client.processClientResponse(response, context); assertNotNull(context.getVariable("BillDate_1")); }
From source file:ru.codeinside.gws3572c.GMPClientSignTest.java
@Test public void validateGMPSample() throws Exception { SOAPMessage sampleDoc = R.getSoapResource("gmp/gmd_sample.xml"); SOAPBody soapBody = sampleDoc.getSOAPBody(); Element unifoTransferMsg = first(soapBody, null, "UnifoTransferMsg"); Assert.assertNotNull(unifoTransferMsg); Element messageData = first(unifoTransferMsg, null, "MessageData"); Assert.assertNotNull(messageData);//w ww . j ava2s .c om Element appData = first(messageData, null, "AppData"); Assert.assertNotNull(appData); Element importData = first(appData, null, "ImportData"); Assert.assertNotNull(importData); Element importRequest = first(importData, "http://roskazna.ru/xsd/PGU_ImportRequest", "ImportRequest"); Assert.assertNotNull("importRequest not found", importRequest); Element charge = first(importRequest, null, "Charge"); Assert.assertNotNull("charge not found", charge); Document docEntity = createDocumentFromElement(charge); Assert.assertNotNull("doc from charge null", docEntity); Assert.assertTrue(" ", signDocVer(docEntity)); }
From source file:test.unit.be.agiv.security.handler.WSSecurityHandlerTest.java
@Test public void testVerifyTimestamp() throws Exception { // setup/*from w ww .j a v a 2 s. com*/ SOAPMessageContext mockContext = EasyMock.createMock(SOAPMessageContext.class); EasyMock.expect(mockContext.get("javax.xml.ws.handler.message.outbound")).andStubReturn(Boolean.FALSE); SOAPMessage soapMessage = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage(); SOAPBody soapBody = soapMessage.getSOAPBody(); soapBody.addBodyElement(new QName("test")); SOAPPart soapPart = soapMessage.getSOAPPart(); WSSecHeader secHeader = new WSSecHeader(); secHeader.insertSecurityHeader(soapPart); WSSecTimestamp timestamp = new WSSecTimestamp(); timestamp.build(soapPart, secHeader); LOG.debug("SOAP message: " + toString(soapMessage.getSOAPPart())); EasyMock.expect(mockContext.getMessage()).andStubReturn(soapMessage); // prepare EasyMock.replay(mockContext); // operate boolean result = this.testedInstance.handleMessage(mockContext); // verify EasyMock.verify(mockContext); assertTrue(result); }
From source file:test.unit.be.agiv.security.handler.WSSecurityHandlerTest.java
@Test public void testVerifyTimestampMissing() throws Exception { // setup// ww w. j av a2 s . c om SOAPMessageContext mockContext = EasyMock.createMock(SOAPMessageContext.class); EasyMock.expect(mockContext.get("javax.xml.ws.handler.message.outbound")).andStubReturn(Boolean.FALSE); SOAPMessage soapMessage = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage(); SOAPBody soapBody = soapMessage.getSOAPBody(); soapBody.addBodyElement(new QName("test")); LOG.debug("SOAP message: " + toString(soapMessage.getSOAPPart())); EasyMock.expect(mockContext.getMessage()).andStubReturn(soapMessage); // prepare EasyMock.replay(mockContext); // operate try { this.testedInstance.handleMessage(mockContext); fail(); } catch (ProtocolException e) { // verify EasyMock.verify(mockContext); } }