Java Code Examples for javax.xml.soap.SOAPHeader#addChildElement()

The following examples show how to use javax.xml.soap.SOAPHeader#addChildElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XRoadProtocolNamespaceStrategyV4.java    From j-road with Apache License 2.0 7 votes vote down vote up
private void addClientElements(SOAPEnvelope env, XRoadServiceConfiguration conf, SOAPHeader header)
    throws SOAPException {
  // TODO: maybe we should create headers differently according to object type?
  XroadObjectType objectType =
      conf.getClientObjectType() != null ? conf.getClientObjectType() : XroadObjectType.SUBSYSTEM;
  SOAPElement client = header.addChildElement("client", protocol.getNamespacePrefix());
  client.addAttribute(env.createName("id:objectType"), objectType.name());
  SOAPElement clientXRoadInstance = client.addChildElement("xRoadInstance", "id");
  clientXRoadInstance.addTextNode(conf.getClientXRoadInstance());
  SOAPElement clientMemberClass = client.addChildElement("memberClass", "id");
  clientMemberClass.addTextNode(conf.getClientMemberClass());
  SOAPElement clientMemberCode = client.addChildElement("memberCode", "id");
  clientMemberCode.addTextNode(conf.getClientMemberCode());

  if (StringUtils.isNotBlank(conf.getClientSubsystemCode())) {
    SOAPElement clientSubsystemCode = client.addChildElement("subsystemCode", "id");
    clientSubsystemCode.addTextNode(conf.getClientSubsystemCode());
  }
}
 
Example 2
Source File: JaxWsSoapContextHandler.java    From googleads-java-lib with Apache License 2.0 6 votes vote down vote up
/**
 * Captures pertinent information from SOAP messages exchanged by the SOAP
 * service this handler is attached to. Also responsible for placing custom
 * (implicit) SOAP headers on outgoing messages.
 *
 * @see SOAPHandler#handleMessage(MessageContext)
 * @param context the context of the SOAP message passing through this handler
 * @return whether this SOAP interaction should continue
 */
@Override
public boolean handleMessage(SOAPMessageContext context) {
  if ((Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
    // Outbound message (request), so reset the last request and response builders.
    lastRequestInfo = new RequestInfo.Builder();
    lastResponseInfo = new ResponseInfo.Builder();      
    SOAPMessage soapMessage = context.getMessage();
    try {
      SOAPHeader soapHeader = soapMessage.getSOAPHeader();
      if (soapHeader == null) {
        soapHeader = soapMessage.getSOAPPart().getEnvelope().addHeader();
      }

      for (SOAPElement header : soapHeaders) {
        soapHeader.addChildElement(header);
      }
    } catch (SOAPException e) {
      throw new ServiceException("Error setting SOAP headers on outbound message.", e);
    }
    captureServiceAndOperationNames(context);
  }
  captureSoapXml(context);
  return true;
}
 
Example 3
Source File: XRoadProtocolNamespaceStrategyV4.java    From j-road with Apache License 2.0 6 votes vote down vote up
@Override
public void addXTeeHeaderElements(SOAPEnvelope env, XRoadServiceConfiguration conf) throws SOAPException {
  SOAPHeader header = env.getHeader();
  if(StringUtils.isNotBlank(conf.getIdCode())) {
    SOAPElement userId = header.addChildElement("userId", protocol.getNamespacePrefix());
    userId.addTextNode(conf.getIdCode());
  }
  SOAPElement id = header.addChildElement("id", protocol.getNamespacePrefix());
  id.addTextNode(generateUniqueMessageId(conf));
  if (StringUtils.isNotBlank(conf.getFile())) {
    SOAPElement issue = header.addChildElement("issue", protocol.getNamespacePrefix());
    issue.addTextNode(conf.getFile());
  }
  SOAPElement protocolVersion = header.addChildElement("protocolVersion", protocol.getNamespacePrefix());
  protocolVersion.addTextNode(protocol.getCode());

  addClientElements(env, conf, header);
  addServiceElements(env, conf, header);
}
 
Example 4
Source File: SOAP.java    From onvif-java-lib with Apache License 2.0 6 votes vote down vote up
protected void createSoapHeader(SOAPMessage soapMessage) throws SOAPException {
	onvifDevice.createNonce();
	String encrypedPassword = onvifDevice.getEncryptedPassword();
	if (encrypedPassword != null && onvifDevice.getUsername() != null) {

		SOAPPart sp = soapMessage.getSOAPPart();
		SOAPEnvelope se = sp.getEnvelope();
		SOAPHeader header = soapMessage.getSOAPHeader();
		se.addNamespaceDeclaration("wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
		se.addNamespaceDeclaration("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");

		SOAPElement securityElem = header.addChildElement("Security", "wsse");
		// securityElem.setAttribute("SOAP-ENV:mustUnderstand", "1");

		SOAPElement usernameTokenElem = securityElem.addChildElement("UsernameToken", "wsse");

		SOAPElement usernameElem = usernameTokenElem.addChildElement("Username", "wsse");
		usernameElem.setTextContent(onvifDevice.getUsername());

		SOAPElement passwordElem = usernameTokenElem.addChildElement("Password", "wsse");
		passwordElem.setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest");
		passwordElem.setTextContent(encrypedPassword);

		SOAPElement nonceElem = usernameTokenElem.addChildElement("Nonce", "wsse");
		nonceElem.setAttribute("EncodingType", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
		nonceElem.setTextContent(onvifDevice.getEncryptedNonce());

		SOAPElement createdElem = usernameTokenElem.addChildElement("Created", "wsu");
		createdElem.setTextContent(onvifDevice.getLastUTCTime());
	}
}
 
Example 5
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private void generateRelateToElement(SOAPHeader soapHeader, WsAddressingRelatesTo relateTo) throws SOAPException {
   SOAPElement relateToElement = soapHeader.addChildElement(RELATESTO);
   if (relateTo.getRelationshipType() != null && !relateTo.getRelationshipType().isEmpty()) {
      relateToElement.addAttribute(RELATIONSHIPTYPE, relateTo.getRelationshipType());
   }

   if (relateTo.getRelationshipType() != null) {
      relateToElement.setTextContent(relateTo.getReleatesTo().toString());
   }

}
 
Example 6
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private void generateRelateToElement(SOAPHeader soapHeader, WsAddressingRelatesTo relateTo) throws SOAPException {
   SOAPElement relateToElement = soapHeader.addChildElement(RELATESTO);
   if (relateTo.getRelationshipType() != null && !relateTo.getRelationshipType().isEmpty()) {
      relateToElement.addAttribute(RELATIONSHIPTYPE, relateTo.getRelationshipType());
   }

   if (relateTo.getRelationshipType() != null) {
      relateToElement.setTextContent(relateTo.getReleatesTo().toString());
   }

}
 
Example 7
Source File: XRoadProtocolNamespaceStrategyV4.java    From j-road with Apache License 2.0 5 votes vote down vote up
private void addServiceElements(SOAPEnvelope env, XRoadServiceConfiguration conf, SOAPHeader header)
    throws SOAPException {

  // TODO: maybe we should create headers differently according to object type?
  XroadObjectType objectType =
      conf.getServiceObjectType() != null ? conf.getServiceObjectType() : XroadObjectType.SERVICE;

  SOAPElement service = header.addChildElement("service", protocol.getNamespacePrefix());
  service.addAttribute(env.createName("id:objectType"), objectType.name());
  SOAPElement serviceXRoadInstance = service.addChildElement("xRoadInstance", "id");
  serviceXRoadInstance.addTextNode(conf.getServiceXRoadInstance());
  SOAPElement serviceMemberClass = service.addChildElement("memberClass", "id");
  serviceMemberClass.addTextNode(conf.getServiceMemberClass());
  SOAPElement serviceMemberCode = service.addChildElement("memberCode", "id");
  serviceMemberCode.addTextNode(conf.getServiceMemberCode());

  if (StringUtils.isNotBlank(conf.getServiceSubsystemCode())) {
    SOAPElement subsystemCode = service.addChildElement("subsystemCode", "id");
    subsystemCode.addTextNode(conf.getServiceSubsystemCode());
  }

  SOAPElement database = service.addChildElement("serviceCode", "id");
  database.addTextNode(conf.getMethod());

  if(StringUtils.isNotBlank(conf.getVersion())){
    SOAPElement serviceVersion = service.addChildElement("serviceVersion", "id");
    serviceVersion.addTextNode(conf.getVersion());
  }

}
 
Example 8
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private void generateRelateToElement(SOAPHeader soapHeader, WsAddressingRelatesTo relateTo) throws SOAPException {
   SOAPElement relateToElement = soapHeader.addChildElement(RELATESTO);
   if (relateTo.getRelationshipType() != null && !relateTo.getRelationshipType().isEmpty()) {
      relateToElement.addAttribute(RELATIONSHIPTYPE, relateTo.getRelationshipType());
   }

   if (relateTo.getRelationshipType() != null) {
      relateToElement.setTextContent(relateTo.getReleatesTo().toString());
   }

}
 
Example 9
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private void generateRelateToElement(SOAPHeader soapHeader, WsAddressingRelatesTo relateTo) throws SOAPException {
   SOAPElement relateToElement = soapHeader.addChildElement(RELATESTO);
   if (relateTo.getRelationshipType() != null && !relateTo.getRelationshipType().isEmpty()) {
      relateToElement.addAttribute(RELATIONSHIPTYPE, relateTo.getRelationshipType());
   }

   if (relateTo.getRelationshipType() != null) {
      relateToElement.setTextContent(relateTo.getReleatesTo().toString());
   }

}
 
Example 10
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private void generateRelateToElement(SOAPHeader soapHeader, WsAddressingRelatesTo relateTo) throws SOAPException {
   SOAPElement relateToElement = soapHeader.addChildElement(RELATESTO);
   if (relateTo.getRelationshipType() != null && !relateTo.getRelationshipType().isEmpty()) {
      relateToElement.addAttribute(RELATIONSHIPTYPE, relateTo.getRelationshipType());
   }

   if (relateTo.getRelationshipType() != null) {
      relateToElement.setTextContent(relateTo.getReleatesTo().toString());
   }

}
 
Example 11
Source File: XTeeUtil.java    From j-road with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a X-Tee header element with given value and using correct namespace, element type is set to
 * <code>xsd:string</code>.
 *
 * @param header Header of the <code>SOAPMessage</code>
 * @param name Header element name
 * @param value Header element value
 */
public static void addHeaderElement(SOAPHeader header, String name, String value, String nsPrefix)
    throws SOAPException {
  SOAPElement element = header.addChildElement(name, nsPrefix);
  SOAPUtil.addTypeAttribute(element, "xsd:string");
  if (value != null) {
    element.addTextNode(value);
  }
}
 
Example 12
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private void processRequiredElements(WsAddressingHeader header, SOAPHeader soapHeader) throws SOAPException {
   SOAPElement actionElement = soapHeader.addChildElement(ACTION);
   actionElement.addAttribute(MUST_UNDERSTAND, header.getMustUnderstand());
   actionElement.setTextContent(header.getAction().toString());
}
 
Example 13
Source File: SOAPRequestBuilder.java    From cougar with Apache License 2.0 4 votes vote down vote up
public void generateSoapHeader(SOAPEnvelope envelope,
		HttpCallBean httpCallBean) throws SOAPException {

	// Remove existing null header
	envelope.getHeader().detachNode();

	// add new soap header
	SOAPHeader soapHeader = envelope.addHeader();

	// header are not set then break
	if (httpCallBean.getAuthority() == null
			&& httpCallBean.getSubject() == null
			&& httpCallBean.getAuthCredentials()== null) {
		return;
	}

	// create element for headers

	if (httpCallBean.getAuthority() != null) {
		String authority = httpCallBean.getAuthority();

		/*soapHeader.addChildElement(
				envelope.createName("Authentication", "", secNameSpace))
				.setTextContent(authority);*/
		
		soapHeader.addChildElement(
				envelope.createName("X-Authentication", "", SECURITY_NAME_SPACE))
				.setValue(authority);

	}

	if (httpCallBean.getAuthCredentials() != null) {
		Map<String, String> credentials = httpCallBean.getAuthCredentials();

		SOAPElement credElement = soapHeader.addChildElement(
				envelope.createName("Credentials", "", SECURITY_NAME_SPACE));
		for(Map.Entry<String,String> entry: credentials.entrySet()){
			credElement.addChildElement(entry.getKey(), "", SECURITY_NAME_SPACE).setValue(entry.getValue());
		}
		
	}

	if (httpCallBean.getSubject() != null) {
		String subject = httpCallBean.getSubject();

		/*soapHeader.addChildElement(
				envelope.createName("Subject", "", secNameSpace))
				.setTextContent(subject);*/
		
		soapHeader.addChildElement(
				envelope.createName("Subject", "", SECURITY_NAME_SPACE))
				.setValue(subject);
	}
}
 
Example 14
Source File: SimpleSecurityHandler.java    From onvif with Apache License 2.0 4 votes vote down vote up
@Override
public boolean handleMessage(final SOAPMessageContext msgCtx) {
  // System.out.println("SimpleSecurityHandler");

  // Indicator telling us which direction this message is going in
  final Boolean outInd = (Boolean) msgCtx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

  // Handler must only add security headers to outbound messages
  if (outInd.booleanValue()) {
    try {
      // Create the xml
      SOAPMessage soapMessage = msgCtx.getMessage();
      SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope();
      SOAPHeader header = envelope.getHeader();
      if (header == null) header = envelope.addHeader();

      SOAPPart sp = soapMessage.getSOAPPart();
      SOAPEnvelope se = sp.getEnvelope();
      se.addNamespaceDeclaration(WSSE_PREFIX, WSSE_NS);
      se.addNamespaceDeclaration(WSU_PREFIX, WSU_NS);

      SOAPElement securityElem = header.addChildElement(WSSE_LN, WSSE_PREFIX);
      // securityElem.setAttribute("SOAP-ENV:mustUnderstand", "1");

      SOAPElement usernameTokenElem =
          securityElem.addChildElement(USERNAME_TOKEN_LN, WSSE_PREFIX);

      SOAPElement usernameElem = usernameTokenElem.addChildElement(USERNAME_LN, WSSE_PREFIX);
      usernameElem.setTextContent(username);

      SOAPElement passwordElem = usernameTokenElem.addChildElement(PASSWORD_LN, WSSE_PREFIX);
      passwordElem.setAttribute(PASSWORD_TYPE_ATTR, PASSWORD_DIGEST);
      passwordElem.setTextContent(encryptPassword(password));

      SOAPElement nonceElem = usernameTokenElem.addChildElement(NONCE_LN, WSSE_PREFIX);
      nonceElem.setAttribute("EncodingType", BASE64_ENCODING);
      nonceElem.setTextContent(Base64.encodeBase64String(nonce.getBytes()));

      SOAPElement createdElem = usernameTokenElem.addChildElement(CREATED_LN, WSU_PREFIX);
      createdElem.setTextContent(getLastUTCTime());
    } catch (final Exception e) {
      e.printStackTrace();
      return false;
    }
  }
  return true;
}
 
Example 15
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private void processRequiredElements(WsAddressingHeader header, SOAPHeader soapHeader) throws SOAPException {
   SOAPElement actionElement = soapHeader.addChildElement(ACTION);
   actionElement.addAttribute(MUST_UNDERSTAND, header.getMustUnderstand());
   actionElement.setTextContent(header.getAction().toString());
}
 
Example 16
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private void processRequiredElements(WsAddressingHeader header, SOAPHeader soapHeader) throws SOAPException {
   SOAPElement actionElement = soapHeader.addChildElement(ACTION);
   actionElement.addAttribute(MUST_UNDERSTAND, header.getMustUnderstand());
   actionElement.setTextContent(header.getAction().toString());
}
 
Example 17
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private void processRequiredElements(WsAddressingHeader header, SOAPHeader soapHeader) throws SOAPException {
   SOAPElement actionElement = soapHeader.addChildElement(ACTION);
   actionElement.addAttribute(MUST_UNDERSTAND, header.getMustUnderstand());
   actionElement.setTextContent(header.getAction().toString());
}
 
Example 18
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private void processRequiredElements(WsAddressingHeader header, SOAPHeader soapHeader) throws SOAPException {
   SOAPElement actionElement = soapHeader.addChildElement(ACTION);
   actionElement.addAttribute(MUST_UNDERSTAND, header.getMustUnderstand());
   actionElement.setTextContent(header.getAction().toString());
}