List of usage examples for javax.xml.soap SOAPFactory newInstance
public static SOAPFactory newInstance() throws SOAPException
From source file:com.qubit.solution.fenixedu.bennu.webservices.services.client.WebServiceClientHandler.java
public boolean handleMessage(SOAPMessageContext smc) { boolean isOutbound = (Boolean) smc.get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY); if (isOutbound) { try {//from ww w .j a va 2s .c o m final byte[] sessionKey = generateAESKey(); final String encriptedPassword = cypher(sessionKey, password); final String encriptedTimestamp = cypher(sessionKey, getTimestamp()); final String nonce = cypherSessionKey(getPublicKey(), sessionKey); SOAPEnvelope envelope = smc.getMessage().getSOAPPart().getEnvelope(); SOAPFactory soapFactory = SOAPFactory.newInstance(); // WSSecurity <Security> header SOAPElement wsSecHeaderElm = soapFactory.createElement("Security", AUTH_PREFIX, AUTH_NS); SOAPElement userNameTokenElm = soapFactory.createElement("UsernameToken", AUTH_PREFIX, AUTH_NS); // Username SOAPElement userNameElm = soapFactory.createElement("Username", AUTH_PREFIX, AUTH_NS); userNameElm.addTextNode(username); // Password SOAPElement passwdElm = soapFactory.createElement("Password", AUTH_PREFIX, AUTH_NS); passwdElm.addTextNode(encriptedPassword); // Nonce SOAPElement nonceElm = soapFactory.createElement("Nonce", AUTH_PREFIX, AUTH_NS); nonceElm.addTextNode(nonce); // Created SOAPElement createdElm = soapFactory.createElement("Created", AUTH_PREFIX, AUTH_NS); createdElm.addTextNode(encriptedTimestamp); userNameTokenElm.addChildElement(userNameElm); userNameTokenElm.addChildElement(passwdElm); userNameTokenElm.addChildElement(nonceElm); userNameTokenElm.addChildElement(createdElm); // add child elements to the root element wsSecHeaderElm.addChildElement(userNameTokenElm); SOAPHeader sh = envelope.getHeader(); if (sh == null) { // create SOAPHeader instance for SOAP envelope sh = envelope.addHeader(); } // add SOAP element for header to SOAP header object sh.addChildElement(wsSecHeaderElm); } catch (Exception e) { throw new RuntimeException("Problems in the securityHandler", e); } } return true; }
From source file:it.cnr.icar.eric.common.cms.AbstractService.java
protected SOAPElement getSOAPElementFromBindingObject(Object obj) throws Exception { SOAPElement soapElem = null;/*from w w w. jav a 2 s .c o m*/ SOAPElement parent = SOAPFactory.newInstance().createElement("dummy"); Marshaller marshaller = getJAXBContext().createMarshaller(); marshaller.marshal(obj, System.err); marshaller.marshal(obj, new DOMResult(parent)); soapElem = (SOAPElement) parent.getChildElements().next(); return soapElem; }
From source file:be.agiv.security.handler.WSAddressingHandler.java
private void handleOutboundMessage(SOAPMessageContext context) throws SOAPException { LOG.debug("adding WS-Addressing headers"); SOAPEnvelope envelope = context.getMessage().getSOAPPart().getEnvelope(); SOAPHeader header = envelope.getHeader(); if (null == header) { header = envelope.addHeader();// ww w.j a va 2s .co m } String wsuPrefix = null; String wsAddrPrefix = null; Iterator namespacePrefixesIter = envelope.getNamespacePrefixes(); while (namespacePrefixesIter.hasNext()) { String namespacePrefix = (String) namespacePrefixesIter.next(); String namespace = envelope.getNamespaceURI(namespacePrefix); if (WSConstants.WS_ADDR_NAMESPACE.equals(namespace)) { wsAddrPrefix = namespacePrefix; } else if (WSConstants.WS_SECURITY_UTILITY_NAMESPACE.equals(namespace)) { wsuPrefix = namespacePrefix; } } if (null == wsAddrPrefix) { wsAddrPrefix = getUniquePrefix("a", envelope); envelope.addNamespaceDeclaration(wsAddrPrefix, WSConstants.WS_ADDR_NAMESPACE); } if (null == wsuPrefix) { /* * Using "wsu" is very important for the IP-STS X509 credential. * Apparently the STS refuses when the namespace prefix of the * wsu:Id on the WS-Addressing To element is different from the * wsu:Id prefix on the WS-Security timestamp. */ wsuPrefix = "wsu"; envelope.addNamespaceDeclaration(wsuPrefix, WSConstants.WS_SECURITY_UTILITY_NAMESPACE); } SOAPFactory factory = SOAPFactory.newInstance(); SOAPHeaderElement actionHeaderElement = header .addHeaderElement(new QName(WSConstants.WS_ADDR_NAMESPACE, "Action", wsAddrPrefix)); actionHeaderElement.setMustUnderstand(true); actionHeaderElement.addTextNode(this.action); SOAPHeaderElement messageIdElement = header .addHeaderElement(new QName(WSConstants.WS_ADDR_NAMESPACE, "MessageID", wsAddrPrefix)); String messageId = "urn:uuid:" + UUID.randomUUID().toString(); context.put(MESSAGE_ID_CONTEXT_ATTRIBUTE, messageId); messageIdElement.addTextNode(messageId); SOAPHeaderElement replyToElement = header .addHeaderElement(new QName(WSConstants.WS_ADDR_NAMESPACE, "ReplyTo", wsAddrPrefix)); SOAPElement addressElement = factory.createElement("Address", wsAddrPrefix, WSConstants.WS_ADDR_NAMESPACE); addressElement.addTextNode("http://www.w3.org/2005/08/addressing/anonymous"); replyToElement.addChildElement(addressElement); SOAPHeaderElement toElement = header .addHeaderElement(new QName(WSConstants.WS_ADDR_NAMESPACE, "To", wsAddrPrefix)); toElement.setMustUnderstand(true); toElement.addTextNode(this.to); String toIdentifier = "to-id-" + UUID.randomUUID().toString(); toElement.addAttribute(new QName(WSConstants.WS_SECURITY_UTILITY_NAMESPACE, "Id", wsuPrefix), toIdentifier); try { toElement.setIdAttributeNS(WSConstants.WS_SECURITY_UTILITY_NAMESPACE, "Id", true); } catch (UnsupportedOperationException e) { // Axis2 has missing implementation of setIdAttributeNS LOG.error("error setting Id attribute: " + e.getMessage()); } context.put(TO_ID_CONTEXT_ATTRIBUTE, toIdentifier); }
From source file:net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuter.java
public JROlapResult getResult() { try {//from w w w .j a v a 2s . c o m this.sf = SOAPFactory.newInstance(); this.connection = createSOAPConnection(); SOAPMessage queryMessage = createQueryMessage(); URL soapURL = new URL(getSoapUrl()); SOAPMessage resultMessage = executeQuery(queryMessage, soapURL); xmlaResult = new JRXmlaResult(); parseResult(resultMessage); } catch (MalformedURLException e) { throw new JRRuntimeException(e); } catch (SOAPException e) { throw new JRRuntimeException(e); } return xmlaResult; }
From source file:com.jkoolcloud.tnt4j.streams.custom.inputs.CastIronWsStream.java
/** * Appends SOAP request message with {@code "sessionId"} header having token received from scenario {@code "login"} * step and saved in streams cache./*from w ww .j a v a2 s .com*/ * * @param soapRequest * SOAP request message instance * @throws javax.xml.soap.SOAPException * if there was an error adding the SOAP message header */ @Override protected void addSoapHeaders(SOAPMessage soapRequest) throws SOAPException { SOAPFactory soapFactory = SOAPFactory.newInstance(); SOAPElement sessionIdElem = soapFactory.createElement("sessionId", "sec", // NON-NLS "http://www.approuter.com/schemas/2008/1/security"); // NON-NLS String cachedToken = String.valueOf(StreamsCache.getValue(tokenCacheKey)); logger().log(OpLevel.DEBUG, StreamsResources.getBundle(WsStreamConstants.RESOURCE_BUNDLE_NAME), "CastIronStream.adding.req.header", sessionIdElem.getLocalName(), cachedToken); sessionIdElem.setTextContent(cachedToken); soapRequest.getSOAPHeader().addChildElement(sessionIdElem); }
From source file:com.snaplogic.snaps.checkfree.SoapExecuteTest.java
@Before public void setup() { injector = Guice.createInjector(new Module() { @Override/* ww w .java 2 s .c o m*/ public void configure(final Binder binder) { binder.bind(ClientBuilderFactory.class).to(ClientBuilderFactoryImpl.class); binder.bind(InvocationService.class).to(MockInvocationService.class); DocumentBuilderFactory documentBuilderFactory = getDocumentBuilderFactory(); binder.bind(DocumentBuilderFactory.class).toInstance(documentBuilderFactory); binder.bind(IntrospectionService.class).to(WsdlIntrospectionService.class).in(Scopes.SINGLETON); TransformerFactory transformerFactory = TransformerFactory.newInstance(); binder.bind(TransformerFactory.class).toInstance(transformerFactory); SOAPFactory soapFactory; try { soapFactory = SOAPFactory.newInstance(); binder.bind(SOAPFactory.class).toInstance(soapFactory); } catch (SOAPException e) { fail("Failed to create soap factory"); } binder.bind(XmlUtils.class).to(XmlUtilsImpl.class).in(Scopes.SINGLETON); binder.bind(TemplateEvaluator.class).to(SOAPExecuteTemplateEvaluatorImpl.class) .in(Scopes.SINGLETON); binder.bind(EditorContentProvider.class).to(XMLEditorContentProviderImpl.class); binder.bind(JsonEditorContentProvider.class).to(JsonEditorContentProviderImpl.class); } }); }
From source file:be.fedict.eid.idp.protocol.saml2.artifact.ArtifactServiceServerHandler.java
private SOAPFaultException createSOAPFaultException(String faultString) { SOAPFault soapFault;/*from w ww .j a v a2 s. c o m*/ try { SOAPFactory soapFactory = SOAPFactory.newInstance(); soapFault = soapFactory.createFault(); soapFault.setFaultString(faultString); } catch (SOAPException e) { throw new RuntimeException("SOAP error"); } return new SOAPFaultException(soapFault); }
From source file:be.fedict.trust.xkms2.WSSecurityServerHandler.java
public static SOAPFaultException createSOAPFaultException(String faultString, String wsseFaultCode) { SOAPFault soapFault;/*from w w w .j a va2 s . com*/ try { SOAPFactory soapFactory = SOAPFactory.newInstance(); soapFault = soapFactory.createFault(faultString, new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", wsseFaultCode, "wsse")); } catch (SOAPException e) { throw new RuntimeException("SOAP error"); } return new SOAPFaultException(soapFault); }
From source file:org.apache.taverna.activities.wsdl.T2WSDLSOAPInvoker.java
@Override protected void addSoapHeader(SOAPEnvelope envelope) throws SOAPException { if (wsrfEndpointReference != null) { // Extract elements // Add WSA-stuff // Add elements Document wsrfDoc;/* ww w .ja v a 2 s .co m*/ try { wsrfDoc = parseWsrfEndpointReference(wsrfEndpointReference); } catch (Exception e) { logger.warn("Could not parse endpoint reference, ignoring:\n" + wsrfEndpointReference, e); return; } Element wsrfRoot = wsrfDoc.getDocumentElement(); Element endpointRefElem = null; if (!wsrfRoot.getNamespaceURI().equals(WSA200403NS) || !wsrfRoot.getLocalName().equals(ENDPOINT_REFERENCE)) { // Only look for child if the parent is not an EPR NodeList nodes = wsrfRoot.getChildNodes(); for (int i = 0, n = nodes.getLength(); i < n; i++) { Node node = nodes.item(i); if (Node.ELEMENT_NODE == node.getNodeType() && node.getLocalName().equals(ENDPOINT_REFERENCE) && node.getNamespaceURI().equals(WSA200403NS)) { // Support wrapped endpoint reference for backward compatibility // and convenience (T2-677) endpointRefElem = (Element) node; break; } } } if (endpointRefElem == null) { logger.warn("Unexpected element name for endpoint reference, but inserting anyway: " + wsrfRoot.getTagName()); endpointRefElem = wsrfRoot; } Element refPropsElem = null; NodeList nodes = endpointRefElem.getChildNodes(); for (int i = 0, n = nodes.getLength(); i < n; i++) { Node node = nodes.item(i); if (Node.ELEMENT_NODE == node.getNodeType() && node.getLocalName().equals(REFERENCE_PROPERTIES) && node.getNamespaceURI().equals(WSA200403NS)) { refPropsElem = (Element) node; break; } } if (refPropsElem == null) { logger.warn("Could not find " + REFERENCE_PROPERTIES); return; } SOAPHeader header = envelope.getHeader(); if (header == null) { header = envelope.addHeader(); } NodeList refProps = refPropsElem.getChildNodes(); for (int i = 0, n = refProps.getLength(); i < n; i++) { Node node = refProps.item(i); if (Node.ELEMENT_NODE == node.getNodeType()) { SOAPElement soapElement = SOAPFactory.newInstance().createElement((Element) node); header.addChildElement(soapElement); Iterator<SOAPHeaderElement> headers = header.examineAllHeaderElements(); while (headers.hasNext()) { SOAPHeaderElement headerElement = headers.next(); if (headerElement.getElementQName().equals(soapElement.getElementQName())) { headerElement.setMustUnderstand(false); headerElement.setActor(null); } } } } } }
From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.olap.OLAPQueryExecuter.java
public JROlapResult createOlapResult() throws Exception { prepareQuery();//ww w . j ava2s. c o m try { IReportConnection conn = IReportManager.getInstance().getDefaultConnection(); if (conn instanceof MondrianConnection) { Connection mconn = ((MondrianConnection) conn).getMondrianConnection(); if (mconn == null) { throw new Exception("The supplied mondrian.olap.Connection object is null."); } Query query = mconn.parseQuery(queryString); xmlaResult = new IROlapResult(); // create result from a Mondrian Query... parseQuery(query); return xmlaResult; //Result result = mconn.execute(query); //return new JRMondrianResult(result); } else if (conn instanceof JRXMLADataSourceConnection) { JRXMLADataSourceConnection xmlaConnection = ((JRXMLADataSourceConnection) conn); xmlaResult = new JRXmlaResult(); try { setAxisSOAPClientConfig(); this.sf = SOAPFactory.newInstance(); this.connection = createSOAPConnection(); SOAPMessage queryMessage = createQueryMessage(xmlaConnection); queryMessage.writeTo(System.out); System.out.println(); URL soapURL = new URL(getSoapUrl(xmlaConnection)); System.out.println("URL: " + soapURL); System.out.flush(); SOAPMessage resultMessage = executeQuery(queryMessage, soapURL); parseResult(resultMessage); } catch (MalformedURLException e) { log.error(e); throw new JRRuntimeException(e); } catch (SOAPException e) { log.error(e); throw new JRRuntimeException(e); } finally { restoreSOAPClientConfig(); } return xmlaResult; } else { throw new Exception( "The supplied Connection is not an OLAP connection. An XML/A or Mondrian connection is required."); } } catch (Exception ex) { ex.printStackTrace(); throw ex; } finally { } }