org.apache.axis.message.SOAPHeaderElement Java Examples

The following examples show how to use org.apache.axis.message.SOAPHeaderElement. 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: AxisHandlerTest.java    From googleads-java-lib with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetChildHeader_valid() {
  Map<String, String> parentValue = Maps.newHashMap();
  axisHandler.setHeader(stub, "namespace", "parent", parentValue);
  String childValue = "123";
  axisHandler.setHeaderChild(stub, "parent", "child", childValue);

  assertEquals("Child was not set to the expected value on the parent header's underlying map",
      childValue, parentValue.get("child"));

  SOAPHeaderElement parentHeaderElement =
      (SOAPHeaderElement) axisHandler.getHeader(stub, "parent");
  @SuppressWarnings("unchecked")
  Map<String, String> actualParentValue =
      (Map<String, String>) parentHeaderElement.getObjectValue();

  String actualChildValue = actualParentValue.get("child");
  assertEquals("Child retrieved by navigating through the parent header does not have the "
      + "expected value", childValue, actualChildValue);

  assertEquals("The only key in the parent header's underlying map should be the child added",
      Sets.newHashSet("child"), parentValue.keySet());
}
 
Example #2
Source File: DynamicWebServiceInvoker.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds the specified SOAP request header to the operation invocation.
 * 
 * @param header
 *          SOAPHeaderElement to add
 * @throws cfmRunTimeException
 */
public void addRequestHeader(SOAPHeaderElement header) throws cfmRunTimeException {
	// If this same header exists, throw an exception
	// (same meaning, identical namespace/name pair)
	for (int i = 0; i < this.requestHeaders.size(); i++) {
		SOAPHeaderElement h = (SOAPHeaderElement) this.requestHeaders.get(i);
		if ((h.getNamespaceURI() == null && header.getNamespaceURI() == null && h.getName() == null && header.getName() == null) || (h.getNamespaceURI() != null && h.getNamespaceURI().equalsIgnoreCase(header.getNamespaceURI()) && h.getName() != null && h.getName().equalsIgnoreCase(header.getName())))
			throw new cfmRunTimeException(catchDataFactory.generalException("errorCode.runtimeError", "SOAP header value: " + header.getNamespaceURI() + ":" + header.getName() + " already set."));
	}
	this.requestHeaders.add(header);
}
 
Example #3
Source File: addSOAPRequestHeader.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
public cfData execute(cfSession _session, List<cfData> parameters) throws cfmRunTimeException {
	cfWSObjectData wso = null;
	String ns = null;
	String n = null;
	cfData val = null;
	boolean mustUnderstand = false;

	int offset = 0;
	if (parameters.size() == 5) {
		mustUnderstand = parameters.get(0).getBoolean();
		offset = 1;
	}
	val = parameters.get(0 + offset);
	n = parameters.get(1 + offset).getString();
	ns = parameters.get(2 + offset).getString();
	wso = (cfWSObjectData) parameters.get(3 + offset);

	// Make sure we haven't already sent the request
	if (!wso.getInvoked()) {
		// Create the header
		SOAPHeaderElement header = createSOAPHeader(val, ns, n, mustUnderstand);

		// Add the header
		((DynamicWebServiceInvoker) wso.getPreparedInvoker()).addRequestHeader(header);

		return cfBooleanData.TRUE;
	} else {
		return cfBooleanData.FALSE;
	}
}
 
Example #4
Source File: addSOAPResponseHeader.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
public cfData execute(cfSession _session, List<cfData> parameters) throws cfmRunTimeException {
	String ns = null;
	String n = null;
	cfData val = null;
	boolean mustUnderstand = false;

	int offset = 0;
	if (parameters.size() == 4) {
		mustUnderstand = parameters.get(0).getBoolean();
		offset = 1;
	}
	val = parameters.get(0 + offset);
	n = parameters.get(1 + offset).getString();
	ns = parameters.get(2 + offset).getString();

	// Create the header
	SOAPHeaderElement header = addSOAPRequestHeader.createSOAPHeader(val, ns, n, mustUnderstand);

	// Add the header
	try {
		MessageContext mc = MessageContext.getCurrentContext();
		if (mc != null && mc.getResponseMessage() != null && mc.getResponseMessage().getSOAPEnvelope() != null) {
			// Check to see if the same header has already been added
			// (same meaning, having the same namespace/name pair)
			if (mc.getResponseMessage().getSOAPEnvelope().getHeaderByName(header.getNamespaceURI(), header.getName()) != null)
				throw new cfmRunTimeException(catchDataFactory.generalException("errorCode.runtimeError", "SOAP header value: " + header.getNamespaceURI() + ":" + header.getName() + " already set."));
			else
				mc.getResponseMessage().getSOAPEnvelope().addHeader(header);
		} else {
			throw new cfmRunTimeException(catchDataFactory.generalException("errorCode.runtimeError", "Could not set SOAP header value. MessageContext response message is not available. " + "Be sure this is being called from a CFC web service function."));
		}
	} catch (AxisFault ex) {
		throw new cfmRunTimeException(catchDataFactory.javaMethodException("errorCode.javaException", ex.getClass().getName(), ex.getMessage(), ex));
	}
	return cfBooleanData.TRUE;
}
 
Example #5
Source File: getSOAPRequestHeader.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
public cfData execute(cfSession _session, List<cfData> parameters) throws cfmRunTimeException {
	SOAPHeaderElement header = null;

	String ns = null;
	String n = null;
	boolean asXml = false;

	int offset = 0;
	if (parameters.size() == 3) {
		asXml = parameters.get(0).getBoolean();
		offset = 1;
	}
	n = parameters.get(0 + offset).getString();
	ns = parameters.get(1 + offset).getString();

	// Get the header
	try {
		MessageContext mc = MessageContext.getCurrentContext();
		if (mc != null && mc.getRequestMessage() != null && mc.getRequestMessage().getSOAPEnvelope() != null)
			header = mc.getRequestMessage().getSOAPEnvelope().getHeaderByName(ns, n);
		else
			throw new cfmRunTimeException(catchDataFactory.generalException("errorCode.runtimeError", "Could not get SOAP header. MessageContext request message is not available. " + "Be sure this is being called from a CFC web service function."));
	} catch (AxisFault ex) {
		throw new cfmRunTimeException(catchDataFactory.javaMethodException("errorCode.javaException", ex.getClass().getName(), ex.getMessage(), ex));
	}

	// Convert the header value into the desired cfData type
	return getSOAPHeaderValue(header, asXml);
}
 
Example #6
Source File: getSOAPResponseHeader.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
public cfData execute(cfSession _session, List<cfData> parameters) throws cfmRunTimeException {
	SOAPHeaderElement header = null;

	cfWSObjectData wso = null;
	String ns = null;
	String n = null;
	boolean asXml = false;

	int offset = 0;
	if (parameters.size() == 4) {
		asXml = parameters.get(0).getBoolean();
		offset = 1;
	}
	n = parameters.get(0 + offset).getString();
	ns = parameters.get(1 + offset).getString();
	wso = (cfWSObjectData) parameters.get(2 + offset);

	// Make sure we have sent the request
	if (wso.getInvoked()) {
		SOAPHeaderElement[] headers = (SOAPHeaderElement[]) wso.getResponseHeaders();
		for (int i = 0; i < headers.length; i++) {
			if (headers[i].getNamespaceURI().equals(ns) && headers[i].getName().equals(n)) {
				header = headers[i];
				break;
			}
		}

		// Convert the header value into the desired cfData type
		return getSOAPRequestHeader.getSOAPHeaderValue(header, asXml);
	} else {
		return cfNullData.NULL;
	}
}
 
Example #7
Source File: AxisHandler.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a SOAP header from the given SOAP client, if it exists.
 *
 * @param soapClient the SOAP client to check for the given header
 * @param headerName the name of the header being looked for
 * @return the header element, if it exists
 */
@Override
public Object getHeader(Stub soapClient, String headerName) {
  SOAPHeaderElement[] soapHeaders = soapClient.getHeaders();
  for (SOAPHeaderElement soapHeader : soapHeaders) {
    if (soapHeader.getName().equals(headerName)) {
      return soapHeader;
    }
  }
  return null;
}
 
Example #8
Source File: AxisHandler.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * @see  SoapClientHandler#setHeader(Object, String, String, Object)
 */
@Override
public void setHeader(Stub soapClient, String namespace, String headerName,
    Object headerValue) {
  try {
    QName qName = new QName(namespace, headerName);
    SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement(qName);
    soapHeaderElement.setObjectValue(headerValue);
    soapHeaderElement.setActor(null);
    soapClient.setHeader(soapHeaderElement);
  } catch (SOAPException e) {
    throw new ServiceException("Could not set header.", e);
  }
}
 
Example #9
Source File: AxisHandlerTest.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetAndGetHeader_valid() {
  axisHandler.setHeader(stub, "namespace", "header", "foo");
  SOAPHeaderElement headerElement = (SOAPHeaderElement) axisHandler.getHeader(stub, "header");
  assertNotNull("getHeader did not return the header that was just set", headerElement);
  assertEquals("value of the header did not match the value set", "foo",
      headerElement.getValue());
}
 
Example #10
Source File: GenericServiceEndpointWrapper.java    From tomee with Apache License 2.0 4 votes vote down vote up
public void setHeader(SOAPHeaderElement soapHeaderElement) {
    genericServiceEndpoint.setHeader(soapHeaderElement);
}
 
Example #11
Source File: GenericServiceEndpointWrapper.java    From tomee with Apache License 2.0 4 votes vote down vote up
public SOAPHeaderElement getHeader(String s, String s1) {
    return genericServiceEndpoint.getHeader(s, s1);
}
 
Example #12
Source File: GenericServiceEndpointWrapper.java    From tomee with Apache License 2.0 4 votes vote down vote up
public SOAPHeaderElement getResponseHeader(String s, String s1) {
    return genericServiceEndpoint.getResponseHeader(s, s1);
}
 
Example #13
Source File: GenericServiceEndpointWrapper.java    From tomee with Apache License 2.0 4 votes vote down vote up
public SOAPHeaderElement[] getHeaders() {
    return genericServiceEndpoint.getHeaders();
}
 
Example #14
Source File: GenericServiceEndpointWrapper.java    From tomee with Apache License 2.0 4 votes vote down vote up
public SOAPHeaderElement[] getResponseHeaders() {
    return genericServiceEndpoint.getResponseHeaders();
}
 
Example #15
Source File: AxisHandler.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
/**
 * @see SoapClientHandlerInterface#createSoapHeaderElement(QName)
 */
@Override
public javax.xml.soap.SOAPHeaderElement createSoapHeaderElement(QName qName) {
  return new SOAPHeaderElement(qName);
}
 
Example #16
Source File: DynamicWebServiceInvoker.java    From openbd-core with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns the response SOAP headers.
 * 
 * @return response SOAP headers
 */
public SOAPHeaderElement[] getResponseHeaders() {
	return this.responseHeaders;
}