Java Code Examples for org.apache.cxf.service.model.BindingOperationInfo#isUnwrapped()

The following examples show how to use org.apache.cxf.service.model.BindingOperationInfo#isUnwrapped() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SoapClient.java    From jea with Apache License 2.0 6 votes vote down vote up
private Object[] convert(Endpoint endpoint, QName opName, Object... params) throws Exception {
	List<Object> listSoapObject = new ArrayList<Object>();
	BindingOperationInfo boi = endpoint.getEndpointInfo().getBinding().getOperation(opName); // Operation name is processOrder  
       BindingMessageInfo inputMessageInfo = null;
       if (!boi.isUnwrapped()) {
           inputMessageInfo = boi.getWrappedOperation().getInput();
       } else {
           inputMessageInfo = boi.getUnwrappedOperation().getInput();
       }
       List<MessagePartInfo> parts = inputMessageInfo.getMessageParts();
       
       int index = 0;
       for(Object obj : params){
       	MessagePartInfo partInfo = parts.get(index++);
       	Class<?> soapClass = partInfo.getTypeClass();
           Object soapObject = copytoSoapObject(obj, soapClass);
           listSoapObject.add(soapObject);
       }
       
       return listSoapObject.toArray();
}
 
Example 2
Source File: ColocMessageObserver.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void setExchangeProperties(Exchange exchange, Message m) {
    exchange.put(Bus.class, bus);
    exchange.put(Endpoint.class, endpoint);
    exchange.put(Service.class, endpoint.getService());
    exchange.put(Binding.class, endpoint.getBinding());

    //Setup the BindingOperationInfo
    QName opName = (QName) m.get(Message.WSDL_OPERATION);
    BindingInfo bi = endpoint.getEndpointInfo().getBinding();
    BindingOperationInfo boi = bi.getOperation(opName);
    if (boi != null && boi.isUnwrapped()) {
        boi = boi.getWrappedOperation();
    }

    exchange.put(BindingOperationInfo.class, boi);
}
 
Example 3
Source File: SwAOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(SoapMessage message) throws Fault {
    Exchange ex = message.getExchange();
    BindingOperationInfo bop = ex.getBindingOperationInfo();
    if (bop == null) {
        return;
    }

    if (bop.isUnwrapped()) {
        bop = bop.getWrappedOperation();
    }

    boolean client = isRequestor(message);
    BindingMessageInfo bmi = client ? bop.getInput() : bop.getOutput();

    if (bmi == null) {
        return;
    }

    SoapBodyInfo sbi = bmi.getExtensor(SoapBodyInfo.class);

    if (sbi == null || sbi.getAttachments() == null || sbi.getAttachments().isEmpty()) {
        Service s = ex.getService();
        DataBinding db = s.getDataBinding();
        if (db instanceof JAXBDataBinding
            && hasSwaRef((JAXBDataBinding) db)) {
            setupAttachmentOutput(message);
        }
        return;
    }
    processAttachments(message, sbi);
}
 
Example 4
Source File: EffectivePolicyImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
Assertor initialisePolicy(EndpointInfo ei,
                      BindingOperationInfo boi,
                      PolicyEngine engine,
                      boolean requestor,
                      boolean request,
                      Assertor assertor,
                      Message m) {

    if (boi.isUnwrapped()) {
        boi = boi.getUnwrappedOperation();
    }

    BindingMessageInfo bmi = request ? boi.getInput() : boi.getOutput();
    EndpointPolicy ep;
    if (requestor) {
        ep = engine.getClientEndpointPolicy(ei, getAssertorAs(assertor, Conduit.class), m);
    } else {
        ep = engine.getServerEndpointPolicy(ei, getAssertorAs(assertor, Destination.class), m);
    }
    policy = ep.getPolicy();
    if (ep instanceof EndpointPolicyImpl) {
        assertor = ((EndpointPolicyImpl)ep).getAssertor();
    }

    policy = policy.merge(((PolicyEngineImpl)engine).getAggregatedOperationPolicy(boi, m));
    if (null != bmi) {
        policy = policy.merge(((PolicyEngineImpl)engine).getAggregatedMessagePolicy(bmi, m));
    }
    policy = policy.normalize(engine.getRegistry(), true);
    return assertor;
}
 
Example 5
Source File: PolicyEngineImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private BindingFaultInfo mapToWrappedBindingFaultInfo(BindingFaultInfo bfi) {
    BindingOperationInfo boi = bfi.getBindingOperation();
    if (boi != null && boi.isUnwrapped()) {
        boi = boi.getWrappedOperation();
        for (BindingFaultInfo bf2 : boi.getFaults()) {
            if (bf2.getFaultInfo().getName().equals(bfi.getFaultInfo().getName())) {
                return bf2;
            }
        }
    }
    return bfi;
}
 
Example 6
Source File: InternalContextUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static SoapOperationInfo getSoapOperationInfo(BindingOperationInfo bindingOpInfo) {
    SoapOperationInfo soi = bindingOpInfo.getExtensor(SoapOperationInfo.class);
    if (soi == null && bindingOpInfo.isUnwrapped()) {
        soi = bindingOpInfo.getWrappedOperation()
            .getExtensor(SoapOperationInfo.class);
    }
    return soi;
}
 
Example 7
Source File: AbstractMetricsInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void addOperationMetrics(ExchangeMetrics ctx, Message m, BindingOperationInfo boi) {
    Object metrics = null;
    if (boi == null) {
        //likely a REST service, let's see if we have a resource name
        Object nameProperty = m.getExchange().get("org.apache.cxf.resource.operation.name");
        if (nameProperty != null) {
            Map<String, Object> restMap = getRestMetricsMap(m.getExchange().getEndpoint());
            metrics = restMap.get(nameProperty.toString());
            if (metrics == null) {
                metrics = createMetricsContextForRestResource(m, nameProperty.toString());
            }
        }
    } else {
        if (boi.isUnwrapped()) {
            boi = boi.getWrappedOperation();
        }
        metrics = boi.getProperty(MetricsContext.class.getName());
        if (metrics == null) {
            synchronized (boi) {
                metrics = createMetricsContextForOperation(m, boi);
            }
        }
    }
    if (metrics instanceof List) {
        List<MetricsContext> list = CastUtils.cast((List<?>)metrics);
        for (MetricsContext c : list) {
            ctx.addContext(c);
        }
    } else if (metrics instanceof MetricsContext) {
        ctx.addContext((MetricsContext)metrics);
    }
}
 
Example 8
Source File: SoapPreProtocolOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void setSoapAction(SoapMessage message) {
    BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();

    // The soap action is set on the wrapped operation.
    if (boi != null && boi.isUnwrapped()) {
        boi = boi.getWrappedOperation();
    }

    String action = getSoapAction(message, boi);

    if (message.getVersion() instanceof Soap11) {
        Map<String, List<String>> tempReqHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        Map<String, List<String>> reqHeaders
                = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
        if (reqHeaders != null) {
            tempReqHeaders.putAll(reqHeaders);
        }
        if (!tempReqHeaders.containsKey(SoapBindingConstants.SOAP_ACTION)) {
            tempReqHeaders.put(SoapBindingConstants.SOAP_ACTION, Collections.singletonList(action));
        }
        message.put(Message.PROTOCOL_HEADERS, tempReqHeaders);
    } else if (message.getVersion() instanceof Soap12 && !"\"\"".equals(action)) {
        String ct = (String) message.get(Message.CONTENT_TYPE);

        if (ct.indexOf("action=\"") == -1) {
            ct = new StringBuilder().append(ct)
                .append("; action=").append(action).toString();
            message.put(Message.CONTENT_TYPE, ct);
        }
    }
}
 
Example 9
Source File: DocLiteralInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private BindingOperationInfo getBindingOperationInfo(DepthXMLStreamReader xmlReader, Exchange exchange,
                                                     BindingOperationInfo bop, boolean client) {
    //bop might be a unwrapped, wrap it back so that we can get correct info
    if (bop != null && bop.isUnwrapped()) {
        bop = bop.getWrappedOperation();
    }

    if (bop == null) {
        QName startQName = xmlReader == null
            ? new QName("http://cxf.apache.org/jaxws/provider", "invoke")
            : xmlReader.getName();
        bop = getBindingOperationInfo(exchange, startQName, client);
    }
    return bop;
}
 
Example 10
Source File: WrappedOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message message) {
    BindingOperationInfo bop = message.getExchange().getBindingOperationInfo();

    if (bop != null && bop.isUnwrapped()) {
        XMLStreamWriter xmlWriter = message.getContent(XMLStreamWriter.class);

        MessageInfo messageInfo;
        if (isRequestor(message)) {
            messageInfo = bop.getWrappedOperation().getOperationInfo().getInput();
        } else {
            messageInfo = bop.getWrappedOperation().getOperationInfo().getOutput();
        }

        QName name = messageInfo.getFirstMessagePart().getConcreteName();

        try {
            String pfx = null;
            Service service = message.getExchange().getService();
            if (service.getDataBinding().getDeclaredNamespaceMappings() != null) {
                pfx = service.getDataBinding().getDeclaredNamespaceMappings().get(name.getNamespaceURI());
            }
            if (pfx == null) {
                pfx = StaxUtils.getUniquePrefix(xmlWriter, name.getNamespaceURI(), false);
            }
            xmlWriter.setPrefix(pfx, name.getNamespaceURI());
            xmlWriter.writeStartElement(pfx, name.getLocalPart(), name.getNamespaceURI());
            if (StringUtils.isEmpty(pfx)) {
                xmlWriter.writeDefaultNamespace(name.getNamespaceURI());
            } else {
                xmlWriter.writeNamespace(pfx, name.getNamespaceURI());
            }
        } catch (XMLStreamException e) {
            throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE), e);
        }

        // Add a final interceptor to write end element
        message.getInterceptorChain().add(ending);
    }
}
 
Example 11
Source File: WrapperClassOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    Exchange ex = message.getExchange();
    BindingOperationInfo bop = ex.getBindingOperationInfo();

    MessageInfo messageInfo = message.get(MessageInfo.class);
    if (messageInfo == null || bop == null || !bop.isUnwrapped()) {
        return;
    }

    BindingOperationInfo newbop = bop.getWrappedOperation();
    MessageInfo wrappedMsgInfo;
    if (Boolean.TRUE.equals(message.get(Message.REQUESTOR_ROLE))) {
        wrappedMsgInfo = newbop.getInput().getMessageInfo();
    } else {
        wrappedMsgInfo = newbop.getOutput().getMessageInfo();
    }

    Class<?> wrapped = null;
    if (wrappedMsgInfo.getMessagePartsNumber() > 0) {
        wrapped = wrappedMsgInfo.getFirstMessagePart().getTypeClass();
    }

    if (wrapped != null) {
        MessagePartInfo firstMessagePart = wrappedMsgInfo.getFirstMessagePart();
        MessageContentsList objs = MessageContentsList.getContentsList(message);
        WrapperHelper helper = firstMessagePart.getProperty("WRAPPER_CLASS", WrapperHelper.class);
        if (helper == null) {
            helper = getWrapperHelper(message, messageInfo, wrappedMsgInfo, wrapped, firstMessagePart);
        }
        if (helper == null) {
            return;
        }

        try {
            MessageContentsList newObjs = new MessageContentsList();
            if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.OUT, message)
                && helper instanceof AbstractWrapperHelper) {
                ((AbstractWrapperHelper)helper).setValidate(true);
            }
            Object o2 = helper.createWrapperObject(objs);
            newObjs.put(firstMessagePart, o2);

            for (MessagePartInfo p : messageInfo.getMessageParts()) {
                if (Boolean.TRUE.equals(p.getProperty(ReflectionServiceFactoryBean.HEADER))) {
                    MessagePartInfo mpi = wrappedMsgInfo.getMessagePart(p.getName());
                    if (objs.hasValue(p)) {
                        newObjs.put(mpi, objs.get(p));
                    }
                }
            }

            message.setContent(List.class, newObjs);
        } catch (Fault f) {
            throw f;
        } catch (Exception e) {
            throw new Fault(e);
        }

        // we've now wrapped the object, so use the wrapped binding op
        ex.put(BindingOperationInfo.class, newbop);

        if (messageInfo == bop.getOperationInfo().getInput()) {
            message.put(MessageInfo.class, newbop.getOperationInfo().getInput());
            message.put(BindingMessageInfo.class, newbop.getInput());
        } else if (messageInfo == bop.getOperationInfo().getOutput()) {
            message.put(MessageInfo.class, newbop.getOperationInfo().getOutput());
            message.put(BindingMessageInfo.class, newbop.getOutput());
        }
    }
}
 
Example 12
Source File: XMLMessageOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();
    MessageInfo mi;
    BindingMessageInfo bmi;
    if (isRequestor(message)) {
        mi = boi.getOperationInfo().getInput();
        bmi = boi.getInput();
    } else {
        mi = boi.getOperationInfo().getOutput();
        bmi = boi.getOutput();
    }
    XMLBindingMessageFormat xmf = bmi.getExtensor(XMLBindingMessageFormat.class);
    QName rootInModel = null;
    if (xmf != null) {
        rootInModel = xmf.getRootNode();
    }
    final int mpn = mi.getMessagePartsNumber();
    if (boi.isUnwrapped()
        || mpn == 1) {
        // wrapper out interceptor created the wrapper
        // or if bare-one-param
        new BareOutInterceptor().handleMessage(message);
    } else {
        if (rootInModel == null) {
            rootInModel = boi.getName();
        }
        if (mpn == 0 && !boi.isUnwrapped()) {
            // write empty operation qname
            writeMessage(message, rootInModel, false);
        } else {
            // multi param, bare mode, needs write root node
            writeMessage(message, rootInModel, true);
        }
    }
    // in the end we do flush ;)
    XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
    try {
        writer.flush();
    } catch (XMLStreamException e) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE, e));
    }
}
 
Example 13
Source File: ClientImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected Object[] processResult(Message message,
                               Exchange exchange,
                               BindingOperationInfo oi,
                               Map<String, Object> resContext) throws Exception {
    Exception ex = null;
    // Check to see if there is a Fault from the outgoing chain if it's an out Message
    if (!message.get(Message.INBOUND_MESSAGE).equals(Boolean.TRUE)) {
        ex = message.getContent(Exception.class);
    }
    boolean mepCompleteCalled = false;
    if (ex != null) {
        completeExchange(exchange);
        mepCompleteCalled = true;
        if (message.getContent(Exception.class) != null) {
            throw ex;
        }
    }
    ex = message.getExchange().get(Exception.class);
    if (ex != null) {
        if (!mepCompleteCalled) {
            completeExchange(exchange);
        }
        throw ex;
    }

    //REVISIT
    // - use a protocol neutral no-content marker instead of 202?
    // - move the decoupled destination property name into api
    Integer responseCode = (Integer)exchange.get(Message.RESPONSE_CODE);
    if (null != responseCode && 202 == responseCode) {
        Endpoint ep = exchange.getEndpoint();
        if (null != ep && null != ep.getEndpointInfo() && null == ep.getEndpointInfo().
            getProperty("org.apache.cxf.ws.addressing.MAPAggregator.decoupledDestination")) {
            return null;
        }
    }

    // Wait for a response if we need to
    if (oi != null && !oi.getOperationInfo().isOneWay()) {
        waitResponse(exchange);
    }

    // leave the input stream open for the caller
    Boolean keepConduitAlive = (Boolean)exchange.get(Client.KEEP_CONDUIT_ALIVE);
    if (keepConduitAlive == null || !keepConduitAlive) {
        completeExchange(exchange);
    }

    // Grab the response objects if there are any
    List<Object> resList = null;
    Message inMsg = exchange.getInMessage();
    if (inMsg != null) {
        if (null != resContext) {
            resContext.putAll(inMsg);
            // remove the recursive reference if present
            resContext.remove(Message.INVOCATION_CONTEXT);
            setResponseContext(resContext);
        }
        resList = CastUtils.cast(inMsg.getContent(List.class));
    }

    // check for an incoming fault
    ex = getException(exchange);

    if (ex != null) {
        throw ex;
    }

    if (resList == null   
        && oi != null && !oi.getOperationInfo().isOneWay()) {
        
        BindingOperationInfo boi = oi;
        if (boi.isUnwrapped()) {
            boi = boi.getWrappedOperation();
        }
        if (!boi.getOutput().getMessageParts().isEmpty()) {
            //we were supposed to get some output, but didn't.
            throw new IllegalEmptyResponseException("Response message did not contain proper response data."
                + " Expected: " + boi.getOutput().getMessageParts().get(0).getConcreteName());
        }
    }
    if (resList != null) {
        return resList.toArray();
    }

    return null;
}