Package org.apache.wsif

Examples of org.apache.wsif.WSIFException


     */
    public void write(javax.jms.Message message) throws WSIFException {
        Trc.entry(this, message);

        if (!isCorrectMessageType(message))
            throw new WSIFException("Incorrect message type");

        if (message instanceof javax.jms.TextMessage)
            write((javax.jms.TextMessage) message);
        else if (message instanceof javax.jms.ObjectMessage)
            write((javax.jms.ObjectMessage) message);
        else
            throw new WSIFException(
                "Unsupported Message Type: " + message.getClass().getName());
        Trc.exit();
    }
View Full Code Here


    private void write(javax.jms.TextMessage message) throws WSIFException {
        Trc.entry(this, message);

        // Need to determine the format type mapping
        if (!XML_ENCODING.equals(getFormatEncoding(fieldBindingModel)))
            throw new WSIFException("Unable to support non XML encodings in a JMS Text Message");

        try {
            ArrayList al = new ArrayList();
            for (Iterator i = this.getPartNames(); i.hasNext();) {
                al.add(i.next());
            }
            String[] partNames = (String[]) al.toArray(new String[al.size()]);

            if (partNames.length == 1) {
                // If there is only one part, set it into the message as is
                String partName = partNames[0];

                javax.wsdl.Part partModel = fieldMessageModel.getPart(partName);

                javax.xml.namespace.QName partQName =
                    new javax.xml.namespace.QName(
                        fieldMessageModel.getQName().getNamespaceURI(),
                        partModel.getName());

                JMSFormatHandler fh = getFormatHandler(partName);

                if (fh != null) {
                    fh.setPartQName(partQName);
                    fh.setObjectPart(parts.get(partName));
                    fh.write(message);
                } else {
                    // No format handler
                    Object part = parts.get(partName);
                    message.setText(part.toString());
                }
            } else {
                // Use my own XML Structure 
                // Prepare the stream writers and the serializers
                java.io.ByteArrayOutputStream os =
                    new java.io.ByteArrayOutputStream();
                java.io.OutputStreamWriter writer =
                    new java.io.OutputStreamWriter(os);

                org.apache.xml.serialize.OutputFormat format =
                    new org.apache.xml.serialize.OutputFormat();
                org.apache.xml.serialize.XMLSerializer serializer =
                    new org.apache.xml.serialize.XMLSerializer(writer, format);

                String namespace = "";

                // Start the document     
                serializer.startDocument();

                // Add the message tag
                serializer.startElement(
                    namespace,
                    fieldMessageModel.getQName().getLocalPart(),
                    "",
                    new org.xml.sax.helpers.AttributesImpl());

                // Cycle the parts, invoking each format handler
                for (int i = 0; i < partNames.length; i++) {
                    String partName = partNames[i];

                    // Add a beginning tag
                    serializer.startElement(
                        namespace,
                        partName,
                        "",
                        new org.xml.sax.helpers.AttributesImpl());

                    javax.wsdl.Part partModel =
                        fieldMessageModel.getPart(partName);
                    javax.xml.namespace.QName partQName =
                        new javax.xml.namespace.QName(
                            fieldMessageModel.getQName().getNamespaceURI(),
                            partModel.getName());

                    // Determine the format handler
                    JMSFormatHandler fh = getFormatHandler(partName);

                    if (fh != null) {
                        fh.setPartQName(partQName);
                        fh.setObjectPart(parts.get(partName));

                        // Send the message since it is the native format
                        // Reinitialize the message content
                        message.setText("");
                        fh.write(message);
                        char[] c = message.getText().toCharArray();
                        serializer.characters(c, 0, c.length);
                    } else {
                        // No format handler
                        Object part = parts.get(partName);
                        char[] c = part.toString().toCharArray();
                        serializer.characters(c, 0, c.length);
                    }

                    // Add the end tag
                    serializer.endElement(partName);
                }

                // Add the end message tag
                serializer.endElement(
                    fieldMessageModel.getQName().getLocalPart());

                // End the document
                serializer.endDocument();

                writer.flush();
                String msgContents = os.toString();
                // Put contents into the message
                message.setText(msgContents);
            }

        } catch (JMSException e) {
            Trc.exception(e);
            throw new WSIFException("Error in write.", e);
        } catch (java.io.IOException e) {
            Trc.exception(e);
            throw new WSIFException("Error in write.", e);
        } catch (org.xml.sax.SAXException e) {
            Trc.exception(e);
            throw new WSIFException("Error in write.", e);
        }
        Trc.exit();
    }
View Full Code Here

    private void write(javax.jms.ObjectMessage message) throws WSIFException {
        Trc.entry(this, message);

        // Need to determine the format type mapping
        if (!JAVA_ENCODING.equals(getFormatEncoding(fieldBindingModel)))
            throw new WSIFException("Unable to support non Java encodings in a JMS Object Message");

        try {

            ArrayList al = new ArrayList();
            for (Iterator i = this.getPartNames(); i.hasNext();) {
                al.add(i.next());
            }
            String[] partNames = (String[]) al.toArray(new String[al.size()]);

            if (partNames.length == 1) {
                // If there is only one part, set it into the message as is
                String partName = partNames[0];

                javax.wsdl.Part partModel = fieldMessageModel.getPart(partName);

                javax.xml.namespace.QName partQName =
                    new javax.xml.namespace.QName(
                        fieldMessageModel.getQName().getNamespaceURI(),
                        partModel.getName());

                JMSFormatHandler fh = getFormatHandler(partName);

                if (fh != null) {
                    fh.setPartQName(partQName);
                    fh.setObjectPart(parts.get(partName));
                    fh.write(message);
                } else {
                    // No format handler
                    Object part = parts.get(partName);
                    // Check to see if it is Serializable.
                    // If so, serialize it
                    try {
                        message.setObject((java.io.Serializable) part);
                    } catch (ClassCastException e) {
                        Trc.exception(e);
                        throw new WSIFException("Unable to serialize a part");
                    }
                }
            } else {
                // Use a hash map to hold the objects
                java.util.HashMap result = new java.util.HashMap();
                for (int i = 0; i < partNames.length; i++) {
                    String partName = partNames[i];

                    javax.wsdl.Part partModel =
                        fieldMessageModel.getPart(partName);

                    javax.xml.namespace.QName partQName =
                        new javax.xml.namespace.QName(
                            fieldMessageModel.getQName().getNamespaceURI(),
                            partModel.getName());

                    JMSFormatHandler fh = getFormatHandler(partName);

                    if (fh != null) {
                        fh.setPartQName(partQName);
                        fh.setObjectPart(parts.get(partName));
                        fh.write(message);
                        result.put(partName, message.getObject());
                    } else {
                        // No format handler
                        Object part = parts.get(partName);
                        // Check to see if it is Serializable.
                        // If so, serialize it
                        try {
                            result.put(partName, (java.io.Serializable) part);
                        } catch (ClassCastException e) {
                            Trc.exception(e);
                            throw new WSIFException("Unable to serialize a part");
                        }
                    }
                }
                message.setObject(result);
            }

        } catch (JMSException e) {
            Trc.exception(e);
            throw new WSIFException("Error in write.", e);
        }
        Trc.exit();
    }
View Full Code Here

     */
    public void read(javax.jms.Message message) throws WSIFException {
        Trc.entry(this, message);

        if (!isCorrectMessageType(message))
            throw new WSIFException("Incorrect message type");

        if (message instanceof javax.jms.TextMessage)
            read((javax.jms.TextMessage) message);
        else if (message instanceof javax.jms.ObjectMessage)
            read((javax.jms.ObjectMessage) message);
        else
            throw new WSIFException(
                "Unsupported Message Type: " + message.getClass().getName());
        Trc.exit();
    }
View Full Code Here

    private void read(javax.jms.TextMessage message) throws WSIFException {
        Trc.entry(this, message);

        // Need to determine the format type mapping
        if (!XML_ENCODING.equals(getFormatEncoding(fieldBindingModel)))
            throw new WSIFException("Unable to support non XML encodings in a JMS Text Message");

        boolean wsifFormat = false;

        try {

            // Read the text into the document
            javax.xml.parsers.DocumentBuilderFactory factory =
                javax.xml.parsers.DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            factory.setValidating(false);

            javax.xml.parsers.DocumentBuilder builder =
                factory.newDocumentBuilder();
            builder.setErrorHandler(null);

            String text = message.getText();
            java.io.ByteArrayInputStream is =
                new java.io.ByteArrayInputStream(text.getBytes());
            org.w3c.dom.Document doc = builder.parse(is);

            // Check to see if the document element is the message
            if (fieldMessageModel
                .getQName()
                .getLocalPart()
                .equals(doc.getDocumentElement().getLocalName())) {

                wsifFormat = true;

                // Need to make the message mutable
                message.clearBody();

                // Parse the document ignoring the document element which should be the message name
                // The contents should represent the parts as elements
                for (org.w3c.dom.Node n =
                    doc.getDocumentElement().getFirstChild();
                    n != null;
                    n = n.getNextSibling()) {
                    if (n.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
                        String partName = n.getLocalName();

                        java.io.ByteArrayOutputStream os =
                            new java.io.ByteArrayOutputStream();

                        org.apache.xml.serialize.OutputFormat format =
                            new org.apache.xml.serialize.OutputFormat();
                        org.apache.xml.serialize.TextSerializer serializer =
                            new org.apache.xml.serialize.TextSerializer();
                        serializer.setOutputFormat(format);
                        serializer.setOutputByteStream(os);

                        format.setOmitXMLDeclaration(true);
                        //format.setOmitDocumentType(true);

                        serializer.serialize((org.w3c.dom.Element) n);
                        os.flush();
                        // Get the contents
                        String partText = os.toString();

                        javax.wsdl.Part partModel =
                            fieldMessageModel.getPart(partName);
                        JMSFormatHandler fh = getFormatHandler(partName);

                        if (fh != null) {

                            fh.setPartQName(
                                new javax.xml.namespace.QName(
                                    fieldMessageModel
                                        .getQName()
                                        .getNamespaceURI(),
                                    partModel.getName()));

                            message.setText(partText);
                            fh.read(message);
                            //fh.setObjectPart(n);

                            setObjectPart(partName, fh.getObjectPart());

                            // ?? Do I want to store the format handler instead???
                            //partToFHMap.put(partKey, formatHandler);

                        } else {
                            // No format handler - pass the part contents directly
                            setObjectPart(partName, partText);
                        }
                    }
                }

                // Reset the message to original text
                message.setText(text);
            }
        } catch (JMSException e) {
            Trc.exception(e);
            throw new WSIFException("Error in read.", e);
        } catch (javax.xml.parsers.ParserConfigurationException e) {
            Trc.exception(e);
            throw new WSIFException("Error in read.", e);
        } catch (Exception e) {
            Trc.exception(e);
            // For all other exceptions ignore since it is likely due to parsing of a non-XML document
        }

        try {
            if (!wsifFormat) {
                // Unknown format - either XML or Text
                // Pass the contents of the message to each part of the message model
                Object[] partNames =
                    fieldMessageParts != null
                        ? fieldMessageParts.toArray()
                        : fieldMessageModel.getParts().keySet().toArray();

                // should only be one part
                if (partNames.length != 1)
                    throw new WSIFException(
                        "There should only be one part defined in "
                            + fieldMessageModel.getQName().getLocalPart());

                String partName = partNames[0].toString();

                javax.wsdl.Part partModel = fieldMessageModel.getPart(partName);
                JMSFormatHandler fh = getFormatHandler(partName);

                if (fh != null) {
                    fh.setPartQName(
                        new javax.xml.namespace.QName(
                            fieldMessageModel.getQName().getNamespaceURI(),
                            partModel.getName()));
                    fh.read(message);

                    setObjectPart(partName, fh.getObjectPart());

                    // ?? Do I want to store the format handler instead???
                    //partToFHMap.put(partKey, formatHandler);

                } else {
                    // No format handler - pass the part contents directly
                    setObjectPart(partName, message.getText());
                }
            }
        } catch (JMSException e) {
            Trc.exception(e);
            throw new WSIFException("Error in read.", e);
        }
        Trc.exit();
    }
View Full Code Here

    private void read(javax.jms.ObjectMessage message) throws WSIFException {
        Trc.entry(this, message);

        // Need to determine the format type mapping
        if (!JAVA_ENCODING.equals(getFormatEncoding(fieldBindingModel)))
            throw new WSIFException("Unable to support non Java encodings in a JMS Object Message");

        try {
            Object object = message.getObject();
            Object[] partNames =
                fieldMessageParts != null
                    ? fieldMessageParts.toArray()
                    : fieldMessageModel.getParts().keySet().toArray();

            // Check to see if there are any parts
            if (partNames.length == 0)
                return;

            // Check to see if it is a known format
            if (object instanceof java.util.Map) {
                // Need to make the message mutable     
                message.clearBody();

                java.util.Map map = (java.util.Map) object;

                // Cycle through the parts of the model
                for (int i = 0; i < partNames.length; i++) {
                    String partName = partNames[i].toString();

                    if (map.containsKey(partName)) {
                        javax.wsdl.Part partModel =
                            fieldMessageModel.getPart(partName);
                        JMSFormatHandler fh = getFormatHandler(partName);

                        if (fh != null) {

                            fh.setPartQName(
                                new javax.xml.namespace.QName(
                                    fieldMessageModel
                                        .getQName()
                                        .getNamespaceURI(),
                                    partModel.getName()));
                            // Should be serializable since retrieved it over the wire
                            message.setObject(
                                (java.io.Serializable) map.get(partName));
                            fh.read(message);
                            //fh.setObjectPart(map.get(partName));
                            setObjectPart(partName, fh.getObjectPart());

                            // ?? Do I want to store the format handler instead???
                            //partToFHMap.put(partKey, formatHandler);

                        } else {
                            // No format handler defined
                            setObjectPart(partName, map.get(partName));
                        }
                    }

                }
                // Reset the message to original text
                message.setObject((java.io.Serializable) object);
            } else {
                // It is an unknown format
                // Pass the contents of the message to each part of the message model

                // should only be one part
                if (partNames.length != 1)
                    throw new WSIFException(
                        "There should only be one part defined in "
                            + fieldMessageModel.getQName().getLocalPart()
                            + " or the JMS ObjectMessage should be a Map of "
                            + "all the parts in the message");

                String partName = partNames[0].toString();

                javax.wsdl.Part partModel = fieldMessageModel.getPart(partName);
                JMSFormatHandler fh = getFormatHandler(partName);

                if (fh != null) {
                    fh.setPartQName(
                        new javax.xml.namespace.QName(
                            fieldMessageModel.getQName().getNamespaceURI(),
                            partModel.getName()));
                    fh.read(message);

                    setObjectPart(partName, fh.getObjectPart());

                    // ?? Do I want to store the format handler instead???
                    //partToFHMap.put(partKey, formatHandler);

                } else {
                    // No format handler defined
                    setObjectPart(partName, message.getObject());
                }

            }
        } catch (JMSException e) {
            Trc.exception(e);
            throw new WSIFException("Error in read.", e);
        }
        Trc.exit();
    }
View Full Code Here

    this.operationStyle = soapOperation.getStyle();

    if (operationStyle == null || operationStyle.length() < 1) {
      operationStyle = wsifPort.getBindingStyle();
    } else if (!WSIFAXISConstants.VALID_STYLES.contains(operationStyle)) {
      throw new WSIFException(
        "unsupported style "
          + operationStyle
          + " for operation "
          + portTypeOperation.getName());
    }
View Full Code Here

        bindinginput,
        MIMEMultipartRelated.class,
        inExtElems);

    if (inSoapBody != null && inMimeMultipart != null) {
      throw new WSIFException(
        "In a binding operation that contains a mime:multipartRelated, "
          + "a soap:body was found that was not in a mime:part. "
          + "OperationName="
          + getName());
    }
    if (inSoapBody == null && inMimeMultipart == null) {
      throw new WSIFException(
        "binding operation input must contain either a soap:body " +
        "or a mime:multipartRelated element. "
          + "OperationName="
          + getName());
    }

    if (inMimeMultipart != null) {
      parseMimeMultipart(inMimeMultipart, true);
    }

    MIMEMimeXml inMimeMimeXml =
      (MIMEMimeXml) wsifPort.getExtElem(
        bindinginput,
        MIMEMimeXml.class,
        inExtElems);
    if (inMimeMimeXml != null)
      throw new WSIFException(
        "WSIF does not support mime:mimeXml. Operation="
          + getName());

    parseSOAPHeaderElement(bindinginput);

    List inJmsProps =
      wsifPort.getExtElems(
        bindinginput,
        JMSProperty.class,
        bindinginput.getExtensibilityElements());
    if (inJmsProps != null && inJmsProps.size() > 0) {
      if (wsifPort.isTransportJMS())
        setInputJmsProperties(inJmsProps);
      else
        throw new WSIFException("jms:property found in non-jms binding");
    }

    List inJmsPropVals =
      wsifPort.getExtElems(
        bindinginput,
        JMSPropertyValue.class,
        bindinginput.getExtensibilityElements());
    if (inJmsPropVals != null && inJmsPropVals.size() > 0) {
      if (wsifPort.isTransportJMS())
        addInputJmsPropertyValues(inJmsPropVals);
      else
        throw new WSIFException("jms:propertyValue found in non-jms binding");
    }
  }
View Full Code Here

          bindingoutput,
          MIMEMultipartRelated.class,
          outExtElems);

      if (outSoapBody != null && outMimeMultipart != null) {
        throw new WSIFException(
          "In a binding operation that contains a mime:multipartRelated, "
            + "a soap:body was found that was not in a mime:part. "
            + "OperationName="
            + getName());
      }
      if (outSoapBody == null && outMimeMultipart == null) {
        throw new WSIFException(
              "binding operation output must contain either a soap:body " +
            "or a mime:multipartRelated element. " +
          "OperationName=" +
          getName());
      }

      if (outMimeMultipart != null) {
        parseMimeMultipart(outMimeMultipart, false);
      }

      MIMEMimeXml outMimeMimeXml =
        (MIMEMimeXml) wsifPort.getExtElem(
          bindingoutput,
          MIMEMimeXml.class,
          outExtElems);
      if (outMimeMimeXml != null) {
        throw new WSIFException(
          "WSIF does not support mime:mimeXml. Operation=" +
            getName());
      }

      parseSOAPHeaderElement(bindingoutput);

      for (Iterator iterator1 =
        bindingOperation.getBindingFaults().values().iterator();
        iterator1.hasNext();
        ) {
        BindingFault bindingfault = (BindingFault) iterator1.next();
        SOAPFault soapfault =
          (SOAPFault) wsifPort.getExtElem(
            bindingfault,
            javax.wsdl.extensions.soap.SOAPFault.class,
            bindingfault.getExtensibilityElements());
      }

      List outJmsProps =
        wsifPort.getExtElems(
          bindingoutput,
          JMSProperty.class,
          outExtElems);
      if (outJmsProps != null && outJmsProps.size() > 0) {
        if (wsifPort.isTransportJMS()) {
          setOutputJmsProperties(outJmsProps);
        } else {
          throw new WSIFException("jms:properties found in non-jms binding");
        }
      }
    }
  }
View Full Code Here

        ((BindingInput) element).getExtensibilityElements();
    } else if (element instanceof BindingOutput) {
      extensabilityElements =
        ((BindingOutput) element).getExtensibilityElements();
    } else {
      throw new WSIFException(
        "internal error, unexpected object: " + element);
    }

    Part soapHeaderPart = null;
    Part soapHeaderFaultPart = null;

    SOAPHeader soapHeader =
      (SOAPHeader) wsifPort.getExtElem(
        element,
        javax.wsdl.extensions.soap.SOAPHeader.class,
        extensabilityElements);
    if (soapHeader != null) {
      QName messageName = soapHeader.getMessage();
      if (messageName == null) {
        throw new WSIFException(
          "no message attribute on soap:header: " + soapHeader);
      }
      String messagePart = soapHeader.getPart();
      if (messagePart == null) {
        throw new WSIFException(
          "no part attribute on soap:header: " + soapHeader);
      }
      soapHeaderPart = getPart(messageName, messagePart);
      if (soapHeaderPart == null) {
        throw new WSIFException(
          "non existent part specified on soap:header: "
            + soapHeader);
      }

      SOAPHeaderFault soapHeaderFault =
        (SOAPHeaderFault) wsifPort.getExtElem(
          soapHeader,
          javax.wsdl.extensions.soap.SOAPHeaderFault.class,
          extensabilityElements);
      if (soapHeaderFault != null) {
        messageName = soapHeader.getMessage();
        if (messageName == null) {
          throw new WSIFException(
            "no message attribute on soap:header: " + soapHeader);
        }
        messagePart = soapHeader.getPart();
        if (messagePart == null) {
          throw new WSIFException(
            "no part attribute on soap:header: " + soapHeader);
        }
        soapHeaderFaultPart = getPart(messageName, messagePart);
        if (soapHeaderFaultPart == null) {
          throw new WSIFException(
            "non existent part specified on soap:header: "
              + soapHeader);
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.wsif.WSIFException

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.