protected String getActionUri(Message message, boolean checkMessage) {
    BindingOperationInfo bop = message.getExchange().getBindingOperationInfo();
    if (bop == null || Boolean.TRUE.equals(bop.getProperty("operation.is.synthetic"))) {
      return null;
    }
    OperationInfo op = bop.getOperationInfo();
    if (op.isUnwrapped()) {
      op = ((UnwrappedOperationInfo) op).getWrappedOperation();
    }

    String actionUri = null;
    if (checkMessage) {
      actionUri = (String) message.get(ContextUtils.ACTION);
      if (actionUri == null) {
        actionUri = (String) message.get(SoapBindingConstants.SOAP_ACTION);
      }
    }
    if (actionUri != null) {
      return actionUri;
    }
    String opNamespace = getActionBaseUri(op);

    boolean inbound = !ContextUtils.isOutbound(message);
    boolean requestor = ContextUtils.isRequestor(message);
    boolean inMsg = requestor ^ inbound;
    if (ContextUtils.isFault(message)) {
      String faultName = getFaultNameFromMessage(message);
      actionUri = getActionFromFaultMessage(op, faultName);
    } else if (inMsg) {
      String explicitAction = getActionFromInputMessage(op);
      if (StringUtils.isEmpty(explicitAction)) {
        SoapOperationInfo soi = InternalContextUtils.getSoapOperationInfo(bop);
        explicitAction = soi == null ? null : soi.getAction();
      }

      if (!StringUtils.isEmpty(explicitAction)) {
        actionUri = explicitAction;
      } else if (null == op.getInputName()) {
        actionUri = addPath(opNamespace, op.getName().getLocalPart() + "Request");
      } else {
        actionUri = addPath(opNamespace, op.getInputName());
      }
    } else {
      String explicitAction = getActionFromOutputMessage(op);
      if (explicitAction != null) {
        actionUri = explicitAction;
      } else if (null == op.getOutputName()) {
        actionUri = addPath(opNamespace, op.getName().getLocalPart() + "Response");
      } else {
        actionUri = addPath(opNamespace, op.getOutputName());
      }
    }
    return actionUri;
  }
 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;
 }
  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;
  }
 private String getActionFromFaultMessage(final OperationInfo operation, final String faultName) {
   if (operation.getFaults() != null) {
     for (FaultInfo faultInfo : operation.getFaults()) {
       if (isSameFault(faultInfo, faultName)) {
         if (faultInfo.getExtensionAttributes() != null) {
           String faultAction = InternalContextUtils.getAction(faultInfo);
           if (!StringUtils.isEmpty(faultAction)) {
             return faultAction;
           }
         }
         return addPath(
             addPath(
                 addPath(getActionBaseUri(operation), operation.getName().getLocalPart()),
                 "Fault"),
             faultInfo.getFaultName().getLocalPart());
       }
     }
   }
   return addPath(
       addPath(addPath(getActionBaseUri(operation), operation.getName().getLocalPart()), "Fault"),
       faultName);
 }
  private BindingOperationInfo setUpBindingOperationInfo(
      String nsuri, String opreq, String opresp, Method method) {
    ServiceInfo si = new ServiceInfo();
    InterfaceInfo iinf =
        new InterfaceInfo(si, new QName(nsuri, method.getDeclaringClass().getSimpleName()));
    OperationInfo opInfo = iinf.addOperation(new QName(nsuri, method.getName()));
    opInfo.setProperty(Method.class.getName(), method);
    opInfo.setInput(opreq, opInfo.createMessage(new QName(nsuri, opreq), Type.INPUT));
    opInfo.setOutput(opresp, opInfo.createMessage(new QName(nsuri, opresp), Type.INPUT));

    BindingOperationInfo bindingOpInfo = new BindingOperationInfo(null, opInfo);

    return bindingOpInfo;
  }
Exemple #6
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 String getActionBaseUri(final OperationInfo operation) {
   String interfaceName = operation.getInterface().getName().getLocalPart();
   return addPath(operation.getName().getNamespaceURI(), interfaceName);
 }
  @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);
    }
  }
Exemple #9
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);
  }
  public BindingInfo createBindingInfo(ServiceInfo si, String bindingid, Object conf) {
    SoapBindingConfiguration config;
    if (conf instanceof SoapBindingConfiguration) {
      config = (SoapBindingConfiguration) conf;
    } else {
      config = new SoapBindingConfiguration();
    }
    if (WSDLConstants.NS_SOAP12.equals(bindingid)
        || WSDLConstants.NS_SOAP12_HTTP_BINDING.equals(bindingid)) {
      config.setVersion(Soap12.getInstance());
      config.setTransportURI(WSDLConstants.NS_SOAP_HTTP_TRANSPORT);
    }
    SoapBindingInfo info = new SoapBindingInfo(si, bindingid, config.getVersion());

    info.setName(config.getBindingName(si));
    info.setStyle(config.getStyle());

    info.setTransportURI(config.getTransportURI());

    if (config.isMtomEnabled()) {
      info.setProperty(Message.MTOM_ENABLED, Boolean.TRUE);
    }

    for (OperationInfo op : si.getInterface().getOperations()) {
      SoapOperationInfo sop = new SoapOperationInfo();
      sop.setAction(config.getSoapAction(op));
      sop.setStyle(config.getStyle(op));

      BindingOperationInfo bop =
          info.buildOperation(op.getName(), op.getInputName(), op.getOutputName());

      bop.addExtensor(sop);

      info.addOperation(bop);

      BindingMessageInfo bInput = bop.getInput();
      if (bInput != null) {
        MessageInfo input = null;
        BindingMessageInfo unwrappedMsg = bInput;
        if (bop.isUnwrappedCapable()) {
          input = bop.getOperationInfo().getUnwrappedOperation().getInput();
          unwrappedMsg = bop.getUnwrappedOperation().getInput();
        } else {
          input = bop.getOperationInfo().getInput();
        }
        setupHeaders(bop, bInput, unwrappedMsg, input, config);
      }

      BindingMessageInfo bOutput = bop.getOutput();
      if (bOutput != null) {
        MessageInfo output = null;
        BindingMessageInfo unwrappedMsg = bOutput;
        if (bop.isUnwrappedCapable()) {
          output = bop.getOperationInfo().getUnwrappedOperation().getOutput();
          unwrappedMsg = bop.getUnwrappedOperation().getOutput();
        } else {
          output = bop.getOperationInfo().getOutput();
        }
        setupHeaders(bop, bOutput, unwrappedMsg, output, config);
      }
    }

    try {
      createSoapBinding(info);
    } catch (WSDLException e) {
      e.printStackTrace();
    }

    return info;
  }
Exemple #12
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;
  }