コード例 #1
0
  protected String addOperationNode(
      NSStack nsStack,
      Message message,
      XMLStreamWriter xmlWriter,
      boolean output,
      BindingOperationInfo boi)
      throws XMLStreamException {
    String responseSuffix = output ? "Response" : "";
    String ns = boi.getName().getNamespaceURI();
    SoapBody body = null;
    if (output) {
      body = boi.getOutput().getExtensor(SoapBody.class);
    } else {
      body = boi.getInput().getExtensor(SoapBody.class);
    }
    if (body != null && !StringUtils.isEmpty(body.getNamespaceURI())) {
      ns = body.getNamespaceURI();
    }

    nsStack.add(ns);
    String prefix = nsStack.getPrefix(ns);
    StaxUtils.writeStartElement(
        xmlWriter, prefix, boi.getName().getLocalPart() + responseSuffix, ns);
    return ns;
  }
コード例 #2
0
  public void handleMessage(Message message) throws Fault {
    if (bus == null) {
      bus = message.getExchange().getBus();
      if (bus == null) {
        bus = BusFactory.getDefaultBus(false);
      }
      if (bus == null) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("BUS_NOT_FOUND", BUNDLE));
      }
    }

    ServerRegistry registry = bus.getExtension(ServerRegistry.class);

    if (registry == null) {
      throw new Fault(new org.apache.cxf.common.i18n.Message("SERVER_REGISTRY_NOT_FOUND", BUNDLE));
    }

    Exchange exchange = message.getExchange();
    Endpoint senderEndpoint = exchange.getEndpoint();

    if (senderEndpoint == null) {
      throw new Fault(new org.apache.cxf.common.i18n.Message("ENDPOINT_NOT_FOUND", BUNDLE));
    }

    BindingOperationInfo boi = exchange.getBindingOperationInfo();

    if (boi == null) {
      throw new Fault(new org.apache.cxf.common.i18n.Message("OPERATIONINFO_NOT_FOUND", BUNDLE));
    }

    Server srv = isColocated(registry.getServers(), senderEndpoint, boi);

    if (srv != null) {
      if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Operation:" + boi.getName() + " dispatched as colocated call.");
      }

      InterceptorChain outChain = message.getInterceptorChain();
      outChain.abort();
      exchange.put(Bus.class, bus);
      message.put(COLOCATED, Boolean.TRUE);
      message.put(Message.WSDL_OPERATION, boi.getName());
      message.put(Message.WSDL_INTERFACE, boi.getBinding().getInterface().getName());
      invokeColocObserver(message, srv.getEndpoint());
      if (!exchange.isOneWay()) {
        invokeInboundChain(exchange, senderEndpoint);
      }
    } else {
      if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Operation:" + boi.getName() + " dispatched as remote call.");
      }

      message.put(COLOCATED, Boolean.FALSE);
    }
  }
コード例 #3
0
  protected void addMessageFromBinding(
      ExtensibilityElement ext, BindingOperationInfo bop, boolean isInput) {
    SoapHeader header = SOAPBindingUtil.getSoapHeader(ext);

    ServiceInfo serviceInfo = bop.getBinding().getService();

    if (header != null && serviceInfo.getMessage(header.getMessage()) == null) {
      Definition def = (Definition) serviceInfo.getProperty(WSDLServiceBuilder.WSDL_DEFINITION);
      SchemaCollection schemas = serviceInfo.getXmlSchemaCollection();

      if (def != null && schemas != null) {
        QName qn = header.getMessage();

        javax.wsdl.Message msg = findMessage(qn, def);
        if (msg != null) {
          addOutOfBandParts(bop, msg, schemas, isInput, header.getPart());
          serviceInfo.refresh();
        } else {
          throw new RuntimeException(
              "Problem with WSDL: soap:header element"
                  + " for operation "
                  + bop.getName()
                  + " is referring to an undefined wsdl:message element: "
                  + qn);
        }
      }
    }
  }
コード例 #4
0
  public void handleMessage(Message message) {
    try {
      NSStack nsStack = new NSStack();
      nsStack.push();

      BindingOperationInfo operation =
          (BindingOperationInfo) message.getExchange().get(BindingOperationInfo.class.getName());

      assert operation.getName() != null;

      XMLStreamWriter xmlWriter = getXMLStreamWriter(message);

      List<MessagePartInfo> parts = null;

      if (!isRequestor(message)) {
        parts = operation.getOutput().getMessageParts();
        addOperationNode(nsStack, message, xmlWriter, true, operation);
      } else {
        parts = operation.getInput().getMessageParts();
        addOperationNode(nsStack, message, xmlWriter, false, operation);
      }

      MessageContentsList objs = MessageContentsList.getContentsList(message);
      if (objs == null) {
        return;
      }

      for (MessagePartInfo part : parts) {
        if (objs.hasValue(part)) {
          Object o = objs.get(part);
          if (o == null) {
            // WSI-BP R2211 - RPC/Lit parts are not allowed to be xsi:nil
            throw new Fault(
                new org.apache.cxf.common.i18n.Message(
                    "BP_2211_RPCLIT_CANNOT_BE_NULL", LOG, part.getConcreteName()));
          }
          // WSI-BP R2737  -RPC/LIG part name space is empty
          // part.setConcreteName(new QName("", part.getConcreteName().getLocalPart()));
        }
      }
      writeParts(message, message.getExchange(), operation, objs, parts);

      // Finishing the writing.
      xmlWriter.writeEndElement();
    } catch (XMLStreamException e) {
      throw new Fault(e);
    }
  }
コード例 #5
0
  protected Server isColocated(List<Server> servers, Endpoint endpoint, BindingOperationInfo boi) {
    if (servers != null) {
      Service senderService = endpoint.getService();
      EndpointInfo senderEI = endpoint.getEndpointInfo();
      for (Server s : servers) {
        Endpoint receiverEndpoint = s.getEndpoint();
        Service receiverService = receiverEndpoint.getService();
        EndpointInfo receiverEI = receiverEndpoint.getEndpointInfo();
        if (receiverService.getName().equals(senderService.getName())
            && receiverEI.getName().equals(senderEI.getName())) {
          // Check For Operation Match.
          BindingOperationInfo receiverOI = receiverEI.getBinding().getOperation(boi.getName());
          if (receiverOI != null && isCompatibleOperationInfo(boi, receiverOI)) {
            return s;
          }
        }
      }
    }

    return null;
  }
コード例 #6
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);
  }
コード例 #7
0
  private void createSoapBinding(final SoapBindingInfo bi) throws WSDLException {
    boolean isSoap12 = bi.getSoapVersion() instanceof Soap12;
    Bus bs = getBus();
    WSDLManager m = bs.getExtension(WSDLManager.class);
    ExtensionRegistry extensionRegistry = m.getExtensionRegistry();

    SoapBinding soapBinding = SOAPBindingUtil.createSoapBinding(extensionRegistry, isSoap12);
    soapBinding.setStyle(bi.getStyle());
    soapBinding.setTransportURI(bi.getTransportURI());
    bi.addExtensor(soapBinding);

    for (BindingOperationInfo b : bi.getOperations()) {
      for (BindingFaultInfo faultInfo : b.getFaults()) {
        SoapFault soapFault = SOAPBindingUtil.createSoapFault(extensionRegistry, isSoap12);
        soapFault.setUse("literal");
        soapFault.setName(faultInfo.getFaultInfo().getFaultName().getLocalPart());
        faultInfo.addExtensor(soapFault);
      }
      SoapOperationInfo soi = b.getExtensor(SoapOperationInfo.class);

      SoapOperation soapOperation =
          SOAPBindingUtil.createSoapOperation(extensionRegistry, isSoap12);
      soapOperation.setSoapActionURI(soi.getAction());
      soapOperation.setStyle(soi.getStyle());
      boolean isRpc = "rpc".equals(soapOperation.getStyle());

      b.addExtensor(soapOperation);

      if (b.getInput() != null) {
        List<String> bodyParts = null;
        List<SoapHeaderInfo> headerInfos = b.getInput().getExtensors(SoapHeaderInfo.class);
        if (headerInfos != null && headerInfos.size() > 0) {
          bodyParts = new ArrayList<String>();
          for (MessagePartInfo part : b.getInput().getMessageParts()) {
            bodyParts.add(part.getName().getLocalPart());
          }

          for (SoapHeaderInfo headerInfo : headerInfos) {
            SoapHeader soapHeader =
                SOAPBindingUtil.createSoapHeader(extensionRegistry, BindingInput.class, isSoap12);
            soapHeader.setMessage(b.getInput().getMessageInfo().getName());
            soapHeader.setPart(headerInfo.getPart().getName().getLocalPart());
            soapHeader.setUse("literal");
            bodyParts.remove(headerInfo.getPart().getName().getLocalPart());
            headerInfo.getPart().setProperty(HEADER, true);
            b.getInput().addExtensor(soapHeader);
          }
        }
        SoapBody body =
            SOAPBindingUtil.createSoapBody(extensionRegistry, BindingInput.class, isSoap12);
        body.setUse("literal");
        if (isRpc) {
          body.setNamespaceURI(b.getName().getNamespaceURI());
        }

        if (bodyParts != null) {
          body.setParts(bodyParts);
        }

        b.getInput().addExtensor(body);
      }

      if (b.getOutput() != null) {
        List<String> bodyParts = null;
        List<SoapHeaderInfo> headerInfos = b.getOutput().getExtensors(SoapHeaderInfo.class);
        if (headerInfos != null && headerInfos.size() > 0) {
          bodyParts = new ArrayList<String>();
          for (MessagePartInfo part : b.getOutput().getMessageParts()) {
            bodyParts.add(part.getName().getLocalPart());
          }
          for (SoapHeaderInfo headerInfo : headerInfos) {
            SoapHeader soapHeader =
                SOAPBindingUtil.createSoapHeader(extensionRegistry, BindingOutput.class, isSoap12);
            soapHeader.setMessage(b.getOutput().getMessageInfo().getName());
            soapHeader.setPart(headerInfo.getPart().getName().getLocalPart());
            soapHeader.setUse("literal");
            bodyParts.remove(headerInfo.getPart().getName().getLocalPart());
            b.getOutput().addExtensor(soapHeader);
          }
        }
        SoapBody body =
            SOAPBindingUtil.createSoapBody(extensionRegistry, BindingOutput.class, isSoap12);
        body.setUse("literal");
        if (isRpc) {
          body.setNamespaceURI(b.getName().getNamespaceURI());
        }

        if (bodyParts != null) {
          body.setParts(bodyParts);
        }

        b.getOutput().addExtensor(body);
      }
    }
  }
コード例 #8
0
ファイル: DefaultCxfBinding.java プロジェクト: hayden74/camel
  /** This method is called by {@link CxfConsumer}. */
  public void populateExchangeFromCxfRequest(
      org.apache.cxf.message.Exchange cxfExchange, Exchange camelExchange) {

    Method method = null;
    QName operationName = null;
    ExchangePattern mep = ExchangePattern.InOut;

    // extract binding operation information
    BindingOperationInfo boi =
        camelExchange.getProperty(BindingOperationInfo.class.getName(), BindingOperationInfo.class);
    if (boi != null) {
      Service service = cxfExchange.get(Service.class);
      if (service != null) {
        MethodDispatcher md = (MethodDispatcher) service.get(MethodDispatcher.class.getName());
        if (md != null) {
          method = md.getMethod(boi);
        }
      }

      if (boi.getOperationInfo().isOneWay()) {
        mep = ExchangePattern.InOnly;
      }

      operationName = boi.getName();
    }

    // set operation name in header
    if (operationName != null) {
      camelExchange
          .getIn()
          .setHeader(CxfConstants.OPERATION_NAMESPACE, boi.getName().getNamespaceURI());
      camelExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, boi.getName().getLocalPart());
      if (LOG.isTraceEnabled()) {
        LOG.trace(
            "Set IN header: {}={}",
            CxfConstants.OPERATION_NAMESPACE,
            boi.getName().getNamespaceURI());
        LOG.trace(
            "Set IN header: {}={}", CxfConstants.OPERATION_NAME, boi.getName().getLocalPart());
      }
    } else if (method != null) {
      camelExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, method.getName());
      if (LOG.isTraceEnabled()) {
        LOG.trace("Set IN header: {}={}", CxfConstants.OPERATION_NAME, method.getName());
      }
    }

    // set message exchange pattern
    camelExchange.setPattern(mep);
    LOG.trace("Set exchange MEP: {}", mep);

    // propagate headers
    Message cxfMessage = cxfExchange.getInMessage();
    propagateHeadersFromCxfToCamel(cxfMessage, camelExchange.getIn(), camelExchange);

    // propagate the security subject from CXF security context
    SecurityContext securityContext = cxfMessage.get(SecurityContext.class);
    if (securityContext instanceof LoginSecurityContext
        && ((LoginSecurityContext) securityContext).getSubject() != null) {
      camelExchange
          .getIn()
          .getHeaders()
          .put(Exchange.AUTHENTICATION, ((LoginSecurityContext) securityContext).getSubject());
    } else if (securityContext != null && securityContext.getUserPrincipal() != null) {
      Subject subject = new Subject();
      subject.getPrincipals().add(securityContext.getUserPrincipal());
      camelExchange.getIn().getHeaders().put(Exchange.AUTHENTICATION, subject);
    }

    // Propagating properties from CXF Exchange to Camel Exchange has an
    // side effect of copying reply side stuff when the producer is retried.
    // So, we do not want to do this.
    // camelExchange.getProperties().putAll(cxfExchange);

    // propagate request context
    Object value = cxfMessage.get(Client.REQUEST_CONTEXT);
    if (value != null
        && !headerFilterStrategy.applyFilterToExternalHeaders(
            Client.REQUEST_CONTEXT, value, camelExchange)) {
      camelExchange.getIn().setHeader(Client.REQUEST_CONTEXT, value);
      LOG.trace("Populate context from CXF message {} value={}", Client.REQUEST_CONTEXT, value);
    }

    // setup the charset from content-type header
    setCharsetWithContentType(camelExchange);

    // set body
    Object body =
        DefaultCxfBinding.getContentFromCxf(
            cxfMessage,
            camelExchange.getProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.class));
    if (body != null) {
      camelExchange.getIn().setBody(body);
    }

    // propagate attachments if the data format is not POJO
    if (cxfMessage.getAttachments() != null
        && !camelExchange
            .getProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.class)
            .equals(DataFormat.POJO)) {
      for (Attachment attachment : cxfMessage.getAttachments()) {
        camelExchange.getIn().addAttachment(attachment.getId(), attachment.getDataHandler());
      }
    }
  }