예제 #1
0
 private void justCheckForJAXBAnnotations(ServiceInfo serviceInfo) {
   for (MessageInfo mi : serviceInfo.getMessages().values()) {
     for (MessagePartInfo mpi : mi.getMessageParts()) {
       checkForJAXBAnnotations(
           mpi, serviceInfo.getXmlSchemaCollection(), serviceInfo.getTargetNamespace());
     }
   }
 }
 protected void resetPartTypeClass(MessageInfo msgInfo) {
   if (msgInfo != null) {
     int size = msgInfo.getMessageParts().size();
     for (int x = 0; x < size; x++) {
       msgInfo.getMessageParts().get(x).setTypeClass(Source.class);
     }
   }
 }
예제 #3
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;
 }
예제 #4
0
  private String getActionFromInputMessage(final OperationInfo operation) {
    MessageInfo inputMessage = operation.getInput();

    if (inputMessage.getExtensionAttributes() != null) {
      String inputAction = InternalContextUtils.getAction(inputMessage);
      if (!StringUtils.isEmpty(inputAction)) {
        return inputAction;
      }
    }
    return null;
  }
예제 #5
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);
    }
  }
  private void buildMessage(
      MessageInfo minfo,
      javax.wsdl.Message msg,
      SchemaCollection schemas,
      int nextId,
      String partNameFilter) {
    for (Part part : cast(msg.getParts().values(), Part.class)) {

      if (StringUtils.isEmpty(partNameFilter) || part.getName().equals(partNameFilter)) {

        if (StringUtils.isEmpty(part.getName())) {
          throw new RuntimeException(
              "Problem with WSDL: part element in message "
                  + msg.getQName().getLocalPart()
                  + " does not specify a name.");
        }
        QName pqname = new QName(minfo.getName().getNamespaceURI(), part.getName());
        MessagePartInfo pi = minfo.getMessagePart(pqname);
        if (pi != null && pi.getMessageInfo().getName().equals(msg.getQName())) {
          continue;
        }
        pi = minfo.addOutOfBandMessagePart(pqname);

        if (!minfo.getName().equals(msg.getQName())) {
          pi.setMessageContainer(new MessageInfo(minfo.getOperation(), null, msg.getQName()));
        }

        if (part.getTypeName() != null) {
          pi.setTypeQName(part.getTypeName());
          pi.setElement(false);
          pi.setXmlSchema(schemas.getTypeByQName(part.getTypeName()));
        } else {
          pi.setElementQName(part.getElementName());
          pi.setElement(true);
          pi.setXmlSchema(schemas.getElementByQName(part.getElementName()));
        }
        pi.setProperty(OUT_OF_BAND_HEADER, Boolean.TRUE);
        pi.setProperty(HEADER, Boolean.TRUE);
        pi.setIndex(nextId);
        nextId++;
      }
    }
  }
예제 #7
0
  public static boolean isSameMessageInfo(MessageInfo mi1, MessageInfo mi2) {
    if ((mi1 == null && mi2 != null) || (mi1 != null && mi2 == null)) {
      return false;
    }

    if (mi1 != null && mi2 != null) {
      List<MessagePartInfo> mpil1 = mi1.getMessageParts();
      List<MessagePartInfo> mpil2 = mi2.getMessageParts();
      if (mpil1.size() != mpil2.size()) {
        return false;
      }
      int idx = 0;
      for (MessagePartInfo mpi1 : mpil1) {
        MessagePartInfo mpi2 = mpil2.get(idx);
        if (!mpi1.getTypeClass().equals(mpi2.getTypeClass())) {
          return false;
        }
        ++idx;
      }
    }
    return true;
  }
  private void setupHeaders(
      BindingOperationInfo op,
      BindingMessageInfo bMsg,
      BindingMessageInfo unwrappedBMsg,
      MessageInfo msg,
      SoapBindingConfiguration config) {
    List<MessagePartInfo> parts = new ArrayList<MessagePartInfo>();
    for (MessagePartInfo part : msg.getMessageParts()) {
      if (config.isHeader(op, part)) {
        SoapHeaderInfo headerInfo = new SoapHeaderInfo();
        headerInfo.setPart(part);
        headerInfo.setUse(config.getUse());

        bMsg.addExtensor(headerInfo);
      } else {
        parts.add(part);
      }
    }
    unwrappedBMsg.setMessageParts(parts);
  }
예제 #9
0
  /**
   * Mediate message flow.
   *
   * @param message the current message
   * @param isFault true if a fault is being mediated
   * @return true if processing should continue on dispatch path
   */
  protected boolean mediate(Message message, boolean isFault) {
    boolean continueProcessing = true;
    if (ContextUtils.isOutbound(message)) {
      if (usingAddressing(message)) {
        // request/response MAPs must be aggregated
        aggregate(message, isFault);
      }
      AddressingProperties theMaps =
          ContextUtils.retrieveMAPs(message, false, ContextUtils.isOutbound(message));
      if (null != theMaps) {
        if (ContextUtils.isRequestor(message)) {
          assertAddressing(message, theMaps.getReplyTo(), theMaps.getFaultTo());
        } else {
          checkReplyTo(message, theMaps);
        }
      }
    } else if (!ContextUtils.isRequestor(message)) {
      // responder validates incoming MAPs
      AddressingProperties maps = getMAPs(message, false, false);
      // check responses
      if (maps != null) {
        checkAddressingResponses(maps.getReplyTo(), maps.getFaultTo());
        assertAddressing(message, maps.getReplyTo(), maps.getFaultTo());
      }
      boolean isOneway = message.getExchange().isOneWay();
      if (null == maps && !addressingRequired) {
        return false;
      }
      continueProcessing = validateIncomingMAPs(maps, message);
      if (maps != null) {
        AddressingProperties theMaps =
            ContextUtils.retrieveMAPs(message, false, ContextUtils.isOutbound(message));
        if (null != theMaps) {
          assertAddressing(message, theMaps.getReplyTo(), theMaps.getFaultTo());
        }

        if (isOneway || !ContextUtils.isGenericAddress(maps.getReplyTo())) {
          InternalContextUtils.rebaseResponse(maps.getReplyTo(), maps, message);
        }
        if (!isOneway) {
          if (ContextUtils.isNoneAddress(maps.getReplyTo())) {
            LOG.warning("Detected NONE value in ReplyTo WSA header for request-respone MEP");
          } else {
            // ensure the inbound MAPs are available in both the full & fault
            // response messages (used to determine relatesTo etc.)
            ContextUtils.propogateReceivedMAPs(maps, message.getExchange());
          }
        }
      }
      if (continueProcessing) {
        // any faults thrown from here on can be correlated with this message
        message.put(FaultMode.class, FaultMode.LOGICAL_RUNTIME_FAULT);
      } else {
        // validation failure => dispatch is aborted, response MAPs
        // must be aggregated
        // isFault = true;
        // aggregate(message, isFault);
        if (isSOAP12(message)) {
          SoapFault soap12Fault =
              new SoapFault(
                  ContextUtils.retrieveMAPFaultReason(message), Soap12.getInstance().getSender());
          soap12Fault.setSubCode(
              new QName(Names.WSA_NAMESPACE_NAME, ContextUtils.retrieveMAPFaultName(message)));
          throw soap12Fault;
        }
        throw new SoapFault(
            ContextUtils.retrieveMAPFaultReason(message),
            new QName(Names.WSA_NAMESPACE_NAME, ContextUtils.retrieveMAPFaultName(message)));
      }
    } else {
      AddressingProperties theMaps =
          ContextUtils.retrieveMAPs(message, false, ContextUtils.isOutbound(message));
      if (null != theMaps) {
        assertAddressing(message, theMaps.getReplyTo(), theMaps.getFaultTo());
      }
      // If the wsa policy is enabled , but the client sets the
      // WSAddressingFeature.isAddressingRequired to false , we need to assert all WSA assertion to
      // true
      if (!ContextUtils.isOutbound(message)
          && ContextUtils.isRequestor(message)
          && getWSAddressingFeature(message) != null
          && !getWSAddressingFeature(message).isAddressingRequired()) {
        assertAddressing(message);
      }
      // CXF-3060 :If wsa policy is not enforced, AddressingProperties map is null and
      // AddressingFeature.isRequired, requestor checks inbound message and throw exception
      if (null == theMaps
          && !ContextUtils.isOutbound(message)
          && ContextUtils.isRequestor(message)
          && getWSAddressingFeature(message) != null
          && getWSAddressingFeature(message).isAddressingRequired()) {
        boolean missingWsaHeader = false;
        AssertionInfoMap aim = message.get(AssertionInfoMap.class);
        if (aim == null || aim.size() == 0) {
          missingWsaHeader = true;
        }
        if (aim != null && aim.size() > 0) {
          missingWsaHeader = true;
          QName[] types =
              new QName[] {
                MetadataConstants.ADDRESSING_ASSERTION_QNAME,
                MetadataConstants.USING_ADDRESSING_2004_QNAME,
                MetadataConstants.USING_ADDRESSING_2005_QNAME,
                MetadataConstants.USING_ADDRESSING_2006_QNAME
              };
          for (QName type : types) {
            for (AssertionInfo assertInfo : aim.getAssertionInfo(type)) {
              if (assertInfo.isAsserted()) {
                missingWsaHeader = false;
              }
            }
          }
        }
        if (missingWsaHeader) {
          throw new SoapFault(
              "MISSING_ACTION_MESSAGE",
              BUNDLE,
              new QName(Names.WSA_NAMESPACE_NAME, Names.HEADER_REQUIRED_NAME));
        }
      }
      if (MessageUtils.isPartialResponse(message)
          && message.getExchange().getOutMessage() != null) {
        // marked as a partial response, let's see if it really is
        MessageInfo min = message.get(MessageInfo.class);
        MessageInfo mout = message.getExchange().getOutMessage().get(MessageInfo.class);
        if (min != null
            && mout != null
            && min.getOperation() == mout.getOperation()
            && message.getContent(List.class) != null) {
          // the in and out messages are on the same operation
          // and we were able to get a response for it.
          message.remove(Message.PARTIAL_RESPONSE_MESSAGE);
        }
      }
    }
    return continueProcessing;
  }
  @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);
    }
  }
예제 #11
0
 private void addSoapBodyPart(MessageInfo msg, List<MessagePartInfo> bodyParts, String partName) {
   MessagePartInfo mpi = msg.getMessagePart(new QName(msg.getName().getNamespaceURI(), partName));
   bodyParts.add(mpi);
 }
예제 #12
0
  private List<MessagePartInfo> handleMimePart(
      MIMEPart mpart,
      List<MessagePartInfo> attParts,
      MessageInfo msg,
      BindingMessageInfo bmsg,
      List<MessagePartInfo> bodyParts,
      List<MessagePartInfo> messageParts) {
    if (mpart.getExtensibilityElements().size() < 1) {
      throw new RuntimeException("MIMEPart should at least contain one element!");
    }
    String partName = null;
    for (Object content : mpart.getExtensibilityElements()) {
      if (content instanceof MIMEContent) {
        MIMEContent mc = (MIMEContent) content;
        partName = mc.getPart();

        if (attParts == null) {
          attParts = new LinkedList<MessagePartInfo>();
        }

        if (StringUtils.isEmpty(partName)) {
          throw new RuntimeException(
              "Problem with WSDL: mime content element in operation "
                  + bmsg.getBindingOperation().getName().getLocalPart()
                  + " does not specify a part.");
        }

        MessagePartInfo mpi =
            msg.getMessagePart(new QName(msg.getName().getNamespaceURI(), partName));
        mpi.setProperty(Message.CONTENT_TYPE, mc.getType());
        attParts.add(mpi);
        // Attachments shouldn't be part of the body message
        bmsg.getMessageParts().remove(mpi);
      } else if (SOAPBindingUtil.isSOAPBody(content)) {
        SoapBody sb = SOAPBindingUtil.getSoapBody(content);
        if (sb.getParts() != null && sb.getParts().size() == 1) {
          partName = (String) sb.getParts().get(0);
        }

        // We can have a list of empty part names here.
        if (partName != null) {
          addSoapBodyPart(msg, bodyParts, partName);
        }
      } else if (SOAPBindingUtil.isSOAPHeader(content)) {
        SoapHeader header = SOAPBindingUtil.getSoapHeader(content);

        SoapHeaderInfo headerInfo = new SoapHeaderInfo();
        headerInfo.setUse(header.getUse());

        if (StringUtils.isEmpty(header.getPart())) {
          throw new RuntimeException(
              "Problem with WSDL: soap:header element in operation "
                  + bmsg.getBindingOperation().getName().getLocalPart()
                  + " does not specify a part.");
        }

        MessagePartInfo mpi =
            msg.getMessagePart(new QName(msg.getName().getNamespaceURI(), header.getPart()));

        if (mpi != null
            && header.getMessage() != null
            && !mpi.getMessageInfo().getName().equals(header.getMessage())) {
          mpi = null;
          // out of band, let's find it
          for (MessagePartInfo mpi2 : msg.getOutOfBandParts()) {
            if (mpi2.getName().getLocalPart().equals(header.getPart())
                && mpi2.getMessageInfo().getName().equals(header.getMessage())) {
              mpi = mpi2;
            }
          }
        }

        if (mpi != null) {
          headerInfo.setPart(mpi);
          messageParts.remove(mpi);
          bmsg.getMessageParts().remove(mpi);
          bmsg.addExtensor(headerInfo);
        }
      }
    }
    return attParts;
  }
예제 #13
0
  private void initializeMessage(
      SoapBindingInfo bi, BindingOperationInfo boi, BindingMessageInfo bmsg) {
    MessageInfo msg = bmsg.getMessageInfo();

    List<MessagePartInfo> messageParts = new ArrayList<MessagePartInfo>();
    messageParts.addAll(msg.getMessageParts());

    List<SoapHeader> headers =
        SOAPBindingUtil.getSoapHeaders(bmsg.getExtensors(ExtensibilityElement.class));
    if (headers != null) {
      for (SoapHeader header : headers) {
        SoapHeaderInfo headerInfo = new SoapHeaderInfo();
        headerInfo.setUse(header.getUse());
        if (StringUtils.isEmpty(header.getPart())) {
          throw new RuntimeException(
              "Problem with WSDL: soap:header element in operation "
                  + boi.getName().getLocalPart()
                  + " does not specify a part.");
        }
        MessagePartInfo part =
            msg.getMessagePart(new QName(msg.getName().getNamespaceURI(), header.getPart()));
        if (part != null
            && header.getMessage() != null
            && !part.getMessageInfo().getName().equals(header.getMessage())) {
          part = null;
          // out of band, let's find it
          for (MessagePartInfo mpi : msg.getOutOfBandParts()) {
            if (mpi.getName().getLocalPart().equals(header.getPart())
                && mpi.getMessageInfo().getName().equals(header.getMessage())) {
              part = mpi;
            }
          }
        }
        if (part != null) {
          headerInfo.setPart(part);
          messageParts.remove(part);
          bmsg.addExtensor(headerInfo);
        }
      }

      // Exclude the header parts from the message part list.
      bmsg.setMessageParts(messageParts);
    }

    SoapBodyInfo bodyInfo = new SoapBodyInfo();
    SoapBody soapBody = SOAPBindingUtil.getSoapBody(bmsg.getExtensors(ExtensibilityElement.class));

    List<?> parts = null;
    if (soapBody == null) {
      MIMEMultipartRelated mmr = bmsg.getExtensor(MIMEMultipartRelated.class);
      if (mmr != null) {
        parts = mmr.getMIMEParts();
      }
    } else {
      bmsg.addExtensor(soapBody);
      bodyInfo.setUse(soapBody.getUse());
      parts = soapBody.getParts();
    }

    // Initialize the body parts.
    List<MessagePartInfo> attParts = null;
    if (parts != null) {
      List<MessagePartInfo> bodyParts = new ArrayList<MessagePartInfo>();
      for (Iterator<?> itr = parts.iterator(); itr.hasNext(); ) {
        Object part = itr.next();
        if (part instanceof MIMEPart) {
          MIMEPart mpart = (MIMEPart) part;
          attParts = handleMimePart(mpart, attParts, msg, bmsg, bodyParts, messageParts);
        } else {
          addSoapBodyPart(msg, bodyParts, (String) part);
        }
      }
      bodyInfo.setParts(bodyParts);
      bodyInfo.setAttachments(attParts);
    } else {
      bodyInfo.setParts(messageParts);
    }

    bmsg.addExtensor(bodyInfo);
  }
예제 #14
0
  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);
  }