Package javax.xml.soap

Examples of javax.xml.soap.SOAPConnection


            MessageFactory mf = MessageFactory.newInstance();
            SOAPMessage request = mf.createMessage();

            createSimpleSOAPPart(request);

            SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
            SOAPMessage response = sCon.call(request, getAddress());
            assertFalse(response.getAttachments().hasNext());
            assertEquals(0, response.countAttachments());

            String requestStr = printSOAPMessage(request);
            String responseStr = printSOAPMessage(response);
            assertTrue(responseStr.indexOf("echo") != -1);
            sCon.close();
        } catch (SOAPException e) {
            e.printStackTrace();
            fail("Unexpected Exception while running test: " + e);
        } catch (IOException e) {
            fail("Unexpected Exception while running test: " + e);
View Full Code Here


        jpegAttach.addMimeHeader("Content-Transfer-Encoding", "binary");
        jpegAttach.setContentId("submitSampleImage@apache.org");
        jpegAttach.setContentType("image/jpg");
        request.addAttachmentPart(jpegAttach);

        SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
        SOAPMessage response = sCon.call(request, getAddress());

        int attachmentCount = response.countAttachments();
        assertTrue(attachmentCount == 2);

        Iterator attachIter = response.getAttachments();

        int i = 0;
        while (attachIter.hasNext()) {
            AttachmentPart attachment = (AttachmentPart)attachIter.next();
            final Object content = attachment.getDataHandler().getContent();
            if (content instanceof String) {
                assertEquals(sampleMessage, (String)content);
            } else if (content instanceof ByteArrayInputStream) {
                ByteArrayInputStream bais = (ByteArrayInputStream)content;
                byte[] b = new byte[15000];
                final int lengthRead = bais.read(b);
                FileOutputStream fos =
                        new FileOutputStream(new File(System.getProperty("basedir", ".") + "/" +
                                "target/test-resources/result" + (i++) + ".jpg"));
                fos.write(b, 0, lengthRead);
                fos.flush();
                fos.close();

                assertTrue(attachment.getContentType().equals("image/jpeg")
                        || attachment.getContentType().equals("text/plain"));
            }
        }

        sCon.close();

    }
View Full Code Here

        jpegAttach.addMimeHeader("Content-Transfer-Encoding", "binary");
        jpegAttach.setContentType("image/jpg");
        request.addAttachmentPart(jpegAttach);


        SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
        SOAPMessage response = sCon.call(request, getAddress());

        int attachmentCount = response.countAttachments();
        assertTrue(attachmentCount == 2);

        Iterator attachIter = response.getAttachments();

        while (attachIter.hasNext()) {
            AttachmentPart attachment = (AttachmentPart)attachIter.next();
            final Object content = attachment.getDataHandler().getContent();
            if (content instanceof String) {
                assertEquals(sampleMessage, (String)content);
            } else if (content instanceof ByteArrayInputStream) {
                ByteArrayInputStream bais = (ByteArrayInputStream)content;
                byte[] b = new byte[15000];
                final int lengthRead = bais.read(b);
                FileOutputStream fos =
                        new FileOutputStream(new File(System.getProperty("basedir", ".") + "/" +
                                "target/target/test-resources/axis2.jpg"));
                fos.write(b, 0, lengthRead);
                fos.flush();
                fos.close();

                assertTrue(attachment.getContentType().equals("image/jpeg")
                        || attachment.getContentType().equals("text/plain"));
            }
        }

        sCon.close();
    }
View Full Code Here

            FileInputStream fileInputStream = new FileInputStream(System.getProperty("basedir", ".") +
                    "/test-resources" + File.separator + "soap-part-iso-8859-1.xml");
            SOAPMessage requestMessage = MessageFactory.newInstance().createMessage(mimeHeaders,fileInputStream);
           

            SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
            SOAPMessage response = sCon.call(requestMessage, getAddress());
            assertFalse(response.getAttachments().hasNext());
            assertEquals(0, response.countAttachments());

            printSOAPMessage(requestMessage);
            String responseStr = printSOAPMessage(response);
            assertTrue(responseStr.indexOf("This is some text.Here are some special chars : öÆÚ®¤") != -1);
            assertTrue(responseStr.indexOf("echo") != -1);
            sCon.close();
        } catch (SOAPException e) {
            e.printStackTrace();
            fail("Unexpected Exception while running test: " + e);
        } catch (IOException e) {
            fail("Unexpected Exception while running test: " + e);
View Full Code Here

            // Create a url endpoint for the recipient of the message.
            URL urlEndpoint = new URL("http://localhost:8080/ReceivingSOAP11Servlet");

            // Send the message to the endpoint using the connection.
            SOAPConnection con = new SOAPConnectionImpl();
            SOAPMessage replymsg = con.call(msg, urlEndpoint);

            // Check if reply message
            if (!validateReplyMessage(replymsg, 1)) {
                //Reply message is correct
            } else {
View Full Code Here

*
*/
public class SOAPConnectionTest extends TestCase {
    public void testClose() {
        try {
            SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
            sCon.close();
        } catch (SOAPException e) {
            fail("Unexpected Exception " + e);
        }
    }
View Full Code Here

            soapConnectionFactory = SOAPConnectionFactory.newInstance();
        } catch (SOAPException e) {
            fail("Unexpected Exception " + e);
        }

        SOAPConnection sCon = null;
        try {
            sCon = soapConnectionFactory.createConnection();
            sCon.close();
        } catch (SOAPException e) {
            fail("Unexpected Exception " + e);
        }

        try {
            sCon.close();
            fail("Expected Exception did not occur");
        } catch (SOAPException e) {
            assertTrue(true);
        }
    }
View Full Code Here

            soapConnectionFactory = SOAPConnectionFactory.newInstance();
        } catch (SOAPException e) {
            fail("Unexpected Exception " + e);
        }

        SOAPConnection sCon = null;
        try {
            sCon = soapConnectionFactory.createConnection();
            sCon.close();
        } catch (SOAPException e) {
            fail("Unexpected Exception " + e);
        }

        try {
            sCon.call(null, new Object());
            fail("Expected Exception did not occur");
        } catch (SOAPException e) {
            assertTrue(true);
        }
    }
View Full Code Here

    public void testGet() {
      if(isNetworkedResourceAvailable("http://java.sun.com/index.html")){
            try {
                SOAPConnectionFactory sf = new SOAPConnectionFactoryImpl();
                SOAPConnection con = sf.createConnection();
                //Create a valid non webservice endpoint for invoking HTTP-GET
                URL urlEndpoint = new URL("http", "java.sun.com", 80, "/index.html");
                //invoking HTTP-GET with a valid non webservice endpoint should throw a SOAPException
                SOAPMessage reply = con.get(urlEndpoint);
            } catch (Exception e) {
                assertTrue(e instanceof SOAPException);
            }
      }else{
        //If resource is not available online, do a mock test
View Full Code Here

        AttachmentPart ap2 = msg.createAttachmentPart();
        ap2.setContent("Attachment content - Part 2", "text/plain");
        msg.addAttachmentPart(ap2);
        msg.saveChanges();
       
        SOAPConnection con = conFac.createConnection();
        URL endpoint = new URL("http://localhost:9008/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit1");
        SOAPMessage response = con.call(msg, endpoint);
        QName sayHiResp = new QName("http://apache.org/hello_world_rpclit", "sayHiResponse");
        assertNotNull(response.getSOAPBody().getChildElements(sayHiResp));
        assertEquals(2, response.countAttachments());
    }
View Full Code Here

TOP

Related Classes of javax.xml.soap.SOAPConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.