Search in sources :

Example 91 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.

the class AbstractWSDLBasedEndpointFactory method createBindingInfo.

protected BindingInfo createBindingInfo() {
    BindingFactoryManager mgr = bus.getExtension(BindingFactoryManager.class);
    String binding = bindingId;
    if (binding == null && bindingConfig != null) {
        binding = bindingConfig.getBindingId();
    }
    if (binding == null) {
        // default to soap binding
        binding = "http://schemas.xmlsoap.org/soap/";
    }
    try {
        if (binding.contains("/soap")) {
            if (bindingConfig == null) {
                bindingConfig = createSoapBindingConfig();
            }
            if (bindingConfig instanceof SoapBindingConfiguration && !((SoapBindingConfiguration) bindingConfig).isSetStyle()) {
                ((SoapBindingConfiguration) bindingConfig).setStyle(serviceFactory.getStyle());
            }
        }
        bindingFactory = mgr.getBindingFactory(binding);
        BindingInfo inf = bindingFactory.createBindingInfo(serviceFactory.getService(), binding, bindingConfig);
        for (BindingOperationInfo boi : inf.getOperations()) {
            serviceFactory.updateBindingOperation(boi);
            Method m = serviceFactory.getMethodDispatcher().getMethod(boi);
            serviceFactory.sendEvent(FactoryBeanListener.Event.BINDING_OPERATION_CREATED, inf, boi, m);
        }
        serviceFactory.sendEvent(FactoryBeanListener.Event.BINDING_CREATED, inf);
        return inf;
    } catch (BusException ex) {
        throw new ServiceConstructionException(new Message("COULD.NOT.RESOLVE.BINDING", LOG, bindingId), ex);
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.common.i18n.Message) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) Method(java.lang.reflect.Method) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) BusException(org.apache.cxf.BusException)

Example 92 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.

the class AbstractMessageResponseTimeInterceptor method getOperationCounterName.

protected ObjectName getOperationCounterName(Exchange ex, ObjectName sericeCounterName) {
    BindingOperationInfo bop = ex.getBindingOperationInfo();
    OperationInfo opInfo = bop == null ? null : bop.getOperationInfo();
    if (opInfo != null) {
        ObjectName o = opInfo.getProperty("javax.management.ObjectName", ObjectName.class);
        if (o != null) {
            return o;
        }
    }
    String operationName = opInfo == null ? null : "\"" + opInfo.getName().getLocalPart() + "\"";
    if (operationName == null) {
        Object nameProperty = ex.get("org.apache.cxf.resource.operation.name");
        if (nameProperty != null) {
            operationName = "\"" + escapePatternChars(nameProperty.toString()) + "\"";
        }
    }
    StringBuilder buffer = new StringBuilder(sericeCounterName.toString());
    if (operationName != null) {
        buffer.append("," + ManagementConstants.OPERATION_NAME_PROP + "=" + operationName);
    }
    String operationCounterName = buffer.toString();
    ObjectName operationCounter = null;
    try {
        operationCounter = new ObjectName(operationCounterName);
        if (opInfo != null) {
            opInfo.setProperty("javax.management.ObjectName", operationCounter);
        }
    } catch (MalformedObjectNameException e) {
        LOG.log(Level.WARNING, "CREATE_COUNTER_OBJECTNAME_FAILED", e);
    }
    return operationCounter;
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) MalformedObjectNameException(javax.management.MalformedObjectNameException) ObjectName(javax.management.ObjectName)

Example 93 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.

the class AbstractMessageResponseTestBase method setupOperationForMessage.

protected void setupOperationForMessage() {
    OperationInfo op = EasyMock.createMock(OperationInfo.class);
    BindingOperationInfo bop = EasyMock.createMock(BindingOperationInfo.class);
    EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(bop);
    EasyMock.expect(bop.getOperationInfo()).andReturn(op);
    EasyMock.expect(op.getName()).andReturn(OPERATION_NAME);
    EasyMock.expect(op.getProperty("javax.management.ObjectName", ObjectName.class)).andReturn(null).anyTimes();
    op.setProperty(EasyMock.eq("javax.management.ObjectName"), EasyMock.anyObject(ObjectName.class));
    EasyMock.expectLastCall();
    EasyMock.replay(bop, op);
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) ObjectName(javax.management.ObjectName)

Example 94 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.

the class AbstractSTSClient method findOperation.

protected BindingOperationInfo findOperation(String suffix) {
    BindingInfo bi = client.getEndpoint().getBinding().getBindingInfo();
    for (BindingOperationInfo boi : bi.getOperations()) {
        SoapOperationInfo soi = boi.getExtensor(SoapOperationInfo.class);
        String soapAction = soi != null ? soi.getAction() : null;
        Object o = boi.getOperationInfo().getInput().getExtensionAttribute(new QName("http://www.w3.org/2007/05/addressing/metadata", "Action"));
        if (o instanceof QName) {
            o = ((QName) o).getLocalPart();
        }
        String wsamAction = o == null ? null : o.toString();
        if ((soapAction != null && soapAction.endsWith(suffix)) || (wsamAction != null && wsamAction.endsWith(suffix))) {
            PolicyEngine pe = bus.getExtension(PolicyEngine.class);
            Conduit conduit = client.getConduit();
            EffectivePolicy effectivePolicy = pe.getEffectiveClientRequestPolicy(client.getEndpoint().getEndpointInfo(), boi, conduit, PhaseInterceptorChain.getCurrentMessage());
            setPolicyInternal(effectivePolicy.getPolicy());
            return boi;
        }
    }
    // we can at least find it by name and then set the action and such manually later.
    for (BindingOperationInfo boi : bi.getOperations()) {
        if (suffix.endsWith(boi.getName().getLocalPart())) {
            return boi;
        }
    }
    // Still didn't find anything useful
    for (BindingOperationInfo boi : bi.getOperations()) {
        if (boi.getInput().getMessageInfo().getMessagePartsNumber() > 0) {
            MessagePartInfo mpi = boi.getInput().getMessageInfo().getFirstMessagePart();
            if ("RequestSecurityToken".equals(mpi.getConcreteName().getLocalPart())) {
                return boi;
            }
        }
    }
    return null;
}
Also used : EffectivePolicy(org.apache.cxf.ws.policy.EffectivePolicy) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) QName(javax.xml.namespace.QName) Conduit(org.apache.cxf.transport.Conduit) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 95 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.

the class AbstractSTSClient method issue.

/**
 * Make an "Issue" invocation and return the response as a STSResponse Object
 */
protected STSResponse issue(String appliesTo, String action, String requestType, String binaryExchange) throws Exception {
    createClient();
    BindingOperationInfo boi = findOperation("/RST/Issue");
    client.getRequestContext().putAll(ctx);
    if (action != null) {
        client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION, action);
    } else if (isSecureConv) {
        client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION, namespace + "/RST/SCT");
    } else {
        client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION, namespace + "/RST/Issue");
    }
    W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
    writer.writeStartElement("wst", "RequestSecurityToken", namespace);
    writer.writeNamespace("wst", namespace);
    if (context != null) {
        writer.writeAttribute(null, "Context", context);
    }
    boolean wroteKeySize = false;
    String keyTypeTemplate = null;
    String sptt = null;
    if (template != null && DOMUtils.getFirstElement(template) != null) {
        if (this.useSecondaryParameters()) {
            writer.writeStartElement("wst", "SecondaryParameters", namespace);
        }
        Element tl = DOMUtils.getFirstElement(template);
        while (tl != null) {
            StaxUtils.copy(tl, writer);
            if ("KeyType".equals(tl.getLocalName())) {
                keyTypeTemplate = DOMUtils.getContent(tl);
            } else if ("KeySize".equals(tl.getLocalName())) {
                wroteKeySize = true;
                keySize = Integer.parseInt(DOMUtils.getContent(tl));
            } else if ("TokenType".equals(tl.getLocalName())) {
                sptt = DOMUtils.getContent(tl);
            }
            tl = DOMUtils.getNextElement(tl);
        }
        if (this.useSecondaryParameters()) {
            writer.writeEndElement();
        }
    }
    if (isSpnego) {
        tokenType = STSUtils.getTokenTypeSCT(namespace);
        sendKeyType = false;
    }
    addRequestType(requestType, writer);
    if (enableAppliesTo) {
        addAppliesTo(writer, appliesTo);
    }
    addClaims(writer);
    Element onBehalfOfToken = getOnBehalfOfToken();
    if (onBehalfOfToken != null) {
        writer.writeStartElement("wst", "OnBehalfOf", namespace);
        StaxUtils.copy(onBehalfOfToken, writer);
        writer.writeEndElement();
    }
    if (sptt == null) {
        addTokenType(writer);
    }
    if (isSecureConv || enableLifetime) {
        addLifetime(writer);
    }
    if (keyTypeTemplate == null) {
        keyTypeTemplate = writeKeyType(writer, keyType);
    }
    byte[] requestorEntropy = null;
    X509Certificate cert = null;
    Crypto crypto = null;
    if (keySize <= 0) {
        keySize = 256;
    }
    if (keyTypeTemplate != null && keyTypeTemplate.endsWith("SymmetricKey")) {
        requestorEntropy = writeElementsForRSTSymmetricKey(writer, wroteKeySize);
    } else if (keyTypeTemplate != null && keyTypeTemplate.endsWith("PublicKey")) {
        // Use the given cert, or else get it from a Crypto instance
        if (useKeyCertificate != null) {
            cert = useKeyCertificate;
        } else {
            crypto = createCrypto(false);
            cert = getCert(crypto);
        }
        writeElementsForRSTPublicKey(writer, cert);
    } else if (isSpnego || isSecureConv) {
        addKeySize(keySize, writer);
    }
    if (binaryExchange != null) {
        addBinaryExchange(binaryExchange, writer);
    }
    Element actAsSecurityToken = getActAsToken();
    if (actAsSecurityToken != null) {
        writer.writeStartElement(STSUtils.WST_NS_08_02, "ActAs");
        StaxUtils.copy(actAsSecurityToken, writer);
        writer.writeEndElement();
    }
    // Write out renewal semantics
    writeRenewalSemantics(writer);
    Element customElement = getCustomContent();
    if (customElement != null) {
        StaxUtils.copy(customElement, writer);
    }
    writer.writeEndElement();
    Object[] obj = client.invoke(boi, new DOMSource(writer.getDocument().getDocumentElement()));
    return new STSResponse((DOMSource) obj[0], requestorEntropy, cert, crypto);
}
Also used : W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Crypto(org.apache.wss4j.common.crypto.Crypto) DOMSource(javax.xml.transform.dom.DOMSource) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Element(org.w3c.dom.Element) X509Certificate(java.security.cert.X509Certificate)

Aggregations

BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)214 QName (javax.xml.namespace.QName)82 BindingInfo (org.apache.cxf.service.model.BindingInfo)57 Test (org.junit.Test)55 Exchange (org.apache.cxf.message.Exchange)50 OperationInfo (org.apache.cxf.service.model.OperationInfo)47 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)42 Endpoint (org.apache.cxf.endpoint.Endpoint)41 Message (org.apache.cxf.message.Message)36 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)36 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)32 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)31 Service (org.apache.cxf.service.Service)29 Fault (org.apache.cxf.interceptor.Fault)24 MessageInfo (org.apache.cxf.service.model.MessageInfo)24 MessageContentsList (org.apache.cxf.message.MessageContentsList)23 Method (java.lang.reflect.Method)22 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)22 ArrayList (java.util.ArrayList)21 BindingFaultInfo (org.apache.cxf.service.model.BindingFaultInfo)16