Package javax.xml.soap

Examples of javax.xml.soap.SOAPConnection


    public boolean echoUsingSAAJ(String filename) throws Exception {
        String endPointURLString =  "http://localhost:" +opts.getPort() + "/axis/services/urn:EchoAttachmentsService";

        SOAPConnectionFactory soapConnectionFactory =
                javax.xml.soap.SOAPConnectionFactory.newInstance();
        SOAPConnection soapConnection =
                soapConnectionFactory.createConnection();

        MessageFactory messageFactory =
                MessageFactory.newInstance();
        SOAPMessage soapMessage =
                messageFactory.createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();
        SOAPEnvelope requestEnvelope =
                soapPart.getEnvelope();
        SOAPBody body = requestEnvelope.getBody();
        SOAPBodyElement operation = body.addBodyElement
                (requestEnvelope.createName("echo"));

        Vector dataHandlersToAdd = new Vector();
        dataHandlersToAdd.add(new DataHandler(new FileDataSource(new
                File(filename))));

        if (dataHandlersToAdd != null) {
            ListIterator dataHandlerIterator =
                    dataHandlersToAdd.listIterator();

            while (dataHandlerIterator.hasNext()) {
                DataHandler dataHandler = (DataHandler)
                        dataHandlerIterator.next();
                javax.xml.soap.SOAPElement element =
                        operation.addChildElement(requestEnvelope.createName("source"));
                javax.xml.soap.AttachmentPart attachment =
                        soapMessage.createAttachmentPart(dataHandler);
                soapMessage.addAttachmentPart(attachment);
                element.addAttribute(requestEnvelope.createName
                                     ("href"), "cid:" + attachment.getContentId());
            }
        }
        javax.xml.soap.SOAPMessage returnedSOAPMessage =
                soapConnection.call(soapMessage, endPointURLString);
        Iterator iterator = returnedSOAPMessage.getAttachments();
        if (!iterator.hasNext()) {
            //The wrong type of object that what was expected.
            System.out.println("Received problem response from server");
            throw new AxisFault("", "Received problem response from server", null, null);
View Full Code Here


            return;
        } else if (exchange.getStatus() == ExchangeStatus.ERROR) {
            done(exchange);
            return;
        }
        SOAPConnection connection = null;
        try {
            connection = getConnectionFactory().createConnection();

            SOAPMessage inMessage = marshaler.createSOAPMessage(exchange.getMessage("in"));
            SOAPMessage response = connection.call(inMessage, soapEndpoint);

            NormalizedMessage outMessage = exchange.createMessage();
            marshaler.toNMS(outMessage, response);

            answer(exchange, outMessage);
        }
        catch (Exception e) {
            fail(exchange, e);
        }
        finally {
            if (connection != null) {
                try {
                    connection.close();
                }
                catch (SOAPException e) {
                    log.warn("Failed to close connection: " + e, e);
                }
            }
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

            SOAPEnvelope requestEnvelope = requestMessage.getSOAPPart().getEnvelope();
            SOAPBody requestBody = requestEnvelope.getBody();
            requestBody.addDocument(document);

            // Send SOAP request
            SOAPConnection connection = soapConnectionFactory.createConnection();
            SOAPMessage responseMessage = connection.call(requestMessage, stiServiceURL);

            // Get STI response
            SOAPEnvelope responseEnvelope = responseMessage.getSOAPPart().getEnvelope();
            SOAPBody responseBody = responseEnvelope.getBody();
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:" + PORT
                               + "/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

            String httpHeaders = (String)map.get("httpHeaders");
            SAXEventBuffer headerContent = (SAXEventBuffer)map.get("header");
            SAXEventBuffer bodyContent = (SAXEventBuffer)map.get("body");
           
            SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();
            SOAPConnection connection = factory.createConnection();
           
            MessageFactory messageFactory = MessageFactory.newInstance();
            SOAPMessage message = messageFactory.createMessage();
            MimeHeaders mimeHeaders = message.getMimeHeaders();
            SOAPEnvelope env = message.getSOAPPart().getEnvelope();
           
            // Add headers, if any
            if (httpHeaders != null) {
                for (StringTokenizer st
                        = new StringTokenizer(httpHeaders, "\n");
                    st.hasMoreElements();) {
                    String hdr = st.nextToken();
                    int sep = hdr.indexOf(':');
                    if (sep < 0) {
                        throw new CannotExecuteException
                            ("Invalid header (missing ':'): " + hdr);
                    }
                    mimeHeaders.addHeader
                        (hdr.substring(0, sep),
                         hdr.substring(sep + 1).trim());
                }
            }

            // Add header content, if any
            if (headerContent != null) {
                SOAPHeader hdr = env.getHeader();
                appendNodes (env, hdr, headerContent);
            }

            // Add body content
            SOAPBody body = env.getBody();
            appendNodes (env, body, bodyContent);
           
            // Now invoke with the created message
            SOAPMessage response = null;
            try {
                response = connection.call(message, new URL(endpoint));
            } catch (SOAPException e) {
                if (e.getMessage().indexOf("ConnectException") >= 0) {
                    // Axis way of reporting this
                    if (logger.isDebugEnabled()) {
                        logger.debug
          ("Cannot invoke (signalled ConnectException): "
           + e.getMessage (), e);
                    }
                    throw new CannotExecuteException
                        ("Assuming connection failure: " + e.getMessage(),
                         new ConnectException (e.getMessage(), e));
                } else if (e.getCause() != null
                           && e.getCause().getCause() != null
                           && (e.getCause().getCause()
                               instanceof java.net.ConnectException)) {
                    // JBossWS way of reporting this
                    throw new CannotExecuteException
                        ("Assuming connection failure: " + e.getMessage(),
                         new ConnectException (e.getMessage(), e));
                }
                throw e;
            } finally {
                connection.close ();
            }
            SOAPPart respPart = response.getSOAPPart ();
           
            Map resData = new HashMap ();
            for (int i = 0; i < formPars.length; i++) {
View Full Code Here

     * @throws MalformedURLException
     */
    private void call(SOAPMessage message, String observer)
        throws SOAPException, MalformedURLException {
        SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = factory.createConnection();
       
        URL endpoint = new URL(observer);
        connection.call(message, endpoint);
    }
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

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.