Search in sources :

Example 1 with OutputResponseAll

use of org.apache.cxf.swa.types.OutputResponseAll in project cxf by apache.

the class ClientServerSwaTest method testSwaTypes.

@Test
public void testSwaTypes() throws Exception {
    SwAService service = new SwAService();
    SwAServiceInterface port = service.getSwAServiceHttpPort();
    setAddress(port, "http://localhost:" + serverPort + "/swa");
    URL url1 = this.getClass().getResource("resources/attach.text");
    URL url2 = this.getClass().getResource("resources/attach.html");
    URL url3 = this.getClass().getResource("resources/attach.xml");
    URL url4 = this.getClass().getResource("resources/attach.jpeg1");
    URL url5 = this.getClass().getResource("resources/attach.gif");
    DataHandler dh1 = new DataHandler(url1);
    DataHandler dh2 = new DataHandler(url2);
    DataHandler dh3 = new DataHandler(url3);
    // DataHandler dh4 = new DataHandler(url4);
    // DataHandler dh5 = new DataHandler(url5);
    Holder<DataHandler> attach1 = new Holder<DataHandler>();
    attach1.value = dh1;
    Holder<DataHandler> attach2 = new Holder<DataHandler>();
    attach2.value = dh2;
    Holder<Source> attach3 = new Holder<Source>();
    attach3.value = new StreamSource(dh3.getInputStream());
    Holder<Image> attach4 = new Holder<Image>();
    Holder<Image> attach5 = new Holder<Image>();
    attach4.value = ImageIO.read(url4);
    attach5.value = ImageIO.read(url5);
    VoidRequest request = new VoidRequest();
    OutputResponseAll response = port.echoAllAttachmentTypes(request, attach1, attach2, attach3, attach4, attach5);
    assertNotNull(response);
    Map<?, ?> map = CastUtils.cast((Map<?, ?>) ((BindingProvider) port).getResponseContext().get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS));
    assertNotNull(map);
    assertEquals(5, map.size());
}
Also used : VoidRequest(org.apache.cxf.swa.types.VoidRequest) SwAServiceInterface(org.apache.cxf.swa.SwAServiceInterface) Holder(javax.xml.ws.Holder) StreamSource(javax.xml.transform.stream.StreamSource) DataHandler(javax.activation.DataHandler) Image(java.awt.Image) OutputResponseAll(org.apache.cxf.swa.types.OutputResponseAll) URL(java.net.URL) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) SwAService(org.apache.cxf.swa.SwAService) Test(org.junit.Test)

Example 2 with OutputResponseAll

use of org.apache.cxf.swa.types.OutputResponseAll in project cxf by apache.

the class SwAServiceImpl method echoAllAttachmentTypes.

public OutputResponseAll echoAllAttachmentTypes(VoidRequest request, Holder<DataHandler> attach1, Holder<DataHandler> attach2, Holder<Source> attach3, Holder<Image> attach4, Holder<Image> attach5) {
    try {
        OutputResponseAll theResponse = new OutputResponseAll();
        theResponse.setResult("ok");
        theResponse.setReason("ok");
        if (attach1 == null || attach1.value == null) {
            System.err.println("attach1.value is null (unexpected)");
            theResponse.setReason("attach1.value is null (unexpected)");
            theResponse.setResult("not ok");
        }
        if (attach2 == null || attach2.value == null) {
            System.err.println("attach2.value is null (unexpected)");
            if (theResponse.getReason().equals("ok")) {
                theResponse.setReason("attach2.value is null (unexpected)");
            } else {
                theResponse.setReason(theResponse.getReason() + "\nattach2.value is null (unexpected)");
            }
            theResponse.setResult("not ok");
        }
        if (attach3 == null || attach3.value == null) {
            System.err.println("attach3.value is null (unexpected)");
            if (theResponse.getReason().equals("ok")) {
                theResponse.setReason("attach3.value is null (unexpected)");
            } else {
                theResponse.setReason(theResponse.getReason() + "\nattach3.value is null (unexpected)");
            }
            theResponse.setResult("not ok");
        }
        if (attach4 == null || attach4.value == null) {
            System.err.println("attach4.value is null (unexpected)");
            if (theResponse.getReason().equals("ok")) {
                theResponse.setReason("attach4.value is null (unexpected)");
            } else {
                theResponse.setReason(theResponse.getReason() + "\nattach4.value is null (unexpected)");
            }
            theResponse.setResult("not ok");
        }
        if (attach5 == null || attach5.value == null) {
            System.err.println("attach5.value is null (unexpected)");
            if (theResponse.getReason().equals("ok")) {
                theResponse.setReason("attach5.value is null (unexpected)");
            } else {
                theResponse.setReason(theResponse.getReason() + "\nattach5.value is null (unexpected)");
            }
            theResponse.setResult("not ok");
        }
        return theResponse;
    } catch (Exception e) {
        throw new WebServiceException(e.getMessage());
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) OutputResponseAll(org.apache.cxf.swa.types.OutputResponseAll) IOException(java.io.IOException) WebServiceException(javax.xml.ws.WebServiceException)

Example 3 with OutputResponseAll

use of org.apache.cxf.swa.types.OutputResponseAll in project cxf by apache.

the class SwAServiceImpl method echoAllAttachmentTypes.

public OutputResponseAll echoAllAttachmentTypes(VoidRequest request, Holder<DataHandler> attach1, Holder<DataHandler> attach2, Holder<Source> attach3, Holder<Image> attach4, Holder<Image> attach5) {
    try {
        OutputResponseAll theResponse = new OutputResponseAll();
        theResponse.setResult("ok");
        theResponse.setReason("ok");
        if (attach1 == null || attach1.value == null) {
            System.err.println("attach1.value is null (unexpected)");
            theResponse.setReason("attach1.value is null (unexpected)");
            theResponse.setResult("not ok");
        }
        if (attach2 == null || attach2.value == null) {
            System.err.println("attach2.value is null (unexpected)");
            if (theResponse.getReason().equals("ok")) {
                theResponse.setReason("attach2.value is null (unexpected)");
            } else {
                theResponse.setReason(theResponse.getReason() + "\nattach2.value is null (unexpected)");
            }
            theResponse.setResult("not ok");
        }
        if (attach3 == null || attach3.value == null) {
            System.err.println("attach3.value is null (unexpected)");
            if (theResponse.getReason().equals("ok")) {
                theResponse.setReason("attach3.value is null (unexpected)");
            } else {
                theResponse.setReason(theResponse.getReason() + "\nattach3.value is null (unexpected)");
            }
            theResponse.setResult("not ok");
        }
        if (attach4 == null || attach4.value == null) {
            System.err.println("attach4.value is null (unexpected)");
            if (theResponse.getReason().equals("ok")) {
                theResponse.setReason("attach4.value is null (unexpected)");
            } else {
                theResponse.setReason(theResponse.getReason() + "\nattach4.value is null (unexpected)");
            }
            theResponse.setResult("not ok");
        }
        if (attach5 == null || attach5.value == null) {
            System.err.println("attach5.value is null (unexpected)");
            if (theResponse.getReason().equals("ok")) {
                theResponse.setReason("attach5.value is null (unexpected)");
            } else {
                theResponse.setReason(theResponse.getReason() + "\nattach5.value is null (unexpected)");
            }
            theResponse.setResult("not ok");
        }
        return theResponse;
    } catch (Exception e) {
        throw new WebServiceException(e.getMessage());
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) OutputResponseAll(org.apache.cxf.swa.types.OutputResponseAll) IOException(java.io.IOException) WebServiceException(javax.xml.ws.WebServiceException)

Aggregations

OutputResponseAll (org.apache.cxf.swa.types.OutputResponseAll)3 IOException (java.io.IOException)2 WebServiceException (javax.xml.ws.WebServiceException)2 Image (java.awt.Image)1 URL (java.net.URL)1 DataHandler (javax.activation.DataHandler)1 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)1 Source (javax.xml.transform.Source)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Holder (javax.xml.ws.Holder)1 SwAService (org.apache.cxf.swa.SwAService)1 SwAServiceInterface (org.apache.cxf.swa.SwAServiceInterface)1 VoidRequest (org.apache.cxf.swa.types.VoidRequest)1 Test (org.junit.Test)1