Examples of Abdera


Examples of org.apache.abdera.Abdera

            // System.out.println(">>>AtomDeleteTestCase.init entry");

            initTestEnvironment(AtomDeleteTestCase.class);

            testService = scaConsumerNode.getService(CustomerClient.class, "CustomerClient");
            abdera = new Abdera();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here

Examples of org.apache.abdera.Abdera

        }

    }

    public static Entry newEntry(String value) {
        Abdera abdera = new Abdera();
        Entry entry = abdera.newEntry();
        entry.setTitle("customer " + value);

        Content content = abdera.getFactory().newContent();
        content.setContentType(Content.Type.TEXT);
        content.setValue(value);
        entry.setContentElement(content);

        return entry;
View Full Code Here

Examples of org.apache.abdera.Abdera

        return entry;
    }

    public static Entry updateEntry(Entry entry, String value) {
        Abdera abdera = new Abdera();
        entry.setTitle("customer " + value);

        Content content = abdera.getFactory().newContent();
        content.setContentType(Content.Type.TEXT);
        content.setValue(value);
        entry.setContentElement(content);

        return entry;
View Full Code Here

Examples of org.apache.abdera.Abdera

            //System.out.println(">>>AtomPutTestCase.init entry");

            initTestEnvironment(AtomPutTestCase.class);

            testService = scaConsumerNode.getService(CustomerClient.class, "CustomerClient");
            abdera = new Abdera();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here

Examples of org.apache.abdera.Abdera

                if (( preferredType != null ) && ((preferredType.indexOf( "json") > -1) || (preferredType.indexOf( "JSON") > -1 ))) {
                    // JSON response body
                    response.setContentType("application/json");

                    try {
                        Abdera abdera = new Abdera();
                        WriterFactory wf = abdera.getWriterFactory();
                        org.apache.abdera.writer.Writer json = wf.getWriter("json");
                        feed.writeTo(json, response.getWriter());
                    } catch (Exception e) {
                        throw new ServletException(e);
                    }

                } else {
                    // Write the Atom feed
                    response.setContentType("application/atom+xml");
                    try {
                        feed.getDocument().writeTo(response.getOutputStream());
                    } catch (IOException ioe) {
                        throw new ServletException(ioe);
                    }
                }
            } else {
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
            }

        } else if (path.startsWith("/")) {
            // Return a specific entry in the collection
            org.apache.abdera.model.Entry feedEntry;

            // Invoke the get operation on the service implementation
            Message requestMessage = messageFactory.createMessage();
            String id = path.substring(1);
            requestMessage.setBody(new Object[] {id});
            Message responseMessage = getInvoker.invoke(requestMessage);
            if (responseMessage.isFault()) {
                Object body = responseMessage.getBody();
                if (body.getClass().getName().endsWith(".NotFoundException")) {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
                    return;
                } else {
                    throw new ServletException((Throwable)responseMessage.getBody());
                }

            }
            if (supportsFeedEntries) {
                // The service implementation returns a feed entry
                feedEntry = responseMessage.getBody();
            } else {
                // The service implementation only returns a data item, create an entry
                // from it
                Entry<Object, Object> entry = new Entry<Object, Object>(id, responseMessage.getBody());
                feedEntry = feedEntry(entry, itemClassType, itemXMLType, mediator, abderaFactory);
            }
            // Write the Atom entry
            if (feedEntry != null) {
                String entryETag = null;
                entryETag = HTTPUtils.calculateHashETag(feedEntry.toString().getBytes("utf-8"));
                Date entryUpdated = feedEntry.getUpdated();
                if ( entryUpdated != null )
                    response.addHeader(LASTMODIFIED, dateFormat.format( entryUpdated ));
                // TODO Check If-Modified-Since If-Unmodified-Since predicates against LASTMODIFIED.
                // If true return 304 and null body.

                Link link = feedEntry.getSelfLink();
                if (link != null) {
                    response.addHeader(LOCATION, link.getHref().toString());
                } else {
                    link = feedEntry.getLink( "Edit" );
                    if (link != null) {
                        response.addHeader(LOCATION, link.getHref().toString());
                    }
                }

                // Test request for predicates.
                String predicate = request.getHeader( "If-Match" );
                if (( predicate != null ) && ( !predicate.equals(entryETag) )) {
                    // No match, should short circuit
                    response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
                    return;
                }
                predicate = request.getHeader( "If-None-Match" );
                if (( predicate != null ) && ( predicate.equals(entryETag) )) {
                    // Match, should short circuit
                    response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
                    return;
                }
                if ( entryUpdated != null ) {
                    predicate = request.getHeader( "If-Unmodified-Since" );
                    if ( predicate != null ) {
                        try {
                            Date predicateDate = dateFormat.parse( predicate );
                            if ( predicateDate.compareTo( entryUpdated ) < 0 ) {
                                // Match, should short circuit
                                response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
                                return;
                            }
                        } catch ( java.text.ParseException e ) {
                            // Ignore and move on
                        }
                    }
                    predicate = request.getHeader( "If-Modified-Since" );
                    if ( predicate != null ) {
                        try {
                            Date predicateDate = dateFormat.parse( predicate );
                            if ( predicateDate.compareTo( entryUpdated ) > 0 ) {
                                // Match, should short circuit
                                response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
                                return;
                            }
                        } catch ( java.text.ParseException e ) {
                            // Ignore and move on
                        }
                    }
                }
                // Provide Etag based on Id and time if given.
                // Ignore if not given. (Browser may cache if trivial ETag is given.)
                if (entryETag != null) {
                    response.addHeader(ETAG, entryETag );
                }
                if ( entryUpdated != null ) {
                    response.addHeader(LASTMODIFIED, dateFormat.format( entryUpdated ));
                }

                //default http header for response
                AtomBindingHttpUtils.prepareHTTPResponse(request, response);

                // Content negotiation
                String acceptType = request.getHeader( "Accept" );
                String preferredType = getContentPreference( acceptType );
                if (( preferredType != null ) && ((preferredType.indexOf( "json") > -1) || (preferredType.indexOf( "JSON") > -1 ))) {
                    // JSON response body
                    response.setContentType("application/json");
                    try {
                        Abdera abdera = new Abdera();
                        WriterFactory wf = abdera.getWriterFactory();
                        org.apache.abdera.writer.Writer json = wf.getWriter("json");
                        feedEntry.writeTo(json, response.getWriter());
                    } catch (Exception e) {
                        throw new ServletException(e);
                    }
View Full Code Here

Examples of org.apache.abdera.Abdera

  }
 
  public static synchronized Abdera getAbdera() {
    if (abdera == null) {
      log.debug(Localizer.sprintf("CREATING.NEW.INSTANCE","Abdera"));
      abdera = new Abdera();
    }
    return abdera;
  }
View Full Code Here

Examples of org.apache.abdera.Abdera

    return abdera;
  }
 
  public Provider newProvider (
    Map<String,String> properties) {
    Abdera abdera = getAbdera();
    String instance = properties.get(PROVIDER);
    log.debug(Localizer.sprintf("CREATING.NEW.INSTANCE","Provider"));
    Provider provider =
      (Provider) ServiceUtil.newInstance(
        PROVIDER,
View Full Code Here

Examples of org.apache.abdera.Abdera

    return getEntryFromCollectionProvider(entryObj, feedIri, request);
  }

  Entry getEntryFromCollectionProvider(T entryObj, IRI feedIri, RequestContext request)
    throws ResponseContextException {
    Abdera abdera = request.getAbdera();
    Factory factory = abdera.getFactory();
    Entry entry = factory.newEntry();

    return buildEntry(entryObj, entry, feedIri, request);
  }
View Full Code Here

Examples of org.apache.abdera.Abdera

        String contentType = mimeType == null ? null : mimeType.toString();
        if (contentType != null &&
            !MimeTypeHelper.isAtom(contentType) &&
            !MimeTypeHelper.isXml(contentType))
          return ProviderHelper.notsupported(request);
        Abdera abdera = request.getAbdera();
        Parser parser = abdera.getParser();
        Entry inputEntry = (Entry) request.getDocument(parser).getRoot();
        Target target = request.getTarget();
        String entryId =
          !createFlag ?
            target.getParameter(
View Full Code Here

Examples of org.apache.abdera.Abdera

  }
 
  private static String getHost(
    Provider provider,
    HttpServletRequest request) {
      Abdera abdera = provider.getAbdera();
      String host = abdera.getConfiguration().getConfigurationOption(
        "org.apache.abdera.protocol.server.Host");
      return (host != null) ?
        host :
        request.getServerName();
  }
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.