List of usage examples for javax.xml.soap SOAPMessage getSOAPPart
public abstract SOAPPart getSOAPPart();
From source file:org.drools.server.CxfSoapClientServerGridTest.java
private SOAPMessage createMessageForKsession(String ksessionName) throws SOAPException { SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody(); QName payloadName = new QName("http://soap.jax.drools.org", "execute", "ns1"); body.addBodyElement(payloadName);/*from w w w . j a va 2 s. c o m*/ String add = ""; String packages = "org.test"; if (ksessionName.equals("ksession2")) { add = "2"; packages = "org.grid.test"; } String cmd = ""; cmd += "<batch-execution lookup=\"" + ksessionName + "\">\n"; cmd += " <insert out-identifier=\"message\">\n"; cmd += " <" + packages + ".Message" + add + ">\n"; cmd += " <text>Helllo World" + ksessionName + "</text>\n"; cmd += " </" + packages + ".Message" + add + ">\n"; cmd += " </insert>\n"; cmd += " <fire-all-rules/>\n"; cmd += "</batch-execution>\n"; body.addTextNode(cmd); OutputStream os = new ByteArrayOutputStream(); try { soapMessage.writeTo(os); } catch (IOException ex) { Logger.getLogger(CxfSoapClientServerGridTest.class.getName()).log(Level.SEVERE, null, ex); } //System.out.println("SOAP = "+os.toString()); return soapMessage; }
From source file:cn.com.ttblog.ssmbootstrap_table.webservice.LicenseHandler.java
@SuppressWarnings("unchecked") @Override/* w w w . j a v a 2 s . c om*/ public boolean handleMessage(SOAPMessageContext context) { try { Boolean out = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); logger.debug("LicenseHandler:{}", out); if (!out) { SOAPMessage message = context.getMessage(); logger.debug("SOAPMessage:{}", ToStringBuilder.reflectionToString(message)); SOAPEnvelope enve = message.getSOAPPart().getEnvelope(); SOAPHeader header = enve.getHeader(); SOAPBody body = enve.getBody(); Node bn = body.getChildNodes().item(0); String partname = bn.getLocalName(); if ("getUser".equals(partname)) { if (header == null) { // ? SOAPFault fault = body.addFault(); fault.setFaultString("??!"); throw new SOAPFaultException(fault); } Iterator<SOAPHeaderElement> iterator = header.extractAllHeaderElements(); if (!iterator.hasNext()) { // ? SOAPFault fault = body.addFault(); fault.setFaultString("??!"); throw new SOAPFaultException(fault); } while (iterator.hasNext()) { SOAPHeaderElement ele = iterator.next(); System.out.println(ele.getTextContent()); } } } } catch (SOAPException e) { e.printStackTrace(); } return true; }
From source file:be.e_contract.mycarenet.xkms.ProofOfPossessionSignatureSOAPHandler.java
@Override public boolean handleMessage(SOAPMessageContext context) { if (null == this.sessionKey) { return true; }//from w ww. j ava2s .com if (null == this.prototypeKeyBindingId) { return true; } Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (false == outboundProperty) { return true; } LOG.debug("adding proof of possession signature"); SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); NodeList registerRequestNodeList = soapPart.getElementsByTagNameNS(XKMS_NAMESPACE, "Register"); Element registerRequestElement = (Element) registerRequestNodeList.item(0); Document xkmsDocument; try { xkmsDocument = copyDocument(registerRequestElement); } catch (ParserConfigurationException e) { LOG.error("error copying XKMS request: " + e.getMessage(), e); return false; } NodeList proofOfPossessionNodeList = xkmsDocument.getElementsByTagNameNS(XKMS_NAMESPACE, "ProofOfPossession"); Element proofOfPossessionElement = (Element) proofOfPossessionNodeList.item(0); try { prepareDocument(xkmsDocument); addSignature(proofOfPossessionElement); } catch (Exception e) { LOG.error("error adding proof signature: " + e.getMessage(), e); return false; } Node signatureNode = soapPart.importNode(proofOfPossessionElement.getFirstChild(), true); proofOfPossessionNodeList = soapPart.getElementsByTagNameNS(XKMS_NAMESPACE, "ProofOfPossession"); proofOfPossessionElement = (Element) proofOfPossessionNodeList.item(0); proofOfPossessionElement.appendChild(signatureNode); return true; }
From source file:com.amazon.advertising.api.common.HmacSecurityHandler.java
public void invoke(MessageContext mc) throws AxisFault { String actionUri = mc.getSOAPActionURI(); String tokens[] = actionUri.split("/"); String action = tokens[tokens.length - 1]; String timestamp = getTimestamp(); String signature;//ww w .j av a 2s . c o m try { signature = this.calculateSignature(action, timestamp); } catch (Exception e) { throw AxisFault.makeFault(e); } try { SOAPMessageContext smc = (SOAPMessageContext) mc; SOAPMessage message = smc.getMessage(); SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); SOAPHeader header = envelope.getHeader(); header.addNamespaceDeclaration(AWS_SECURITY_NS_PREFIX, AWS_SECURITY_NS); Name akidName = envelope.createName("AWSAccessKeyId", AWS_SECURITY_NS_PREFIX, AWS_SECURITY_NS); Name tsName = envelope.createName("Timestamp", AWS_SECURITY_NS_PREFIX, AWS_SECURITY_NS); Name sigName = envelope.createName("Signature", AWS_SECURITY_NS_PREFIX, AWS_SECURITY_NS); SOAPHeaderElement akidElement = header.addHeaderElement(akidName); SOAPHeaderElement tsElement = header.addHeaderElement(tsName); SOAPHeaderElement sigElement = header.addHeaderElement(sigName); akidElement.addTextNode(awsAccessKeyId); tsElement.addTextNode(timestamp); sigElement.addTextNode(signature); } catch (SOAPException e) { throw AxisFault.makeFault(e); } }
From source file:be.e_contract.mycarenet.xkms2.ProofOfPossessionSignatureSOAPHandler.java
@Override public boolean handleMessage(SOAPMessageContext context) { if (null == this.sessionKey) { return true; }//from w w w . ja va 2s. c om if (null == this.prototypeKeyBindingId) { return true; } Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (false == outboundProperty) { return true; } LOG.debug("adding proof of possession signature"); SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); NodeList registerRequestNodeList = soapPart.getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, "RegisterRequest"); Element registerRequestElement = (Element) registerRequestNodeList.item(0); Document xkmsDocument; try { xkmsDocument = copyDocument(registerRequestElement); } catch (ParserConfigurationException e) { LOG.error("error copying XKMS request: " + e.getMessage(), e); return false; } NodeList proofOfPossessionNodeList = xkmsDocument .getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, "ProofOfPossession"); Element proofOfPossessionElement = (Element) proofOfPossessionNodeList.item(0); try { prepareDocument(xkmsDocument); addSignature(proofOfPossessionElement); } catch (Exception e) { LOG.error("error adding proof signature: " + e.getMessage(), e); return false; } Node signatureNode = soapPart.importNode(proofOfPossessionElement.getFirstChild(), true); proofOfPossessionNodeList = soapPart.getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, "ProofOfPossession"); proofOfPossessionElement = (Element) proofOfPossessionNodeList.item(0); proofOfPossessionElement.appendChild(signatureNode); return true; }
From source file:SendSOAPMessage.java
/** * send a simple soap message with JAXM API. *///w w w .j a v a 2 s . com public void sendMessage(String url) { try { /** * Construct a default SOAP message factory. */ MessageFactory mf = MessageFactory.newInstance(); /** * Create a SOAP message object. */ SOAPMessage soapMessage = mf.createMessage(); /** * Get SOAP part. */ SOAPPart soapPart = soapMessage.getSOAPPart(); /** * Get SOAP envelope. */ SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); /** * Get SOAP body. */ SOAPBody soapBody = soapEnvelope.getBody(); /** * Add child element with the specified name. */ SOAPElement element = soapBody.addChildElement("HelloWorld"); /** * Add text message */ element.addTextNode("Welcome to SunOne Web Services!"); soapMessage.saveChanges(); /** * Construct a default SOAP connection factory. */ SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance(); /** * Get SOAP connection. */ SOAPConnection soapConnection = connectionFactory.createConnection(); /** * Construct endpoint object. */ URLEndpoint endpoint = new URLEndpoint(url); /** * Send SOAP message. */ SOAPMessage resp = soapConnection.call(soapMessage, endpoint); /** * Print response to the std output. */ resp.writeTo(System.out); /** * close the connection */ soapConnection.close(); } catch (java.io.IOException ioe) { ioe.printStackTrace(); } catch (SOAPException soape) { soape.printStackTrace(); } }
From source file:be.fedict.eid.idp.protocol.saml2.artifact.ArtifactServiceServerHandler.java
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, soapMessageContext); } else {//from w ww . j a v a2 s .c om handleInboundDocument(soapPart); } return true; }
From source file:com.profesorfalken.payzen.webservices.sdk.handler.soap.HeaderHandler.java
/** * Takes the outgoing SOAP message and modifies it adding the header * information// w w w.j a v a 2 s. c om * * @param smc SOAP message context * @return */ @Override public boolean handleMessage(SOAPMessageContext smc) { Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (Boolean.TRUE.equals(outboundProperty)) { SOAPMessage message = smc.getMessage(); try { SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); //Creates header into SOAP envelope SOAPHeader header = envelope.getHeader(); if (header == null) { header = envelope.addHeader(); } // Add shopId addHeaderField(header, "shopId", this.shopId); // Timestamp TimeZone tz = TimeZone.getTimeZone("UTC"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); df.setTimeZone(tz); String nowAsISO = df.format(new Date()); addHeaderField(header, "timestamp", nowAsISO); // Mode addHeaderField(header, "mode", this.mode); // Add requestId String requestId = UUID.randomUUID().toString(); addHeaderField(header, "requestId", requestId); // Authentication token String tokenString = requestId + nowAsISO; addHeaderField(header, "authToken", sign(tokenString, shopKey)); } catch (SOAPException e) { logger.error("Error sending header", e); } } return outboundProperty; }
From source file:com.github.thesmartenergy.cnr.SmartChargingProvider.java
private SOAPMessage createSoapMessage(GetChargingPlans value) throws PEPException { try {// w ww. j a v a 2 s.co m JAXBContext jaxbContext = JAXBContext.newInstance(GetChargingPlans.class); Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); jaxbContext.createMarshaller().marshal(value, document); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); soapMessage.getSOAPBody().addDocument(document); Name headername = soapMessage.getSOAPPart().getEnvelope().createName("Action", "", "http://schemas.microsoft.com/ws/2005/05/addressing/none/"); SOAPHeaderElement soapAction = soapMessage.getSOAPHeader().addHeaderElement(headername); soapAction.setMustUnderstand(true); soapAction.setTextContent("http://tempuri.org/ISmartCharging/GetChargingPlans"); return soapMessage; } catch (DOMException | JAXBException | ParserConfigurationException | SOAPException ex) { throw new PEPException(ex); } }
From source file:backend.Weather.java
private SOAPMessage createSOAPRequest() throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); String serverURI = "http://ws.cdyne.com/"; SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPBody soapBody = envelope.getBody(); SOAPElement soapBodyElem = soapBody.addChildElement("GetCityWeatherByZIP"); QName attributeName = new QName("xmlns"); soapBodyElem.addAttribute(attributeName, "http://ws.cdyne.com/WeatherWS/"); SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("ZIP"); soapBodyElem1.addTextNode("02215"); soapMessage.saveChanges();/*from ww w . ja va2 s. c om*/ return soapMessage; }