List of usage examples for javax.xml.soap SOAPMessage getSOAPHeader
public SOAPHeader getSOAPHeader() throws SOAPException
From source file:Main.java
public static void main(String[] args) throws Exception { SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance(); SOAPConnection connection = sfc.createConnection(); MessageFactory mf = MessageFactory.newInstance(); SOAPMessage sm = mf.createMessage(); SOAPHeader sh = sm.getSOAPHeader(); SOAPBody sb = sm.getSOAPBody(); sh.detachNode();/*w w w. j a va 2 s . com*/ QName bodyName = new QName("http://quoteCompany.com", "GetQuote", "d"); SOAPBodyElement bodyElement = sb.addBodyElement(bodyName); QName qn = new QName("aName"); SOAPElement quotation = bodyElement.addChildElement(qn); quotation.addTextNode("TextMode"); System.out.println("\n Soap Request:\n"); sm.writeTo(System.out); System.out.println(); URL endpoint = new URL("http://yourServer.com"); SOAPMessage response = connection.call(sm, endpoint); System.out.println(response.getContentDescription()); }
From source file:SOAPRequest.java
public static void main(String[] args) { try {/*from w ww .j a v a 2 s .c o m*/ SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance(); SOAPConnection connection = sfc.createConnection(); MessageFactory mf = MessageFactory.newInstance(); SOAPMessage sm = mf.createMessage(); SOAPHeader sh = sm.getSOAPHeader(); SOAPBody sb = sm.getSOAPBody(); sh.detachNode(); QName bodyName = new QName("http://quoteCompany.com", "GetQuote", "d"); SOAPBodyElement bodyElement = sb.addBodyElement(bodyName); QName qn = new QName("aName"); SOAPElement quotation = bodyElement.addChildElement(qn); quotation.addTextNode("TextMode"); System.out.println("\n Soap Request:\n"); sm.writeTo(System.out); System.out.println(); URL endpoint = new URL("http://yourServer.com"); SOAPMessage response = connection.call(sm, endpoint); System.out.println(response.getContentDescription()); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:ee.ria.xroad.common.message.SoapUtils.java
private static String getServiceCode(SOAPMessage soap, QName requestElementQName) throws SOAPException { for (SOAPElement eachHeaderElement : getChildElements(soap.getSOAPHeader())) { QName headerElementQName = eachHeaderElement.getElementQName(); if (!"service".equals(headerElementQName.getLocalPart())) { continue; }//from www. j a va2s .c o m for (SOAPElement eachServicePart : getChildElements(eachHeaderElement)) { QName headerPartQName = eachServicePart.getElementQName(); if (headerPartQName.getLocalPart().equals("serviceCode")) { return eachServicePart.getValue(); } } } return requestElementQName.getLocalPart(); }
From source file:be.fedict.hsm.client.WSSecuritySOAPHandler.java
private void handleOutboundMessage(SOAPMessageContext context) throws SOAPException, WSSecurityException { if (null == this.privateKey) { LOG.warn("no adding a WS-Security header"); return;//from ww w .j ava2 s.c o m } SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); soapMessage.getSOAPHeader(); WSSecHeader wsSecHeader = new WSSecHeader(); wsSecHeader.setMustUnderstand(true); wsSecHeader.insertSecurityHeader(soapPart); WSSecTimestamp wsSecTimeStamp = new WSSecTimestamp(); wsSecTimeStamp.prepare(soapPart); wsSecTimeStamp.prependToHeader(wsSecHeader); WSSecurityCrypto crypto = new WSSecurityCrypto(this.privateKey, this.certificate); WSSConfig wssConfig = new WSSConfig(); WSSecSignature sign = new WSSecSignature(wssConfig); sign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE); sign.prepare(soapPart, crypto, wsSecHeader); String bstId = sign.getBSTTokenId(); sign.appendBSTElementToHeader(wsSecHeader); sign.setDigestAlgo("http://www.w3.org/2001/04/xmlenc#sha256"); sign.setSignatureAlgorithm("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"); Vector<WSEncryptionPart> signParts = new Vector<WSEncryptionPart>(); signParts.add(new WSEncryptionPart(wsSecTimeStamp.getId())); signParts.add(new WSEncryptionPart(WSConstants.ELEM_BODY, WSConstants.URI_SOAP12_ENV, "")); signParts.add(new WSEncryptionPart(bstId)); sign.addReferencesToSign(signParts, wsSecHeader); List<Reference> referenceList = sign.addReferencesToSign(signParts, wsSecHeader); sign.computeSignature(referenceList, false, null); }
From source file:eu.domibus.ebms3.common.handler.AbstractFaultHandler.java
/** * This method extracts a ebMS3 messaging header {@link eu.domibus.common.model.org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.Messaging} from a {@link javax.xml.soap.SOAPMessage} * * @param soapMessage//from w ww . j ava2 s. co m * @return */ protected Messaging extractMessaging(SOAPMessage soapMessage) { Messaging messaging = null; try { messaging = ((JAXBElement<Messaging>) this.jaxbContext.createUnmarshaller().unmarshal( (Node) soapMessage.getSOAPHeader().getChildElements(ObjectFactory._Messaging_QNAME).next())) .getValue(); } catch (JAXBException | SOAPException e) { //TODO: make nice AbstractFaultHandler.LOG.error("Error extracting messaging object", e); } return messaging; }
From source file:com.nortal.jroad.mapping.XTeeEndpointMapping.java
@Override protected Object getEndpointInternal(MessageContext messageCtx) throws Exception { SOAPMessage message = SOAPUtil.extractSoapMessage(messageCtx.getRequest()); if (message.getSOAPHeader() != null) { AbstractXTeeBaseEndpoint endpoint = methodMap.get(getRequestMethod(message.getSOAPHeader())); if (endpoint != null) { if (log.isDebugEnabled()) { log.debug("Matched " + endpoint + " to " + endpoint.getClass().getSimpleName()); }/* w ww . j a va2 s . com*/ return endpoint; } } try { if (SOAPUtil.getNodeByXPath(message.getSOAPBody(), "/*/*/*[local-name()='listMethods']") != null) { log.debug("Matched headerless listMethods request."); return getApplicationContext() .getBean(getApplicationContext().getBeanNamesForType(ListMethodsEndpoint.class)[0]); } } catch (NullPointerException e) { // ListMethods lookup failed } return null; }
From source file:be.fedict.eid.idp.protocol.ws_federation.sts.WSSecuritySoapHandler.java
private void handleOutboundMessage(SOAPMessageContext context) throws SOAPException { SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPHeader soapHeader = soapMessage.getSOAPHeader(); if (null == soapHeader) { SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); soapHeader = soapEnvelope.addHeader(); }/*from w w w. j av a 2 s . c om*/ WSSecHeader wsSecHeader = new WSSecHeader(); Element securityElement; try { securityElement = wsSecHeader.insertSecurityHeader(soapPart); } catch (WSSecurityException e) { throw new SOAPException("WS-Security error: " + e.getMessage(), e); } soapHeader.removeChild(securityElement); soapHeader.appendChild(securityElement); WSSecTimestamp wsSecTimeStamp = new WSSecTimestamp(); wsSecTimeStamp.build(soapPart, wsSecHeader); }
From source file:eu.domibus.ebms3.sender.EbmsErrorChecker.java
public EbmsErrorChecker.CheckResult check(SOAPMessage request, SOAPMessage response, String pmodeKey) throws EbMS3Exception { Messaging messaging;/*from w ww.ja va 2s . c om*/ try { messaging = this.jaxbContext.createUnmarshaller() .unmarshal( (Node) response.getSOAPHeader().getChildElements(ObjectFactory._Messaging_QNAME).next(), Messaging.class) .getValue(); } catch (JAXBException | SOAPException e) { EbmsErrorChecker.LOG.error(e.getMessage(), e); return EbmsErrorChecker.CheckResult.ERROR; } SignalMessage signalMessage = messaging.getSignalMessage(); if (signalMessage.getError() == null || signalMessage.getError().size() == 0) { return EbmsErrorChecker.CheckResult.OK; } for (Error error : signalMessage.getError()) { if (EbMS3Exception.SEVERITY_FAILURE.equalsIgnoreCase(error.getSeverity())) { throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.findErrorCodeBy(error.getErrorCode()), error.getErrorDetail(), error.getRefToMessageInError(), null, MSHRole.SENDING); } if (EbMS3Exception.SEVERITY_WARNING.equalsIgnoreCase(error.getSeverity())) { ErrorLogEntry errorLogEntry = new ErrorLogEntry( new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.findErrorCodeBy(error.getErrorCode()), error.getErrorDetail(), error.getRefToMessageInError(), null, MSHRole.SENDING)); this.errorLogDao.create(errorLogEntry); } } return EbmsErrorChecker.CheckResult.WARNING; }
From source file:eu.domibus.common.validators.EbMS3MessageValidator.java
public void validate(final SOAPMessage message, final String pModeKey) throws EbMS3Exception { final Messaging messaging; try {/*from w w w . j av a 2 s. c o m*/ messaging = this.ebmsContext.createUnmarshaller() .unmarshal( (Node) message.getSOAPHeader().getChildElements(ObjectFactory._Messaging_QNAME).next(), Messaging.class) .getValue(); } catch (JAXBException | SOAPException e) { EbMS3MessageValidator.LOG.error("", e); throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0004, null, e, null); } if (messaging.getUserMessage() == null && messaging.getSignalMessage() == null) { //There is no ebms message EbMS3MessageValidator.LOG.error("messaging element is empty"); throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0004, null, null, null); } final UserMessage userMessage = messaging.getUserMessage(); final SignalMessage signalMessage = messaging.getSignalMessage(); if (userMessage != null) { this.validateUserMessage(userMessage, pModeKey); } if (signalMessage != null) { this.validateSignalMessage(signalMessage, pModeKey); } }
From source file:com.nortal.jroad.endpoint.AbstractXTeeBaseEndpoint.java
@SuppressWarnings("unchecked") private XTeeHeader parseXteeHeader(SOAPMessage paringMessage) throws SOAPException { XTeeHeader pais = new XTeeHeader(); if (paringMessage.getSOAPHeader() == null) { return pais; }//from ww w . j a va 2 s . c om SOAPHeader header = paringMessage.getSOAPHeader(); for (Iterator<Node> headerElemendid = header.getChildElements(); headerElemendid.hasNext();) { Node headerElement = headerElemendid.next(); if (!SOAPUtil.isTextNode(headerElement) && headerElement.getFirstChild() != null) { String localName = headerElement.getLocalName(); String value = headerElement.getFirstChild().getNodeValue(); pais.addElement(new QName(headerElement.getNamespaceURI(), localName), value); } } return pais; }