Search in sources :

Example 1 with IllegalEmptyResponseException

use of org.apache.cxf.endpoint.ClientImpl.IllegalEmptyResponseException in project cxf by apache.

the class DispatchImpl method invoke.

@SuppressWarnings("unchecked")
public T invoke(T obj, boolean isOneWay) {
    checkError();
    try {
        if (obj instanceof SOAPMessage) {
            SOAPMessage msg = (SOAPMessage) obj;
            if (msg.countAttachments() > 0) {
                client.getRequestContext().put(AttachmentOutInterceptor.WRITE_ATTACHMENTS, Boolean.TRUE);
            }
        } else if (context != null) {
            Boolean unwrapProperty = obj instanceof JAXBElement ? Boolean.FALSE : Boolean.TRUE;
            getRequestContext().put("unwrap.jaxb.element", unwrapProperty);
        }
        QName opName = (QName) getRequestContext().get(MessageContext.WSDL_OPERATION);
        boolean hasOpName;
        if (opName == null) {
            hasOpName = false;
            opName = isOneWay ? INVOKE_ONEWAY_QNAME : INVOKE_QNAME;
        } else {
            hasOpName = true;
            BindingOperationInfo bop = client.getEndpoint().getBinding().getBindingInfo().getOperation(opName);
            if (bop == null) {
                addInvokeOperation(opName, isOneWay);
            }
        }
        Holder<T> holder = new Holder<>(obj);
        opName = calculateOpName(holder, opName, hasOpName);
        Object[] ret = client.invokeWrapped(opName, holder.value);
        if (isOneWay || ret == null || ret.length == 0) {
            return null;
        }
        return (T) ret[0];
    } catch (IllegalEmptyResponseException ie) {
        return null;
    } catch (Exception ex) {
        throw mapException(ex);
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) QName(javax.xml.namespace.QName) Holder(javax.xml.ws.Holder) JAXBElement(javax.xml.bind.JAXBElement) SOAPMessage(javax.xml.soap.SOAPMessage) HTTPException(javax.xml.ws.http.HTTPException) SOAPException(javax.xml.soap.SOAPException) XMLStreamException(javax.xml.stream.XMLStreamException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) IllegalEmptyResponseException(org.apache.cxf.endpoint.ClientImpl.IllegalEmptyResponseException) IOException(java.io.IOException) WebServiceException(javax.xml.ws.WebServiceException) IllegalEmptyResponseException(org.apache.cxf.endpoint.ClientImpl.IllegalEmptyResponseException)

Example 2 with IllegalEmptyResponseException

use of org.apache.cxf.endpoint.ClientImpl.IllegalEmptyResponseException in project cxf by apache.

the class EmptySOAPBodyTest method testPlaintext.

@org.junit.Test
public void testPlaintext() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = EmptySOAPBodyTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = EmptySOAPBodyTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItPlaintextPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, PORT);
    try {
        port.doubleIt(25);
        fail("Should have thown an exception");
    } catch (SOAPFaultException t) {
        assertTrue("Wrong exception cause " + t.getCause(), t.getCause() instanceof IllegalEmptyResponseException);
    }
    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) XMLService(org.apache.hello_world_xml_http.bare.XMLService) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) URL(java.net.URL) IllegalEmptyResponseException(org.apache.cxf.endpoint.ClientImpl.IllegalEmptyResponseException)

Aggregations

QName (javax.xml.namespace.QName)2 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)2 IllegalEmptyResponseException (org.apache.cxf.endpoint.ClientImpl.IllegalEmptyResponseException)2 IOException (java.io.IOException)1 URL (java.net.URL)1 JAXBElement (javax.xml.bind.JAXBElement)1 SOAPException (javax.xml.soap.SOAPException)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 Holder (javax.xml.ws.Holder)1 Service (javax.xml.ws.Service)1 WebServiceException (javax.xml.ws.WebServiceException)1 HTTPException (javax.xml.ws.http.HTTPException)1 Bus (org.apache.cxf.Bus)1 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)1 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)1 XMLService (org.apache.hello_world_xml_http.bare.XMLService)1 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)1