List of usage examples for javax.xml.soap SOAPEnvelope getBody
public SOAPBody getBody() throws SOAPException;
From source file:org.wso2.carbon.identity.provisioning.connector.InweboUserManager.java
private static SOAPMessage deleteUserSOAPMessage(Properties inweboProperties, String loginId, String userId, String serviceId) throws SOAPException { MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); String serverURI = inweboProperties.getProperty(InweboConnectorConstants.INWEBO_URI); SOAPEnvelope envelope = soapPart.getEnvelope(); String namespacePrefix = InweboConnectorConstants.SOAPMessage.SOAP_NAMESPACE_PREFIX; envelope.addNamespaceDeclaration(namespacePrefix, serverURI); SOAPBody soapBody = envelope.getBody(); SOAPElement soapBodyElem = soapBody .addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_ACTION_LOGIN_DELETE, namespacePrefix); SOAPElement soapBodyElem1 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_USER_ID, namespacePrefix);/* w ww . ja va 2s . c o m*/ soapBodyElem1.addTextNode(userId); SOAPElement soapBodyElem2 = soapBodyElem .addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_SERVICE_ID, namespacePrefix); soapBodyElem2.addTextNode(serviceId); SOAPElement soapBodyElem3 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_LOGIN_ID, namespacePrefix); soapBodyElem3.addTextNode(loginId); MimeHeaders headers = soapMessage.getMimeHeaders(); headers.addHeader(InweboConnectorConstants.SOAPMessage.SOAP_ACTION, serverURI + InweboConnectorConstants.SOAPMessage.SOAP_ACTION_HEADER); soapMessage.saveChanges(); return soapMessage; }
From source file:org.wso2.carbon.identity.provisioning.connector.UserCreation.java
private static SOAPMessage createUser(String userId, String serviceId, String login, String firstName, String name, String mail, String phone, String status, String role, String access, String codetype, String language, String extrafields) throws SOAPException, IdentityProvisioningException { MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); String serverURI = InweboConnectorConstants.INWEBO_URI; SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration("con", serverURI); SOAPBody soapBody = envelope.getBody(); SOAPElement soapBodyElem = soapBody.addChildElement("loginCreate", "con"); SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("userid", "con"); soapBodyElem1.addTextNode(userId);// w ww .j av a 2 s . co m SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("serviceid", "con"); soapBodyElem2.addTextNode(serviceId); SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("login", "con"); soapBodyElem3.addTextNode(login); SOAPElement soapBodyElem4 = soapBodyElem.addChildElement("firstname", "con"); soapBodyElem4.addTextNode(firstName); SOAPElement soapBodyElem5 = soapBodyElem.addChildElement("name", "con"); soapBodyElem5.addTextNode(name); SOAPElement soapBodyElem6 = soapBodyElem.addChildElement("mail", "con"); soapBodyElem6.addTextNode(mail); SOAPElement soapBodyElem7 = soapBodyElem.addChildElement("phone", "con"); soapBodyElem7.addTextNode(phone); SOAPElement soapBodyElem8 = soapBodyElem.addChildElement("status", "con"); soapBodyElem8.addTextNode(status); SOAPElement soapBodyElem9 = soapBodyElem.addChildElement("role", "con"); soapBodyElem9.addTextNode(role); SOAPElement soapBodyElem10 = soapBodyElem.addChildElement("access", "con"); soapBodyElem10.addTextNode(access); SOAPElement soapBodyElem11 = soapBodyElem.addChildElement("codetype", "con"); soapBodyElem11.addTextNode(codetype); SOAPElement soapBodyElem12 = soapBodyElem.addChildElement("lang", "con"); soapBodyElem12.addTextNode(language); SOAPElement soapBodyElem13 = soapBodyElem.addChildElement("extrafields", "con"); soapBodyElem13.addTextNode(extrafields); MimeHeaders headers = soapMessage.getMimeHeaders(); headers.addHeader("SOAPAction", serverURI + "/services/ConsoleAdmin"); soapMessage.saveChanges(); return soapMessage; }
From source file:org.wso2.carbon.identity.provisioning.connector.UserDeletion.java
private static SOAPMessage deleteUsers(String loginId, String userId, String serviceId) throws SOAPException, IdentityProvisioningException { MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); try {/*from w ww . ja v a 2 s . com*/ SOAPPart soapPart = soapMessage.getSOAPPart(); String serverURI = InweboConnectorConstants.INWEBO_URI; SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration("con", serverURI); SOAPBody soapBody = envelope.getBody(); SOAPElement soapBodyElem = soapBody.addChildElement("loginDelete", "con"); SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("userid", "con"); soapBodyElem1.addTextNode(userId); SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("serviceid", "con"); soapBodyElem2.addTextNode(serviceId); SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("loginid", "con"); soapBodyElem3.addTextNode(loginId); MimeHeaders headers = soapMessage.getMimeHeaders(); headers.addHeader("SOAPAction", serverURI + "/services/ConsoleAdmin"); soapMessage.saveChanges(); } catch (SOAPException e) { throw new IdentityProvisioningException("Error while delete the user", e); } return soapMessage; }
From source file:org.wso2.carbon.identity.provisioning.connector.UserUpdation.java
private static SOAPMessage createUserObject(String userId, String serviceId, String loginId, String login, String firstName, String name, String mail, String phone, String status, String role, String extraFields) throws SOAPException, IdentityProvisioningException { MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); String serverURI = InweboConnectorConstants.INWEBO_URI; SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration("con", serverURI); SOAPBody soapBody = envelope.getBody(); SOAPElement soapBodyElem = soapBody.addChildElement("loginUpdate", "con"); SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("userid", "con"); soapBodyElem1.addTextNode(userId);//from ww w . j a v a2 s . co m SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("serviceid", "con"); soapBodyElem2.addTextNode(serviceId); SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("loginid", "con"); soapBodyElem3.addTextNode(loginId); SOAPElement soapBodyElem4 = soapBodyElem.addChildElement("login", "con"); soapBodyElem4.addTextNode(login); SOAPElement soapBodyElem5 = soapBodyElem.addChildElement("firstname", "con"); soapBodyElem5.addTextNode(firstName); SOAPElement soapBodyElem6 = soapBodyElem.addChildElement("name", "con"); soapBodyElem6.addTextNode(name); SOAPElement soapBodyElem7 = soapBodyElem.addChildElement("mail", "con"); soapBodyElem7.addTextNode(mail); SOAPElement soapBodyElem8 = soapBodyElem.addChildElement("phone", "con"); soapBodyElem8.addTextNode(phone); SOAPElement soapBodyElem9 = soapBodyElem.addChildElement("status", "con"); soapBodyElem9.addTextNode(status); SOAPElement soapBodyElem10 = soapBodyElem.addChildElement("role", "con"); soapBodyElem10.addTextNode(role); SOAPElement soapBodyElem11 = soapBodyElem.addChildElement("extrafields", "con"); soapBodyElem11.addTextNode(extraFields); MimeHeaders headers = soapMessage.getMimeHeaders(); headers.addHeader("SOAPAction", serverURI + "/services/ConsoleAdmin"); soapMessage.saveChanges(); return soapMessage; }
From source file:org.wso2.carbon.identity.sso.saml.util.SAMLSOAPUtils.java
/** * * Creates a SOAP Fault message including the fault code and fault string. * @param faultString detailed error message * @param faultcode//w w w .j av a2 s .co m * @return */ public static String createSOAPFault(String faultString, String faultcode) throws TransformerException, SOAPException { SOAPMessage soapMsg; MessageFactory factory = MessageFactory.newInstance(); soapMsg = factory.createMessage(); SOAPPart part = soapMsg.getSOAPPart(); SOAPEnvelope envelope = part.getEnvelope(); SOAPBody body = envelope.getBody(); SOAPFault fault = body.addFault(); fault.setFaultString(faultString); fault.setFaultCode(new QName(SAMLECPConstants.SOAPNamespaceURI.SOAP_NAMESPACE_URI, faultcode)); return convertSOAPMsgToString(soapMsg).replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", ""); }
From source file:org.wso2.carbon.identity.sso.saml.util.SAMLSOAPUtils.java
/** * * @param samlRes SAML Response/* www.j a va 2s . 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.functional.TestJAXMSamples.java
public void testJWSFault() throws Exception { try {/*from w ww . j a v a 2s . c om*/ SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance(); SOAPConnection con = scFactory.createConnection(); MessageFactory factory = MessageFactory.newInstance(); SOAPMessage message = factory.createMessage(); SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); SOAPBody body = envelope.getBody(); Name bodyName = envelope.createName("echo"); SOAPBodyElement bodyElement = body.addBodyElement(bodyName); Name name = envelope.createName("arg0"); SOAPElement symbol = bodyElement.addChildElement(name); symbol.addTextNode("Hello"); URLEndpoint endpoint = new URLEndpoint("http://localhost:8080/jws/FaultTest.jws"); SOAPMessage response = con.call(message, endpoint); SOAPBody respBody = response.getSOAPPart().getEnvelope().getBody(); assertTrue(respBody.hasFault()); } catch (javax.xml.soap.SOAPException e) { Throwable t = e.getCause(); if (t != null) { t.printStackTrace(); if (t instanceof AxisFault) { AxisFault af = (AxisFault) t; if ((af.detail instanceof SocketException) || (af.getFaultCode().getLocalPart().equals("HTTP"))) { System.out.println("Connect failure caused testJWSFault to be skipped."); return; } } throw new Exception("Fault returned from test: " + t); } else { e.printStackTrace(); throw new Exception("Exception returned from test: " + e); } } catch (Throwable t) { t.printStackTrace(); throw new Exception("Fault returned from test: " + t); } }
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);// www .ja v a 2 s . co m 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(); }
From source file:unit.test.be.e_contract.mycarenet.ehealth.common.WSSecuritySOAPHandlerTest.java
@Test public void testHandleMessage() throws Exception { KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); KeyPair keyPair = keyPairGenerator.generateKeyPair(); PrivateKey privateKey = keyPair.getPrivate(); String samlAssertion = "<Assertion xmlns=\"urn:oasis:names:tc:SAML:1.0:assertion\"" + " AssertionID=\"_42e7a00652420d86ee884f295a3fbf02\">" + "</Assertion>"; WSSecuritySOAPHandler testedInstance = new WSSecuritySOAPHandler(); testedInstance.setPrivateKey(privateKey); testedInstance.setAssertion(samlAssertion); SOAPMessageContext mockSoapMessageContext = EasyMock.createMock(SOAPMessageContext.class); EasyMock.expect(mockSoapMessageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)).andReturn(true); MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); SOAPBody soapBody = soapEnvelope.getBody(); soapBody.addBodyElement(new QName("http://www.example.com", "Test")); EasyMock.expect(mockSoapMessageContext.getMessage()).andReturn(soapMessage); // prepare/* w w w . j av a2 s .c om*/ EasyMock.replay(mockSoapMessageContext); // operate testedInstance.handleMessage(mockSoapMessageContext); // verify EasyMock.verify(mockSoapMessageContext); LOG.debug(toString(soapPart)); }