Merge pull request #265 from mishako/mega-merge

Merging all rome projects into one repository
This commit is contained in:
Patrick Gotthard 2016-02-20 08:38:07 +01:00
commit 5daf64747a
1130 changed files with 85458 additions and 631 deletions

4
.gitignore vendored
View file

@ -1,5 +1,3 @@
/.checkstyle
/.classpath
/.project
/.settings
/.project
/target

207
LICENSE
View file

@ -1,16 +1,201 @@
Copyright 2004 Sun Microsystems, Inc.
Copyright 2011 The ROME Team
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
1. Definitions.
http://www.apache.org/licenses/LICENSE-2.0
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View file

@ -1,27 +1,4 @@
# ROME
rome-parent
===========
ROME is a set of RSS and Atom Utilities for Java. It makes it easy to work in Java with most syndication formats: RSS 0.90, RSS 0.91 Netscape,
RSS 0.91 Userland, RSS 0.92, RSS 0.93, RSS 0.94, RSS 1.0, RSS 2.0, Atom 0.3, Atom 1.0
More Information: http://rometools.github.io/rome/
## Changelog
### 1.5.1
- solved an [XML bomb](https://en.wikipedia.org/wiki/Billion_laughs) vulnerability
Important note: due to the security fix ROME now forbids all Doctype declarations by default. This will break compatibility with RSS 0.91 Netscape
because it requires a Doctype declaration. When you experience problems you have to activate the property **allowDoctypes** on the SyndFeedInput object. You
should only use this possibility when the feeds that you process are absolutely trustful.
### 1.5.0
- many (untracked) enhancements
- code cleanup
- renamed packages (was required to be able to push to Maven Central after years again)
- updated sourcecode to Java 1.6
### Prior to 1.5.0
- see [http://rometools.github.io/rome/ROMEReleases](http://rometools.github.io/rome/ROMEReleases)
Parent for all ROME projects

View file

@ -0,0 +1,115 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<!--
This configuration file was written by the eclipse-cs plugin configuration editor
-->
<!--
Checkstyle-Configuration: ROME
Description:
CheckStyle configuration for the ROME project
-->
<module name="Checker">
<property name="severity" value="warning"/>
<module name="TreeWalker">
<property name="tabWidth" value="4"/>
<module name="JavadocMethod">
<property name="allowMissingPropertyJavadoc" value="true"/>
<property name="suppressLoadErrors" value="true"/>
</module>
<module name="JavadocType"/>
<module name="JavadocVariable">
<property name="severity" value="ignore"/>
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
</module>
<module name="JavadocStyle"/>
<module name="ConstantName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>
<module name="AvoidStarImport"/>
<module name="IllegalImport"/>
<module name="RedundantImport"/>
<module name="UnusedImports"/>
<module name="LineLength">
<property name="max" value="160"/>
<property name="tabWidth" value="4"/>
</module>
<module name="MethodLength"/>
<module name="ParameterNumber"/>
<module name="EmptyForIteratorPad"/>
<module name="MethodParamPad"/>
<module name="NoWhitespaceAfter">
<property name="tokens" value="BNOT,DEC,DOT,INC,LNOT,UNARY_MINUS,UNARY_PLUS"/>
</module>
<module name="NoWhitespaceBefore"/>
<module name="OperatorWrap"/>
<module name="ParenPad"/>
<module name="TypecastParenPad"/>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround"/>
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>
<module name="AvoidNestedBlocks"/>
<module name="EmptyBlock"/>
<module name="LeftCurly"/>
<module name="NeedBraces"/>
<module name="RightCurly"/>
<module name="AvoidInlineConditionals"/>
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="HiddenField">
<property name="severity" value="ignore"/>
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
</module>
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<module name="MagicNumber"/>
<module name="MissingSwitchDefault"/>
<module name="RedundantThrows">
<property name="suppressLoadErrors" value="true"/>
</module>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<module name="DesignForExtension">
<property name="severity" value="ignore"/>
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
</module>
<module name="FinalClass"/>
<module name="HideUtilityClassConstructor"/>
<module name="InterfaceIsType"/>
<module name="VisibilityModifier"/>
<module name="ArrayTypeStyle"/>
<module name="FinalParameters"/>
<module name="TodoComment">
<property name="severity" value="ignore"/>
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
</module>
<module name="UpperEll"/>
</module>
<module name="JavadocPackage">
<property name="severity" value="ignore"/>
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
</module>
<module name="NewlineAtEndOfFile">
<property name="severity" value="ignore"/>
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
</module>
<module name="Translation"/>
<module name="FileLength"/>
<module name="FileTabCharacter">
<property name="severity" value="ignore"/>
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
</module>
<module name="RegexpSingleline">
<property name="severity" value="ignore"/>
<property name="format" value="\s+$"/>
<property name="message" value="Line has trailing spaces."/>
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
</module>
</module>

59
conf/eclipse/cleanup.xml Normal file
View file

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="2">
<profile kind="CleanUpProfile" name="ROME" version="2">
<setting id="cleanup.qualify_static_method_accesses_with_declaring_class" value="false"/>
<setting id="cleanup.always_use_this_for_non_static_method_access" value="false"/>
<setting id="cleanup.organize_imports" value="true"/>
<setting id="cleanup.remove_trailing_whitespaces_ignore_empty" value="false"/>
<setting id="cleanup.format_source_code_changes_only" value="false"/>
<setting id="cleanup.qualify_static_field_accesses_with_declaring_class" value="false"/>
<setting id="cleanup.add_generated_serial_version_id" value="false"/>
<setting id="cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class" value="true"/>
<setting id="cleanup.remove_unused_imports" value="true"/>
<setting id="cleanup.make_private_fields_final" value="true"/>
<setting id="cleanup.use_lambda" value="true"/>
<setting id="cleanup.always_use_blocks" value="true"/>
<setting id="cleanup.use_this_for_non_static_field_access_only_if_necessary" value="true"/>
<setting id="cleanup.sort_members_all" value="false"/>
<setting id="cleanup.remove_trailing_whitespaces_all" value="true"/>
<setting id="cleanup.add_missing_annotations" value="true"/>
<setting id="cleanup.always_use_this_for_non_static_field_access" value="false"/>
<setting id="cleanup.make_parameters_final" value="true"/>
<setting id="cleanup.sort_members" value="false"/>
<setting id="cleanup.remove_private_constructors" value="true"/>
<setting id="cleanup.always_use_parentheses_in_expressions" value="false"/>
<setting id="cleanup.remove_unused_local_variables" value="false"/>
<setting id="cleanup.convert_to_enhanced_for_loop" value="true"/>
<setting id="cleanup.remove_unused_private_fields" value="true"/>
<setting id="cleanup.never_use_blocks" value="false"/>
<setting id="cleanup.add_missing_deprecated_annotations" value="true"/>
<setting id="cleanup.use_this_for_non_static_field_access" value="true"/>
<setting id="cleanup.remove_unnecessary_nls_tags" value="true"/>
<setting id="cleanup.qualify_static_member_accesses_through_instances_with_declaring_class" value="true"/>
<setting id="cleanup.add_missing_nls_tags" value="false"/>
<setting id="cleanup.remove_unnecessary_casts" value="true"/>
<setting id="cleanup.use_blocks_only_for_return_and_throw" value="false"/>
<setting id="cleanup.format_source_code" value="true"/>
<setting id="cleanup.convert_functional_interfaces" value="true"/>
<setting id="cleanup.add_default_serial_version_id" value="true"/>
<setting id="cleanup.remove_unused_private_methods" value="true"/>
<setting id="cleanup.remove_trailing_whitespaces" value="true"/>
<setting id="cleanup.make_type_abstract_if_missing_method" value="false"/>
<setting id="cleanup.add_serial_version_id" value="true"/>
<setting id="cleanup.use_this_for_non_static_method_access" value="true"/>
<setting id="cleanup.use_this_for_non_static_method_access_only_if_necessary" value="true"/>
<setting id="cleanup.use_anonymous_class_creation" value="false"/>
<setting id="cleanup.add_missing_override_annotations_interface_methods" value="true"/>
<setting id="cleanup.remove_unused_private_members" value="false"/>
<setting id="cleanup.make_local_variable_final" value="true"/>
<setting id="cleanup.add_missing_methods" value="false"/>
<setting id="cleanup.never_use_parentheses_in_expressions" value="true"/>
<setting id="cleanup.qualify_static_member_accesses_with_declaring_class" value="true"/>
<setting id="cleanup.use_parentheses_in_expressions" value="true"/>
<setting id="cleanup.add_missing_override_annotations" value="true"/>
<setting id="cleanup.use_blocks" value="true"/>
<setting id="cleanup.make_variable_declarations_final" value="true"/>
<setting id="cleanup.correct_indentation" value="true"/>
<setting id="cleanup.remove_unused_private_types" value="true"/>
</profile>
</profiles>

295
conf/eclipse/formatter.xml Normal file
View file

@ -0,0 +1,295 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="12">
<profile kind="CodeFormatterProfile" name="ROME" version="12">
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="100"/>
<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_lambda_body" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/>
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
<setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.compiler.source" value="1.8"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.8"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.8"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="160"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
</profile>
</profiles>

321
pom.xml
View file

@ -4,130 +4,133 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.rometools</groupId>
<artifactId>rome-parent</artifactId>
<version>1.6.0-SNAPSHOT</version>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>9</version>
</parent>
<artifactId>rome</artifactId>
<groupId>com.rometools</groupId>
<artifactId>rome-parent</artifactId>
<version>1.6.0-SNAPSHOT</version>
<packaging>jar</packaging>
<packaging>pom</packaging>
<name>rome</name>
<modules>
<module>rome</module>
<module>rome-certiorem</module>
<module>rome-certiorem-webapp</module>
<module>rome-fetcher</module>
<module>rome-modules</module>
<module>rome-opml</module>
<module>rome-propono</module>
<module>rome-utils</module>
</modules>
<description>All Roads Lead to ROME. ROME is a set of Atom/RSS Java utilities that make it
easy to work in Java with most syndication formats. Today it accepts all flavors of RSS
(0.90, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0), Atom 0.3 and Atom 1.0 feeds. Rome includes
a set of parsers and generators for the various flavors of feeds, as well as converters
to convert from one format to another. The parsers can give you back Java objects that
are either specific for the format you want to work with, or a generic normalized
SyndFeed object that lets you work on with the data without bothering about the
underlying format.
</description>
<name>rome-parent</name>
<url>http://rometools.github.io/rome/</url>
<description>Parent for all ROME projects</description>
<url>http://rometools.github.io/rome-parent/</url>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<connection>scm:git:ssh://github.com/rometools/rome.git</connection>
<developerConnection>scm:git:ssh://git@github.com/rometools/rome.git</developerConnection>
<url>https://github.com/rometools/rome</url>
<connection>scm:git:ssh://github.com/rometools/rome-parent.git</connection>
<developerConnection>scm:git:ssh://git@github.com/rometools/rome-parent.git</developerConnection>
<url>https://github.com/rometools/rome-parent</url>
</scm>
<developers>
<developer>
<name>Alejandro Abdelnur</name>
<url>http://blog.sun.com/roller/page/tucu</url>
<timezone>0</timezone>
</developer>
<developer>
<name>Dave Johnson</name>
<url>http://rollerweblogger.org/roller</url>
<timezone>-5</timezone>
</developer>
<developer>
<name>Elaine Chien</name>
<timezone>0</timezone>
</developer>
<developer>
<name>Patrick Chanezon</name>
<url>http://www.chanezon.com/pat/weblog</url>
<timezone>-9</timezone>
</developer>
<developer>
<name>Patrick Gotthard</name>
<email>patrick@patrick-gotthard.de</email>
<url>http://www.patrick-gotthard.de</url>
<timezone>+1</timezone>
</developer>
<developer>
<name>Robert Cooper</name>
<email>kebernet@gmail.com</email>
<url>http://www.screaming-penguin.com</url>
<timezone>-4</timezone>
</developer>
<developer>
<id>farrukhnajmi</id>
<name>Farrukh Najmi</name>
<url>http://www.wellfleetsoftware.com/farrukh</url>
</developer>
<developer>
<id>imk</id>
<name>Martin Kurz</name>
<timezone>Europe/Berlin</timezone>
</developer>
</developers>
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-publish-plugin</artifactId>
<version>1.0</version>
</plugin>
<!-- The following plugin doesn't modify the build. It is
only used to hide irrelevant warnings in Eclipse -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>enforce</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>bundle</id>
<phase>package</phase>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-module-markdown</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-module-confluence</artifactId>
<version>1.5</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-publish-plugin</artifactId>
<configuration>
<scmBranch>gh-pages</scmBranch>
<pubScmUrl>${project.scm.developerConnection}</pubScmUrl>
<content>${project.build.directory}/site</content>
</configuration>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
@ -159,32 +162,96 @@
</configuration>
</plugin>
</plugins>
</build>
</reporting>
<dependencies>
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome-utils</artifactId>
<version>1.6.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<!-- JDOM -->
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
<version>2.0.5</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.10</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
</dependency>
<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!-- Hamcrest -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
</dependency>
<!-- JavaX -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
<!-- Guice -->
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-servlet</artifactId>
<version>2.0</version>
</dependency>
<!-- Apache Commons -->
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.2</version>
</dependency>
<!-- Jetty -->
<dependency>
<groupId>jetty</groupId>
<artifactId>jetty</artifactId>
<version>4.2.12</version>
</dependency>
<!-- XML-RPC -->
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xmlrpc-client</artifactId>
<version>3.1.3</version>
</dependency>
<!-- OAuth -->
<dependency>
<groupId>net.oauth.core</groupId>
<artifactId>oauth</artifactId>
<version>20100527</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>

4
rome-certiorem-webapp/.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
/.classpath
/.project
/.settings
/target

View file

@ -0,0 +1,4 @@
rome-certiorem-webapp
=====================
Example project using rome-certiorem

View file

@ -0,0 +1,61 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.rometools</groupId>
<artifactId>rome-parent</artifactId>
<version>1.6.0-SNAPSHOT</version>
</parent>
<artifactId>rome-certiorem-webapp</artifactId>
<packaging>war</packaging>
<name>rome-certiorem-webapp</name>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<connection>scm:git:git@github.com:rometools/rome-certiorem-webapp.git</connection>
<developerConnection>scm:git:git@github.com:rometools/rome-certiorem-webapp.git</developerConnection>
<url>https://github.com/rometools/rome-certiorem-webapp/</url>
</scm>
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome-certiorem</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-servlet</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,27 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rometools.certiorem.webapp;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.rometools.certiorem.hub.Hub;
import com.rometools.certiorem.web.AbstractHubServlet;
/**
*
* @author robert.cooper
*/
@Singleton
public class HubServlet extends AbstractHubServlet {
private static final long serialVersionUID = 1L;
@Inject
public HubServlet(final Hub hub) {
super(hub);
}
}

View file

@ -0,0 +1,42 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rometools.certiorem.webapp;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.Singleton;
import com.rometools.certiorem.pub.NotificationException;
import com.rometools.certiorem.pub.Publisher;
/**
*
* @author robert.cooper
*/
@Singleton
public class NotifyTest extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final Logger LOG = LoggerFactory.getLogger(NotifyTest.class);
@Override
public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException {
final Publisher pub = new Publisher();
try {
pub.sendUpdateNotification("http://localhost/webapp/hub", "http://localhost/webapp/research-atom.xml");
} catch (final NotificationException ex) {
LOG.error(null, ex);
throw new ServletException(ex);
}
}
}

View file

@ -0,0 +1,71 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rometools.certiorem.webapp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.servlet.GuiceServletContextListener;
import com.google.inject.servlet.ServletModule;
import com.rometools.certiorem.hub.Hub;
import com.rometools.certiorem.hub.data.ram.InMemoryHubDAO;
import com.rometools.certiorem.hub.notify.standard.UnthreadedNotifier;
import com.rometools.certiorem.hub.verify.standard.UnthreadedVerifier;
import com.rometools.certiorem.sub.Subscriptions;
import com.rometools.certiorem.sub.data.ram.InMemorySubDAO;
import com.rometools.certiorem.sub.request.AsyncRequester;
import com.rometools.fetcher.FeedFetcher;
import com.rometools.fetcher.impl.HashMapFeedInfoCache;
import com.rometools.fetcher.impl.HttpURLFeedFetcher;
/**
*
* @author robert.cooper
*/
public class ServerModule extends GuiceServletContextListener {
private static final Logger LOG = LoggerFactory.getLogger(ServerModule.class);
@Override
protected Injector getInjector() {
return Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
}
@Provides
@Singleton
public Hub buildHub() {
final FeedFetcher fetcher = new HttpURLFeedFetcher(new HashMapFeedInfoCache());
final Hub hub = new Hub(new InMemoryHubDAO(), new UnthreadedVerifier(), new UnthreadedNotifier(), fetcher);
return hub;
}
@Provides
@Singleton
public Subscriptions buildSubs() {
LOG.debug("buildSubs");
final Subscriptions subs = new Subscriptions(new HashMapFeedInfoCache(), new AsyncRequester(), "http://localhost/webapp/subscriptions/",
new InMemorySubDAO());
return subs;
}
}, new ServletModule() {
@Override
protected void configureServlets() {
serve("/hub*").with(HubServlet.class);
serve("/subscriptions/*").with(SubServlet.class);
serve("/test/sub").with(SubTest.class);
serve("/test/pub").with(NotifyTest.class);
}
});
}
}

View file

@ -0,0 +1,27 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rometools.certiorem.webapp;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.rometools.certiorem.sub.Subscriptions;
import com.rometools.certiorem.web.AbstractSubServlet;
/**
*
* @author robert.cooper
*/
@Singleton
public class SubServlet extends AbstractSubServlet {
private static final long serialVersionUID = 1L;
@Inject
public SubServlet(final Subscriptions subscriptions) {
super(subscriptions);
}
}

View file

@ -0,0 +1,67 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rometools.certiorem.webapp;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.rometools.certiorem.sub.Subscriptions;
import com.rometools.certiorem.sub.data.Subscription;
import com.rometools.certiorem.sub.data.SubscriptionCallback;
import com.rometools.fetcher.impl.SyndFeedInfo;
/**
*
* @author robert.cooper
*/
@Singleton
public class SubTest extends HttpServlet {
private static final Logger LOG = LoggerFactory.getLogger(SubTest.class);
private static final long serialVersionUID = 1L;
private final Subscriptions subs;
@Inject
public SubTest(final Subscriptions subs) {
this.subs = subs;
}
@Override
public void doGet(final HttpServletRequest request, final HttpServletResponse response) {
subs.subscribe("http://localhost/webapp/hub", "http://localhost/webapp/research-atom.xml", true, -1L, null, new SubscriptionCallback() {
@Override
public void onFailure(final Exception e) {
e.printStackTrace();
}
@Override
public void onSubscribe(final Subscription subscribed) {
LOG.debug("Subscribed {} {}", subscribed.getId(), subscribed.getSourceUrl());
}
@Override
public void onNotify(final Subscription subscribed, final SyndFeedInfo feedInfo) {
// TODO Auto-generated method stub
}
@Override
public void onUnsubscribe(final Subscription subscribed) {
// TODO Auto-generated method stub
}
});
}
}

View file

@ -0,0 +1 @@
# needed to commit empty folder

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
<sun-web-app error-url="">
<context-root>/webapp</context-root>
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</sun-web-app>

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>rome-certiorem-webapp</display-name>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<display-name>Guice config</display-name>
<listener-class>com.rometools.certiorem.example.ServerModule</listener-class>
</listener>
</web-app>

View file

@ -0,0 +1,13 @@
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>

View file

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8" ?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#"
xmlns:g="http://base.google.com/ns/1.0">
<title>The name of your feed</title>
<link href="The URL to the HTML website"
rel="alternate" type="text/html"/>
<modified>2003-12-13T18:30:02Z</modified>
<author>
<name>The name of the author</name>
</author>
<entry>
<title>Analysis of tsunami on the economy</title>
<summary>Analysis of the recent tsumani on the economy</summary>
<link rel="alternate" type="text/html"
href="http://provider-website.com/item1-info-page.html"/>
<id>tag:providers-website-item1.com,2003:3.2397</id>
<issued>2003-12-13T08:29:29-04:00</issued>
<modified>2003-12-13T18:30:02Z</modified>
<g:image_link>http://www.providers-website.com/image1.jpg</g:image_link>
<g:expiration_date>2005-12-20</g:expiration_date>
<g:label>Economy</g:label>
<g:label>Tsunami</g:label>
<g:publish_date>2005-02-25</g:publish_date>
<g:author>James Smith</g:author>
<g:publication_name>Tsunami and the Economy</g:publication_name>
<g:publication_volume>III</g:publication_volume>
<g:pages>5</g:pages>
</entry>
<entry>
<title>Google and the internet</title>
<summary>Analysis of Google's impact on the internet</summary>
<link rel="alternate" type="text/html"
href="http://provider-website.com/item2-info-page.html"/>
<id>tag:providers-website-item1.com,2003:3.2397</id>
<issued>2003-12-13T08:29:29-04:00</issued>
<modified>2003-12-13T18:30:02Z</modified>
<g:image_link>http://www.providers-website.com/image2.jpg</g:image_link>
<g:expiration_date>2005-12-20</g:expiration_date>
<g:label>Internet</g:label>
<g:label>Search Engine</g:label>
<g:publish_date>2004-01-29</g:publish_date>
<g:author>Sue Smith</g:author>
<g:publication_name>Google and the Internet</g:publication_name>
<g:publication_volume>VI</g:publication_volume>
<g:pages>23</g:pages>
</entry>
</feed>

View file

@ -0,0 +1 @@
# needed to commit empty folder

View file

@ -0,0 +1 @@
# needed to commit empty folder

4
rome-certiorem/.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
/.classpath
/.project
/.settings
/target

202
rome-certiorem/LICENSE Normal file
View file

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

9
rome-certiorem/README Normal file
View file

@ -0,0 +1,9 @@
ROME Certiorem
Build Instructions
-------------------------------------------------------------------------------
To build with Maven 2+:
> mvn package

111
rome-certiorem/pom.xml Normal file
View file

@ -0,0 +1,111 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.rometools</groupId>
<artifactId>rome-parent</artifactId>
<version>1.6.0-SNAPSHOT</version>
</parent>
<artifactId>rome-certiorem</artifactId>
<version>1.6.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>rome-certiorem</name>
<description>A PubSubHubub implementation for Java based on ROME</description>
<scm>
<connection>scm:git:ssh://github.com/rometools/rome-certiorem.git</connection>
<developerConnection>scm:git:ssh://git@github.com/rometools/rome-certiorem.git</developerConnection>
<url>https://github.com/rometools/rome-certiorem</url>
</scm>
<developers>
<developer>
<name>Robert Cooper</name>
<email>kebernet@gmail.comM</email>
<url>http://www.kebernet.net</url>
</developer>
<developer>
<name>Farrukh Najmi</name>
<url>http://wellfleetsoftware.com</url>
</developer>
</developers>
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<configuration>
<port>9000</port>
<tempWebappDirectory>${basedir}/target/site/tempdir</tempWebappDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-publish-plugin</artifactId>
<configuration>
<scmBranch>gh-pages</scmBranch>
<pubScmUrl>${project.scm.developerConnection}</pubScmUrl>
<content>${project.build.directory}/site</content>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome-fetcher</artifactId>
<version>1.6.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>commons-httpclient</artifactId>
<groupId>commons-httpclient</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,40 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem;
/**
*
* @author robert.cooper
*/
public class HttpStatusCodeException extends RuntimeException {
private static final long serialVersionUID = 1L;
private final int status;
public HttpStatusCodeException(final int status, final String message, final Throwable cause) {
super(message, cause);
this.status = status;
}
public int getStatus() {
return status;
}
}

View file

@ -0,0 +1,51 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rometools.certiorem.hub;
import java.net.URL;
import com.rometools.fetcher.impl.FeedFetcherCache;
import com.rometools.fetcher.impl.SyndFeedInfo;
/**
* Wrapper FeedFetcherCache that wraps a backing FeedFetcherCache and makes sure that any
* SyndFeedInfo used within it are replaced with a DeltaSyndFeedInfo which is capable of tracking
* changes to entries in the underlying feed.
*
* @author najmi
*/
public class DeltaFeedInfoCache implements FeedFetcherCache {
FeedFetcherCache backingCache;
public DeltaFeedInfoCache(final FeedFetcherCache backingCache) {
this.backingCache = backingCache;
}
@Override
public SyndFeedInfo getFeedInfo(final URL feedUrl) {
return backingCache.getFeedInfo(feedUrl);
}
@Override
public void setFeedInfo(final URL feedUrl, SyndFeedInfo syndFeedInfo) {
// Make sure that syndFeedInfo is an instance of DeltaSyndFeedInfo
if (!(syndFeedInfo instanceof DeltaSyndFeedInfo)) {
syndFeedInfo = new DeltaSyndFeedInfo(syndFeedInfo);
}
backingCache.setFeedInfo(feedUrl, syndFeedInfo);
}
@Override
public void clear() {
backingCache.clear();
}
@Override
public SyndFeedInfo remove(final URL feedUrl) {
return backingCache.remove(feedUrl);
}
}

View file

@ -0,0 +1,133 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rometools.certiorem.hub;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.rometools.fetcher.impl.SyndFeedInfo;
import com.rometools.rome.feed.synd.SyndEntry;
import com.rometools.rome.feed.synd.SyndFeed;
/**
* Extends SyndFeedInfo to also track etags for individual entries. This may be used with
* DeltaFeedInfoCache to only return feed with a subset of entries that have changed since last
* fetch.
*
* @author najmi
*/
public class DeltaSyndFeedInfo extends SyndFeedInfo {
/**
*
*/
private static final long serialVersionUID = 1L;
Map<String, String> entryTagsMap = new HashMap<String, String>();
Map<String, Boolean> changedMap = new HashMap<String, Boolean>();
public DeltaSyndFeedInfo(final SyndFeedInfo backingFeedInfo) {
setETag(backingFeedInfo.getETag());
setId(backingFeedInfo.getId());
setLastModified(backingFeedInfo.getLastModified());
setSyndFeed(backingFeedInfo.getSyndFeed());
}
/**
* Gets a filtered version of the SyndFeed that only has entries that were changed in the last
* setSyndFeed() call.
*
* @return
*/
@Override
public synchronized SyndFeed getSyndFeed() {
try {
final SyndFeed feed = (SyndFeed) super.getSyndFeed().clone();
final List<SyndEntry> changedEntries = new ArrayList<SyndEntry>();
final List<SyndEntry> entries = feed.getEntries();
for (final SyndEntry entry : entries) {
if (changedMap.containsKey(entry.getUri())) {
changedEntries.add(entry);
}
}
feed.setEntries(changedEntries);
return feed;
} catch (final CloneNotSupportedException ex) {
throw new RuntimeException(ex);
}
}
/**
* Overrides super class method to update changedMap and entryTagsMap for tracking changed
* entries.
*
* @param feed
*/
@Override
public final synchronized void setSyndFeed(final SyndFeed feed) {
super.setSyndFeed(feed);
changedMap.clear();
final List<SyndEntry> entries = feed.getEntries();
for (final SyndEntry entry : entries) {
final String currentEntryTag = computeEntryTag(entry);
final String previousEntryTag = entryTagsMap.get(entry.getUri());
if (previousEntryTag == null || !currentEntryTag.equals(previousEntryTag)) {
// Entry has changed
changedMap.put(entry.getUri(), Boolean.TRUE);
}
entryTagsMap.put(entry.getUri(), currentEntryTag);
}
}
private String computeEntryTag(final SyndEntry entry) {
// Following hash algorithm suggested by Robert Cooper needs to be
// evaluated in future.
// int hash = ( entry.getUri() != null ? entry.getUri().hashCode() :
// entry.getLink().hashCode() ) ^
// (entry.getUpdatedDate() != null ? entry.getUpdatedDate().hashCode() :
// entry.getPublishedDate().hashCode()) ^
// entry.getTitle().hashCode() ^
// entry.getDescription().hashCode();
final String id = entry.getUri();
Date updateDate = entry.getUpdatedDate();
final Date publishedDate = entry.getPublishedDate();
if (updateDate == null) {
if (publishedDate != null) {
updateDate = publishedDate;
} else {
// For misbehaving feeds that do not set updateDate or
// publishedDate we use current tiem which pretty mucg assures
// that it will be viewed as
// changed even when it is not
updateDate = new Date();
}
}
final String key = id + ":" + entry.getUpdatedDate();
return computeDigest(key);
}
private String computeDigest(final String content) {
try {
final MessageDigest md = MessageDigest.getInstance("SHA");
final byte[] digest = md.digest(content.getBytes());
final BigInteger bi = new BigInteger(digest);
return bi.toString(16);
} catch (final Exception e) {
return "";
}
}
}

View file

@ -0,0 +1,259 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rometools.certiorem.HttpStatusCodeException;
import com.rometools.certiorem.hub.Notifier.SubscriptionSummaryCallback;
import com.rometools.certiorem.hub.Verifier.VerificationCallback;
import com.rometools.certiorem.hub.data.HubDAO;
import com.rometools.certiorem.hub.data.Subscriber;
import com.rometools.certiorem.hub.data.SubscriptionSummary;
import com.rometools.fetcher.FeedFetcher;
import com.rometools.rome.feed.synd.SyndFeed;
/**
* The basic business logic controller for the Hub implementation. It is intended to be usable under
* a very thin servlet wrapper, or other, non-HTTP notification methods you might want to use.
*
* @author robert.cooper
*/
public class Hub {
private static final Logger LOG = LoggerFactory.getLogger(Hub.class);
private static final HashSet<String> STANDARD_SCHEMES = new HashSet<String>();
static {
STANDARD_SCHEMES.add("http");
STANDARD_SCHEMES.add("https");
}
private final FeedFetcher fetcher;
private final HubDAO dao;
private final Notifier notifier;
private final Set<Integer> validPorts;
private final Set<String> validSchemes;
private final Set<String> validTopics;
private final Verifier verifier;
/**
* Constructs a new Hub instance
*
* @param dao The persistence HubDAO to use
* @param verifier The verification strategy to use.
*/
public Hub(final HubDAO dao, final Verifier verifier, final Notifier notifier, final FeedFetcher fetcher) {
this.dao = dao;
this.verifier = verifier;
this.notifier = notifier;
this.fetcher = fetcher;
validSchemes = STANDARD_SCHEMES;
validPorts = Collections.emptySet();
validTopics = Collections.emptySet();
}
/**
* Constructs a new Hub instance.
*
* @param dao The persistence HubDAO to use
* @param verifier The verification strategy to use
* @param validSchemes A list of valid URI schemes for callbacks (default: http, https)
* @param validPorts A list of valid port numbers for callbacks (default: any)
* @param validTopics A set of valid topic URIs which can be subscribed to (default: any)
*/
public Hub(final HubDAO dao, final Verifier verifier, final Notifier notifier, final FeedFetcher fetcher, final Set<String> validSchemes,
final Set<Integer> validPorts, final Set<String> validTopics) {
this.dao = dao;
this.verifier = verifier;
this.notifier = notifier;
this.fetcher = fetcher;
final Set<String> readOnlySchemes = Collections.unmodifiableSet(validSchemes);
this.validSchemes = readOnlySchemes == null ? STANDARD_SCHEMES : readOnlySchemes;
final Set<Integer> readOnlyPorts = Collections.unmodifiableSet(validPorts);
if (readOnlyPorts == null) {
this.validPorts = Collections.emptySet();
} else {
this.validPorts = readOnlyPorts;
}
final Set<String> readOnlyTopics = Collections.unmodifiableSet(validTopics);
if (validTopics == null) {
this.validTopics = Collections.emptySet();
} else {
this.validTopics = readOnlyTopics;
}
}
/**
* Sends a notification to the subscribers
*
* @param requestHost the host name the hub is running on. (Used for the user agent)
* @param topic the URL of the topic that was updated.
* @throws HttpStatusCodeException a wrapper exception with a recommended status code for the
* request.
*/
public void sendNotification(final String requestHost, final String topic) {
// FIXME assert should not be used for validation because it can be disabled
assert validTopics.isEmpty() || validTopics.contains(topic) : "That topic is not supported by this hub. " + topic;
LOG.debug("Sending notification for {}", topic);
try {
final List<? extends Subscriber> subscribers = dao.subscribersForTopic(topic);
if (subscribers.isEmpty()) {
LOG.debug("No subscribers to notify for {}", topic);
return;
}
final List<? extends SubscriptionSummary> summaries = dao.summariesForTopic(topic);
int total = 0;
final StringBuilder hosts = new StringBuilder();
for (final SubscriptionSummary s : summaries) {
if (s.getSubscribers() > 0) {
total += s.getSubscribers();
hosts.append(" (").append(s.getHost()).append("; ").append(s.getSubscribers()).append(" subscribers)");
}
}
final StringBuilder userAgent = new StringBuilder("ROME-Certiorem (+http://").append(requestHost).append("; ").append(total)
.append(" subscribers)").append(hosts);
final SyndFeed feed = fetcher.retrieveFeed(userAgent.toString(), new URL(topic));
LOG.debug("Got feed for {} Sending to {} subscribers.", topic, subscribers.size());
notifier.notifySubscribers(subscribers, feed, new SubscriptionSummaryCallback() {
@Override
public void onSummaryInfo(final SubscriptionSummary summary) {
dao.handleSummary(topic, summary);
}
});
} catch (final Exception ex) {
LOG.debug("Exception getting " + topic, ex);
throw new HttpStatusCodeException(500, ex.getMessage(), ex);
}
}
/**
* Subscribes to a topic.
*
* @param callback Callback URI
* @param topic Topic URI
* @param verify Verification Type
* @param lease_seconds Duration of the lease
* @param secret Secret value
* @param verify_token verify_token;
* @return Boolean.TRUE if the subscription succeeded synchronously, Boolean.FALSE if the
* subscription failed synchronously, or null if the request is asynchronous.
* @throws HttpStatusCodeException a wrapper exception with a recommended status code for the
* request.
*/
public Boolean subscribe(final String callback, final String topic, final String verify, final long lease_seconds, final String secret,
final String verify_token) {
LOG.debug("{} wants to subscribe to {}", callback, topic);
try {
try {
// FIXME assert should not be used for validation because it can be disabled
assert callback != null : "Callback URL is required.";
assert topic != null : "Topic URL is required.";
final URI uri = new URI(callback);
assert validSchemes.contains(uri.getScheme()) : "Not a valid protocol " + uri.getScheme();
assert validPorts.isEmpty() || validPorts.contains(uri.getPort()) : "Not a valid port " + uri.getPort();
assert validTopics.isEmpty() || validTopics.contains(topic) : "Not a supported topic " + topic;
} catch (final URISyntaxException ex) {
assert false : "Not a valid URI " + callback;
}
assert verify != null && (verify.equals(Subscriber.VERIFY_ASYNC) || verify.equals(Subscriber.VERIFY_SYNC)) : "Unexpected verify value " + verify;
final Subscriber subscriber = new Subscriber();
subscriber.setCallback(callback);
subscriber.setLeaseSeconds(lease_seconds);
subscriber.setSecret(secret);
subscriber.setTopic(topic);
subscriber.setVerify(verify);
subscriber.setVertifyToken(verify_token);
final VerificationCallback verified = new VerificationCallback() {
@Override
public void onVerify(final boolean verified) {
if (verified) {
LOG.debug("Verified {} subscribed to {}", subscriber.getCallback(), subscriber.getTopic());
dao.addSubscriber(subscriber);
}
}
};
if (Subscriber.VERIFY_SYNC.equals(subscriber.getVerify())) {
final boolean result = verifier.verifySubcribeSyncronously(subscriber);
verified.onVerify(result);
return result;
} else {
verifier.verifySubscribeAsyncronously(subscriber, verified);
return null;
}
} catch (final AssertionError ae) {
throw new HttpStatusCodeException(400, ae.getMessage(), ae);
} catch (final Exception e) {
throw new HttpStatusCodeException(500, e.getMessage(), e);
}
}
public Boolean unsubscribe(final String callback, final String topic, final String verify, final String secret, final String verifyToken) {
final Subscriber subscriber = dao.findSubscriber(topic, callback);
if (subscriber == null) {
throw new HttpStatusCodeException(400, "Not a valid subscription.", null);
}
subscriber.setVertifyToken(verifyToken);
subscriber.setSecret(secret);
if (Subscriber.VERIFY_SYNC.equals(verify)) {
final boolean ret = verifier.verifyUnsubcribeSyncronously(subscriber);
if (ret) {
dao.removeSubscriber(topic, callback);
}
} else {
verifier.verifyUnsubscribeAsyncronously(subscriber, new VerificationCallback() {
@Override
public void onVerify(final boolean verified) {
LOG.debug("Unsubscribe for {} at {} verified {}", subscriber.getTopic(), subscriber.getCallback(), verified);
if (verified) {
dao.removeSubscriber(topic, callback);
}
}
});
}
return null;
}
}

View file

@ -0,0 +1,51 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub;
import java.util.List;
import com.rometools.certiorem.hub.data.Subscriber;
import com.rometools.certiorem.hub.data.SubscriptionSummary;
import com.rometools.rome.feed.synd.SyndFeed;
/**
*
* @author robert.cooper
*/
public interface Notifier {
/**
* Instructs the notifier to begin sending notifications to the list of subscribers
*
* @param subscribers Subscribers to notify
* @param value The SyndFeed to send them
* @param callback A callback that is invoked each time a subscriber is notified.
*/
public void notifySubscribers(List<? extends Subscriber> subscribers, SyndFeed value, SubscriptionSummaryCallback callback);
/**
* A callback that is invoked each time a subscriber is notified.
*/
public static interface SubscriptionSummaryCallback {
/**
*
* @param summary A summary of the data received from the subscriber
*/
public void onSummaryInfo(SubscriptionSummary summary);
}
}

View file

@ -0,0 +1,81 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub;
import com.rometools.certiorem.hub.data.Subscriber;
/**
* A strategy interface for verification of subscriptions.
*
* @author robert.cooper
*/
public interface Verifier {
/**
* Value for hub.mode = subscribe
*/
public static final String MODE_SUBSCRIBE = "subscribe";
/**
* Value for hub.mode = unsubscribe
*/
public static final String MODE_UNSUBSCRIBE = "unsubscribe";
/**
* Verifies a subscriber (possibly) asyncronously
*
* @param subscriber the Subscriber to verify
* @param callback a callback with the result of the verification.
*/
public void verifySubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback);
/**
* Verifies a subscriber syncronously
*
* @param subscriber The subscriber data
* @return boolean result;
*/
public boolean verifySubcribeSyncronously(Subscriber subscriber);
/**
* Verifies am unsubscribe (possibly) asyncronously
*
* @param subscriber The subscriber data
* @param callback result
*/
public void verifyUnsubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback);
/**
* Verifies an unsubscribe syncronously
*
* @param subscriber The subscriber data
* @return boolean result;
*/
public boolean verifyUnsubcribeSyncronously(Subscriber subscriber);
/**
* An interface for capturing the result of a verification (subscribe or unsubscribe)
*/
public static interface VerificationCallback {
/**
*
* @param verified success state of the verification
*/
public void onVerify(boolean verified);
}
}

View file

@ -0,0 +1,41 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub.data;
import java.util.List;
/**
*
* @author robert.cooper
*/
public interface HubDAO {
public List<? extends Subscriber> subscribersForTopic(String topic);
public Subscriber addSubscriber(Subscriber subscriber);
public Subscriber findSubscriber(String topic, String callbackUrl);
public void removeSubscriber(String topic, String callback);
public void handleSummary(String topic, SubscriptionSummary summary);
public List<? extends SubscriptionSummary> summariesForTopic(String topic);
}

View file

@ -0,0 +1,224 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub.data;
import java.io.Serializable;
/**
*
* @author robert.cooper
*/
public class Subscriber implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
public static final String VERIFY_SYNC = "sync";
public static final String VERIFY_ASYNC = "async";
private String callback;
private String secret;
private String topic;
private String verify;
private String vertifyToken;
private long creationTime = System.currentTimeMillis();
private long leaseSeconds;
/**
* Set the value of callback
*
* @param newcallback new value of callback
*/
public void setCallback(final String newcallback) {
callback = newcallback;
}
/**
* Get the value of callback
*
* @return the value of callback
*/
public String getCallback() {
return callback;
}
/**
* Set the value of creationTime
*
* @param newcreationTime new value of creationTime
*/
public void setCreationTime(final long newcreationTime) {
creationTime = newcreationTime;
}
/**
* Get the value of creationTime
*
* @return the value of creationTime
*/
public long getCreationTime() {
return creationTime;
}
/**
* Set the value of leaseSeconds
*
* @param newleaseSeconds new value of leaseSeconds
*/
public void setLeaseSeconds(final long newleaseSeconds) {
leaseSeconds = newleaseSeconds;
}
/**
* Get the value of leaseSeconds
*
* @return the value of leaseSeconds
*/
public long getLeaseSeconds() {
return leaseSeconds;
}
/**
* Set the value of secret
*
* @param newsecret new value of secret
*/
public void setSecret(final String newsecret) {
secret = newsecret;
}
/**
* Get the value of secret
*
* @return the value of secret
*/
public String getSecret() {
return secret;
}
/**
* Set the value of topic
*
* @param newtopic new value of topic
*/
public void setTopic(final String newtopic) {
topic = newtopic;
}
/**
* Get the value of topic
*
* @return the value of topic
*/
public String getTopic() {
return topic;
}
/**
* Set the value of verify
*
* @param newverify new value of verify
*/
public void setVerify(final String newverify) {
verify = newverify;
}
/**
* Get the value of verify
*
* @return the value of verify
*/
public String getVerify() {
return verify;
}
/**
* Set the value of vertifyToken
*
* @param newvertifyToken new value of vertifyToken
*/
public void setVertifyToken(final String newvertifyToken) {
vertifyToken = newvertifyToken;
}
/**
* Get the value of vertifyToken
*
* @return the value of vertifyToken
*/
public String getVertifyToken() {
return vertifyToken;
}
@Override
public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof Subscriber)) {
return false;
}
final Subscriber other = (Subscriber) obj;
if (callback == null ? other.callback != null : !callback.equals(other.callback)) {
return false;
}
if (secret == null ? other.secret != null : !secret.equals(other.secret)) {
return false;
}
if (topic == null ? other.topic != null : !topic.equals(other.topic)) {
return false;
}
if (verify == null ? other.verify != null : !verify.equals(other.verify)) {
return false;
}
if (vertifyToken == null ? other.vertifyToken != null : !vertifyToken.equals(other.vertifyToken)) {
return false;
}
if (creationTime != other.creationTime) {
return false;
}
if (leaseSeconds != other.leaseSeconds) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 7;
hash = 67 * hash + (callback != null ? callback.hashCode() : 0);
hash = 67 * hash + (secret != null ? secret.hashCode() : 0);
hash = 67 * hash + (topic != null ? topic.hashCode() : 0);
hash = 67 * hash + (verify != null ? verify.hashCode() : 0);
hash = 67 * hash + (vertifyToken != null ? vertifyToken.hashCode() : 0);
hash = 67 * hash + (int) (creationTime ^ creationTime >>> 32);
hash = 67 * hash + (int) (leaseSeconds ^ leaseSeconds >>> 32);
return hash;
}
}

View file

@ -0,0 +1,89 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub.data;
import java.io.Serializable;
/**
*
* @author robert.cooper
*/
public class SubscriptionSummary implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String host;
private boolean lastPublishSuccessful = true;
private int subscribers = 0;
/**
* Set the value of host
*
* @param newhost new value of host
*/
public void setHost(final String newhost) {
host = newhost;
}
/**
* Get the value of host
*
* @return the value of host
*/
public String getHost() {
return host;
}
/**
* Set the value of lastPublishSuccessful
*
* @param newlastPublishSuccessful new value of lastPublishSuccessful
*/
public void setLastPublishSuccessful(final boolean newlastPublishSuccessful) {
lastPublishSuccessful = newlastPublishSuccessful;
}
/**
* Get the value of lastPublishSuccessful
*
* @return the value of lastPublishSuccessful
*/
public boolean isLastPublishSuccessful() {
return lastPublishSuccessful;
}
/**
* Set the value of subscribers
*
* @param newsubscribers new value of subscribers
*/
public void setSubscribers(final int newsubscribers) {
subscribers = newsubscribers;
}
/**
* Get the value of subscribers
*
* @return the value of subscribers
*/
public int getSubscribers() {
return subscribers;
}
}

View file

@ -0,0 +1,131 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub.data.jpa;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import com.rometools.certiorem.hub.data.HubDAO;
import com.rometools.certiorem.hub.data.Subscriber;
import com.rometools.certiorem.hub.data.SubscriptionSummary;
/**
*
* @author robert.cooper
*/
public class JPADAO implements HubDAO {
private final EntityManagerFactory factory;
private final boolean purgeExpired;
public JPADAO(final EntityManagerFactory factory, final boolean purgeExpired) {
this.factory = factory;
this.purgeExpired = purgeExpired;
}
@Override
public List<? extends Subscriber> subscribersForTopic(final String topic) {
final LinkedList<JPASubscriber> result = new LinkedList<JPASubscriber>();
final EntityManager em = factory.createEntityManager();
final EntityTransaction tx = em.getTransaction();
tx.begin();
final Query query = em.createNamedQuery("Subcriber.forTopic");
query.setParameter("topic", topic);
try {
@SuppressWarnings("unchecked")
final List<JPASubscriber> subscribers = query.getResultList();
for (final JPASubscriber subscriber : subscribers) {
if (subscriber.getLeaseSeconds() == -1) {
result.add(subscriber);
continue;
}
if (subscriber.getSubscribedAt().getTime() < System.currentTimeMillis() - 1000 * subscriber.getLeaseSeconds()) {
subscriber.setExpired(true);
} else {
result.add(subscriber);
}
if (subscriber.isExpired() && purgeExpired) {
em.remove(subscriber);
}
}
} catch (final NoResultException e) {
tx.rollback();
em.close();
return result;
}
if (!tx.getRollbackOnly()) {
tx.commit();
} else {
tx.rollback();
}
em.close();
return result;
}
@Override
public Subscriber addSubscriber(final Subscriber subscriber) {
// FIXME assert should not be used for validation because it can be disabled
assert subscriber != null : "Attempt to store a null subscriber";
final EntityManager em = factory.createEntityManager();
final EntityTransaction tx = em.getTransaction();
tx.begin();
final JPASubscriber data = new JPASubscriber();
data.copyFrom(subscriber);
data.setId(UUID.randomUUID().toString());
em.persist(data);
tx.commit();
em.close();
return data;
}
@Override
public Subscriber findSubscriber(final String topic, final String callbackUrl) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void handleSummary(final String topic, final SubscriptionSummary summary) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public List<? extends SubscriptionSummary> summariesForTopic(final String topic) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void removeSubscriber(final String topic, final String callback) {
throw new UnsupportedOperationException("Not supported yet.");
}
}

View file

@ -0,0 +1,111 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub.data.jpa;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import com.rometools.certiorem.hub.data.Subscriber;
/**
*
* @author robert.cooper
*/
@Entity
@NamedQueries({ @NamedQuery(name = "Subcriber.forTopic", query = "SELECT o FROM JPASubscriber o WHERE o.topic = :topic AND o.expired = false ORDER BY o.subscribedAt") })
public class JPASubscriber extends Subscriber implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private Date subscribedAt = new Date();
private String id;
private boolean expired = false;
/**
* Set the value of expired
*
* @param newexpired new value of expired
*/
public void setExpired(final boolean newexpired) {
expired = newexpired;
}
/**
* Get the value of expired
*
* @return the value of expired
*/
public boolean isExpired() {
return expired;
}
/**
* Set the value of id
*
* @param newid new value of id
*/
public void setId(final String newid) {
id = newid;
}
/**
* Get the value of id
*
* @return the value of id
*/
@Id
public String getId() {
return id;
}
/**
* Set the value of subscribedAt
*
* @param newsubscribedAt new value of subscribedAt
*/
public void setSubscribedAt(final Date newsubscribedAt) {
subscribedAt = newsubscribedAt;
}
/**
* Get the value of subscribedAt
*
* @return the value of subscribedAt
*/
@Temporal(TemporalType.TIMESTAMP)
public Date getSubscribedAt() {
return subscribedAt;
}
public void copyFrom(final Subscriber source) {
setLeaseSeconds(source.getLeaseSeconds());
setSecret(source.getSecret());
setTopic(source.getTopic());
setVerify(source.getVerify());
setVertifyToken(source.getVertifyToken());
}
}

View file

@ -0,0 +1,28 @@
<!--
Copyright (C) The ROME Team 2011
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<title>jpa</title>
</head>
<body>
A stock data implementation based on the Java Persistence API.
</body>
</html>

View file

@ -0,0 +1,29 @@
<!--
Copyright (C) The ROME Team 2011
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<title>data</title>
</head>
<body>
This package defines the basic data types and persistence mechanisms
that are required for a hub implementation.
</body>
</html>

View file

@ -0,0 +1,136 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub.data.ram;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import com.rometools.certiorem.hub.data.HubDAO;
import com.rometools.certiorem.hub.data.Subscriber;
import com.rometools.certiorem.hub.data.SubscriptionSummary;
/**
* A Simple In-Memory HubDAO for subscribers.
*
* @author robert.cooper
*/
public class InMemoryHubDAO implements HubDAO {
private final ConcurrentHashMap<String, List<Subscriber>> subscribers = new ConcurrentHashMap<String, List<Subscriber>>();
private final ConcurrentHashMap<String, ConcurrentHashMap<String, SubscriptionSummary>> summaries = new ConcurrentHashMap<String, ConcurrentHashMap<String, SubscriptionSummary>>();
@Override
public Subscriber addSubscriber(final Subscriber subscriber) {
// FIXME assert should not be used for validation because it can be disabled
assert subscriber != null : "Attempt to store a null subscriber";
List<Subscriber> subList = subscribers.get(subscriber.getTopic());
if (subList == null) {
synchronized (this) {
subList = new CopyOnWriteArrayList<Subscriber>();
subscribers.put(subscriber.getTopic(), subList);
}
}
subList.add(subscriber);
return subscriber;
}
@Override
public void handleSummary(final String topic, final SubscriptionSummary summary) {
ConcurrentHashMap<String, SubscriptionSummary> hostsToSummaries = summaries.get(topic);
if (hostsToSummaries == null) {
synchronized (this) {
hostsToSummaries = new ConcurrentHashMap<String, SubscriptionSummary>();
summaries.put(topic, hostsToSummaries);
}
}
hostsToSummaries.put(summary.getHost(), summary);
}
@Override
public List<? extends Subscriber> subscribersForTopic(final String topic) {
if (subscribers.containsKey(topic)) {
final List<Subscriber> result = new LinkedList<Subscriber>();
final LinkedList<Subscriber> expired = new LinkedList<Subscriber>();
for (final Subscriber s : subscribers.get(topic)) {
if (s.getLeaseSeconds() > 0 && System.currentTimeMillis() >= s.getCreationTime() + s.getLeaseSeconds() * 1000L) {
expired.add(s);
} else {
result.add(s);
}
}
if (!expired.isEmpty()) {
subscribers.get(topic).removeAll(expired);
}
return result;
} else {
return Collections.emptyList();
}
}
@Override
public List<? extends SubscriptionSummary> summariesForTopic(final String topic) {
final LinkedList<SubscriptionSummary> result = new LinkedList<SubscriptionSummary>();
if (summaries.containsKey(topic)) {
result.addAll(summaries.get(topic).values());
}
return result;
}
@Override
public Subscriber findSubscriber(final String topic, final String callbackUrl) {
for (final Subscriber s : subscribersForTopic(topic)) {
if (callbackUrl.equals(s.getCallback())) {
return s;
}
}
return null;
}
@Override
public void removeSubscriber(final String topic, final String callback) {
final List<Subscriber> subs = subscribers.get(topic);
if (subs == null) {
return;
}
Subscriber match = null;
for (final Subscriber s : subs) {
if (s.getCallback().equals(callback)) {
match = s;
break;
}
}
if (match != null) {
subs.remove(match);
}
}
}

View file

@ -0,0 +1,25 @@
<!--
Copyright (C) The ROME Team 2011
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<body>
Contains a Memory-Resident implemtnation of the Hub DAO.
</body>
</html>

View file

@ -0,0 +1,162 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub.notify.standard;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rometools.certiorem.hub.Notifier;
import com.rometools.certiorem.hub.data.Subscriber;
import com.rometools.certiorem.hub.data.SubscriptionSummary;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.SyndFeedOutput;
/**
*
* @author robert.cooper
*/
public abstract class AbstractNotifier implements Notifier {
private static final Logger LOG = LoggerFactory.getLogger(AbstractNotifier.class);
/**
* This method will serialize the synd feed and build Notifications for the implementation class
* to handle.
*
* @see enqueueNotification
*
* @param subscribers List of subscribers to notify
* @param value The SyndFeed object to send
* @param callback A callback that will be invoked each time a subscriber is notified.
*
*/
@Override
public void notifySubscribers(final List<? extends Subscriber> subscribers, final SyndFeed value, final SubscriptionSummaryCallback callback) {
String mimeType = null;
if (value.getFeedType().startsWith("rss")) {
mimeType = "application/rss+xml";
} else {
mimeType = "application/atom+xml";
}
final SyndFeedOutput output = new SyndFeedOutput();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
output.output(value, new OutputStreamWriter(baos));
baos.close();
} catch (final IOException ex) {
LOG.error("Unable to output the feed", ex);
throw new RuntimeException("Unable to output the feed.", ex);
} catch (final FeedException ex) {
LOG.error("Unable to output the feed", ex);
throw new RuntimeException("Unable to output the feed.", ex);
}
final byte[] payload = baos.toByteArray();
for (final Subscriber s : subscribers) {
final Notification not = new Notification();
not.callback = callback;
not.lastRun = 0;
not.mimeType = mimeType;
not.payload = payload;
not.retryCount = 0;
not.subscriber = s;
enqueueNotification(not);
}
}
/**
* Implementation method that queues/sends a notification
*
* @param not notification to send.
*/
protected abstract void enqueueNotification(Notification not);
/**
* POSTs the payload to the subscriber's callback and returns a SubscriptionSummary with
* subscriber counts (where possible) and the success state of the notification.
*
* @param subscriber subscriber data.
* @param mimeType MIME type for the request
* @param payload payload of the feed to send
* @return SubscriptionSummary with the returned data.
*/
protected SubscriptionSummary postNotification(final Subscriber subscriber, final String mimeType, final byte[] payload) {
final SubscriptionSummary result = new SubscriptionSummary();
try {
final URL target = new URL(subscriber.getCallback());
LOG.info("Posting notification to subscriber {}", subscriber.getCallback());
result.setHost(target.getHost());
final HttpURLConnection connection = (HttpURLConnection) target.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", mimeType);
connection.setDoOutput(true);
connection.connect();
final OutputStream os = connection.getOutputStream();
os.write(payload);
os.close();
final int responseCode = connection.getResponseCode();
final String subscribers = connection.getHeaderField("X-Hub-On-Behalf-Of");
connection.disconnect();
if (responseCode != 200) {
LOG.warn("Got code {} from {}", responseCode, target);
result.setLastPublishSuccessful(false);
return result;
}
if (subscribers != null) {
try {
result.setSubscribers(Integer.parseInt(subscribers));
} catch (final NumberFormatException nfe) {
LOG.warn("Invalid subscriber value " + subscribers + " " + target, nfe);
result.setSubscribers(-1);
}
} else {
result.setSubscribers(-1);
}
} catch (final MalformedURLException ex) {
LOG.warn(null, ex);
result.setLastPublishSuccessful(false);
} catch (final IOException ex) {
LOG.error(null, ex);
result.setLastPublishSuccessful(false);
}
return result;
}
}

View file

@ -0,0 +1,37 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub.notify.standard;
import com.rometools.certiorem.hub.Notifier.SubscriptionSummaryCallback;
import com.rometools.certiorem.hub.data.Subscriber;
/**
*
* @author robert.cooper
*/
public class Notification {
int retryCount = 0;
long lastRun = 0;
Subscriber subscriber;
String mimeType;
byte[] payload;
SubscriptionSummaryCallback callback;
}

View file

@ -0,0 +1,112 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub.notify.standard;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import com.rometools.certiorem.hub.data.SubscriptionSummary;
/**
* A notifier implementation that uses a thread pool to deliver notifications to subscribers
*
* @author robert.cooper
*/
public class ThreadPoolNotifier extends AbstractNotifier {
private static final long TWO_MINUTES = 2 * 60 * 1000;
protected final ThreadPoolExecutor exeuctor;
private final Timer timer = new Timer();
private final ConcurrentSkipListSet<String> pendings = new ConcurrentSkipListSet<String>();
public ThreadPoolNotifier() {
this(2, 5, 5);
}
public ThreadPoolNotifier(final int startPoolSize, final int maxPoolSize, final int queueSize) {
exeuctor = new ThreadPoolExecutor(startPoolSize, maxPoolSize, 300, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(queueSize));
}
protected ThreadPoolNotifier(final ThreadPoolExecutor executor) {
exeuctor = executor;
}
/**
* Enqueues a notification to run. If the notification fails, it will be retried every two
* minutes until 5 attempts are completed. Notifications to the same callback should be
* delivered successfully in order.
*
* @param not
*/
@Override
protected void enqueueNotification(final Notification not) {
final Runnable r = new Runnable() {
@Override
public void run() {
not.lastRun = System.currentTimeMillis();
final SubscriptionSummary summary = postNotification(not.subscriber, not.mimeType, not.payload);
if (!summary.isLastPublishSuccessful()) {
not.retryCount++;
if (not.retryCount <= 5) {
retry(not);
}
}
not.callback.onSummaryInfo(summary);
}
};
exeuctor.execute(r);
}
/**
* Schedules a notification to retry in two minutes.
*
* @param not Notification to retry
*/
protected void retry(final Notification not) {
if (!pendings.contains(not.subscriber.getCallback())) {
// We don't have a current retry for this callback pending, so we
// will schedule the retry
pendings.add(not.subscriber.getCallback());
timer.schedule(new TimerTask() {
@Override
public void run() {
pendings.remove(not.subscriber.getCallback());
enqueueNotification(not);
}
}, TWO_MINUTES);
} else {
// There is a retry in front of this one, so we will just schedule
// it to retry again in a bit
timer.schedule(new TimerTask() {
@Override
public void run() {
retry(not);
}
}, TWO_MINUTES);
}
}
}

View file

@ -0,0 +1,43 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub.notify.standard;
import com.rometools.certiorem.hub.data.SubscriptionSummary;
/**
* A notifier that does not use threads. All calls are blocking and synchronous.
*
* @author robert.cooper
*/
public class UnthreadedNotifier extends AbstractNotifier {
/**
* A blocking call that performs a notification. If there are pending retries that are older
* than two minutes old, they will be retried before the method returns.
*
* @param not
*/
@Override
protected void enqueueNotification(final Notification not) {
not.lastRun = System.currentTimeMillis();
final SubscriptionSummary summary = postNotification(not.subscriber, not.mimeType, not.payload);
not.callback.onSummaryInfo(summary);
}
}

View file

@ -0,0 +1,32 @@
<!--
Copyright (C) The ROME Team 2011
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<title>verify</title>
</head>
<body>
This package contains a set of standard Verifier implementations.
<p>
These implementations all use the standard java.net.* classes for
making requests to URLs.
</p>
</body>
</html>

View file

@ -0,0 +1,30 @@
<!--
Copyright (C) The ROME Team 2011
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<title>hub</title>
</head>
<body>
This package contains the core of the Hub implementation.
<h1>Getting Started</h1>
<p>The Hub implementation </p>
</body>
</html>

View file

@ -0,0 +1,99 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub.verify.standard;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rometools.certiorem.hub.Verifier;
import com.rometools.certiorem.hub.data.Subscriber;
/**
* An abstract verifier based on the java.net HTTP classes. This implements only synchronous
* operations, and expects a child class to do Async ops.
*
* @author robert.cooper
*/
public abstract class AbstractVerifier implements Verifier {
private static final Logger LOG = LoggerFactory.getLogger(AbstractVerifier.class);
@Override
public boolean verifySubcribeSyncronously(final Subscriber subscriber) {
return doOp(Verifier.MODE_SUBSCRIBE, subscriber);
}
@Override
public boolean verifyUnsubcribeSyncronously(final Subscriber subscriber) {
return doOp(Verifier.MODE_UNSUBSCRIBE, subscriber);
}
private boolean doOp(final String mode, final Subscriber subscriber) {
try {
final String challenge = UUID.randomUUID().toString();
final StringBuilder queryString = new StringBuilder();
queryString.append("hub.mode=").append(mode).append("&hub.topic=").append(URLEncoder.encode(subscriber.getTopic(), "UTF-8"))
.append("&hub.challenge=").append(challenge);
if (subscriber.getLeaseSeconds() != -1) {
queryString.append("&hub.lease_seconds=").append(subscriber.getLeaseSeconds());
}
if (subscriber.getVertifyToken() != null) {
queryString.append("&hub.verify_token=").append(URLEncoder.encode(subscriber.getVertifyToken(), "UTF-8"));
}
final URL url = new URL(subscriber.getCallback() + "?" + queryString.toString());
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
// connection.setRequestProperty("Host", url.getHost());
// connection.setRequestProperty("Port",
// Integer.toString(url.getPort()));
connection.setRequestProperty("User-Agent", "ROME-Certiorem");
connection.connect();
final int rc = connection.getResponseCode();
final InputStream is = connection.getInputStream();
final BufferedReader reader = new BufferedReader(new InputStreamReader(is));
final String result = reader.readLine();
reader.close();
connection.disconnect();
if (rc != 200 || !challenge.equals(result.trim())) {
return false;
} else {
return true;
}
} catch (final UnsupportedEncodingException ex) {
LOG.error("Unsupported encoding", ex);
throw new RuntimeException("Should not happen. UTF-8 threw unsupported encoding", ex);
} catch (final IOException ex) {
LOG.error("An IOException occured", ex);
return false;
}
}
}

View file

@ -0,0 +1,66 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub.verify.standard;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import com.rometools.certiorem.hub.data.Subscriber;
/**
* Uses a ThreadPoolExecutor to do async verifications.
*
* @author robert.cooper
*/
public class ThreadPoolVerifier extends AbstractVerifier {
protected final ThreadPoolExecutor exeuctor;
protected ThreadPoolVerifier(final ThreadPoolExecutor executor) {
exeuctor = executor;
}
public ThreadPoolVerifier() {
this(2, 5, 5);
}
public ThreadPoolVerifier(final int startPoolSize, final int maxPoolSize, final int queueSize) {
exeuctor = new ThreadPoolExecutor(startPoolSize, maxPoolSize, 300, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(queueSize));
}
@Override
public void verifySubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) {
exeuctor.execute(new Runnable() {
@Override
public void run() {
callback.onVerify(verifySubcribeSyncronously(subscriber));
}
});
}
@Override
public void verifyUnsubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) {
exeuctor.execute(new Runnable() {
@Override
public void run() {
callback.onVerify(verifyUnsubcribeSyncronously(subscriber));
}
});
}
}

View file

@ -0,0 +1,33 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub.verify.standard;
import java.util.concurrent.ThreadPoolExecutor;
/**
*
* @author robert.cooper
*/
public class ThreadpoolVerifierAdvanced extends ThreadPoolVerifier {
public ThreadpoolVerifierAdvanced(final ThreadPoolExecutor executor) {
super(executor);
}
}

View file

@ -0,0 +1,40 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub.verify.standard;
import com.rometools.certiorem.hub.data.Subscriber;
/**
* A verifier that does not use threads. Suitable for Google App Engine.
*
* @author robert.cooper
*/
public class UnthreadedVerifier extends AbstractVerifier {
@Override
public void verifySubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) {
callback.onVerify(verifySubcribeSyncronously(subscriber));
}
@Override
public void verifyUnsubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) {
callback.onVerify(verifyUnsubcribeSyncronously(subscriber));
}
}

View file

@ -0,0 +1,32 @@
<!--
Copyright (C) The ROME Team 2011
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<title>verify</title>
</head>
<body>
This package contains a set of standard Verifier implementations.
<p>
These implementations all use the standard java.net.* classes for
making requests to URLs.
</p>
</body>
</html>

View file

@ -0,0 +1,30 @@
<!--
Copyright (C) The ROME Team 2011
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<body>
A pub sub hubub implementation for Java.
</body>
</html>

View file

@ -0,0 +1,40 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.pub;
/**
*
* @author robert.cooper
*/
public class NotificationException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
public NotificationException(final String message) {
super(message);
}
public NotificationException(final String message, final Throwable cause) {
super(message, cause);
}
}

View file

@ -0,0 +1,251 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.pub;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.concurrent.ThreadPoolExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.feed.synd.SyndLink;
/**
* A class for sending update notifications to a hub.
*
* @author robert.cooper
*/
public class Publisher {
private static final Logger LOG = LoggerFactory.getLogger(Publisher.class);
private ThreadPoolExecutor executor;
/**
* Constructs a new publisher. This publisher will spawn a new thread for each async send.
*/
public Publisher() {
}
/**
* Constructs a new publisher with an optional ThreadPoolExector for sending updates.
*/
public Publisher(final ThreadPoolExecutor executor) {
this.executor = executor;
}
/**
* Sends the HUB url a notification of a change in topic
*
* @param hub URL of the hub to notify.
* @param topic The Topic that has changed
* @throws NotificationException Any failure
*/
public void sendUpdateNotification(final String hub, final String topic) throws NotificationException {
try {
final StringBuilder sb = new StringBuilder("hub.mode=publish&hub.url=").append(URLEncoder.encode(topic, "UTF-8"));
final URL hubUrl = new URL(hub);
final HttpURLConnection connection = (HttpURLConnection) hubUrl.openConnection();
// connection.setRequestProperty("Host", hubUrl.getHost());
connection.setRequestProperty("User-Agent", "ROME-Certiorem");
connection.setRequestProperty("ContentType", "application/x-www-form-urlencoded");
connection.setDoOutput(true);
connection.connect();
final OutputStream os = connection.getOutputStream();
os.write(sb.toString().getBytes("UTF-8"));
os.close();
final int rc = connection.getResponseCode();
connection.disconnect();
if (rc != 204) {
throw new NotificationException("Server returned an unexcepted response code: " + rc + " " + connection.getResponseMessage());
}
} catch (final UnsupportedEncodingException ex) {
LOG.error("Could not encode URL", ex);
throw new NotificationException("Could not encode URL", ex);
} catch (final IOException ex) {
LOG.error("Communication error", ex);
throw new NotificationException("Unable to communicate with " + hub, ex);
}
}
/**
* Sends a notification for a feed located at "topic". The feed MUST contain rel="hub".
*
* @param topic URL for the feed
* @param feed The feed itself
* @throws NotificationException Any failure
*/
public void sendUpdateNotification(final String topic, final SyndFeed feed) throws NotificationException {
for (final SyndLink link : feed.getLinks()) {
if ("hub".equals(link.getRel())) {
sendUpdateNotification(link.getRel(), topic);
return;
}
}
throw new NotificationException("Hub link not found.");
}
/**
* Sends a notification for a feed. The feed MUST contain rel="hub" and rel="self" links.
*
* @param feed The feed to notify
* @throws NotificationException Any failure
*/
public void sendUpdateNotification(final SyndFeed feed) throws NotificationException {
SyndLink hub = null;
SyndLink self = null;
for (final SyndLink link : feed.getLinks()) {
if ("hub".equals(link.getRel())) {
hub = link;
}
if ("self".equals(link.getRel())) {
self = link;
}
if (hub != null && self != null) {
break;
}
}
if (hub == null) {
throw new NotificationException("A link rel='hub' was not found in the feed.");
}
if (self == null) {
throw new NotificationException("A link rel='self' was not found in the feed.");
}
sendUpdateNotification(hub.getRel(), self.getHref());
}
/**
* Sends the HUB url a notification of a change in topic asynchronously
*
* @param hub URL of the hub to notify.
* @param topic The Topic that has changed
* @param callback A callback invoked when the notification completes.
* @throws NotificationException Any failure
*/
public void sendUpdateNotificationAsyncronously(final String hub, final String topic, final AsyncNotificationCallback callback) {
final Runnable r = new Runnable() {
@Override
public void run() {
try {
sendUpdateNotification(hub, topic);
callback.onSuccess();
} catch (final Throwable t) {
callback.onFailure(t);
}
}
};
if (executor != null) {
executor.execute(r);
} else {
new Thread(r).start();
}
}
/**
* Asynchronously sends a notification for a feed located at "topic". The feed MUST contain
* rel="hub".
*
* @param topic URL for the feed
* @param feed The feed itself
* @param callback A callback invoked when the notification completes.
* @throws NotificationException Any failure
*/
public void sendUpdateNotificationAsyncronously(final String topic, final SyndFeed feed, final AsyncNotificationCallback callback) {
final Runnable r = new Runnable() {
@Override
public void run() {
try {
sendUpdateNotification(topic, feed);
callback.onSuccess();
} catch (final Throwable t) {
callback.onFailure(t);
}
}
};
if (executor != null) {
executor.execute(r);
} else {
new Thread(r).start();
}
}
/**
* Asyncronously sends a notification for a feed. The feed MUST contain rel="hub" and rel="self"
* links.
*
* @param feed The feed to notify
* @param callback A callback invoked when the notification completes.
* @throws NotificationException Any failure
*/
public void sendUpdateNotificationAsyncronously(final SyndFeed feed, final AsyncNotificationCallback callback) {
final Runnable r = new Runnable() {
@Override
public void run() {
try {
sendUpdateNotification(feed);
callback.onSuccess();
} catch (final Throwable t) {
callback.onFailure(t);
}
}
};
if (executor != null) {
executor.execute(r);
} else {
new Thread(r).start();
}
}
/**
* A callback interface for asynchronous notifications.
*/
public static interface AsyncNotificationCallback {
/**
* Called when a notification fails
*
* @param thrown Whatever was thrown during the failure
*/
public void onFailure(Throwable thrown);
/**
* Invoked with the asyncronous notification completes successfully.
*/
public void onSuccess();
}
}

View file

@ -0,0 +1,29 @@
<!--
Copyright (C) The ROME Team 2011
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<title>pub</title>
</head>
<body>
This package contains a utility class to send update notifications.
</body>
</html>

View file

@ -0,0 +1,38 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.sub;
import com.rometools.certiorem.sub.data.Subscription;
/**
*
* @author robert.cooper
*/
public interface Requester {
public void sendSubscribeRequest(String hubUrl, Subscription subscription, String verifySync, long leaseSeconds, String secret, String callbackUrl,
RequestCallback callback);
public void sendUnsubscribeRequest(String hubUrl, Subscription subscription, String verifySync, String secret, String callbackUrl, RequestCallback callback);
public static interface RequestCallback {
public void onFailure(Exception e);
public void onSuccess();
}
}

View file

@ -0,0 +1,284 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.sub;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rometools.certiorem.HttpStatusCodeException;
import com.rometools.certiorem.sub.Requester.RequestCallback;
import com.rometools.certiorem.sub.data.SubDAO;
import com.rometools.certiorem.sub.data.Subscription;
import com.rometools.certiorem.sub.data.SubscriptionCallback;
import com.rometools.fetcher.impl.FeedFetcherCache;
import com.rometools.fetcher.impl.SyndFeedInfo;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.feed.synd.SyndLink;
import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.SyndFeedInput;
/**
*
* @author robert.cooper
*/
public class Subscriptions {
private static final Logger LOG = LoggerFactory.getLogger(Subscriptions.class);
// TODO unsubscribe.
private FeedFetcherCache cache;
private Requester requester;
private String callbackPrefix;
private SubDAO dao;
public Subscriptions() {
}
public Subscriptions(final FeedFetcherCache cache, final Requester requester, final String callbackPrefix, final SubDAO dao) {
this.cache = cache;
this.requester = requester;
this.callbackPrefix = callbackPrefix;
this.dao = dao;
}
public void callback(final String callbackPath, final String feed) {
try {
this.callback(callbackPath, feed.getBytes("UTF-8"));
} catch (final UnsupportedEncodingException ex) {
LOG.error("Unable to parse feed", ex);
throw new HttpStatusCodeException(400, "Unable to parse feed.", ex);
}
}
public void callback(final String callbackPath, final InputStream feed) {
final SyndFeedInput input = new SyndFeedInput();
try {
this.callback(callbackPath, input.build(new InputStreamReader(feed)));
} catch (final IllegalArgumentException ex) {
LOG.error("Unable to parse feed", ex);
throw new HttpStatusCodeException(500, "Unable to parse feed.", ex);
} catch (final FeedException ex) {
LOG.error("Unable to parse feed", ex);
throw new HttpStatusCodeException(400, "Unable to parse feed.", ex);
}
}
public void callback(final String callbackPath, final byte[] feed) {
this.callback(callbackPath, new ByteArrayInputStream(feed));
}
public void callback(final String callbackPath, final SyndFeed feed) {
if (!callbackPath.startsWith(callbackPrefix)) {
throw new HttpStatusCodeException(404, "Not a valid callback prefix.", new Exception(callbackPath + " doesnt start with " + callbackPrefix));
}
final String id = callbackPath.substring(callbackPrefix.length());
LOG.debug("Got callback for {}", id);
final Subscription s = dao.findById(id);
if (s == null) {
throw new HttpStatusCodeException(404, "Not a valid callback.", null);
}
validateLink(feed, s.getSourceUrl());
SyndFeedInfo info = null;
URL url = null;
try {
url = new URL(s.getSourceUrl());
info = cache.getFeedInfo(url);
} catch (final MalformedURLException ex) {
LOG.error("Malformed URL", ex);
}
if (info == null) {
info = new SyndFeedInfo();
info.setId(s.getId());
info.setUrl(url);
}
info.setLastModified(System.currentTimeMillis());
info.setSyndFeed(feed);
cache.setFeedInfo(url, info);
s.getCallback().onNotify(s, info);
}
public void unsubscribe(final Subscription subscription, final String hubUrl, final boolean sync, final String secret, final SubscriptionCallback callback) {
subscription.setUnsubscribed(true);
requester.sendUnsubscribeRequest(hubUrl, subscription, sync ? "sync" : "async", secret, callbackPrefix + subscription.getId(), new RequestCallback() {
@Override
public void onSuccess() {
callback.onUnsubscribe(subscription);
}
@Override
public void onFailure(final Exception e) {
callback.onFailure(e);
}
});
}
public void subscribe(final String hubUrl, final String topic, final boolean sync, final long leaseSeconds, final String secret,
final SubscriptionCallback callback) {
final Subscription s = new Subscription();
s.setId(UUID.randomUUID().toString());
s.setVerifyToken(UUID.randomUUID().toString());
s.setSourceUrl(topic);
s.setCallback(callback);
if (leaseSeconds > 0) {
s.setExpirationTime(System.currentTimeMillis() + leaseSeconds * 1000);
}
final Subscription stored = dao.addSubscription(s);
requester.sendSubscribeRequest(hubUrl, stored, sync ? "sync" : "async", leaseSeconds, secret, callbackPrefix + stored.getId(), new RequestCallback() {
@Override
public void onSuccess() {
callback.onSubscribe(stored);
}
@Override
public void onFailure(final Exception e) {
callback.onFailure(e);
}
});
}
public void subscribe(final String topic, final boolean sync, final long leaseSeconds, final String secret, final SubscriptionCallback callback)
throws IllegalArgumentException, IOException, FeedException {
final SyndFeedInput input = new SyndFeedInput();
final SyndFeed feed = input.build(new InputStreamReader(new URL(topic).openStream()));
final String hubUrl = findHubUrl(feed);
if (hubUrl == null) {
throw new FeedException("No hub link");
}
this.subscribe(hubUrl, topic, sync, leaseSeconds, secret, callback);
}
public String validate(final String callbackPath, final String topic, final String mode, final String challenge, final String leaseSeconds,
final String verifyToken) {
if (!callbackPath.startsWith(callbackPrefix)) {
throw new HttpStatusCodeException(404, "Not a valid callback prefix.", new Exception(callbackPath + " doesnt start with " + callbackPrefix));
}
final String id = callbackPath.substring(callbackPrefix.length());
LOG.debug("Handling validation request for id {}", id);
final Subscription s = dao.findById(id);
if (s == null) {
throw new HttpStatusCodeException(404, "Not a valid subscription id", null);
}
if (!s.getVerifyToken().equals(verifyToken)) {
throw new HttpStatusCodeException(403, "Verification Token Mismatch.", null);
}
if ("unsubscribe".equals(mode)) {
if (!s.isUnsubscribed()) {
throw new HttpStatusCodeException(400, "Unsubscribe not requested.", null);
}
dao.removeSubscription(s);
} else if ("subscribe".equals(mode)) {
if (s.isValidated()) {
throw new HttpStatusCodeException(400, "Duplicate validation.", null);
}
s.setValidated(true);
dao.updateSubscription(s);
} else {
throw new HttpStatusCodeException(400, "Unsupported mode " + mode, null);
}
LOG.debug("Validated. Returning {}", challenge);
return challenge;
}
private String findHubUrl(final SyndFeed feed) {
for (final SyndLink l : feed.getLinks()) {
if ("hub".equals(l.getRel())) {
return l.getHref();
}
}
return null;
}
private void validateLink(final SyndFeed feed, final String source) {
for (final SyndLink l : feed.getLinks()) {
if ("self".equalsIgnoreCase(l.getRel())) {
try {
final URI u = new URI(l.getHref());
final URI t = new URI(source);
if (!u.equals(t)) {
throw new HttpStatusCodeException(400, "Feed self link does not match the subscribed URI.", null);
}
break;
} catch (final URISyntaxException ex) {
LOG.error(null, ex);
}
}
}
}
/**
* @param cache the cache to set
*/
public void setCache(final FeedFetcherCache cache) {
this.cache = cache;
}
/**
* @param requester the requester to set
*/
public void setRequester(final Requester requester) {
this.requester = requester;
}
/**
* @param callbackPrefix the callbackPrefix to set
*/
public void setCallbackPrefix(final String callbackPrefix) {
this.callbackPrefix = callbackPrefix;
}
/**
* @param dao the dao to set
*/
public void setDao(final SubDAO dao) {
this.dao = dao;
}
}

View file

@ -0,0 +1,35 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.sub.data;
/**
*
* @author robert.cooper
*/
public interface SubDAO {
public Subscription findById(String id);
public Subscription addSubscription(Subscription s);
public Subscription updateSubscription(Subscription s);
public void removeSubscription(Subscription s);
}

View file

@ -0,0 +1,161 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.sub.data;
import java.io.Serializable;
/**
*
* @author robert.cooper
*/
public class Subscription implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String id;
private String sourceUrl;
private String verifyToken;
private boolean unsubscribed;
private boolean validated;
private long expirationTime;
private SubscriptionCallback callback;
/**
* Set the value of expirationTime
*
* @param newexpirationTime new value of expirationTime
*/
public void setExpirationTime(final long newexpirationTime) {
expirationTime = newexpirationTime;
}
/**
* Get the value of expirationTime
*
* @return the value of expirationTime
*/
public long getExpirationTime() {
return expirationTime;
}
/**
* Set the value of id
*
* @param newid new value of id
*/
public void setId(final String newid) {
id = newid;
}
/**
* Get the value of id
*
* @return the value of id
*/
public String getId() {
return id;
}
/**
* Set the value of sourceUrl
*
* @param newsourceUrl new value of sourceUrl
*/
public void setSourceUrl(final String newsourceUrl) {
sourceUrl = newsourceUrl;
}
/**
* Get the value of sourceUrl
*
* @return the value of sourceUrl
*/
public String getSourceUrl() {
return sourceUrl;
}
/**
* Set the value of unsubscribed
*
* @param newunsubscribed new value of unsubscribed
*/
public void setUnsubscribed(final boolean newunsubscribed) {
unsubscribed = newunsubscribed;
}
/**
* Get the value of unsubscribed
*
* @return the value of unsubscribed
*/
public boolean isUnsubscribed() {
return unsubscribed;
}
/**
* Set the value of validated
*
* @param newvalidated new value of validated
*/
public void setValidated(final boolean newvalidated) {
validated = newvalidated;
}
/**
* Get the value of validated
*
* @return the value of validated
*/
public boolean isValidated() {
return validated;
}
/**
* Set the value of verifyToken
*
* @param newverifyToken new value of verifyToken
*/
public void setVerifyToken(final String newverifyToken) {
verifyToken = newverifyToken;
}
/**
* Get the value of verifyToken
*
* @return the value of verifyToken
*/
public String getVerifyToken() {
return verifyToken;
}
/**
* @return the callback
*/
public SubscriptionCallback getCallback() {
return callback;
}
/**
* @param callback the callback to set
*/
public void setCallback(final SubscriptionCallback callback) {
this.callback = callback;
}
}

View file

@ -0,0 +1,23 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rometools.certiorem.sub.data;
import com.rometools.fetcher.impl.SyndFeedInfo;
/**
*
* @author najmi
*/
public interface SubscriptionCallback {
void onNotify(Subscription subscribed, SyndFeedInfo feedInfo);
void onFailure(Exception e);
void onSubscribe(Subscription subscribed);
void onUnsubscribe(Subscription subscribed);
}

View file

@ -0,0 +1,28 @@
<!--
Copyright (C) The ROME Team 2011
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<title>data</title>
</head>
<body>
Data classes for the Subscription management.
</body>
</html>

View file

@ -0,0 +1,78 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rometools.certiorem.sub.data.ram;
import java.util.Date;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rometools.certiorem.sub.data.SubDAO;
import com.rometools.certiorem.sub.data.Subscription;
/**
*
* @author robert.cooper
*/
public class InMemorySubDAO implements SubDAO {
private static final Logger LOG = LoggerFactory.getLogger(InMemorySubDAO.class);
private final ConcurrentHashMap<String, Subscription> subscriptions = new ConcurrentHashMap<String, Subscription>();
@Override
public Subscription findById(final String id) {
final Subscription s = subscriptions.get(id);
if (s == null) {
return null;
}
if (s.getExpirationTime() > 0 && s.getExpirationTime() <= System.currentTimeMillis()) {
LOG.debug("Subscription {} expired at {}", s.getSourceUrl(), new Date(s.getExpirationTime()));
subscriptions.remove(id);
return null;
}
return s;
}
@Override
public Subscription addSubscription(final Subscription s) {
subscriptions.put(s.getId(), s);
LOG.debug("Stored subscription {} {}", s.getSourceUrl(), s.getId());
return s;
}
@Override
public Subscription updateSubscription(final Subscription s) {
subscriptions.put(s.getId(), s);
return s;
}
@Override
public void removeSubscription(final Subscription s) {
subscriptions.remove(s.getId());
}
}

View file

@ -0,0 +1,28 @@
<!--
Copyright (C) The ROME Team 2011
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<title>ram</title>
</head>
<body>
An In-Memory DAO for subscriptions.
</body>
</html>

View file

@ -0,0 +1,30 @@
<!--
Copyright (C) The ROME Team 2011
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<title>sub</title>
</head>
<body>
This package contains the business class Subscriptions that manages subscriptions and updates a
FeedInfoCache.
</body>
</html>

View file

@ -0,0 +1,72 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.sub.request;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import com.rometools.certiorem.sub.Requester;
import com.rometools.certiorem.sub.data.Subscription;
/**
*
* @author robert.cooper
*/
public abstract class AbstractRequester implements Requester {
protected boolean sendRequest(final String hubUrl, final String mode, final Subscription subscription, final String verifySync, final long leaseSeconds,
final String secret, final String callbackUrl, final RequestCallback callback) throws IOException {
final StringBuilder sb = new StringBuilder("hub.callback=").append(URLEncoder.encode(callbackUrl, "UTF-8")).append("&hub.topic=")
.append(URLEncoder.encode(subscription.getSourceUrl(), "UTF-8")).append("&hub.verify=").append(URLEncoder.encode(verifySync, "UTF-8"))
.append("&hub.mode=").append(URLEncoder.encode(mode, "UTF-8"));
if (leaseSeconds > 0) {
sb.append("&hub.lease_seconds=").append(Long.toString(leaseSeconds));
}
if (secret != null) {
sb.append("&hub.secret=").append(URLEncoder.encode(secret, "UTF-8"));
}
if (subscription.getVerifyToken() != null) {
sb.append("&hub.verify_token=").append(URLEncoder.encode(subscription.getVerifyToken(), "UTF-8"));
}
final URL url = new URL(hubUrl);
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setDoOutput(true);
// connection.setRequestProperty("Host", url.getHost());
connection.setRequestProperty("User-Agent", "ROME-Certiorem");
connection.connect();
connection.getOutputStream().write(sb.toString().getBytes("UTF-8"));
final int rc = connection.getResponseCode();
connection.disconnect();
if (rc != 204) {
throw new RuntimeException("Unexpected repsonse code. " + rc);
}
return true;
}
}

View file

@ -0,0 +1,72 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.sub.request;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rometools.certiorem.sub.data.Subscription;
/**
* A simple requester implementation that always makes requests as Async.
*
* @author robert.cooper
*/
public class AsyncRequester extends AbstractRequester {
private static final Logger LOG = LoggerFactory.getLogger(AsyncRequester.class);
@Override
public void sendSubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final long leaseSeconds,
final String secret, final String callbackUrl, final RequestCallback callback) {
LOG.debug("Sending subscribe request to {} for {} to {}", hubUrl, subscription.getSourceUrl(), callbackUrl);
final Runnable r = new Runnable() {
@Override
public void run() {
try {
sendRequest(hubUrl, "subscribe", subscription, verifySync, leaseSeconds, secret, callbackUrl, callback);
} catch (final Exception ex) {
LOG.error(null, ex);
callback.onFailure(ex);
}
}
};
new Thread(r).start();
}
@Override
public void sendUnsubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final String secret,
final String callbackUrl, final RequestCallback callback) {
LOG.debug("Sending unsubscribe request to {} for {} to {}", hubUrl, subscription.getSourceUrl(), callbackUrl);
final Runnable r = new Runnable() {
@Override
public void run() {
try {
sendRequest(hubUrl, "unsubscribe", subscription, verifySync, -1, secret, callbackUrl, callback);
} catch (final IOException ex) {
LOG.error(null, ex);
callback.onFailure(ex);
}
}
};
new Thread(r).start();
}
}

View file

@ -0,0 +1,66 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rometools.certiorem.sub.request;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rometools.certiorem.sub.data.Subscription;
/**
* A simple requester implementation that always makes requests as Async.
*
* @author Farrukh Najmi
*/
public class SyncRequester extends AbstractRequester {
private static final Logger LOG = LoggerFactory.getLogger(SyncRequester.class);
@Override
public void sendSubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final long leaseSeconds,
final String secret, final String callbackUrl, final RequestCallback callback) {
LOG.info("Sending subscribe request to {} for {} to {}", hubUrl, subscription.getSourceUrl(), callbackUrl);
try {
sendRequest(hubUrl, "subscribe", subscription, verifySync, leaseSeconds, secret, callbackUrl, callback);
callback.onSuccess();
} catch (final Exception ex) {
LOG.error(null, ex);
callback.onFailure(ex);
}
}
@Override
public void sendUnsubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final String secret,
final String callbackUrl, final RequestCallback callback) {
LOG.info("Sending unsubscribe request to {} for {} to {}", hubUrl, subscription.getSourceUrl(), callbackUrl);
try {
sendRequest(hubUrl, "unsubscribe", subscription, verifySync, -1, secret, callbackUrl, callback);
callback.onSuccess();
} catch (final IOException ex) {
LOG.error(null, ex);
callback.onFailure(ex);
}
}
}

View file

@ -0,0 +1,28 @@
<!--
Copyright (C) The ROME Team 2011
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<title>request</title>
</head>
<body>
Standard requester implementations.
</body>
</html>

View file

@ -0,0 +1,84 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.web;
import java.io.IOException;
import java.util.Arrays;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.rometools.certiorem.HttpStatusCodeException;
import com.rometools.certiorem.hub.Hub;
/**
*
* @author robert.cooper
*/
public abstract class AbstractHubServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
public static final String HUBMODE = "hub.mode";
private final Hub hub;
protected AbstractHubServlet(final Hub hub) {
super();
this.hub = hub;
}
@Override
protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
try {
if ("publish".equals(req.getParameter(HUBMODE))) {
hub.sendNotification(req.getServerName(), req.getParameter("hub.url"));
} else {
final String callback = req.getParameter("hub.callback");
final String topic = req.getParameter("hub.topic");
final String[] verifies = req.getParameterValues("hub.verify");
final String leaseString = req.getParameter("hub.lease_seconds");
final String secret = req.getParameter("hub.secret");
final String verifyToken = req.getParameter("hub.verify_token");
final String verifyMode = Arrays.asList(verifies).contains("async") ? "async" : "sync";
Boolean result = null;
if ("subscribe".equals(req.getParameter(HUBMODE))) {
final long leaseSeconds = leaseString != null ? Long.parseLong(leaseString) : -1;
result = hub.subscribe(callback, topic, verifyMode, leaseSeconds, secret, verifyToken);
} else if ("unsubscribe".equals(req.getParameter(HUBMODE))) {
result = hub.unsubscribe(callback, topic, verifyMode, secret, verifyToken);
}
if (result != null && !result) {
throw new HttpStatusCodeException(500, "Operation failed.", null);
}
}
} catch (final HttpStatusCodeException sc) {
resp.setStatus(sc.getStatus());
resp.getWriter().println(sc.getMessage());
return;
}
resp.setStatus(204);
}
}

View file

@ -0,0 +1,77 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.web;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.rometools.certiorem.HttpStatusCodeException;
import com.rometools.certiorem.sub.Subscriptions;
/**
*
* @author robert.cooper
*/
public abstract class AbstractSubServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private final Subscriptions subscriptions;
protected AbstractSubServlet(final Subscriptions subscriptions) {
this.subscriptions = subscriptions;
}
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
final String mode = req.getParameter("hub.mode");
final String topic = req.getParameter("hub.topic");
final String challenge = req.getParameter("hub.challenge");
final String leaseString = req.getParameter("hub.lease_seconds");
final String verifyToken = req.getParameter("hub.verify_token");
try {
final String result = subscriptions.validate(req.getRequestURL().toString(), topic, mode, challenge, leaseString, verifyToken);
resp.setStatus(200);
resp.getWriter().print(result);
} catch (final HttpStatusCodeException e) {
e.printStackTrace();
resp.setStatus(e.getStatus());
resp.getWriter().print(e.getMessage());
}
}
@Override
protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
try {
final String requestUrl = req.getRequestURL().toString();
final ServletInputStream inputStream = req.getInputStream();
subscriptions.callback(requestUrl, inputStream);
} catch (final HttpStatusCodeException e) {
e.printStackTrace();
resp.setStatus(e.getStatus());
resp.getWriter().println(e.getMessage());
}
}
}

View file

@ -0,0 +1,31 @@
<!--
Copyright (C) The ROME Team 2011
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<title>web</title>
</head>
<body>
Contains base servlet implementations for doing hub and sub services.
<p>
Extends these as needed in your web application.
</p>
</body>
</html>

View file

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) The ROME Team 2011
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="certiorem" transaction-type="RESOURCE_LOCAL">
<jta-data-source>jdbc/certiorem-datasource</jta-data-source>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables" />
</properties>
</persistence-unit>
</persistence>

View file

@ -0,0 +1,124 @@
-----
Certiorem Tutorial
-----
kebernet
-----
2011-12-06 19:23:15.220
-----
Certiorem Tutorial
Certiorem is a PubSubHubub (PSH) implementation for ROME. It isn't an application, but an API for building each of the three components (Publisher, Subscriber and Hub) into your web apps.
You can see an {{{https://github.com/rometools/rome-incubator/tree/master/pubsubhubub/webapp}example webapp here}}.
Creating a Hub
Hubs take notifications, or "Pings" that tell it the content of a feed has been updated, fetch the feed, then notify each of the subscribers of the change. As you will begin to see, Certiorem is very much about "Composition" of classes. The Hub class is a prime example of this.
Looking at the example webapp we see:
+------+
@Provides
@Singleton
public Hub buildHub() {
FeedFetcher fetcher = new HttpURLFeedFetcher(new DeltaFeedInfoCache());
    Hub hub = new Hub(new InMemoryHubDAO(), new UnthreadedVerifier(), new UnthreadedNotifier(), fetcher);
    return hub;
}
+------+
First we construct an instance of FeedFetcher, from the Fetcher subproject. This will be used to fetch feeds from remote hosts. There are a number of implementations for FeedFetcher and FeedInfoCache in the Fetcher project. Please look there for info on what is what.
Next we need a HubDAO implementation. This is a DAO for managing Subscriber and SubscriptionSummary classes. Here we are using an in\-memory DAO, which like the HashMapFeedInfoCache will evaporate if we restart our web application. A JPA implementation for persistence is also available, but incomplete at time of writing.
Next we need two implementations of network client interfaces: a Verifier, and a Notifier. The Verifier calls back to the Subscribers and verifies their subscribe/unsubscribe operations. A Notifier is used to send updates to to the clients. There are two basic implementations of these provided: A ThreadPool\* and Unthreaded\* version of each. The thread pool version uses a ThreadPoolExecutor to run queues of outbound calls. The Unthreaded version of each, makes the network calls in\-line with the request to the hub. These are suitable for environments like Google App Engine where spawning threads from servlets is absolutely verboten.
There are other constructors that contain lists of restrictions for what the hub will support: acceptable topic feeds, ports, protocols, etc.
The hub here is just a business logic class. In order to have a functioning hub, we need a servlet exposing the Hub. In the "web" package, there is an abstract servlet you can use to do just this. In the Guice wired example, we simply create a servlet with an injected Hub implementation.
+------+
@Singleton
public class HubServlet extends AbstractHubServlet {
@Inject
public HubServlet(final Hub hub){
super(hub);
}
}
//... in the ServerModule...
serve("/hub*").with(HubServlet.class);
+------+
We can now include a \<link rel\="hub"\> value in our feeds and publish notifications of changes. 
Publishing Ping Notifications
This is perhaps the easiest thing to do. The Publisher class will take various combinations of URLs and SyndFeeds and send the appropriate notification. If your SyndFeed contains a \<link rel\='sel' /\> and \<link rel\='hub' /\> you can just pass the SyndFeed object. Otherwise, you can use the URL strings where appropriate.
The example couldn't be simpler:
+------+
Publisher pub = new Publisher();
try {
pub.sendUpdateNotification("http://localhost/webapp/hub", "http://localhost/webapp/research-atom.xml");
} catch (NotificationException ex) {
Logger.getLogger(NotifyTest.class.getName()).log(Level.SEVERE, null, ex);
throw new ServletException(ex);
}
+------+
Once this notification is sent, the hub will make a request to the feed and notify the clients of new entries.
Subscribing to Feeds
To set up a feed subscriber, you need to go through a process very much like setting up a Hub. First, create the Subscriptions class by composition:
+------+
@Provides
@Singleton
public Subscriptions buildSubs(){
    Subscriptions subs = new Subscriptions(new HashMapFeedInfoCache(), new AsyncRequester(),
            "http://localhost/webapp/subscriptions/", new InMemorySubDAO());
    return subs;
}
+------+
First we need a FeedInfoCache implementation. This will be updated as notifications come in, so in your web app, you want to make sure this is shared with the FeedFetcher implementation you are using to read feeds. Next you need a Requester, this is a network class that makes subscription requests to remote hubs. Next, a URL prefix for where the callbacks will live. This really means the URL to the SubServlet that is resolvable externally. Finally, a DAO for storing and retrieving Subscription objects.
As in the Hub, we need a wrapper servlet to call into the Subscriptions class
+------+
@Singleton
public class SubServlet extends AbstractSubServlet {
@Inject
public SubServlet(final Subscriptions subscriptions){
super(subscriptions);
}
}
// In the ServerModule...
serve("/subscriptions/*").with(SubServlet.class)
+------+
Now if we want to subscribe to a feed, we get a reference to the Subscriptions object, and pass in either the SyndFeed (with appropriate rel\="hub" and rel\="self" links) or simply a couple of URLs:
+------+
 subs.subscribe("http://localhost/webapp/hub", "http://localhost/webapp/research-atom.xml", true, -1, null, new SubscriptionCallback(){
public void onFailure(Exception e) {
e.printStackTrace();
}
public void onSubscribe(Subscription subscribed) {
System.out.println("Subscribed "+subscribed.getId() +" "+subscribed.getSourceUrl());
}
});
+------+
Here we pass in the URL of the Hub, the URL of the feed, a boolean indicating we want to make the subscription request synchronously, the lease seconds we want to keep the subscription for, a null cryptographic secret, and a Callback invoked when the subscribe request completes.

View file

@ -0,0 +1,47 @@
-----
certiorem
-----
kebernet
-----
2011-03-19 10:30:35.292
-----
Certiorem
Certiorem is an implementation of the {{{http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub\-core\-0.3.html}PubSubHubub }}protocol for ROME.
It is dependent on ROME and ROME\-Fetcher for the base implementations, and will provide standard plugins for Propono to allow for publish eventing, where applicable.
*Primary Components
*Hub Implementation and Scaffolding (Done)
The first part of Certiorem is a basic set of scaffolding classes that can be used to create a PSH notification hub. Initially, this will include a non\-guaranteed delivery hub, with standard implementations suitable for deployment on most JavaEE application servers or Google App Engine. It is intended that there should be at least one simple, drop in WAR file, utilizing JavaEE classes that can work in a default configuration for various standard web containers. Subsequently,  each of the classes in the PSH implementation up through the primary Controller class use constructor\-time composition/configuration so that the user/developer can easily construct a custom configuration of the Hub.
**Client Implementation Integrated with ROME\-Fetcher (Done)
For web\-based applications that use ROME\-Fetcher, an extended push\-notified store wrapper that will update based on callbacks from a Hub of change notifications. This will include a highly configurable callback servlet to write into the Fetcher cache as changes are made. Additionally, the system should support (semi\-)real time notifications of changes in the form of a listener that exectutes in a TBD thread state relative to the callback servlet. This should be packaged as a simple JAR with no more deps than fetcher that defines the callback servlet, and automagically does subscribes where link\=rel appropriate.
**Notification Implementation for Propono based and JAX\-RS based Servers (In Progress)
This should be a simple API call to notify a Hub of changes to topics. Again, this should provide real\-time notifications either synchronously or asynchronously. Importantly for Asynchronous notifications, they should block subsequent change notifications pending a notification to the Hub.
References: 
{{{https://github.com/nlothian/RTUpdates/blob/master/src/com/nicklothian/pubsubhub/PubSubHubSubscriptionServlet.java}https://github.com/nlothian/RTUpdates/blob/master/src/com/nicklothian/pubsubhub/PubSubHubSubscriptionServlet.java}}
{{{http://grack.com/blog/2009/09/09/parsing\-the\-pubsubhubbub\-notifications/}http://grack.com/blog/2009/09/09/parsing\-the\-pubsubhubbub\-notifications/}}
Notes on the Code
It is still mostly a rough sketch, but the big outlines are there:
There are three main packages: pub, sub and hub.
The pub package is basically just a single utility class for pushing notifications to a hub.
The hub package contains the Hub class. This is a general business controller that is intended to allow you to build a servlet around it with a very, very thin veneer, but you could also use it to drive an XMPP or JMS version too. It is basically built by composition of a number of classes, for which there are some default implementations: A Verifier, which makes the callback to verify new subscriptions, the HubDAO which stores the current subscriptions and subscriber statistics, and a Notifier which actually sends notifications to the subscribers. There are a couple of implementations of each of these (though the JPA HubDAO is still in process). Mostly the implementations for the Verifier and Notifier support threadpooling or no\-threads (for App Engine use).
I have just started sketching out the sub package, but it basically has a "Subscriptions" class that will take in notifications (using the same "thin veneer" pattern that the Hub class uses). It is also constructed with some impls: A SubscriptionDAO that stores you current subscription information, a FeedFetcherCache that holds the received data, and a Requester that makes the subscription requests to hubs.
I am hoping to have a basic end to end example working sometime in the next week or so, but if anyone wants to look over what is there, feel free.

View file

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View file

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/DECORATION/1.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/DECORATION/1.3.0 http://maven.apache.org/xsd/decoration-1.3.0.xsd"
name="ROME Certiorem">
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>1.3.0</version>
</skin>
<custom>
<fluidoSkin>
<gitHub>
<projectId>rometools/rome-certiorem</projectId>
<ribbonOrientation>right</ribbonOrientation>
<ribbonColor>gray</ribbonColor>
</gitHub>
</fluidoSkin>
</custom>
<bannerLeft>
<name>ROME</name>
<src>images/romelogo.png</src>
<href>http://github.com/rometools/</href>
</bannerLeft>
<publishDate position="right" />
<version position="left" />
<body>
<menu name="ROME Certiorem">
<item name="Overview" href="index.html" />
<item name="Tutorial" href="CertioremTutorial.html" />
<item name="Example project" href="http://github.com/rometools/rome-certiorem-webapp/"/>
</menu>
<menu ref="reports" />
</body>
</project>

View file

@ -0,0 +1,50 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub;
import com.rometools.certiorem.hub.Verifier;
import com.rometools.certiorem.hub.data.Subscriber;
/**
*
* @author robert.cooper
*/
public class AlwaysVerifier implements Verifier {
@Override
public void verifySubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) {
callback.onVerify(true);
}
@Override
public boolean verifySubcribeSyncronously(final Subscriber subscriber) {
return true;
}
@Override
public void verifyUnsubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) {
callback.onVerify(true);
}
@Override
public boolean verifyUnsubcribeSyncronously(final Subscriber subscriber) {
return true;
}
}

View file

@ -0,0 +1,131 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rometools.certiorem.HttpStatusCodeException;
import com.rometools.certiorem.hub.Hub;
import com.rometools.certiorem.hub.Notifier;
import com.rometools.certiorem.hub.data.HubDAO;
import com.rometools.certiorem.hub.data.ram.InMemoryHubDAO;
import com.rometools.fetcher.FeedFetcher;
import com.rometools.fetcher.impl.HashMapFeedInfoCache;
import com.rometools.fetcher.impl.HttpURLFeedFetcher;
/**
*
* @author robert.cooper
*/
public class ControllerTest {
private static final Logger LOG = LoggerFactory.getLogger(ControllerTest.class);
public ControllerTest() {
}
@BeforeClass
public static void setUpClass() throws Exception {
}
@AfterClass
public static void tearDownClass() throws Exception {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of subscribe method, of class Hub.
*/
@Test
public void testSubscribe() {
LOG.info("subscribe");
final String callback = "http://localhost/doNothing";
final String topic = "http://feeds.feedburner.com/screaming-penguin";
final long lease_seconds = -1;
final String secret = null;
final String verify_token = "MyVoiceIsMyPassport";
final HubDAO dao = new InMemoryHubDAO();
final Notifier notifier = null;
final FeedFetcher fetcher = new HttpURLFeedFetcher(HashMapFeedInfoCache.getInstance());
Hub instance = new Hub(dao, new AlwaysVerifier(), notifier, fetcher);
Boolean result = instance.subscribe(callback, topic, "sync", lease_seconds, secret, verify_token);
assertEquals(true, result);
instance = new Hub(dao, new NeverVerifier(), notifier, fetcher);
result = instance.subscribe(callback, topic, "sync", lease_seconds, secret, verify_token);
assertEquals(false, result);
result = instance.subscribe(callback, topic, "async", lease_seconds, secret, verify_token);
assertEquals(null, result);
// Test internal assertions
try {
instance.subscribe(null, topic, "async", lease_seconds, secret, verify_token);
fail();
} catch (final HttpStatusCodeException e) {
assertEquals(400, e.getStatus());
LOG.info(e.getMessage());
}
try {
instance.subscribe(callback, null, "async", lease_seconds, secret, verify_token);
fail();
} catch (final HttpStatusCodeException e) {
assertEquals(400, e.getStatus());
LOG.info(e.getMessage());
}
try {
instance.subscribe(callback, topic, "foo", lease_seconds, secret, verify_token);
fail();
} catch (final HttpStatusCodeException e) {
assertEquals(400, e.getStatus());
LOG.info(e.getMessage());
}
// test general exception
instance = new Hub(dao, new ExceptionVerifier(), notifier, fetcher);
try {
result = instance.subscribe(callback, topic, "sync", lease_seconds, secret, verify_token);
fail();
} catch (final HttpStatusCodeException e) {
assertEquals(500, e.getStatus());
}
}
}

View file

@ -0,0 +1,62 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rometools.certiorem.hub;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import com.rometools.certiorem.hub.DeltaFeedInfoCache;
import com.rometools.fetcher.impl.HashMapFeedInfoCache;
import com.rometools.fetcher.impl.HttpURLFeedFetcher;
import com.rometools.rome.feed.synd.SyndEntry;
import com.rometools.rome.feed.synd.SyndFeed;
/**
*
* @author najmi
*/
public class DeltaSyndFeedInfoTest {
private DeltaFeedInfoCache feedInfoCache;
private HttpURLFeedFetcher feedFetcher;
private SyndFeed feed;
@Before
public void setUp() {
feedInfoCache = new DeltaFeedInfoCache(new HashMapFeedInfoCache());
feedFetcher = new HttpURLFeedFetcher(feedInfoCache);
}
/**
* Test of getSyndFeed method, of class DeltaSyndFeedInfo.
*/
@Test
public void testGetSyndFeed() throws Exception {
feed = feedFetcher.retrieveFeed(getFeedUrl());
List<SyndEntry> entries = feed.getEntries();
assertTrue(!entries.isEmpty());
// Fetch again and this time the entries should be empty as none have
// changed.
feed = feedFetcher.retrieveFeed(getFeedUrl());
entries = feed.getEntries();
assertTrue(entries.isEmpty());
}
private URL getFeedUrl() throws IOException {
final URL feedUrl = new URL("http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&output=rss");
// URL feedUrl = new
// URL("http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml");
return feedUrl;
}
}

View file

@ -0,0 +1,50 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub;
import com.rometools.certiorem.hub.Verifier;
import com.rometools.certiorem.hub.data.Subscriber;
/**
*
* @author robert.cooper
*/
public class ExceptionVerifier implements Verifier {
@Override
public void verifySubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean verifySubcribeSyncronously(final Subscriber subscriber) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void verifyUnsubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean verifyUnsubcribeSyncronously(final Subscriber subscriber) {
throw new UnsupportedOperationException("Not supported yet.");
}
}

View file

@ -0,0 +1,50 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub;
import com.rometools.certiorem.hub.Verifier;
import com.rometools.certiorem.hub.data.Subscriber;
/**
*
* @author robert.cooper
*/
public class NeverVerifier implements Verifier {
@Override
public void verifySubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) {
callback.onVerify(false);
}
@Override
public boolean verifySubcribeSyncronously(final Subscriber subscriber) {
return false;
}
@Override
public void verifyUnsubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) {
callback.onVerify(false);
}
@Override
public boolean verifyUnsubcribeSyncronously(final Subscriber subscriber) {
return false;
}
}

View file

@ -0,0 +1,97 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub.data;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rometools.certiorem.hub.data.HubDAO;
import com.rometools.certiorem.hub.data.Subscriber;
/**
*
* @author robert.cooper
*/
public abstract class AbstractDAOTest {
private static final Logger LOG = LoggerFactory.getLogger(AbstractDAOTest.class);
protected abstract HubDAO get();
@Test
public void testSubscribe() {
final HubDAO instance = get();
LOG.info("{} testSubscribe", instance.getClass().getName());
final Subscriber subscriber = new Subscriber();
subscriber.setCallback("http://localhost:9797/noop");
subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin");
subscriber.setLeaseSeconds(-1);
subscriber.setVerify("VerifyMe");
final Subscriber result = instance.addSubscriber(subscriber);
Assert.assertTrue("Subscriber not equal", result.equals(subscriber));
final List<? extends Subscriber> subscribers = instance.subscribersForTopic(subscriber.getTopic());
Assert.assertTrue("Subscriber not in result", subscribers.contains(result));
}
@Test
public void testLeaseExpire() throws InterruptedException {
final HubDAO instance = get();
LOG.info("{} testLeaseExpire", instance.getClass().getName());
final Subscriber subscriber = new Subscriber();
subscriber.setCallback("http://localhost:9797/noop");
subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin");
subscriber.setLeaseSeconds(1);
subscriber.setVerify("VerifyMe");
final Subscriber result = instance.addSubscriber(subscriber);
Assert.assertEquals("Subscriber not equal", subscriber, result);
// quick test for store.
List<? extends Subscriber> subscribers = instance.subscribersForTopic(subscriber.getTopic());
Assert.assertTrue("Subscriber not in result", subscribers.contains(result));
// sleep past expiration
Thread.sleep(1100);
subscribers = instance.subscribersForTopic(subscriber.getTopic());
Assert.assertFalse("Subscriber should have expired", subscribers.contains(result));
}
@Test
public void testUnsubscribe() throws InterruptedException {
final HubDAO instance = get();
LOG.info("{} testUnsubscribe", instance.getClass().getName());
final Subscriber subscriber = new Subscriber();
subscriber.setCallback("http://localhost:9797/noop");
subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin");
subscriber.setLeaseSeconds(1);
subscriber.setVerify("VerifyMe");
// TODO
// final Subscriber result = instance.addSubscriber(subscriber);
}
}

View file

@ -0,0 +1,40 @@
/**
*
* Copyright (C) The ROME Team 2011
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.certiorem.hub.data.ram;
import com.rometools.certiorem.hub.data.AbstractDAOTest;
import com.rometools.certiorem.hub.data.HubDAO;
import com.rometools.certiorem.hub.data.ram.InMemoryHubDAO;
/**
*
* @author robert.cooper
*/
public class InMemoryDAOTest extends AbstractDAOTest {
private final InMemoryHubDAO dao = new InMemoryHubDAO();
public InMemoryDAOTest() {
}
@Override
protected HubDAO get() {
return dao;
}
}

View file

@ -0,0 +1 @@
# needed to commit empty folder

7
rome-fetcher/.gitignore vendored Normal file
View file

@ -0,0 +1,7 @@
.classpath
.project
.settings
target
.idea
*.iml
atlassian-ide-plugin.xml

14
rome-fetcher/LICENSE Normal file
View file

@ -0,0 +1,14 @@
Copyright 2004 Sun Microsystems, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

7
rome-fetcher/README.md Normal file
View file

@ -0,0 +1,7 @@
rome
====
ROME is a set of RSS and Atom Utilities for Java. It makes it easy to work in Java with most syndication formats: RSS 0.90, RSS 0.91 Netscape,
RSS 0.91 Userland, RSS 0.92, RSS 0.93, RSS 0.94, RSS 1.0, RSS 2.0, Atom 0.3, Atom 1.0
More Information: http://rometools.github.io/rome-fetcher/

123
rome-fetcher/pom.xml Normal file
View file

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.rometools</groupId>
<artifactId>rome-parent</artifactId>
<version>1.6.0-SNAPSHOT</version>
</parent>
<artifactId>rome-fetcher</artifactId>
<version>1.6.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>rome-fetcher</name>
<description>A well behaved feed fetcher API for ROME</description>
<url>http://rometools.github.io/rome-fetcher/</url>
<scm>
<connection>scm:git:ssh://github.com/rometools/rome-fetcher.git</connection>
<developerConnection>scm:git:ssh://git@github.com/rometools/rome-fetcher.git</developerConnection>
<url>https://github.com/rometools/rome-fetcher</url>
</scm>
<developers>
<developer>
<name>Nick Lothian</name>
<url>http://nicklothian.com</url>
</developer>
<developer>
<name>Robert Cooper</name>
<email>kebernet@gmail.comM</email>
</developer>
</developers>
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-publish-plugin</artifactId>
<configuration>
<scmBranch>gh-pages</scmBranch>
<pubScmUrl>${project.scm.developerConnection}</pubScmUrl>
<content>${project.build.directory}/site</content>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Export-Package>
com.rometools.fetcher,
com.rometools.fetcher.impl
</Export-Package>
<Import-Package>
com.rometools.rome.feed.impl,
com.rometools.rome.feed.synd,
com.rometools.rome.io,
com.rometools.utils,
org.apache.commons.httpclient;resolution:=optional,
org.apache.commons.httpclient.auth;resolution:=optional,
org.apache.commons.httpclient.methods;resolution:=optional,
org.apache.commons.httpclient.params;resolution:=optional,
org.slf4j
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome</artifactId>
<version>1.6.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<optional />
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jetty</groupId>
<artifactId>jetty</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,120 @@
/*
* Copyright 2004 Sun Microsystems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.rometools.fetcher;
import java.io.IOException;
import java.net.URL;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.io.FeedException;
public interface FeedFetcher {
/**
* <p>
* The default user agent. It is not marked final so buggy java compiler will not write this
* string into all classes that reference it.
* </p>
*
* <p>
* http://tinyurl.com/64t5n points to https://rome.dev.java.net Some servers ban user agents
* with "Java" in the name.
* </p>
*
*/
public static String DEFAULT_USER_AGENT = "Rome Client (http://tinyurl.com/64t5n)";
/**
* @param string The User-Agent to sent to servers
*/
public abstract void setUserAgent(String string);
/**
* @return the User-Agent currently being sent to servers
*/
public abstract String getUserAgent();
/**
* <p>
* Turn on or off rfc3229 delta encoding
* </p>
*
* <p>
* See http://www.ietf.org/rfc/rfc3229.txt and
* http://bobwyman.pubsub.com/main/2004/09/using_rfc3229_w.html
* </p>
*
* <p>
* NOTE: This is experimental and feedback is welcome!
* </p>
*
* @param useDeltaEncoding
*/
public abstract void setUsingDeltaEncoding(boolean useDeltaEncoding);
/**
* <p>
* Is this fetcher using rfc3229 delta encoding?
* </p>
*
* @return
*/
public abstract boolean isUsingDeltaEncoding();
/**
* <p>
* Add a FetcherListener.
* </p>
*
* <p>
* The FetcherListener will receive an FetcherEvent when a Fetcher event (feed polled,
* retrieved, etc) occurs
* </p>
*
* @param listener The FetcherListener to recieve the event
*/
public abstract void addFetcherEventListener(FetcherListener listener);
/**
* <p>
* Remove a FetcherListener
* </p>
*
* @param listener The FetcherListener to remove
*/
public abstract void removeFetcherEventListener(FetcherListener listener);
/**
* Retrieve a feed over HTTP
*
* @param feedUrl A non-null URL of a RSS/Atom feed to retrieve
* @return A {@link com.rometools.rome.feed.synd.SyndFeed} object
* @throws IllegalArgumentException if the URL is null;
* @throws IOException if a TCP error occurs
* @throws FeedException if the feed is not valid
* @throws FetcherException if a HTTP error occurred
*/
public abstract SyndFeed retrieveFeed(URL feedUrl) throws IllegalArgumentException, IOException, FeedException, FetcherException;
public SyndFeed retrieveFeed(String userAgent, URL url) throws IllegalArgumentException, IOException, FeedException, FetcherException;
/**
* If set to true, the WireFeed will be made accessible from the SyndFeed object returned from
* the Fetcher via the originalWireFeed() method. Each Entry in the feed will have the
* corresponding wireEntry property set.
*/
void setPreserveWireFeed(boolean preserveWireFeed);
}

View file

@ -0,0 +1,90 @@
package com.rometools.fetcher;
import java.util.EventObject;
import com.rometools.rome.feed.synd.SyndFeed;
/**
* Implementation note: FetcherEvent is not thread safe. Make sure that they are only ever accessed
* by one thread. If necessary, make all getters and setters synchronized, or alternatively make all
* fields final.
*
* @author nl
*/
public class FetcherEvent extends EventObject {
private static final long serialVersionUID = 1L;
public static final String EVENT_TYPE_FEED_POLLED = "FEED_POLLED";
public static final String EVENT_TYPE_FEED_RETRIEVED = "FEED_RETRIEVED";
public static final String EVENT_TYPE_FEED_UNCHANGED = "FEED_UNCHANGED";
private String eventType;
private String urlString;
private SyndFeed feed;
public FetcherEvent(final Object source) {
super(source);
}
public FetcherEvent(final Object source, final String urlStr, final String eventType) {
this(source);
setUrlString(urlStr);
setEventType(eventType);
}
public FetcherEvent(final Object source, final String urlStr, final String eventType, final SyndFeed feed) {
this(source, urlStr, eventType);
setFeed(feed);
}
/**
* @return Returns the feed.
*
* <p>
* The feed will only be set if the eventType is EVENT_TYPE_FEED_RETRIEVED
* </p>
*/
public SyndFeed getFeed() {
return feed;
}
/**
* @param feed The feed to set.
*
* <p>
* The feed will only be set if the eventType is EVENT_TYPE_FEED_RETRIEVED
* </p>
*/
public void setFeed(final SyndFeed feed) {
this.feed = feed;
}
/**
* @return Returns the eventType.
*/
public String getEventType() {
return eventType;
}
/**
* @param eventType The eventType to set.
*/
public void setEventType(final String eventType) {
this.eventType = eventType;
}
/**
* @return Returns the urlString.
*/
public String getUrlString() {
return urlString;
}
/**
* @param urlString The urlString to set.
*/
public void setUrlString(final String urlString) {
this.urlString = urlString;
}
}

View file

@ -0,0 +1,51 @@
/*
* Copyright 2004 Sun Microsystems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.rometools.fetcher;
/**
* @author Nick Lothian
*
*/
public class FetcherException extends Exception {
private static final long serialVersionUID = 1L;
int responseCode;
public FetcherException(final Throwable cause) {
super();
initCause(cause);
}
public FetcherException(final String message, final Throwable cause) {
super(message);
initCause(cause);
}
public FetcherException(final String message) {
super(message);
}
public FetcherException(final int responseCode, final String message) {
this(message);
this.responseCode = responseCode;
}
public int getResponseCode() {
return responseCode;
}
}

View file

@ -0,0 +1,16 @@
package com.rometools.fetcher;
import java.util.EventListener;
public interface FetcherListener extends EventListener {
/**
* <p>
* Called when a fetcher event occurs
* </p>
*
* @param event the event that fired
*/
public void fetcherEvent(FetcherEvent event);
}

View file

@ -0,0 +1,225 @@
/*
* Copyright 2004 Sun Microsystems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.rometools.fetcher.impl;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLConnection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rometools.fetcher.FeedFetcher;
import com.rometools.fetcher.FetcherEvent;
import com.rometools.fetcher.FetcherException;
import com.rometools.fetcher.FetcherListener;
import com.rometools.rome.feed.synd.SyndFeed;
public abstract class AbstractFeedFetcher implements FeedFetcher {
private static final Logger LOG = LoggerFactory.getLogger(AbstractFeedFetcher.class);
private final Set<FetcherListener> listeners;
private String userAgent;
private boolean usingDeltaEncoding;
private boolean preserveWireFeed;
public AbstractFeedFetcher() {
listeners = Collections.synchronizedSet(new HashSet<FetcherListener>());
final Properties props = new Properties(System.getProperties());
final String resourceName = "fetcher.properties";
try {
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(resourceName);
if (inputStream == null) {
inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
}
if (inputStream != null) {
props.load(inputStream);
System.getProperties().putAll(props);
inputStream.close();
} else {
LOG.warn("Could not find {} on classpath", resourceName);
}
} catch (final IOException e) {
// do nothing - we don't want to fail just because we could not find the version
LOG.error("Error reading {} from classpath: {}", resourceName, e.getMessage());
}
setUserAgent(DEFAULT_USER_AGENT + " Ver: " + System.getProperty("rome.fetcher.version", "UNKNOWN"));
}
/**
* @return the User-Agent currently being sent to servers
*/
@Override
public synchronized String getUserAgent() {
return userAgent;
}
/**
* @param string The User-Agent to sent to servers
*/
@Override
public synchronized void setUserAgent(final String string) {
userAgent = string;
}
/**
* @param eventType The event type to fire
* @param connection the current connection
*/
protected void fireEvent(final String eventType, final URLConnection connection) {
fireEvent(eventType, connection.getURL().toExternalForm(), null);
}
/**
* @param eventType The event type to fire
* @param connection the current connection
* @param feed The feed to pass to the event
*/
protected void fireEvent(final String eventType, final URLConnection connection, final SyndFeed feed) {
fireEvent(eventType, connection.getURL().toExternalForm(), feed);
}
/**
* @param eventType The event type to fire
* @param urlStr the current url as a string
*/
protected void fireEvent(final String eventType, final String urlStr) {
fireEvent(eventType, urlStr, null);
}
/**
* @param eventType The event type to fire
* @param urlStr the current url as a string
* @param feed The feed to pass to the event
*/
protected void fireEvent(final String eventType, final String urlStr, final SyndFeed feed) {
final FetcherEvent fetcherEvent = new FetcherEvent(this, urlStr, eventType, feed);
synchronized (listeners) {
for (final FetcherListener fetcherEventListener : listeners) {
fetcherEventListener.fetcherEvent(fetcherEvent);
}
}
}
@Override
public void addFetcherEventListener(final FetcherListener listener) {
if (listener != null) {
listeners.add(listener);
}
}
@Override
public void removeFetcherEventListener(final FetcherListener listener) {
if (listener != null) {
listeners.remove(listener);
}
}
/**
* @return Returns the useDeltaEncoding.
*/
@Override
public synchronized boolean isUsingDeltaEncoding() {
return usingDeltaEncoding;
}
/**
* @param useDeltaEncoding The useDeltaEncoding to set.
*/
@Override
public synchronized void setUsingDeltaEncoding(final boolean useDeltaEncoding) {
usingDeltaEncoding = useDeltaEncoding;
}
/**
* <p>
* Handles HTTP error codes.
* </p>
*
* @param responseCode the HTTP response code
* @throws FetcherException if response code is in the range 400 to 599 inclusive
*/
protected void handleErrorCodes(final int responseCode) throws FetcherException {
// Handle 2xx codes as OK, so ignore them here
// 3xx codes are handled by the HttpURLConnection class
if (responseCode == 403) {
// Authentication is required
throwAuthenticationError(responseCode);
} else if (responseCode >= 400 && responseCode < 500) {
throw4XXError(responseCode);
} else if (responseCode >= 500 && responseCode < 600) {
throw new FetcherException(responseCode, "The server encounted an error. HTTP Response code was:" + responseCode);
}
}
protected void throw4XXError(final int responseCode) throws FetcherException {
throw new FetcherException(responseCode, "The requested resource could not be found. HTTP Response code was:" + responseCode);
}
protected void throwAuthenticationError(final int responseCode) throws FetcherException {
throw new FetcherException(responseCode, "Authentication required for that resource. HTTP Response code was:" + responseCode);
}
/**
* <p>
* Combine the entries in two feeds into a single feed.
* </p>
*
* <p>
* The returned feed will have the same data as the newFeed parameter, with the entries from
* originalFeed appended to the end of its entries.
* </p>
*
* @param originalFeed
* @param newFeed
* @return
*/
public static SyndFeed combineFeeds(final SyndFeed originalFeed, final SyndFeed newFeed) {
try {
final SyndFeed result = (SyndFeed) newFeed.clone();
result.getEntries().addAll(result.getEntries().size(), originalFeed.getEntries());
return result;
} catch (final CloneNotSupportedException e) {
final IllegalArgumentException iae = new IllegalArgumentException("Cannot clone feed");
iae.initCause(e);
throw iae;
}
}
public boolean isPreserveWireFeed() {
return preserveWireFeed;
}
@Override
public void setPreserveWireFeed(final boolean preserveWireFeed) {
this.preserveWireFeed = preserveWireFeed;
}
}

View file

@ -0,0 +1,33 @@
package com.rometools.fetcher.impl;
import java.beans.EventSetDescriptor;
import java.beans.SimpleBeanInfo;
import java.lang.reflect.Method;
import com.rometools.fetcher.FetcherEvent;
import com.rometools.fetcher.FetcherListener;
public class AbstractFeedFetcherBeanInfo extends SimpleBeanInfo {
@Override
public EventSetDescriptor[] getEventSetDescriptors() {
try {
// get the class object which we'll describe
final Class<AbstractFeedFetcher> clz = AbstractFeedFetcher.class;
final Method addMethod = clz.getMethod("addFetcherEventListener", new Class[] { FetcherListener.class });
final Method removeMethod = clz.getMethod("removeFetcherEventListener", new Class[] { FetcherListener.class });
final Method listenerMethod = FetcherListener.class.getMethod("fetcherEvent", new Class[] { FetcherEvent.class });
final EventSetDescriptor est = new EventSetDescriptor("fetcherEvent", clz, new Method[] { listenerMethod }, addMethod, removeMethod);
return new EventSetDescriptor[] { est };
} catch (final Exception e) {
// IntrospectionException, SecurityException and/or NoSuchMethodException can be thrown
// here. The best we can do is to convert them to runtime exceptions
throw new RuntimeException(e);
}
}
}

View file

@ -0,0 +1,158 @@
/*
* Copyright 2005 Sun Microsystems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rometools.fetcher.impl;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.URL;
import com.rometools.utils.IO;
/**
* Disk based feed cache.
*/
public class DiskFeedInfoCache implements FeedFetcherCache {
protected String cachePath = null;
public DiskFeedInfoCache(final String cachePath) {
this.cachePath = cachePath;
}
@Override
public SyndFeedInfo getFeedInfo(final URL url) {
final String fileName = generateFilename(url);
return getFeedInfo(fileName);
}
@Override
public void setFeedInfo(final URL url, final SyndFeedInfo feedInfo) {
final String fileName = generateFilename(url);
FileOutputStream fos = null;
ObjectOutputStream oos = null;
try {
fos = new FileOutputStream(fileName);
oos = new ObjectOutputStream(fos);
oos.writeObject(feedInfo);
fos.flush();
} catch (final FileNotFoundException e) {
throw new RuntimeException("Error while writing to cache", e);
} catch (final IOException e) {
throw new RuntimeException("Error while writing to cache", e);
} finally {
IO.closeQuietly(fos);
IO.closeQuietly(oos);
}
}
@Override
public synchronized void clear() {
final File file = new File(cachePath);
// only do the delete if the directory exists
if (file.exists() && file.canWrite()) {
// make the directory empty
final String[] files = file.list();
final int len = files.length;
for (int i = 0; i < len; i++) {
final File deleteMe = new File(cachePath + File.separator + files[i]);
deleteMe.delete();
}
// don't delete the cache directory
}
}
@Override
public SyndFeedInfo remove(final URL url) {
final String fileName = generateFilename(url);
final SyndFeedInfo info = getFeedInfo(fileName);
if (info != null) {
final File file = new File(fileName);
if (file.exists()) {
file.delete();
}
}
return info;
}
private SyndFeedInfo getFeedInfo(final String fileName) {
SyndFeedInfo info = null;
FileInputStream fis = null;
ObjectInputStream ois = null;
try {
fis = new FileInputStream(fileName);
ois = new ObjectInputStream(fis);
info = (SyndFeedInfo) ois.readObject();
} catch (final FileNotFoundException e) {
// feed is not cached yet
} catch (final ClassNotFoundException e) {
throw new RuntimeException("Unable to read from cache", e);
} catch (final IOException e) {
throw new RuntimeException("Unable to read from cache", e);
} finally {
IO.closeQuietly(fis);
IO.closeQuietly(ois);
}
return info;
}
private static String replaceNonAlphanumeric(final String string, final char character) {
final StringBuffer buffer = new StringBuffer(string.length());
for (final char singleChar : string.toCharArray()) {
if (Character.isLetterOrDigit(singleChar)) {
buffer.append(singleChar);
} else {
buffer.append(character);
}
}
return buffer.toString();
}
private String generateFilename(final URL url) {
return cachePath + File.separator + "feed_" + replaceNonAlphanumeric(url.toString(), '_').trim();
}
}

View file

@ -0,0 +1,60 @@
/*
* Copyright 2004 Sun Microsystems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.rometools.fetcher.impl;
import java.net.URL;
/**
* <p>
* An interface to allow caching of feed details. Implementing this allows the
* {@link com.rometools.fetcher.io.HttpURLFeedFetcher} class to enable conditional gets
* </p>
*
* @author Nick Lothian
*
*/
public interface FeedFetcherCache {
/**
* Get a SyndFeedInfo object from the cache.
*
* @param feedUrl The url of the feed
* @return A SyndFeedInfo or null if it is not in the cache
*/
public SyndFeedInfo getFeedInfo(URL feedUrl);
/**
* Add a SyndFeedInfo object to the cache
*
* @param feedUrl The url of the feed
* @param syndFeedInfo A SyndFeedInfo for the feed
*/
public void setFeedInfo(URL feedUrl, SyndFeedInfo syndFeedInfo);
/**
* Removes all items from the cache.
*/
public void clear();
/**
* Removes the SyndFeedInfo identified by the url from the cache.
*
* @return The removed SyndFeedInfo
*/
public SyndFeedInfo remove(URL feedUrl);
}

Some files were not shown because too many files have changed in this diff Show more