Ejemplo n.º 1
0
 /** Writes an Atom updated tag. */
 public void writeUpdated(long updated) throws XMLStreamException {
   String updatedStr = DateTimeHelper.formatHttpDateTime(updated);
   XMLUtils.write(
       getWriter(), XMLConstants.PREFIX_APP, XMLConstants.NAMESPACE_APP, "edited", updatedStr);
   XMLUtils.write(
       getWriter(), XMLConstants.PREFIX_ATOM, XMLConstants.NAMESPACE_ATOM, "updated", updatedStr);
 }
Ejemplo n.º 2
0
  /** Writes an Atom collection. */
  public void writeCollection(String href, String collectionType, String text, String... accept)
      throws XMLStreamException {
    XMLStreamWriter xsw = getWriter();

    xsw.writeStartElement(XMLConstants.PREFIX_APP, "collection", XMLConstants.NAMESPACE_APP);
    xsw.writeAttribute("href", href);

    if (collectionType != null) {
      XMLUtils.write(
          xsw,
          XMLConstants.PREFIX_RESTATOM,
          XMLConstants.NAMESPACE_RESTATOM,
          "collectionType",
          collectionType);
    }

    xsw.writeStartElement(XMLConstants.PREFIX_ATOM, "title", XMLConstants.NAMESPACE_ATOM);
    xsw.writeAttribute("type", "text");
    xsw.writeCharacters(text);
    xsw.writeEndElement();

    for (String ct : accept) {
      XMLUtils.write(xsw, XMLConstants.PREFIX_APP, XMLConstants.NAMESPACE_APP, "accept", ct);
    }

    xsw.writeEndElement();
  }
Ejemplo n.º 3
0
  /** Writes an Atom author tag. */
  public void writeAuthor(String author) throws XMLStreamException {
    XMLStreamWriter xsw = getWriter();

    xsw.writeStartElement(XMLConstants.PREFIX_ATOM, "author", XMLConstants.NAMESPACE_ATOM);
    XMLUtils.write(xsw, XMLConstants.PREFIX_ATOM, XMLConstants.NAMESPACE_ATOM, "name", author);
    xsw.writeEndElement();
  }
Ejemplo n.º 4
0
 /** Writes an Atom published tag. */
 public void writePublished(long published) throws XMLStreamException {
   XMLUtils.write(
       getWriter(),
       XMLConstants.PREFIX_ATOM,
       XMLConstants.NAMESPACE_ATOM,
       "published",
       DateTimeHelper.formatHttpDateTime(published));
 }
Ejemplo n.º 5
0
 /** Writes a CMIS relativePathSegment tag. */
 public void writeRelativePathSegment(String relativePathSegment) throws XMLStreamException {
   XMLUtils.write(
       getWriter(),
       XMLConstants.PREFIX_RESTATOM,
       XMLConstants.NAMESPACE_RESTATOM,
       "relativePathSegment",
       relativePathSegment);
 }
  @Override
  public Element getSOAPHeaders(Object portObject) {

    String securityToken = getSecurityToken();

    // Exit if no security token found
    if (securityToken == null) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("securityToken is null");
      }
      return null;
    }

    // Set time
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    long created = System.currentTimeMillis();
    long expires = created + 24 * 60 * 60 * 1000; // 24 hours

    // Create the SOAP WSSecurity header
    try {
      Document document = XMLUtils.newDomDocument();

      Element wsseSecurityElement = document.createElementNS(WSSE_NAMESPACE, "Security");

      Element wsuTimestampElement = document.createElementNS(WSU_NAMESPACE, "Timestamp");
      wsseSecurityElement.appendChild(wsuTimestampElement);

      Element tsCreatedElement = document.createElementNS(WSU_NAMESPACE, "Created");
      tsCreatedElement.appendChild(document.createTextNode(sdf.format(created)));
      wsuTimestampElement.appendChild(tsCreatedElement);

      Element tsExpiresElement = document.createElementNS(WSU_NAMESPACE, "Expires");
      tsExpiresElement.appendChild(document.createTextNode(sdf.format(expires)));
      wsuTimestampElement.appendChild(tsExpiresElement);

      // Add the BinarySecurityToken (contains the LTPAv2 token)
      Element wsseBinarySecurityTokenElement =
          document.createElementNS(WSSE_NAMESPACE, "BinarySecurityToken");
      wsseBinarySecurityTokenElement.setAttribute("xmlns:wsu", WSU_NAMESPACE);
      wsseBinarySecurityTokenElement.setAttribute(
          "xmlns:wsst", "http://www.ibm.com/websphere/appserver/tokentype");
      wsseBinarySecurityTokenElement.setAttribute("wsu:Id", "ltpa_20");
      wsseBinarySecurityTokenElement.setAttribute("ValueType", "wsst:LTPAv2");
      wsseBinarySecurityTokenElement.appendChild(document.createTextNode(securityToken));

      // Append BinarySecurityToken to Security section
      wsseSecurityElement.appendChild(wsseBinarySecurityTokenElement);

      return wsseSecurityElement;
    } catch (ParserConfigurationException e) {
      // shouldn't happen...
      throw new CmisRuntimeException("Could not build SOAP header: " + e.getMessage(), e);
    }
  }
  protected void assertQueryType11(QueryTypeImpl data, boolean validate) throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    XMLStreamWriter writer = XMLUtils.createWriter(out);
    XMLUtils.startXmlDocument(writer);
    XMLConverter.writeQuery(writer, CmisVersion.CMIS_1_1, data);
    XMLUtils.endXmlDocument(writer);

    byte[] xml = out.toByteArray();

    if (validate) {
      validate(xml, CmisVersion.CMIS_1_1);
    }

    XMLStreamReader parser = XMLUtils.createParser(new ByteArrayInputStream(xml));
    XMLUtils.findNextStartElemenet(parser);
    QueryTypeImpl result = XMLConverter.convertQuery(parser);
    parser.close();

    assertNotNull(result);
    assertDataObjectsEquals("QueryType", data, result, null);
    assertNull(result.getExtensions());
  }
Ejemplo n.º 8
0
 protected String readText(final XmlPullParser parser) throws XmlPullParserException {
   return XMLUtils.readText(parser, XMLConstraints.MAX_STRING_LENGTH);
 }
Ejemplo n.º 9
0
 /** Writes an Atom published tag. */
 public void writePublished(GregorianCalendar published) throws XMLStreamException {
   XMLUtils.write(
       getWriter(), XMLConstants.PREFIX_ATOM, XMLConstants.NAMESPACE_ATOM, "published", published);
 }
Ejemplo n.º 10
0
 /** Writes an Atom updated tag. */
 public void writeUpdated(GregorianCalendar updated) throws XMLStreamException {
   XMLUtils.write(
       getWriter(), XMLConstants.PREFIX_APP, XMLConstants.NAMESPACE_APP, "edited", updated);
   XMLUtils.write(
       getWriter(), XMLConstants.PREFIX_ATOM, XMLConstants.NAMESPACE_ATOM, "updated", updated);
 }
Ejemplo n.º 11
0
 /** Writes an Atom title tag. */
 public void writeTitle(String title) throws XMLStreamException {
   XMLUtils.write(
       getWriter(), XMLConstants.PREFIX_ATOM, XMLConstants.NAMESPACE_ATOM, "title", title);
 }
Ejemplo n.º 12
0
 /** Writes an Atom id tag. */
 public void writeId(String id) throws XMLStreamException {
   XMLUtils.write(getWriter(), XMLConstants.PREFIX_ATOM, XMLConstants.NAMESPACE_ATOM, "id", id);
 }
    public void serve(
        CallContext context,
        CmisService service,
        String repositoryId,
        HttpServletRequest request,
        HttpServletResponse response)
        throws Exception {
      assert context != null;
      assert service != null;
      assert repositoryId != null;
      assert request != null;
      assert response != null;

      // get parameters
      String statement = null;
      Boolean searchAllVersions = null;
      Boolean includeAllowableActions = null;
      IncludeRelationships includeRelationships = null;
      String renditionFilter = null;
      BigInteger maxItems = null;
      BigInteger skipCount = null;

      int statusCode = 0;

      if (Dispatcher.METHOD_POST.equals(request.getMethod())) {
        // POST -> read from stream

        QueryTypeImpl queryType = null;
        XMLStreamReader parser = null;
        try {
          parser = XMLUtils.createParser(request.getInputStream());
          XMLUtils.findNextStartElemenet(parser);
          queryType = XMLConverter.convertQuery(parser);
        } catch (XMLStreamException e) {
          throw new CmisInvalidArgumentException("Invalid query request!", e);
        } finally {
          if (parser != null) {
            try {
              parser.close();
            } catch (XMLStreamException e2) {
              // ignore
            }
          }
        }

        statement = queryType.getStatement();
        searchAllVersions = queryType.getSearchAllVersions();
        includeAllowableActions = queryType.getIncludeAllowableActions();
        includeRelationships = queryType.getIncludeRelationships();
        renditionFilter = queryType.getRenditionFilter();
        maxItems = queryType.getMaxItems();
        skipCount = queryType.getSkipCount();

        statusCode = HttpServletResponse.SC_CREATED;
      } else if (Dispatcher.METHOD_GET.equals(request.getMethod())) {
        // GET -> parameters
        statement = getStringParameter(request, Constants.PARAM_Q);
        searchAllVersions = getBooleanParameter(request, Constants.PARAM_SEARCH_ALL_VERSIONS);
        includeAllowableActions = getBooleanParameter(request, Constants.PARAM_ALLOWABLE_ACTIONS);
        includeRelationships =
            getEnumParameter(request, Constants.PARAM_RELATIONSHIPS, IncludeRelationships.class);
        // since CMIS 1.1
        renditionFilter = getStringParameter(request, Constants.PARAM_RENDITION_FILTER);
        maxItems = getBigIntegerParameter(request, Constants.PARAM_MAX_ITEMS);
        skipCount = getBigIntegerParameter(request, Constants.PARAM_SKIP_COUNT);

        statusCode = HttpServletResponse.SC_OK;
      } else {
        throw new CmisRuntimeException("Invalid HTTP method!");
      }

      // execute
      if (stopBeforeService(service)) {
        return;
      }

      ObjectList results =
          service.query(
              repositoryId,
              statement,
              searchAllVersions,
              includeAllowableActions,
              includeRelationships,
              renditionFilter,
              maxItems,
              skipCount,
              null);

      if (stopAfterService(service)) {
        return;
      }

      if (results == null) {
        throw new CmisRuntimeException("Results are null!");
      }

      // set headers
      UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);

      UrlBuilder pagingUrl = compileUrlBuilder(baseUrl, RESOURCE_QUERY, null);
      pagingUrl.addParameter(Constants.PARAM_Q, statement);
      pagingUrl.addParameter(Constants.PARAM_SEARCH_ALL_VERSIONS, searchAllVersions);
      pagingUrl.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
      pagingUrl.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);

      UrlBuilder location = new UrlBuilder(pagingUrl);
      location.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
      location.addParameter(Constants.PARAM_SKIP_COUNT, skipCount);

      response.setStatus(statusCode);
      response.setContentType(Constants.MEDIATYPE_FEED);

      // The Content-Location header is optional (CMIS specification
      // 3.7.2.1).
      // Since it can cause problems with long query statements it is
      // deactivated.
      // response.setHeader("Content-Location", location.toString());

      // The Location header is not optional (CMIS specification 3.7.2.1).
      response.setHeader("Location", location.toString());

      // write XML
      AtomFeed feed = new AtomFeed();
      feed.startDocument(response.getOutputStream(), getNamespaces(service));
      feed.startFeed(true);

      // write basic Atom feed elements
      GregorianCalendar now = new GregorianCalendar();
      feed.writeFeedElements("query", null, "", "Query", now, null, results.getNumItems());

      // write links
      feed.writeServiceLink(baseUrl.toString(), repositoryId);

      feed.writePagingLinks(
          pagingUrl, maxItems, skipCount, results.getNumItems(), results.hasMoreItems(), PAGE_SIZE);

      CmisVersion cmisVersion = context.getCmisVersion();
      if (results.getObjects() != null) {
        AtomEntry entry = new AtomEntry(feed.getWriter());
        int idCounter = 0;
        for (ObjectData result : results.getObjects()) {
          if (result == null) {
            continue;
          }
          idCounter++;
          writeQueryResultEntry(entry, result, "id-" + idCounter, now, cmisVersion);
        }
      }

      // write extensions
      feed.writeExtensions(results);

      // we are done
      feed.endFeed();
      feed.endDocument();
    }