Examples of SOAPConnection


Examples of javax.xml.soap.SOAPConnection

        System.out.print("The last price for SUNW is " + stockQuote.getStockQuote("SUNW"));
    }

    public String getStockQuote(String tickerSymbol) throws Exception {
        SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection con = scFactory.createConnection();

        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage message = factory.createMessage();

        SOAPPart soapPart = message.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();

        SOAPHeader header = envelope.getHeader();
        SOAPBody body = envelope.getBody();

        header.detachNode();

        Name bodyName = envelope.createName("getQuote", "n", "urn:xmethods-delayed-quotes");
        SOAPBodyElement gltp = body.addBodyElement(bodyName);

        Name name = envelope.createName("symbol");
        SOAPElement symbol = gltp.addChildElement(name);
        symbol.addTextNode(tickerSymbol);

        URLEndpoint endpoint = new URLEndpoint("http://66.28.98.121:9090/soap");
        SOAPMessage response = con.call(message, endpoint);
        con.close();

        SOAPPart sp = response.getSOAPPart();
        SOAPEnvelope se = sp.getEnvelope();
        SOAPBody sb = se.getBody();
        Iterator it = sb.getChildElements();
View Full Code Here

Examples of javax.xml.soap.SOAPConnection

    }

    public static void searchUDDI(String name, String url) throws Exception {
        // Create the connection and the message factory.
        SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = scf.createConnection();
        MessageFactory msgFactory = MessageFactory.newInstance();

        // Create a message
        SOAPMessage msg = msgFactory.createMessage();

        // Create an envelope in the message
        SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();

        // Get hold of the the body
        SOAPBody body = envelope.getBody();

        javax.xml.soap.SOAPBodyElement bodyElement = body.addBodyElement(envelope.createName("find_business", "",
                "urn:uddi-org:api"));

        bodyElement.addAttribute(envelope.createName("generic"), "1.0")
                .addAttribute(envelope.createName("maxRows"), "100")
                .addChildElement("name")
                .addTextNode(name);

        URLEndpoint endpoint = new URLEndpoint(url);
        msg.saveChanges();

        SOAPMessage reply = connection.call(msg, endpoint);
        //System.out.println("Received reply from: " + endpoint);
        //reply.writeTo(System.out);
        connection.close();
    }
View Full Code Here

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

Examples of javax.xml.soap.SOAPConnection

            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

Examples of javax.xml.soap.SOAPConnection

        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

Examples of javax.xml.soap.SOAPConnection

            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

Examples of javax.xml.soap.SOAPConnection

        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

Examples of javax.xml.soap.SOAPConnection

            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

Examples of javax.xml.soap.SOAPConnection

     * @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

Examples of javax.xml.soap.SOAPConnection

            // 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
TOP
Copyright © 2018 www.massapi.com. 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.