org.apache.axis.message.MessageElement Java Examples

The following examples show how to use org.apache.axis.message.MessageElement. 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: OdeConnector.java    From container with Apache License 2.0 5 votes vote down vote up
private String resolveServiceAddress(final MessageElement msgElement) {
    final String serviceAddress = null;

    if (msgElement != null) {
        // Check if the root element is a BPEL service reference
        if (msgElement.getNamespaceURI().equals(NS_SERVICE_REF)) {
            final NodeList nodeList = msgElement.getElementsByTagNameNS(NS_WS_ADDRESSING, "EndpointReference");

            if (nodeList != null && nodeList.getLength() > 0) {
                int index = 0;
                while (index < nodeList.getLength()) {
                    final Node node = nodeList.item(index);

                    if (node.getNodeType() == Node.ELEMENT_NODE) {
                        final Element epr = (Element) node;
                        final NodeList addList = epr.getElementsByTagNameNS(NS_WS_ADDRESSING, "Address");
                        if (addList != null && addList.getLength() > 0) {
                            // By default there should be only one address element, therefore we take the
                            // first node
                            if (addList.item(0).getFirstChild() != null) {
                                return addList.item(0).getFirstChild().getNodeValue();
                            }
                        }
                    }

                    index++;
                }
            }
        }
    }

    return serviceAddress;
}
 
Example #2
Source File: AxisDeserializer.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public <ResultT> List<ResultT> deserializeBatchJobMutateResults(
    URL url,
    List<TypeMapping> serviceTypeMappings,
    Class<ResultT> resultClass,
    QName resultQName,
    int startIndex,
    int numberResults)
    throws Exception {

  List<ResultT> results = Lists.newArrayList();

  // Build a wrapped input stream from the response.
  InputStream wrappedStream =
      ByteSource.concat(
              ByteSource.wrap(SOAP_START_BODY.getBytes(UTF_8)),
              batchJobHelperUtility.buildWrappedByteSource(url, startIndex, numberResults),
              ByteSource.wrap(SOAP_END_BODY.getBytes(UTF_8)))
          .openStream();

  // Create a MessageContext with a new TypeMappingRegistry that will only
  // contain deserializers derived from serviceTypeMappings and the
  // result class/QName pair.
  MessageContext messageContext = new MessageContext(new AxisClient());
  TypeMappingRegistryImpl typeMappingRegistry = new TypeMappingRegistryImpl(true);
  messageContext.setTypeMappingRegistry(typeMappingRegistry);

  // Construct an Axis deserialization context.
  DeserializationContext deserializationContext =
      new DeserializationContext(
          new InputSource(wrappedStream), messageContext, Message.RESPONSE);

  // Register all type mappings with the new type mapping registry.
  TypeMapping registryTypeMapping =
      typeMappingRegistry.getOrMakeTypeMapping(messageContext.getEncodingStyle());
  registerTypeMappings(registryTypeMapping, serviceTypeMappings);

  // Parse the wrapped input stream.
  deserializationContext.parse();

  // Read the deserialized mutate results from the parsed stream.
  SOAPEnvelope envelope = deserializationContext.getEnvelope();
  MessageElement body = envelope.getFirstBody();

  for (Iterator<?> iter = body.getChildElements(); iter.hasNext(); ) {
    Object child = iter.next();
    MessageElement childElm = (MessageElement) child;
    @SuppressWarnings("unchecked")
    ResultT mutateResult = (ResultT) childElm.getValueAsType(resultQName, resultClass);
    results.add(mutateResult);
  }
  return results;
}