Example #1
0
  /**
   * Get the content type of the attachments.
   *
   * @param sc provides the default content type
   * @return a <code>String</code> giving the content type of the attachment
   * @throws AxisFault if there was an error deducing the content type from this message
   */
  public String getContentType(SOAPConstants sc) throws AxisFault {
    boolean soap12 = false;

    if (sc != null) {
      if (sc == SOAPConstants.SOAP12_CONSTANTS) {
        soap12 = true;
      }
    } else {
      // Support of SOAP 1.2 HTTP binding
      SOAPEnvelope envelope = getSOAPEnvelope();
      if (envelope != null) {
        if (envelope.getSOAPConstants() == SOAPConstants.SOAP12_CONSTANTS) {
          soap12 = true;
        }
      }
    }

    String encoding = XMLUtils.getEncoding(this, msgContext);
    ;
    String ret = sc.getContentType() + "; charset=" + encoding.toLowerCase();

    // Support of SOAP 1.2 HTTP binding
    if (soap12) {
      ret = HTTPConstants.HEADER_ACCEPT_APPL_SOAP + "; charset=" + encoding;
    }

    if (getSendType() != Attachments.SEND_TYPE_NONE
        && mAttachments != null
        && 0 != mAttachments.getAttachmentCount()) {
      ret = mAttachments.getContentType();
    }
    return ret;
  }
Example #2
0
 public Element[] testElement(Element[] bodyElems) throws Exception {
   if (bodyElems == null || bodyElems.length != 1) {
     throw new AxisFault("Wrong number of Elements in array!");
   }
   Element el = bodyElems[0];
   if (el == null) {
     throw new AxisFault("Null Element in array!");
   }
   if (!"http://db.com".equals(el.getNamespaceURI())) {
     throw new AxisFault(
         "Wrong namespace for Element (was \""
             + el.getNamespaceURI()
             + "\" should be "
             + "\"http://db.com\"!");
   }
   String xml = "<m:elementResult xmlns:m=\"http://db.com\"/>";
   Document doc = XMLUtils.newDocument(new ByteArrayInputStream(xml.getBytes()));
   Element result = doc.getDocumentElement();
   return new Element[] {result};
 }
Example #3
0
 /**
  * Writes this <CODE>SOAPMessage</CODE> object to the given output stream. The externalization
  * format is as defined by the SOAP 1.1 with Attachments specification.
  *
  * <p>If there are no attachments, just an XML stream is written out. For those messages that have
  * attachments, <CODE>writeTo</CODE> writes a MIME-encoded byte stream.
  *
  * @param os the <CODE>OutputStream</CODE> object to which this <CODE>SOAPMessage</CODE> object
  *     will be written
  * @throws SOAPException if there was a problem in externalizing this SOAP message
  * @throws IOException if an I/O error occurs
  */
 public void writeTo(java.io.OutputStream os) throws SOAPException, IOException {
   // Do it the old fashion way.
   if (getSendType() == Attachments.SEND_TYPE_NONE
       || mAttachments == null
       || 0 == mAttachments.getAttachmentCount()) {
     try {
       String charEncoding = XMLUtils.getEncoding(this, msgContext);
       ;
       mSOAPPart.setEncoding(charEncoding);
       mSOAPPart.writeTo(os);
     } catch (java.io.IOException e) {
       log.error(Messages.getMessage("javaIOException00"), e);
     }
   } else {
     try {
       mAttachments.writeContentToStream(os);
     } catch (java.lang.Exception e) {
       log.error(Messages.getMessage("exception00"), e);
     }
   }
 }
Example #4
0
  public void testEmptyXMLNS() {
    try {
      MessageContext msgContext = new MessageContext(new AxisServer());
      msgContext.setSOAPConstants(SOAPConstants.SOAP12_CONSTANTS);
      msgContext.setProperty(Constants.MC_NO_OPERATION_OK, Boolean.TRUE);

      String req =
          "<xsd1:A xmlns:xsd1=\"urn:myNamespace\">"
              + "<xsd1:B>"
              + "<xsd1:C>foo bar</xsd1:C>"
              + "</xsd1:B>"
              + "</xsd1:A>";

      StringWriter stringWriter = new StringWriter();
      StringReader reqReader = new StringReader(req);
      InputSource reqSource = new InputSource(reqReader);

      Document document = XMLUtils.newDocument(reqSource);

      String msgString = null;

      SOAPEnvelope msg = new SOAPEnvelope(SOAPConstants.SOAP12_CONSTANTS);
      RPCParam arg1 = new RPCParam("urn:myNamespace", "testParam", document.getFirstChild());
      arg1.setXSITypeGeneration(Boolean.FALSE);

      RPCElement body = new RPCElement("urn:myNamespace", "method1", new Object[] {arg1});
      msg.addBodyElement(body);
      body.setEncodingStyle(Constants.URI_LITERAL_ENC);

      SerializationContext context = new SerializationContext(stringWriter, msgContext);
      msg.output(context);

      msgString = stringWriter.toString();
      assertTrue(msgString.indexOf("xmlns=\"\"") == -1);
    } catch (Exception e) {
      fail(e.getMessage());
    }
  }
  /**
   * This method is called when 'Finish' button is pressed in the wizard. We will create an
   * operation and run it using wizard as execution context.
   */
  public boolean performFinish() {
    try {
      Options opts = new Options(new String[0]);
      opts.setDefaultURL(serverPage.getSelectedServer() + "/services/NMRShiftDB");
      Service service = new Service();
      Call call = (Call) service.createCall();
      call.setOperationName("doSearch");
      call.setTargetEndpointAddress(new URL(opts.getURL()));
      DocumentBuilder builder;
      builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      SOAPBodyElement[] input = new SOAPBodyElement[1];
      Document doc = builder.newDocument();
      Element cdataElem;
      cdataElem = doc.createElementNS("http://www.nmrshiftdb.org/ws/NMRShiftDB/", "doSearch");
      Element reqElem;
      reqElem = doc.createElementNS("http://www.nmrshiftdb.org/ws/NMRShiftDB/", "searchstring");

      /*DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();
      Node node = db.parse(new ByteArrayInputStream(new Convertor(true,"").cdkAtomContainerToCMLMolecule(ac).toXML().getBytes()));*/
      Node node =
          DOMConverter.convert(
                  new nu.xom.Document(new Convertor(true, "").cdkAtomContainerToCMLMolecule(ac)),
                  builder.getDOMImplementation())
              .getFirstChild();
      reqElem.appendChild(doc.importNode(node, true));
      Element reqElem2;
      reqElem2 = doc.createElementNS("http://www.nmrshiftdb.org/ws/NMRShiftDB/", "searchtype");
      Node node2;
      node2 = doc.createTextNode("--");
      reqElem2.appendChild(node2);
      Element reqElem3;
      reqElem3 = doc.createElementNS("http://www.nmrshiftdb.org/ws/NMRShiftDB/", "searchfield");
      Node node3;
      node3 = doc.createTextNode(NmrshiftdbUtils.replaceSpaces(serverPage.selectedOption()));
      reqElem3.appendChild(node3);
      cdataElem.appendChild(reqElem);
      cdataElem.appendChild(reqElem2);
      cdataElem.appendChild(reqElem3);
      input[0] = new SOAPBodyElement(cdataElem);
      Vector elems = (Vector) call.invoke(input);
      SOAPBodyElement elem = (SOAPBodyElement) elems.get(0);
      Element e = elem.getAsDOM();
      CMLBuilder cmlbuilder = new CMLBuilder();
      CMLElement cmlElement = (CMLElement) cmlbuilder.parseString(XMLUtils.ElementToString(e));
      if (cmlElement.getChildCount() > 0) {
        IFolder folder = NmrshiftdbUtils.createVirtualFolder();
        for (int i = 0; i < cmlElement.getChildCount(); i++) {
          net.bioclipse.specmol.Activator.getDefault()
              .getJavaSpecmolManager()
              .saveSpecmol(
                  new JumboSpecmol((CMLCml) cmlElement.getChildCMLElements().get(i)),
                  folder.getFile(
                      ((CMLMolecule)
                                  cmlElement
                                      .getChildCMLElements()
                                      .get(i)
                                      .getChildCMLElement("molecule", 0))
                              .getId()
                          + "."
                          + SpectrumEditor.CML_TYPE));
        }
      } else {
        MessageDialog.openInformation(
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            "No results",
            "No spectra in NMRShiftDB for this structure!");
      }
    } catch (Exception ex) {
      LogUtils.handleException(ex, logger);
    }
    return true;
  }