Example usage for javax.xml.soap SOAPMessage getSOAPBody

List of usage examples for javax.xml.soap SOAPMessage getSOAPBody

Introduction

In this page you can find the example usage for javax.xml.soap SOAPMessage getSOAPBody.

Prototype

public SOAPBody getSOAPBody() throws SOAPException 

Source Link

Document

Gets the SOAP Body contained in this SOAPMessage object.

Usage

From source file:edu.xtec.colex.client.beans.ColexIndexBean.java

/**
 * Calls the web service operation <I>listGuestCollections (User) :
 * [Collection+Guest]</I>// w  w w.ja  v a  2 s  . c  o  m
 *
 * @throws javax.xml.soap.SOAPException when a SOAPException error occurs
 */
private void listGuestCollections() throws SOAPException {
    logger.debug("listGuestCollections IN <<");
    User uRequest = new User(getUserId());
    Vector vGuestCollections = new Vector();

    try {

        smRequest = mf.createMessage();

        SOAPBodyElement sbeRequest = setRequestName(smRequest, "listGuestCollections");

        addParam(sbeRequest, uRequest);

        smRequest.saveChanges();

        SOAPMessage smResponse = sendMessage(smRequest,
                this.getJspProperties().getProperty("url.servlet.share"));

        SOAPBody sbResponse = smResponse.getSOAPBody();

        if (sbResponse.hasFault()) {
            checkFault(sbResponse, "listGuestCollections");
        } else {
            vGuestCollections = getListGuestCollections(smResponse);

            if (vGuestCollections != null) {
                vCollections.addAll(vGuestCollections);
            }
        }
        logger.debug("listGuestCollections OUT >> " + vCollections);
    } catch (SOAPException se) {
        throw se;
    }
}

From source file:hk.hku.cecid.corvus.ws.EBMSMessageHistoryQuerySenderTest.java

private EBMSMessageHistoryRequestData getHttpRequestData() throws Exception {
    // Check content Type
    String contentType = monitor.getContentType();

    if (contentType == null) {
        System.out.println((monitor == null ? "Null Monitor" : "Monitor not null"));
        System.out.println("Lengeth " + monitor.getContentLength());
        Assert.fail("Null Content");
    }//from www . j a  v a2  s .com

    String mediaType = contentType.split(";")[0];
    assertEquals("Invalid content type", "text/xml", mediaType);

    // Check the multi-part content.
    // Make a request context that bridge the content from our monitor to FileUpload library.    
    RequestContext rc = new RequestContext() {
        public String getCharacterEncoding() {
            return "charset=utf-8";
        }

        public int getContentLength() {
            return monitor.getContentLength();
        }

        public String getContentType() {
            return monitor.getContentType();
        }

        public InputStream getInputStream() {
            return monitor.getInputStream();
        }
    };

    BufferedReader bReader = new BufferedReader(new InputStreamReader(monitor.getInputStream()));

    String strLine = "";
    do {
        strLine = bReader.readLine();
    } while (!strLine.contains("SOAP-ENV"));

    MimeHeaders header = new MimeHeaders();
    header.addHeader("Content-Type", "text/xml");

    SOAPMessage msg = MessageFactory.newInstance().createMessage(header,
            new ByteArrayInputStream(strLine.getBytes()));

    EBMSMessageHistoryRequestData data = new EBMSMessageHistoryRequestData();
    data.setMessageId(getElementValue(msg.getSOAPBody(), "tns:messageId"));
    data.setMessageBox(getElementValue(msg.getSOAPBody(), "tns:messageBox"));
    data.setStatus(getElementValue(msg.getSOAPBody(), "tns:status"));
    data.setService(getElementValue(msg.getSOAPBody(), "tns:service"));
    data.setAction(getElementValue(msg.getSOAPBody(), "tns:action"));
    data.setConversationId(getElementValue(msg.getSOAPBody(), "tns:conversationId"));
    data.setCpaId(getElementValue(msg.getSOAPBody(), "tns:cpaId"));
    return data;
}

From source file:edu.xtec.colex.client.beans.ColexIndexBean.java

/**
 * Calls the web service operation <I>createCollection(User,Collection) :
 * void</I>/*from   w w w . j  av a 2  s . c om*/
 *
 * @param sCollection the String name of the Collection to create
 * @throws javax.xml.soap.SOAPException when a SOAPException error occurs
 * @throws java.io.IOException when an IOException error occurs
 */
private void createCollection(String sCollection) throws SOAPException, IOException {
    User uRequest = new User(getUserId());
    Collection cRequest = new Collection(sCollection);

    cRequest.setDescription("");
    cRequest.setTags("");
    cRequest.setIsPublic(0);

    try {

        smRequest = mf.createMessage();

        SOAPBodyElement sbeRequest = setRequestName(smRequest, "createCollection");

        addParam(sbeRequest, uRequest);
        addParam(sbeRequest, cRequest);

        smRequest.saveChanges();

        SOAPMessage smResponse = sendMessage(smRequest,
                this.getJspProperties().getProperty("url.servlet.collection"));

        SOAPBody sbResponse = smResponse.getSOAPBody();

        if (sbResponse.hasFault()) {
            checkFault(sbResponse, "create");
        } else {
            try {
                String sRedirectPage = buildRedirectURL(request, "structure.jsp?collection=" + sCollection);
                response.sendRedirect(sRedirectPage);
            } catch (IOException ioe) {
                throw ioe;
            }
        }
    } catch (SOAPException se) {
        throw se;
    }
}

From source file:edu.xtec.colex.client.beans.ColexIndexBean.java

/**
 * Calls the web service operation <I>importCollection(User,Collection,FILE)
 * : void</I>//from ww  w.  ja  va2s .  c  o  m
 *
 * @param importName the String name of the Collection to import
 * @param fiImport the FileItem Zip of the Collection to import
 * @throws java.lang.Exception when an Exception error occurs
 */
private void importCollection(String importName, FileItem fiImport) throws Exception {
    User uRequest = new User(getUserId());
    Collection cRequest = new Collection(importName);
    File fTemp = null;

    try {
        smRequest = mf.createMessage();

        SOAPBody sbRequest = smRequest.getSOAPBody();

        Name n = sf.createName("importCollection");

        SOAPBodyElement sbeRequest = sbRequest.addBodyElement(n);

        sbeRequest.addChildElement(uRequest.toXml());
        sbeRequest.addChildElement(cRequest.toXml());

        String sNomFitxer = Utils.getFileName(fiImport.getName());

        fTemp = File.createTempFile("attach", null);

        fiImport.write(fTemp);

        URL urlFile = new URL("file://" + fTemp.getPath());

        AttachmentPart ap = smRequest.createAttachmentPart(new DataHandler(urlFile));

        smRequest.addAttachmentPart(ap);

        smRequest.saveChanges();

        SOAPMessage smResponse = sendMessage(smRequest,
                this.getJspProperties().getProperty("url.servlet.collection"));

        SOAPBody sbResponse = smResponse.getSOAPBody();

        if (sbResponse.hasFault()) {
            checkFault(sbResponse, "import");
        } else {

        }

    } catch (Exception e) {
        throw e;
    } finally {
        if (fTemp != null) {
            fTemp.delete();
        }
    }
}

From source file:com.offbynull.portmapper.upnpigd.UpnpIgdController.java

private Map<String, String> parseResponseXml(String expectedTagName, byte[] data) {
    try {//from w  w  w  .  j  a  v  a  2s .  c  o  m
        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage soapMessage = factory.createMessage(new MimeHeaders(), new ByteArrayInputStream(data));

        if (soapMessage.getSOAPBody().hasFault()) {
            StringWriter writer = new StringWriter();
            try {
                Transformer transformer = TransformerFactory.newInstance().newTransformer();
                transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
                transformer.transform(new DOMSource(soapMessage.getSOAPPart()), new StreamResult(writer));
            } catch (IllegalArgumentException | TransformerException | TransformerFactoryConfigurationError e) {
                writer.append("Failed to dump fault: " + e);
            }

            throw new ResponseException(writer.toString());
        }

        Iterator<SOAPBodyElement> responseBlockIt = soapMessage.getSOAPBody()
                .getChildElements(new QName(serviceType, expectedTagName));
        if (!responseBlockIt.hasNext()) {
            throw new ResponseException(expectedTagName + " tag missing");
        }

        Map<String, String> ret = new HashMap<>();

        SOAPBodyElement responseNode = responseBlockIt.next();
        Iterator<SOAPBodyElement> responseChildrenIt = responseNode.getChildElements();
        while (responseChildrenIt.hasNext()) {
            SOAPBodyElement param = responseChildrenIt.next();
            String name = StringUtils.trim(param.getLocalName().trim());
            String value = StringUtils.trim(param.getValue().trim());

            ret.put(name, value);
        }

        return ret;
    } catch (IllegalArgumentException | IOException | SOAPException | DOMException e) {
        throw new IllegalStateException(e); // should never happen
    }
}

From source file:edu.xtec.colex.client.beans.ColexIndexBean.java

/**
 * Calls the web service operation <I>listCollections(User) :
 * [Collection]</I>//from   w w w.j  a  v a 2 s  .co m
 *
 * @throws javax.xml.soap.SOAPException when a SOAPException error occurs
 */
private void listCollections() throws SOAPException {
    logger.debug("ListCollections IN << ");
    User uRequest = new User(getUserId());
    logger.debug("uRequest: " + uRequest);

    vCollections = new Vector();

    try {

        smRequest = mf.createMessage();
        logger.debug("smRequest: " + smRequest);

        SOAPBodyElement sbeRequest = setRequestName(smRequest, "listCollections");

        addParam(sbeRequest, uRequest);

        smRequest.saveChanges();
        logger.debug("sbeRequest: " + sbeRequest);

        SOAPMessage smResponse = sendMessage(smRequest,
                this.getJspProperties().getProperty("url.servlet.collection"));
        logger.debug("smResponse: " + smResponse);

        SOAPBody sbResponse = smResponse.getSOAPBody();
        logger.debug("sbResponse: " + sbResponse);

        if (sbResponse.hasFault()) {
            logger.debug("sbResponse.hasFault() IN ");
            checkFault(sbResponse, "list");
            logger.debug("sbResponse.hasFault() OUT");
        } else {
            vCollections = getCollections(smResponse);
            iOwnedCollections = vCollections.size();
        }
        logger.debug("ListCollections OUT >> " + vCollections);
    } catch (SOAPException se) {
        throw se;
    }
}

From source file:com.inbravo.scribe.rest.service.crm.ms.auth.SOAPExecutor.java

/**
 * Executes SOAP message//from  w w w  . ja v  a 2  s  .c o m
 * 
 * @param endpointUrl SOAP endpoint
 * @param message SOAP request
 * @return SOAP response message
 * @throws SOAPException in case of a SOAP issue
 * @throws IOException in case of an IO issue
 */
private final SOAPMessage execute(final String endpointUrl, final SOAPMessage message) throws Exception {
    SOAPConnection conn = null;
    try {

        /* Create new SOAP connection */
        conn = SOAPConnectionFactory.newInstance().createConnection();

        if (logger.isDebugEnabled()) {
            logger.debug("----Inside execute, going to execute SOAP message : "
                    + message.getSOAPBody().getTextContent());
        }

        /* Call SOAP service */
        final SOAPMessage response = conn.call(message, endpointUrl);

        /* Get SOAP response body */
        final SOAPBody body = response.getSOAPBody();

        if (logger.isDebugEnabled()) {
            logger.debug("----Inside execute, has fault? :  " + body.hasFault());
        }

        if (body.hasFault() && body.getFault() != null) {

            logger.error("----Inside execute, fault :  " + body.getFault().getTextContent()
                    + ", fault reason : " + body.getFault().getFaultString());

            /* Throw error */
            throw new SOAPException(body.getFault().getTextContent());
        }
        return response;
    } catch (final Exception e) {

        logger.error("----Inside execute, error recieved :  " + e.getMessage() + ", error : " + e);

        /* Throw user error */
        throw new SOAPException(e);
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}

From source file:edu.duke.cabig.c3pr.webservice.studyimportexport.impl.StudyImportExportImpl.java

/**
 * Creates the import study response.//from   w w w  .  ja  v a 2s  .  co  m
 *
 * @return the sOAP message
 * @throws SOAPException the sOAP exception
 */
private SOAPMessage createImportStudyResponse() throws SOAPException {
    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage response = mf.createMessage();
    SOAPBody body = response.getSOAPBody();
    body.addChildElement(new QName(SERVICE_NS, "ImportStudyResponse"));
    response.saveChanges();
    return response;
}

From source file:edu.duke.cabig.c3pr.webservice.studyimportexport.impl.StudyImportExportImpl.java

public SOAPMessage invoke(SOAPMessage request) {
    try {//from   www  . j a  va 2  s.  com
        SOAPBody body = request.getSOAPBody();
        RequestType type = determineRequestType(body);
        if (type == RequestType.IMPORT_STUDY) {
            return processStudyImportRequest(body);
        } else {
            return processStudyExportRequest(body);
        }
    } catch (Exception e) {
        log.error(ExceptionUtils.getFullStackTrace(e));
        throw new WebServiceException(createSOAPFaultException(e.getMessage()));
    }
}

From source file:edu.duke.cabig.c3pr.webservice.studyimportexport.impl.StudyImportExportImpl.java

/**
 * Creates the export study response./*from  www.  j a  v a2 s. co m*/
 *
 * @param study the study
 * @return the sOAP message
 * @throws SOAPException the sOAP exception
 * @throws XMLUtilityException the xML utility exception
 * @throws ParserConfigurationException the parser configuration exception
 * @throws SAXException the sAX exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
private SOAPMessage createExportStudyResponse(Study study)
        throws SOAPException, XMLUtilityException, ParserConfigurationException, SAXException, IOException {
    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage response = mf.createMessage();
    SOAPBody body = response.getSOAPBody();
    SOAPElement exportStudyResponse = body.addChildElement(new QName(SERVICE_NS, "ExportStudyResponse"));
    String xml = marshaller.toXML(study);

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setSchema(SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
            .newSchema(XmlMarshaller.class.getResource(C3PR_DOMAIN_XSD_URL)));
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(IOUtils.toInputStream(xml));
    Element studyEl = (Element) doc.getFirstChild();
    exportStudyResponse.appendChild(body.getOwnerDocument().importNode(studyEl, true));
    response.saveChanges();
    return response;
}