Exemplo n.º 1
0
 private String getActionFromOutputMessage(final OperationInfo operation) {
   MessageInfo outputMessage = operation.getOutput();
   if (outputMessage != null && outputMessage.getExtensionAttributes() != null) {
     String outputAction = InternalContextUtils.getAction(outputMessage);
     if (!StringUtils.isEmpty(outputAction)) {
       return outputAction;
     }
   }
   return null;
 }
Exemplo n.º 2
0
  private void visitOperation(OperationInfo o) {
    MessageInfo in = o.getInput();
    if (in != null) {
      begin(in);

      for (MessagePartInfo part : in.getMessageParts()) {
        begin(part);
        end(part);
      }

      end(in);
    }

    MessageInfo out = o.getOutput();
    if (out != null) {
      begin(out);

      for (MessagePartInfo part : out.getMessageParts()) {
        begin(part);
        end(part);
      }

      end(out);
    }

    for (FaultInfo f : o.getFaults()) {
      begin(f);

      for (MessagePartInfo part : f.getMessageParts()) {
        begin(part);
        end(part);
      }

      end(f);
    }

    if (o.isUnwrappedCapable()) {
      OperationInfo uop = o.getUnwrappedOperation();
      begin(uop);
      visitOperation(o.getUnwrappedOperation());
      end(uop);
    }
  }
  @Override
  public void begin(MessagePartInfo part) {
    Class<?> clazz = part.getTypeClass();
    if (clazz == null) {
      return;
    }

    if (Exception.class.isAssignableFrom(clazz)) {
      // exceptions are handled special, make sure we mark it
      part.setProperty(JAXBDataBinding.class.getName() + ".CUSTOM_EXCEPTION", Boolean.TRUE);
    }
    boolean isFromWrapper = part.getMessageInfo().getOperation().isUnwrapped();
    if (isFromWrapper && !Boolean.TRUE.equals(part.getProperty("messagepart.isheader"))) {
      UnwrappedOperationInfo uop = (UnwrappedOperationInfo) part.getMessageInfo().getOperation();
      OperationInfo op = uop.getWrappedOperation();
      MessageInfo inf = null;
      if (uop.getInput() == part.getMessageInfo()) {
        inf = op.getInput();
      } else if (uop.getOutput() == part.getMessageInfo()) {
        inf = op.getOutput();
      }
      if (inf != null && inf.getMessagePart(0).getTypeClass() != null) {
        // if the wrapper has a type class, we don't need to do anything
        // as everything would have been discovered when walking the
        // wrapper type (unless it's a header which wouldn't be in the wrapper)
        return;
      }
    }
    if (isFromWrapper && clazz.isArray() && !Byte.TYPE.equals(clazz.getComponentType())) {
      clazz = clazz.getComponentType();
    }

    Annotation[] a = (Annotation[]) part.getProperty("parameter.annotations");
    checkForAdapter(clazz, a);

    Type genericType = (Type) part.getProperty("generic.type");
    if (genericType != null) {
      boolean isList = Collection.class.isAssignableFrom(clazz);
      if (isFromWrapper) {
        if (genericType instanceof Class && ((Class<?>) genericType).isArray()) {
          Class<?> cl2 = (Class<?>) genericType;
          if (cl2.isArray() && !Byte.TYPE.equals(cl2.getComponentType())) {
            genericType = cl2.getComponentType();
          }
          addType(genericType);
        } else if (!isList) {
          addType(genericType);
        }
      } else {
        addType(genericType, true);
      }

      if (isList && genericType instanceof ParameterizedType) {
        ParameterizedType pt = (ParameterizedType) genericType;
        if (pt.getActualTypeArguments().length > 0
            && pt.getActualTypeArguments()[0] instanceof Class) {

          Class<? extends Object> arrayCls =
              Array.newInstance((Class<?>) pt.getActualTypeArguments()[0], 0).getClass();
          clazz = arrayCls;
          part.setTypeClass(clazz);
          if (isFromWrapper) {
            addType(clazz.getComponentType(), true);
          }
        } else if (pt.getActualTypeArguments().length > 0
            && pt.getActualTypeArguments()[0] instanceof GenericArrayType) {
          GenericArrayType gat = (GenericArrayType) pt.getActualTypeArguments()[0];
          gat.getGenericComponentType();
          Class<? extends Object> arrayCls =
              Array.newInstance((Class<?>) gat.getGenericComponentType(), 0).getClass();
          clazz = Array.newInstance(arrayCls, 0).getClass();
          part.setTypeClass(clazz);
          if (isFromWrapper) {
            addType(clazz.getComponentType(), true);
          }
        }
      }
      if (isFromWrapper && isList) {
        clazz = null;
      }
    }
    if (clazz != null) {
      if (!isFromWrapper
          && clazz.getAnnotation(XmlRootElement.class) == null
          && clazz.getAnnotation(XmlType.class) != null
          && StringUtils.isEmpty(clazz.getAnnotation(XmlType.class).name())) {
        Object ref = JAXBClassLoaderUtils.createTypeReference(part.getName(), clazz);
        if (ref != null) {
          typeReferences.add(ref);
        }
      }

      addClass(clazz);
    }
  }
Exemplo n.º 4
0
 public static boolean isSameOperationInfo(OperationInfo oi1, OperationInfo oi2) {
   return oi1.getName().equals(oi2.getName())
       && isSameMessageInfo(oi1.getInput(), oi2.getInput())
       && isSameMessageInfo(oi1.getOutput(), oi2.getOutput())
       && isSameFaultInfo(oi1.getFaults(), oi2.getFaults());
 }
  private void addOutOfBandParts(
      final BindingOperationInfo bop,
      final javax.wsdl.Message msg,
      final SchemaCollection schemas,
      boolean isInput,
      final String partName) {
    MessageInfo minfo = null;
    MessageInfo.Type type;

    int nextId = 0;
    minfo = bop.getOperationInfo().getInput();
    if (minfo != null) {
      for (MessagePartInfo part : minfo.getMessageParts()) {
        if (part.getIndex() >= nextId) {
          nextId = part.getIndex() + 1;
        }
      }
    }
    minfo = bop.getOperationInfo().getOutput();
    if (minfo != null) {
      for (MessagePartInfo part : minfo.getMessageParts()) {
        if (part.getIndex() >= nextId) {
          nextId = part.getIndex() + 1;
        }
      }
    }

    if (isInput) {
      type = MessageInfo.Type.INPUT;
      minfo = bop.getOperationInfo().getInput();
    } else {
      type = MessageInfo.Type.OUTPUT;
      minfo = bop.getOperationInfo().getOutput();
    }

    if (minfo == null) {
      minfo = new MessageInfo(null, type, msg.getQName());
    }
    buildMessage(minfo, msg, schemas, nextId, partName);

    // for wrapped style
    OperationInfo unwrapped = bop.getOperationInfo().getUnwrappedOperation();
    if (unwrapped == null) {
      return;
    }

    nextId = 0;
    minfo = unwrapped.getInput();
    if (minfo != null) {
      for (MessagePartInfo part : minfo.getMessageParts()) {
        if (part.getIndex() >= nextId) {
          nextId = part.getIndex() + 1;
        }
      }
    }
    minfo = unwrapped.getOutput();
    if (minfo != null) {
      for (MessagePartInfo part : minfo.getMessageParts()) {
        if (part.getIndex() >= nextId) {
          nextId = part.getIndex() + 1;
        }
      }
    }

    if (isInput) {
      minfo = unwrapped.getInput();
      type = MessageInfo.Type.INPUT;
    } else {
      minfo = unwrapped.getOutput();
      type = MessageInfo.Type.OUTPUT;
    }

    if (minfo == null) {
      minfo = new MessageInfo(unwrapped, type, msg.getQName());
    }
    buildMessage(minfo, msg, schemas, nextId, partName);
  }
Exemplo n.º 6
0
  protected static List<Source> getPayloadBodyElements(Message message, Map<String, String> nsMap) {
    // take the namespace attribute from soap envelop
    Map<String, String> bodyNC = CastUtils.cast((Map<?, ?>) message.get("soap.body.ns.context"));
    if (bodyNC != null) {
      // if there is no Node and the addNamespaceContext option is enabled, this map is available
      nsMap.putAll(bodyNC);
    } else {
      Document soapEnv = (Document) message.getContent(Node.class);
      if (soapEnv != null) {
        NamedNodeMap attrs = soapEnv.getFirstChild().getAttributes();
        for (int i = 0; i < attrs.getLength(); i++) {
          Node node = attrs.item(i);
          if (!node.getNodeValue().equals(Soap11.SOAP_NAMESPACE)
              && !node.getNodeValue().equals(Soap12.SOAP_NAMESPACE)) {
            nsMap.put(node.getLocalName(), node.getNodeValue());
          }
        }
      }
    }
    MessageContentsList inObjects = MessageContentsList.getContentsList(message);
    if (inObjects == null) {
      return new ArrayList<Source>(0);
    }
    org.apache.cxf.message.Exchange exchange = message.getExchange();
    BindingOperationInfo boi = exchange.getBindingOperationInfo();

    OperationInfo op = boi.getOperationInfo();

    if (boi.isUnwrapped()) {
      op = boi.getWrappedOperation().getOperationInfo();
    }

    List<MessagePartInfo> partInfos = null;
    boolean client = Boolean.TRUE.equals(message.get(Message.REQUESTOR_ROLE));
    if (client) {
      // it is a response
      partInfos = op.getOutput().getMessageParts();

    } else {
      // it is a request
      partInfos = op.getInput().getMessageParts();
    }

    List<Source> answer = new ArrayList<Source>();

    for (MessagePartInfo partInfo : partInfos) {
      if (!inObjects.hasValue(partInfo)) {
        continue;
      }

      Object part = inObjects.get(partInfo);

      if (part instanceof Holder) {
        part = ((Holder<?>) part).value;
      }

      if (part instanceof Source) {
        Element element = null;
        if (part instanceof DOMSource) {
          element = getFirstElement(((DOMSource) part).getNode());
        }

        if (element != null) {
          addNamespace(element, nsMap);
          answer.add(new DOMSource(element));
        } else {
          answer.add((Source) part);
        }

        if (LOG.isTraceEnabled()) {
          LOG.trace("Extract body element {}", element == null ? "null" : getXMLString(element));
        }
      } else if (part instanceof Element) {
        addNamespace((Element) part, nsMap);
        answer.add(new DOMSource((Element) part));
      } else {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Unhandled part type '{}'", part.getClass());
        }
      }
    }

    return answer;
  }