repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
KaesDingeling/Hybrid-Menu
HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/components/LeftMenu.java
// Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/data/enums/ToggleMode.java // public enum ToggleMode { // NORMAL, MINIMAL; // } // // Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/data/interfaces/MenuComponent.java // public interface MenuComponent<T extends Component> extends Component { // public <C extends MenuComponent<?>> C add(C c); // public <C extends MenuComponent<?>> C addAsFirst(C c); // public <C extends MenuComponent<?>> C addAt(C c, int index); // public int count(); // public <C extends MenuComponent<?>> T remove(C c); // public List<MenuComponent<?>> getList(); // public String getRootStyle(); // } // // Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/utils/Utils.java // public class Utils { // public static <C extends MenuComponent<?>> C setDefaults(C c) { // c.setPrimaryStyleName(c.getRootStyle()); // return c; // } // // public static <C extends MenuComponent<?>> C setTopMenuDefaults(C c) { // if (c.getCaption() != null && !c.getCaption().trim().isEmpty()) { // c.setCaption(null); // } // c.setPrimaryStyleName(c.getRootStyle()); // return c; // } // }
import java.util.ArrayList; import java.util.List; import com.vaadin.server.VaadinSession; import com.vaadin.ui.Component; import com.vaadin.ui.VerticalLayout; import kaesdingeling.hybridmenu.data.enums.ToggleMode; import kaesdingeling.hybridmenu.data.interfaces.MenuComponent; import kaesdingeling.hybridmenu.utils.Utils;
switch (toggleMode) { case MINIMAL: setWidth(50, Unit.PIXELS); getParent().addStyleName(ToggleMode.MINIMAL.name().toLowerCase()); break; case NORMAL: setWidth(250, Unit.PIXELS); getParent().removeStyleName(ToggleMode.MINIMAL.name().toLowerCase()); break; } VaadinSession session = VaadinSession.getCurrent(); if (session != null) { session.setAttribute(ToggleMode.class, toggleMode); } } return this; } public ToggleMode getToggleMode() { VaadinSession session = VaadinSession.getCurrent(); if (session != null) { ToggleMode toggleMode = session.getAttribute(ToggleMode.class); if (toggleMode != null) { return toggleMode; } } return ToggleMode.NORMAL; } public <C extends MenuComponent<?>> C add(C c) {
// Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/data/enums/ToggleMode.java // public enum ToggleMode { // NORMAL, MINIMAL; // } // // Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/data/interfaces/MenuComponent.java // public interface MenuComponent<T extends Component> extends Component { // public <C extends MenuComponent<?>> C add(C c); // public <C extends MenuComponent<?>> C addAsFirst(C c); // public <C extends MenuComponent<?>> C addAt(C c, int index); // public int count(); // public <C extends MenuComponent<?>> T remove(C c); // public List<MenuComponent<?>> getList(); // public String getRootStyle(); // } // // Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/utils/Utils.java // public class Utils { // public static <C extends MenuComponent<?>> C setDefaults(C c) { // c.setPrimaryStyleName(c.getRootStyle()); // return c; // } // // public static <C extends MenuComponent<?>> C setTopMenuDefaults(C c) { // if (c.getCaption() != null && !c.getCaption().trim().isEmpty()) { // c.setCaption(null); // } // c.setPrimaryStyleName(c.getRootStyle()); // return c; // } // } // Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/components/LeftMenu.java import java.util.ArrayList; import java.util.List; import com.vaadin.server.VaadinSession; import com.vaadin.ui.Component; import com.vaadin.ui.VerticalLayout; import kaesdingeling.hybridmenu.data.enums.ToggleMode; import kaesdingeling.hybridmenu.data.interfaces.MenuComponent; import kaesdingeling.hybridmenu.utils.Utils; switch (toggleMode) { case MINIMAL: setWidth(50, Unit.PIXELS); getParent().addStyleName(ToggleMode.MINIMAL.name().toLowerCase()); break; case NORMAL: setWidth(250, Unit.PIXELS); getParent().removeStyleName(ToggleMode.MINIMAL.name().toLowerCase()); break; } VaadinSession session = VaadinSession.getCurrent(); if (session != null) { session.setAttribute(ToggleMode.class, toggleMode); } } return this; } public ToggleMode getToggleMode() { VaadinSession session = VaadinSession.getCurrent(); if (session != null) { ToggleMode toggleMode = session.getAttribute(ToggleMode.class); if (toggleMode != null) { return toggleMode; } } return ToggleMode.NORMAL; } public <C extends MenuComponent<?>> C add(C c) {
addComponent(Utils.setDefaults(c));
KaesDingeling/Hybrid-Menu
HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/components/Notification.java
// Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/data/MenuConfig.java // @SuppressWarnings("deprecation") // public class MenuConfig { // public static MenuConfig get() { // return new MenuConfig(); // } // // private DesignItem designItem = DesignItem.getDarkDesign(); // // private FontIcon subMenuIcon = FontAwesome.ANGLE_UP; // // private Resource notificationButtonIcon = FontAwesome.BELL; // private Resource notificationButtonEmptyIcon = FontAwesome.BELL_O; // private Resource notificationCenterCloseIcon = FontAwesome.ANGLE_RIGHT; // private Resource notificationRemoveIcon = FontAwesome.TIMES; // // private NotificationPosition notificationPopupPosition = NotificationPosition.BOTTOM; // private NotificationPosition notificationButtonLinePosition = NotificationPosition.BOTTOM; // // private long notificationDisplayTime = 5000; // // private int notificationPopupMaxContentLength = 100; // // private Resource breadcrumbSeperatorIcon = FontAwesome.ANGLE_RIGHT; // private boolean breadcrumbs = true; // // public static int notificationQueueMax = 200; // // public DesignItem getDesignItem() { // return designItem; // } // public MenuConfig withDesignItem(DesignItem designItem) { // this.designItem = designItem; // return this; // } // public FontIcon getSubMenuIcon() { // return subMenuIcon; // } // public MenuConfig withSubMenuIcon(FontIcon subMenuIcon) { // this.subMenuIcon = subMenuIcon; // return this; // } // public Resource getNotificationButtonIcon() { // return notificationButtonIcon; // } // public MenuConfig withNotificationButtonIcon(Resource notificationButtonIcon) { // this.notificationButtonIcon = notificationButtonIcon; // return this; // } // public Resource getNotificationButtonEmptyIcon() { // return notificationButtonEmptyIcon; // } // public MenuConfig withNotificationButtonEmptyIcon(Resource notificationButtonEmptyIcon) { // this.notificationButtonEmptyIcon = notificationButtonEmptyIcon; // return this; // } // public Resource getNotificationCenterCloseIcon() { // return notificationCenterCloseIcon; // } // public MenuConfig withNotificationCenterCloseIcon(Resource notificationCenterCloseIcon) { // this.notificationCenterCloseIcon = notificationCenterCloseIcon; // return this; // } // public Resource getNotificationRemoveIcon() { // return notificationRemoveIcon; // } // public MenuConfig withNotificationRemoveIcon(Resource notificationRemoveIcon) { // this.notificationRemoveIcon = notificationRemoveIcon; // return this; // } // public NotificationPosition getNotificationPopupPosition() { // return notificationPopupPosition; // } // public MenuConfig setNotificationPopupPosition(NotificationPosition notificationPopupPosition) { // this.notificationPopupPosition = notificationPopupPosition; // return this; // } // public NotificationPosition getNotificationButtonLinePosition() { // return notificationButtonLinePosition; // } // public MenuConfig setNotificationButtonLinePosition(NotificationPosition notificationButtonLinePosition) { // this.notificationButtonLinePosition = notificationButtonLinePosition; // return this; // } // public long getNotificationDisplayTime() { // return notificationDisplayTime; // } // public MenuConfig setNotificationDisplayTime(long notificationDisplayTime) { // this.notificationDisplayTime = notificationDisplayTime; // return this; // } // public int getNotificationPopupMaxContentLength() { // return notificationPopupMaxContentLength; // } // public MenuConfig setNotificationPopupMaxContentLength(int notificationPopupMaxContentLength) { // this.notificationPopupMaxContentLength = notificationPopupMaxContentLength; // return this; // } // public Resource getBreadcrumbSeperatorIcon() { // return breadcrumbSeperatorIcon; // } // public MenuConfig withBreadcrumbSeperatorIcon(Resource breadcrumbSeperatorIcon) { // this.breadcrumbSeperatorIcon = breadcrumbSeperatorIcon; // return this; // } // public boolean isBreadcrumbs() { // return breadcrumbs; // } // public MenuConfig withBreadcrumbs(boolean breadcrumbs) { // this.breadcrumbs = breadcrumbs; // return this; // } // }
import java.util.Date; import org.ocpsoft.prettytime.PrettyTime; import com.vaadin.server.Resource; import com.vaadin.server.VaadinSession; import com.vaadin.shared.ui.ContentMode; import com.vaadin.ui.Button; import com.vaadin.ui.CssLayout; import com.vaadin.ui.Label; import kaesdingeling.hybridmenu.data.MenuConfig;
package kaesdingeling.hybridmenu.components; public class Notification extends CssLayout { private static final long serialVersionUID = 3572068667525046443L;
// Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/data/MenuConfig.java // @SuppressWarnings("deprecation") // public class MenuConfig { // public static MenuConfig get() { // return new MenuConfig(); // } // // private DesignItem designItem = DesignItem.getDarkDesign(); // // private FontIcon subMenuIcon = FontAwesome.ANGLE_UP; // // private Resource notificationButtonIcon = FontAwesome.BELL; // private Resource notificationButtonEmptyIcon = FontAwesome.BELL_O; // private Resource notificationCenterCloseIcon = FontAwesome.ANGLE_RIGHT; // private Resource notificationRemoveIcon = FontAwesome.TIMES; // // private NotificationPosition notificationPopupPosition = NotificationPosition.BOTTOM; // private NotificationPosition notificationButtonLinePosition = NotificationPosition.BOTTOM; // // private long notificationDisplayTime = 5000; // // private int notificationPopupMaxContentLength = 100; // // private Resource breadcrumbSeperatorIcon = FontAwesome.ANGLE_RIGHT; // private boolean breadcrumbs = true; // // public static int notificationQueueMax = 200; // // public DesignItem getDesignItem() { // return designItem; // } // public MenuConfig withDesignItem(DesignItem designItem) { // this.designItem = designItem; // return this; // } // public FontIcon getSubMenuIcon() { // return subMenuIcon; // } // public MenuConfig withSubMenuIcon(FontIcon subMenuIcon) { // this.subMenuIcon = subMenuIcon; // return this; // } // public Resource getNotificationButtonIcon() { // return notificationButtonIcon; // } // public MenuConfig withNotificationButtonIcon(Resource notificationButtonIcon) { // this.notificationButtonIcon = notificationButtonIcon; // return this; // } // public Resource getNotificationButtonEmptyIcon() { // return notificationButtonEmptyIcon; // } // public MenuConfig withNotificationButtonEmptyIcon(Resource notificationButtonEmptyIcon) { // this.notificationButtonEmptyIcon = notificationButtonEmptyIcon; // return this; // } // public Resource getNotificationCenterCloseIcon() { // return notificationCenterCloseIcon; // } // public MenuConfig withNotificationCenterCloseIcon(Resource notificationCenterCloseIcon) { // this.notificationCenterCloseIcon = notificationCenterCloseIcon; // return this; // } // public Resource getNotificationRemoveIcon() { // return notificationRemoveIcon; // } // public MenuConfig withNotificationRemoveIcon(Resource notificationRemoveIcon) { // this.notificationRemoveIcon = notificationRemoveIcon; // return this; // } // public NotificationPosition getNotificationPopupPosition() { // return notificationPopupPosition; // } // public MenuConfig setNotificationPopupPosition(NotificationPosition notificationPopupPosition) { // this.notificationPopupPosition = notificationPopupPosition; // return this; // } // public NotificationPosition getNotificationButtonLinePosition() { // return notificationButtonLinePosition; // } // public MenuConfig setNotificationButtonLinePosition(NotificationPosition notificationButtonLinePosition) { // this.notificationButtonLinePosition = notificationButtonLinePosition; // return this; // } // public long getNotificationDisplayTime() { // return notificationDisplayTime; // } // public MenuConfig setNotificationDisplayTime(long notificationDisplayTime) { // this.notificationDisplayTime = notificationDisplayTime; // return this; // } // public int getNotificationPopupMaxContentLength() { // return notificationPopupMaxContentLength; // } // public MenuConfig setNotificationPopupMaxContentLength(int notificationPopupMaxContentLength) { // this.notificationPopupMaxContentLength = notificationPopupMaxContentLength; // return this; // } // public Resource getBreadcrumbSeperatorIcon() { // return breadcrumbSeperatorIcon; // } // public MenuConfig withBreadcrumbSeperatorIcon(Resource breadcrumbSeperatorIcon) { // this.breadcrumbSeperatorIcon = breadcrumbSeperatorIcon; // return this; // } // public boolean isBreadcrumbs() { // return breadcrumbs; // } // public MenuConfig withBreadcrumbs(boolean breadcrumbs) { // this.breadcrumbs = breadcrumbs; // return this; // } // } // Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/components/Notification.java import java.util.Date; import org.ocpsoft.prettytime.PrettyTime; import com.vaadin.server.Resource; import com.vaadin.server.VaadinSession; import com.vaadin.shared.ui.ContentMode; import com.vaadin.ui.Button; import com.vaadin.ui.CssLayout; import com.vaadin.ui.Label; import kaesdingeling.hybridmenu.data.MenuConfig; package kaesdingeling.hybridmenu.components; public class Notification extends CssLayout { private static final long serialVersionUID = 3572068667525046443L;
private MenuConfig menuConfig = VaadinSession.getCurrent().getAttribute(MenuConfig.class);
KaesDingeling/Hybrid-Menu
HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/components/ColorPicker.java
// Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/data/interfaces/ValueChangeListener.java // public interface ValueChangeListener<T> { // public void change(T value); // } // // Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/design/DesignColor.java // public class DesignColor { // private int red = 255; // private int green = 255; // private int blue = 255; // private int alpha = 255; // // public static DesignColor get() { // return new DesignColor(); // } // public static DesignColor get(Color color) { // return new DesignColor(color); // } // public static DesignColor get(int red, int green, int blue) { // return new DesignColor(red, green, blue); // } // // public DesignColor() { // // } // public DesignColor(Color color) { // convert(color); // } // public DesignColor(int red, int green, int blue) { // this.red = red; // this.green = green; // this.blue = blue; // } // public int getRed() { // return red; // } // public void setRed(int red) { // this.red = red; // } // public int getGreen() { // return green; // } // public void setGreen(int green) { // this.green = green; // } // public int getBlue() { // return blue; // } // public void setBlue(int blue) { // this.blue = blue; // } // public int getAlpha() { // return alpha; // } // public void setAlpha(int alpha) { // this.alpha = alpha; // } // public void convert(Color color) { // red = color.getRed(); // green = color.getGreen(); // blue = color.getBlue(); // alpha = color.getAlpha(); // } // public Color getColor() { // return new Color(red, green, blue, alpha); // } // }
import java.util.HashSet; import java.util.Set; import com.vaadin.shared.ui.colorpicker.Color; import com.vaadin.ui.Button; import com.vaadin.ui.UI; import kaesdingeling.hybridmenu.data.interfaces.ValueChangeListener; import kaesdingeling.hybridmenu.design.DesignColor;
package kaesdingeling.hybridmenu.components; public class ColorPicker extends Button { private static final long serialVersionUID = 2366670234096059323L; private Color value = null; private boolean showCss = false;
// Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/data/interfaces/ValueChangeListener.java // public interface ValueChangeListener<T> { // public void change(T value); // } // // Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/design/DesignColor.java // public class DesignColor { // private int red = 255; // private int green = 255; // private int blue = 255; // private int alpha = 255; // // public static DesignColor get() { // return new DesignColor(); // } // public static DesignColor get(Color color) { // return new DesignColor(color); // } // public static DesignColor get(int red, int green, int blue) { // return new DesignColor(red, green, blue); // } // // public DesignColor() { // // } // public DesignColor(Color color) { // convert(color); // } // public DesignColor(int red, int green, int blue) { // this.red = red; // this.green = green; // this.blue = blue; // } // public int getRed() { // return red; // } // public void setRed(int red) { // this.red = red; // } // public int getGreen() { // return green; // } // public void setGreen(int green) { // this.green = green; // } // public int getBlue() { // return blue; // } // public void setBlue(int blue) { // this.blue = blue; // } // public int getAlpha() { // return alpha; // } // public void setAlpha(int alpha) { // this.alpha = alpha; // } // public void convert(Color color) { // red = color.getRed(); // green = color.getGreen(); // blue = color.getBlue(); // alpha = color.getAlpha(); // } // public Color getColor() { // return new Color(red, green, blue, alpha); // } // } // Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/components/ColorPicker.java import java.util.HashSet; import java.util.Set; import com.vaadin.shared.ui.colorpicker.Color; import com.vaadin.ui.Button; import com.vaadin.ui.UI; import kaesdingeling.hybridmenu.data.interfaces.ValueChangeListener; import kaesdingeling.hybridmenu.design.DesignColor; package kaesdingeling.hybridmenu.components; public class ColorPicker extends Button { private static final long serialVersionUID = 2366670234096059323L; private Color value = null; private boolean showCss = false;
private Set<ValueChangeListener<Color>> valueChangeListenerList = new HashSet<ValueChangeListener<Color>>();
KaesDingeling/Hybrid-Menu
HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/components/ColorPicker.java
// Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/data/interfaces/ValueChangeListener.java // public interface ValueChangeListener<T> { // public void change(T value); // } // // Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/design/DesignColor.java // public class DesignColor { // private int red = 255; // private int green = 255; // private int blue = 255; // private int alpha = 255; // // public static DesignColor get() { // return new DesignColor(); // } // public static DesignColor get(Color color) { // return new DesignColor(color); // } // public static DesignColor get(int red, int green, int blue) { // return new DesignColor(red, green, blue); // } // // public DesignColor() { // // } // public DesignColor(Color color) { // convert(color); // } // public DesignColor(int red, int green, int blue) { // this.red = red; // this.green = green; // this.blue = blue; // } // public int getRed() { // return red; // } // public void setRed(int red) { // this.red = red; // } // public int getGreen() { // return green; // } // public void setGreen(int green) { // this.green = green; // } // public int getBlue() { // return blue; // } // public void setBlue(int blue) { // this.blue = blue; // } // public int getAlpha() { // return alpha; // } // public void setAlpha(int alpha) { // this.alpha = alpha; // } // public void convert(Color color) { // red = color.getRed(); // green = color.getGreen(); // blue = color.getBlue(); // alpha = color.getAlpha(); // } // public Color getColor() { // return new Color(red, green, blue, alpha); // } // }
import java.util.HashSet; import java.util.Set; import com.vaadin.shared.ui.colorpicker.Color; import com.vaadin.ui.Button; import com.vaadin.ui.UI; import kaesdingeling.hybridmenu.data.interfaces.ValueChangeListener; import kaesdingeling.hybridmenu.design.DesignColor;
package kaesdingeling.hybridmenu.components; public class ColorPicker extends Button { private static final long serialVersionUID = 2366670234096059323L; private Color value = null; private boolean showCss = false; private Set<ValueChangeListener<Color>> valueChangeListenerList = new HashSet<ValueChangeListener<Color>>(); public ColorPicker() { build(); } public ColorPicker(boolean showCss) { this.showCss = showCss; build(); } public ColorPicker(Color value) { this.value = value; build(); }
// Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/data/interfaces/ValueChangeListener.java // public interface ValueChangeListener<T> { // public void change(T value); // } // // Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/design/DesignColor.java // public class DesignColor { // private int red = 255; // private int green = 255; // private int blue = 255; // private int alpha = 255; // // public static DesignColor get() { // return new DesignColor(); // } // public static DesignColor get(Color color) { // return new DesignColor(color); // } // public static DesignColor get(int red, int green, int blue) { // return new DesignColor(red, green, blue); // } // // public DesignColor() { // // } // public DesignColor(Color color) { // convert(color); // } // public DesignColor(int red, int green, int blue) { // this.red = red; // this.green = green; // this.blue = blue; // } // public int getRed() { // return red; // } // public void setRed(int red) { // this.red = red; // } // public int getGreen() { // return green; // } // public void setGreen(int green) { // this.green = green; // } // public int getBlue() { // return blue; // } // public void setBlue(int blue) { // this.blue = blue; // } // public int getAlpha() { // return alpha; // } // public void setAlpha(int alpha) { // this.alpha = alpha; // } // public void convert(Color color) { // red = color.getRed(); // green = color.getGreen(); // blue = color.getBlue(); // alpha = color.getAlpha(); // } // public Color getColor() { // return new Color(red, green, blue, alpha); // } // } // Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/components/ColorPicker.java import java.util.HashSet; import java.util.Set; import com.vaadin.shared.ui.colorpicker.Color; import com.vaadin.ui.Button; import com.vaadin.ui.UI; import kaesdingeling.hybridmenu.data.interfaces.ValueChangeListener; import kaesdingeling.hybridmenu.design.DesignColor; package kaesdingeling.hybridmenu.components; public class ColorPicker extends Button { private static final long serialVersionUID = 2366670234096059323L; private Color value = null; private boolean showCss = false; private Set<ValueChangeListener<Color>> valueChangeListenerList = new HashSet<ValueChangeListener<Color>>(); public ColorPicker() { build(); } public ColorPicker(boolean showCss) { this.showCss = showCss; build(); } public ColorPicker(Color value) { this.value = value; build(); }
public ColorPicker(DesignColor value) {
KaesDingeling/Hybrid-Menu
HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/components/BreadCrumbs.java
// Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/data/interfaces/MenuComponent.java // public interface MenuComponent<T extends Component> extends Component { // public <C extends MenuComponent<?>> C add(C c); // public <C extends MenuComponent<?>> C addAsFirst(C c); // public <C extends MenuComponent<?>> C addAt(C c, int index); // public int count(); // public <C extends MenuComponent<?>> T remove(C c); // public List<MenuComponent<?>> getList(); // public String getRootStyle(); // } // // Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/utils/Utils.java // public class Utils { // public static <C extends MenuComponent<?>> C setDefaults(C c) { // c.setPrimaryStyleName(c.getRootStyle()); // return c; // } // // public static <C extends MenuComponent<?>> C setTopMenuDefaults(C c) { // if (c.getCaption() != null && !c.getCaption().trim().isEmpty()) { // c.setCaption(null); // } // c.setPrimaryStyleName(c.getRootStyle()); // return c; // } // }
import java.util.ArrayList; import java.util.List; import com.vaadin.ui.Component; import com.vaadin.ui.HorizontalLayout; import kaesdingeling.hybridmenu.data.interfaces.MenuComponent; import kaesdingeling.hybridmenu.utils.Utils;
package kaesdingeling.hybridmenu.components; public class BreadCrumbs extends HorizontalLayout implements MenuComponent<BreadCrumbs> { private static final long serialVersionUID = 5825929144162024583L; private HMButton root = null; public BreadCrumbs() { setStyleName("breadcrumbs"); setWidth(100, Unit.PERCENTAGE); setMargin(false); setSpacing(true); } public BreadCrumbs setRoot(HMButton root) { this.root = HMButton.get().withCaption(root.getCaption()).withStyleName("clickable").withClickListener(e -> root.click()); add(this.root); return this; } public HMButton getRoot() { return this.root; } public BreadCrumbs clear() { for (MenuComponent<?> menuComponent : getList()) { if (!menuComponent.equals(root)) { remove(menuComponent); } } return this; } public <C extends MenuComponent<?>> C add(C c) {
// Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/data/interfaces/MenuComponent.java // public interface MenuComponent<T extends Component> extends Component { // public <C extends MenuComponent<?>> C add(C c); // public <C extends MenuComponent<?>> C addAsFirst(C c); // public <C extends MenuComponent<?>> C addAt(C c, int index); // public int count(); // public <C extends MenuComponent<?>> T remove(C c); // public List<MenuComponent<?>> getList(); // public String getRootStyle(); // } // // Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/utils/Utils.java // public class Utils { // public static <C extends MenuComponent<?>> C setDefaults(C c) { // c.setPrimaryStyleName(c.getRootStyle()); // return c; // } // // public static <C extends MenuComponent<?>> C setTopMenuDefaults(C c) { // if (c.getCaption() != null && !c.getCaption().trim().isEmpty()) { // c.setCaption(null); // } // c.setPrimaryStyleName(c.getRootStyle()); // return c; // } // } // Path: HybridMenu-addon/src/main/java/kaesdingeling/hybridmenu/components/BreadCrumbs.java import java.util.ArrayList; import java.util.List; import com.vaadin.ui.Component; import com.vaadin.ui.HorizontalLayout; import kaesdingeling.hybridmenu.data.interfaces.MenuComponent; import kaesdingeling.hybridmenu.utils.Utils; package kaesdingeling.hybridmenu.components; public class BreadCrumbs extends HorizontalLayout implements MenuComponent<BreadCrumbs> { private static final long serialVersionUID = 5825929144162024583L; private HMButton root = null; public BreadCrumbs() { setStyleName("breadcrumbs"); setWidth(100, Unit.PERCENTAGE); setMargin(false); setSpacing(true); } public BreadCrumbs setRoot(HMButton root) { this.root = HMButton.get().withCaption(root.getCaption()).withStyleName("clickable").withClickListener(e -> root.click()); add(this.root); return this; } public HMButton getRoot() { return this.root; } public BreadCrumbs clear() { for (MenuComponent<?> menuComponent : getList()) { if (!menuComponent.equals(root)) { remove(menuComponent); } } return this; } public <C extends MenuComponent<?>> C add(C c) {
addComponent(Utils.setDefaults(c));
tyzlmjj/AndroidUI
ChangeTheme/app/src/main/java/com/mjj/changetheme/activity/SecondActivity.java
// Path: ChangeTheme/app/src/main/java/com/mjj/changetheme/app/MyAppliction.java // public class MyAppliction extends Application { // // private static int MyTheme = 0; // @Override // public void onCreate() { // super.onCreate(); // getLocalData(); // } // // private void getLocalData() { // SharedPreferences sharedPreferences = getSharedPreferences("theme",MODE_PRIVATE); // MyTheme = sharedPreferences.getInt("theme",0); // // } // public static int getThemeValue(){ // return MyTheme; // } // // public static void setThemeValue(int themeValue){ // MyTheme = themeValue; // } // // public static int getThemeResources(){ // switch (MyTheme){ // case Theme.DAYTHEME: // return Theme.RESOURCES_DAYTHEME; // case Theme.NIGHTTHEME: // return Theme.RESOURCES_NIGHTTHEME; // default: // return Theme.RESOURCES_DAYTHEME; // } // } // // // }
import android.os.Bundle; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import com.mjj.changetheme.R; import com.mjj.changetheme.app.MyAppliction;
package com.mjj.changetheme.activity; public class SecondActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) {
// Path: ChangeTheme/app/src/main/java/com/mjj/changetheme/app/MyAppliction.java // public class MyAppliction extends Application { // // private static int MyTheme = 0; // @Override // public void onCreate() { // super.onCreate(); // getLocalData(); // } // // private void getLocalData() { // SharedPreferences sharedPreferences = getSharedPreferences("theme",MODE_PRIVATE); // MyTheme = sharedPreferences.getInt("theme",0); // // } // public static int getThemeValue(){ // return MyTheme; // } // // public static void setThemeValue(int themeValue){ // MyTheme = themeValue; // } // // public static int getThemeResources(){ // switch (MyTheme){ // case Theme.DAYTHEME: // return Theme.RESOURCES_DAYTHEME; // case Theme.NIGHTTHEME: // return Theme.RESOURCES_NIGHTTHEME; // default: // return Theme.RESOURCES_DAYTHEME; // } // } // // // } // Path: ChangeTheme/app/src/main/java/com/mjj/changetheme/activity/SecondActivity.java import android.os.Bundle; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import com.mjj.changetheme.R; import com.mjj.changetheme.app.MyAppliction; package com.mjj.changetheme.activity; public class SecondActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) {
setTheme(MyAppliction.getThemeResources());
tyzlmjj/AndroidUI
ClickEffect/app/src/main/java/com/mjj/clickeffect/ListActivity.java
// Path: ClickEffect/app/src/main/java/com/mjj/clickeffect/adapter/ListAdapter.java // public class ListAdapter extends BaseAdapter{ // // // private Context mContext; // // private TypedValue mTypedValue; // private TypedValue mTypedValue_Borderless; // // public ListAdapter(Context context) { // mContext =context; // // mTypedValue = new TypedValue(); // mContext.getTheme().resolveAttribute(R.attr.selectableItemBackground, mTypedValue, true); // mTypedValue_Borderless = new TypedValue(); // mContext.getTheme().resolveAttribute(R.attr.selectableItemBackgroundBorderless, mTypedValue_Borderless, true); // } // // @Override // public int getCount() { // return 100; // } // // @Override // public Object getItem(int position) { // return position; // } // // @Override // public long getItemId(int position) { // return position; // } // // @SuppressLint("NewApi") // @Override // public View getView(int position, View convertView, ViewGroup parent) { // MyViewHolder viewHolder = null; // if(convertView == null){ // viewHolder = new MyViewHolder(); // convertView = LayoutInflater.from(mContext).inflate(android.R.layout.simple_list_item_1,parent,false); // viewHolder.textView = (TextView) convertView.findViewById(android.R.id.text1); // convertView.setTag(viewHolder); // }else{ // viewHolder = (MyViewHolder) convertView.getTag(); // } // // if(position%2 == 0){ // convertView.setBackgroundResource(mTypedValue_Borderless.resourceId); // viewHolder.textView.setText("无边界的波纹效果,5.0以上"); // }else{ // convertView.setBackgroundResource(mTypedValue.resourceId); // viewHolder.textView.setText("有边界的波纹效果,5.0以上"); // } // // return convertView; // } // // class MyViewHolder{ // TextView textView; // } // // // }
import android.os.Bundle; import android.widget.ListView; import com.mjj.clickeffect.adapter.ListAdapter;
package com.mjj.clickeffect; public class ListActivity extends ABSActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); ListView list = (ListView) findViewById(R.id.listView);
// Path: ClickEffect/app/src/main/java/com/mjj/clickeffect/adapter/ListAdapter.java // public class ListAdapter extends BaseAdapter{ // // // private Context mContext; // // private TypedValue mTypedValue; // private TypedValue mTypedValue_Borderless; // // public ListAdapter(Context context) { // mContext =context; // // mTypedValue = new TypedValue(); // mContext.getTheme().resolveAttribute(R.attr.selectableItemBackground, mTypedValue, true); // mTypedValue_Borderless = new TypedValue(); // mContext.getTheme().resolveAttribute(R.attr.selectableItemBackgroundBorderless, mTypedValue_Borderless, true); // } // // @Override // public int getCount() { // return 100; // } // // @Override // public Object getItem(int position) { // return position; // } // // @Override // public long getItemId(int position) { // return position; // } // // @SuppressLint("NewApi") // @Override // public View getView(int position, View convertView, ViewGroup parent) { // MyViewHolder viewHolder = null; // if(convertView == null){ // viewHolder = new MyViewHolder(); // convertView = LayoutInflater.from(mContext).inflate(android.R.layout.simple_list_item_1,parent,false); // viewHolder.textView = (TextView) convertView.findViewById(android.R.id.text1); // convertView.setTag(viewHolder); // }else{ // viewHolder = (MyViewHolder) convertView.getTag(); // } // // if(position%2 == 0){ // convertView.setBackgroundResource(mTypedValue_Borderless.resourceId); // viewHolder.textView.setText("无边界的波纹效果,5.0以上"); // }else{ // convertView.setBackgroundResource(mTypedValue.resourceId); // viewHolder.textView.setText("有边界的波纹效果,5.0以上"); // } // // return convertView; // } // // class MyViewHolder{ // TextView textView; // } // // // } // Path: ClickEffect/app/src/main/java/com/mjj/clickeffect/ListActivity.java import android.os.Bundle; import android.widget.ListView; import com.mjj.clickeffect.adapter.ListAdapter; package com.mjj.clickeffect; public class ListActivity extends ABSActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); ListView list = (ListView) findViewById(R.id.listView);
list.setAdapter(new ListAdapter(this));
tyzlmjj/AndroidUI
ChangeTheme/app/src/main/java/com/mjj/changetheme/app/MyAppliction.java
// Path: ChangeTheme/app/src/main/java/com/mjj/changetheme/data/Theme.java // public class Theme { // //对应attrs.xml文件的MyTheme // public static final int DAYTHEME = 0; // public static final int NIGHTTHEME = 1; // // //对应Style // public static final int RESOURCES_DAYTHEME = R.style.DayTheme; // public static final int RESOURCES_NIGHTTHEME = R.style.NightTheme; // }
import android.app.Application; import android.content.SharedPreferences; import com.mjj.changetheme.R; import com.mjj.changetheme.data.Theme; import java.util.Map;
package com.mjj.changetheme.app; public class MyAppliction extends Application { private static int MyTheme = 0; @Override public void onCreate() { super.onCreate(); getLocalData(); } private void getLocalData() { SharedPreferences sharedPreferences = getSharedPreferences("theme",MODE_PRIVATE); MyTheme = sharedPreferences.getInt("theme",0); } public static int getThemeValue(){ return MyTheme; } public static void setThemeValue(int themeValue){ MyTheme = themeValue; } public static int getThemeResources(){ switch (MyTheme){
// Path: ChangeTheme/app/src/main/java/com/mjj/changetheme/data/Theme.java // public class Theme { // //对应attrs.xml文件的MyTheme // public static final int DAYTHEME = 0; // public static final int NIGHTTHEME = 1; // // //对应Style // public static final int RESOURCES_DAYTHEME = R.style.DayTheme; // public static final int RESOURCES_NIGHTTHEME = R.style.NightTheme; // } // Path: ChangeTheme/app/src/main/java/com/mjj/changetheme/app/MyAppliction.java import android.app.Application; import android.content.SharedPreferences; import com.mjj.changetheme.R; import com.mjj.changetheme.data.Theme; import java.util.Map; package com.mjj.changetheme.app; public class MyAppliction extends Application { private static int MyTheme = 0; @Override public void onCreate() { super.onCreate(); getLocalData(); } private void getLocalData() { SharedPreferences sharedPreferences = getSharedPreferences("theme",MODE_PRIVATE); MyTheme = sharedPreferences.getInt("theme",0); } public static int getThemeValue(){ return MyTheme; } public static void setThemeValue(int themeValue){ MyTheme = themeValue; } public static int getThemeResources(){ switch (MyTheme){
case Theme.DAYTHEME:
tyzlmjj/AndroidUI
ClickEffect/app/src/main/java/com/mjj/clickeffect/StateListAnimActivity.java
// Path: ClickEffect/app/src/main/java/com/mjj/clickeffect/adapter/StateListAnimAdapter.java // public class StateListAnimAdapter extends RecyclerView.Adapter<ViewHolder> { // // @Override // public int getItemCount() { // return 100; // } // // @Override // public void onBindViewHolder(ViewHolder arg0, int arg1) { // // } // // @Override // public ViewHolder onCreateViewHolder(ViewGroup parent, int arg1) { // // View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_statelist_item,parent,false); // return new ViewHolder(view) {}; // } // // // // // // }
import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.View; import com.mjj.clickeffect.adapter.StateListAnimAdapter;
package com.mjj.clickeffect; public class StateListAnimActivity extends ABSActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_statelistanim); RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView); recyclerView.setLayoutManager(new LinearLayoutManager(this));
// Path: ClickEffect/app/src/main/java/com/mjj/clickeffect/adapter/StateListAnimAdapter.java // public class StateListAnimAdapter extends RecyclerView.Adapter<ViewHolder> { // // @Override // public int getItemCount() { // return 100; // } // // @Override // public void onBindViewHolder(ViewHolder arg0, int arg1) { // // } // // @Override // public ViewHolder onCreateViewHolder(ViewGroup parent, int arg1) { // // View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_statelist_item,parent,false); // return new ViewHolder(view) {}; // } // // // // // // } // Path: ClickEffect/app/src/main/java/com/mjj/clickeffect/StateListAnimActivity.java import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.View; import com.mjj.clickeffect.adapter.StateListAnimAdapter; package com.mjj.clickeffect; public class StateListAnimActivity extends ABSActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_statelistanim); RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView); recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(new StateListAnimAdapter());
janexner/analytics-tests-test
selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/WebDriverBasedTestCase.java
// Path: selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/AllTests.java // public class AllTests extends TestSuite { // private final static String TESTDESCRIPTIONFILENAME = "testdescription.json"; // private final static Logger LOGGER = Logger.getLogger(AllTests.class.getName()); // // private static GenericObjectPool<WebDriver> _webDriverPool; // // public static Test suite() throws FileNotFoundException, IOException, ParseException, InterruptedException { // // try loading JSON from the file // JSONParser parser = new JSONParser(); // String filename = TESTDESCRIPTIONFILENAME; // String fnProperty = System.getProperty("test.description.file"); // if (null != fnProperty && fnProperty.length() > 0) { // filename = fnProperty; // } // File tempFile = new File(filename); // if (!tempFile.exists() || !tempFile.canRead()) { // throw new FileNotFoundException("Could not find test description file " + filename); // } // LOGGER.log(Level.CONFIG, "Reading test description from file " + filename); // Object stuff = parser.parse(new FileReader(filename)); // JSONObject jsonObject = (JSONObject) stuff; // // // use the JSON for test setup // TestSuiteFactory factory = new TestSuiteFactory(); // TestSuite suite = factory.makeSuiteFromJSON(jsonObject); // // TestSetup ts = new TestSetup(suite) { // // protected void setUp() throws Exception { // LOGGER.log(Level.INFO, "Setting up web driver pool"); // GenericObjectPoolConfig _webDriverPoolConfig = new GenericObjectPoolConfig(); // _webDriverPoolConfig.setBlockWhenExhausted(true); // _webDriverPoolConfig.setMinIdle(5); // _webDriverPoolConfig.setMaxTotal(15); // BasePooledWebDriverFactory factory = new BasePooledWebDriverFactory(); // _webDriverPool = new GenericObjectPool<WebDriver>(PoolUtils.synchronizedPooledFactory(factory), // _webDriverPoolConfig); // } // // protected void tearDown() throws Exception { // LOGGER.log(Level.CONFIG, "Closing web driver pool"); // _webDriverPool.close(); // } // // }; // // return ts; // } // // public static GenericObjectPool<WebDriver> getWebDriverPool() { // return _webDriverPool; // } // // }
import java.util.logging.Level; import java.util.logging.Logger; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.support.ui.WebDriverWait; import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.AllTests; import com.google.common.base.Predicate; import junit.framework.TestCase;
package com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests; public abstract class WebDriverBasedTestCase extends TestCase { private final static Logger LOGGER = Logger.getLogger(WebDriverBasedTestCase.class.getName()); protected final String _pageURL; protected WebDriver _webDriver; protected JavascriptExecutor _jsExecutor; protected WebDriverBasedTestCase(String pageURL) { super(); _pageURL = pageURL; } @Override protected void setUp() throws Exception { super.setUp(); LOGGER.log(Level.FINE, "Setting up test for " + _pageURL);
// Path: selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/AllTests.java // public class AllTests extends TestSuite { // private final static String TESTDESCRIPTIONFILENAME = "testdescription.json"; // private final static Logger LOGGER = Logger.getLogger(AllTests.class.getName()); // // private static GenericObjectPool<WebDriver> _webDriverPool; // // public static Test suite() throws FileNotFoundException, IOException, ParseException, InterruptedException { // // try loading JSON from the file // JSONParser parser = new JSONParser(); // String filename = TESTDESCRIPTIONFILENAME; // String fnProperty = System.getProperty("test.description.file"); // if (null != fnProperty && fnProperty.length() > 0) { // filename = fnProperty; // } // File tempFile = new File(filename); // if (!tempFile.exists() || !tempFile.canRead()) { // throw new FileNotFoundException("Could not find test description file " + filename); // } // LOGGER.log(Level.CONFIG, "Reading test description from file " + filename); // Object stuff = parser.parse(new FileReader(filename)); // JSONObject jsonObject = (JSONObject) stuff; // // // use the JSON for test setup // TestSuiteFactory factory = new TestSuiteFactory(); // TestSuite suite = factory.makeSuiteFromJSON(jsonObject); // // TestSetup ts = new TestSetup(suite) { // // protected void setUp() throws Exception { // LOGGER.log(Level.INFO, "Setting up web driver pool"); // GenericObjectPoolConfig _webDriverPoolConfig = new GenericObjectPoolConfig(); // _webDriverPoolConfig.setBlockWhenExhausted(true); // _webDriverPoolConfig.setMinIdle(5); // _webDriverPoolConfig.setMaxTotal(15); // BasePooledWebDriverFactory factory = new BasePooledWebDriverFactory(); // _webDriverPool = new GenericObjectPool<WebDriver>(PoolUtils.synchronizedPooledFactory(factory), // _webDriverPoolConfig); // } // // protected void tearDown() throws Exception { // LOGGER.log(Level.CONFIG, "Closing web driver pool"); // _webDriverPool.close(); // } // // }; // // return ts; // } // // public static GenericObjectPool<WebDriver> getWebDriverPool() { // return _webDriverPool; // } // // } // Path: selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/WebDriverBasedTestCase.java import java.util.logging.Level; import java.util.logging.Logger; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.support.ui.WebDriverWait; import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.AllTests; import com.google.common.base.Predicate; import junit.framework.TestCase; package com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests; public abstract class WebDriverBasedTestCase extends TestCase { private final static Logger LOGGER = Logger.getLogger(WebDriverBasedTestCase.class.getName()); protected final String _pageURL; protected WebDriver _webDriver; protected JavascriptExecutor _jsExecutor; protected WebDriverBasedTestCase(String pageURL) { super(); _pageURL = pageURL; } @Override protected void setUp() throws Exception { super.setUp(); LOGGER.log(Level.FINE, "Setting up test for " + _pageURL);
_webDriver = AllTests.getWebDriverPool().borrowObject();
janexner/analytics-tests-test
selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/adobe/AnalyticsCodeLoadedTestCase.java
// Path: selenium-webdriver/GenericTests4AnalyticsProject/src/main/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/Tools.java // public class Tools { // // public static final String DTM = "Activation/DTM"; // public static final String AA = "Adobe Analytics"; // public static final String AT = "Adobe Target"; // public static final String AAM = "Adobe Audience Manager"; // public static final String MCVID = "Marketing Cloud Visitor ID Service"; // public static final String TEALIUM = "Tealium IQ"; // public static final String GA = "Google Analytics"; // public static final String GUA = "Google Universal Analytics"; // // public static boolean testVersionNotOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return true; // } else if (bvm > tvm) { // return false; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return true; // } else if (testVersionElements.length < baseVersionElements.length) { // return false; // } // // return true; // } // // public static boolean testVersionIsOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return false; // } else if (bvm > tvm) { // return true; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return false; // } else if (testVersionElements.length < baseVersionElements.length) { // return true; // } // // return false; // } // } // // Path: selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/WebDriverBasedTestCase.java // public abstract class WebDriverBasedTestCase extends TestCase { // private final static Logger LOGGER = Logger.getLogger(WebDriverBasedTestCase.class.getName()); // // protected final String _pageURL; // protected WebDriver _webDriver; // protected JavascriptExecutor _jsExecutor; // // protected WebDriverBasedTestCase(String pageURL) { // super(); // _pageURL = pageURL; // } // // @Override // protected void setUp() throws Exception { // super.setUp(); // LOGGER.log(Level.FINE, "Setting up test for " + _pageURL); // _webDriver = AllTests.getWebDriverPool().borrowObject(); // try { // _webDriver.get(_pageURL); // _jsExecutor = (JavascriptExecutor) _webDriver; // _jsExecutor.executeScript("localStorage.setItem('sdsat_debug', true);"); // _jsExecutor.executeScript("if (typeof _satellite !== 'undefined') { _satellite.setDebug(true); }"); // _webDriver.get(_pageURL); // // // Wait up to 10 seconds for jQuery to load // WebDriverWait waiting = new WebDriverWait(_webDriver, 10); // waiting.until(new Predicate<WebDriver>() { // public boolean apply(WebDriver driver) { // String testresult = (String) ((JavascriptExecutor) driver).executeScript("return typeof jQuery"); // LOGGER.log(Level.FINE, "Page " + _pageURL + " - jQuery status: " + testresult); // return testresult.equals("function"); // } // }); // } catch (Exception e) { // LOGGER.log(Level.SEVERE, e.getMessage()); // AllTests.getWebDriverPool().returnObject(_webDriver); // _webDriver = null; // } // // } // // @Override // protected void tearDown() throws Exception { // LOGGER.log(Level.FINE, "Tearing down test for " + _pageURL); // if (null != _webDriver) { // AllTests.getWebDriverPool().returnObject(_webDriver); // } // super.tearDown(); // } // // }
import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.Tools; import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests.WebDriverBasedTestCase;
package com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests.adobe; public class AnalyticsCodeLoadedTestCase extends WebDriverBasedTestCase { public AnalyticsCodeLoadedTestCase(String pageURL, Object params) { super(pageURL);
// Path: selenium-webdriver/GenericTests4AnalyticsProject/src/main/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/Tools.java // public class Tools { // // public static final String DTM = "Activation/DTM"; // public static final String AA = "Adobe Analytics"; // public static final String AT = "Adobe Target"; // public static final String AAM = "Adobe Audience Manager"; // public static final String MCVID = "Marketing Cloud Visitor ID Service"; // public static final String TEALIUM = "Tealium IQ"; // public static final String GA = "Google Analytics"; // public static final String GUA = "Google Universal Analytics"; // // public static boolean testVersionNotOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return true; // } else if (bvm > tvm) { // return false; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return true; // } else if (testVersionElements.length < baseVersionElements.length) { // return false; // } // // return true; // } // // public static boolean testVersionIsOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return false; // } else if (bvm > tvm) { // return true; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return false; // } else if (testVersionElements.length < baseVersionElements.length) { // return true; // } // // return false; // } // } // // Path: selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/WebDriverBasedTestCase.java // public abstract class WebDriverBasedTestCase extends TestCase { // private final static Logger LOGGER = Logger.getLogger(WebDriverBasedTestCase.class.getName()); // // protected final String _pageURL; // protected WebDriver _webDriver; // protected JavascriptExecutor _jsExecutor; // // protected WebDriverBasedTestCase(String pageURL) { // super(); // _pageURL = pageURL; // } // // @Override // protected void setUp() throws Exception { // super.setUp(); // LOGGER.log(Level.FINE, "Setting up test for " + _pageURL); // _webDriver = AllTests.getWebDriverPool().borrowObject(); // try { // _webDriver.get(_pageURL); // _jsExecutor = (JavascriptExecutor) _webDriver; // _jsExecutor.executeScript("localStorage.setItem('sdsat_debug', true);"); // _jsExecutor.executeScript("if (typeof _satellite !== 'undefined') { _satellite.setDebug(true); }"); // _webDriver.get(_pageURL); // // // Wait up to 10 seconds for jQuery to load // WebDriverWait waiting = new WebDriverWait(_webDriver, 10); // waiting.until(new Predicate<WebDriver>() { // public boolean apply(WebDriver driver) { // String testresult = (String) ((JavascriptExecutor) driver).executeScript("return typeof jQuery"); // LOGGER.log(Level.FINE, "Page " + _pageURL + " - jQuery status: " + testresult); // return testresult.equals("function"); // } // }); // } catch (Exception e) { // LOGGER.log(Level.SEVERE, e.getMessage()); // AllTests.getWebDriverPool().returnObject(_webDriver); // _webDriver = null; // } // // } // // @Override // protected void tearDown() throws Exception { // LOGGER.log(Level.FINE, "Tearing down test for " + _pageURL); // if (null != _webDriver) { // AllTests.getWebDriverPool().returnObject(_webDriver); // } // super.tearDown(); // } // // } // Path: selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/adobe/AnalyticsCodeLoadedTestCase.java import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.Tools; import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests.WebDriverBasedTestCase; package com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests.adobe; public class AnalyticsCodeLoadedTestCase extends WebDriverBasedTestCase { public AnalyticsCodeLoadedTestCase(String pageURL, Object params) { super(pageURL);
setName(Tools.AA + " JS code loaded on page - " + pageURL);
janexner/analytics-tests-test
selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/others/TealiumIQLoadedTestCase.java
// Path: selenium-webdriver/GenericTests4AnalyticsProject/src/main/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/Tools.java // public class Tools { // // public static final String DTM = "Activation/DTM"; // public static final String AA = "Adobe Analytics"; // public static final String AT = "Adobe Target"; // public static final String AAM = "Adobe Audience Manager"; // public static final String MCVID = "Marketing Cloud Visitor ID Service"; // public static final String TEALIUM = "Tealium IQ"; // public static final String GA = "Google Analytics"; // public static final String GUA = "Google Universal Analytics"; // // public static boolean testVersionNotOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return true; // } else if (bvm > tvm) { // return false; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return true; // } else if (testVersionElements.length < baseVersionElements.length) { // return false; // } // // return true; // } // // public static boolean testVersionIsOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return false; // } else if (bvm > tvm) { // return true; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return false; // } else if (testVersionElements.length < baseVersionElements.length) { // return true; // } // // return false; // } // } // // Path: selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/WebDriverBasedTestCase.java // public abstract class WebDriverBasedTestCase extends TestCase { // private final static Logger LOGGER = Logger.getLogger(WebDriverBasedTestCase.class.getName()); // // protected final String _pageURL; // protected WebDriver _webDriver; // protected JavascriptExecutor _jsExecutor; // // protected WebDriverBasedTestCase(String pageURL) { // super(); // _pageURL = pageURL; // } // // @Override // protected void setUp() throws Exception { // super.setUp(); // LOGGER.log(Level.FINE, "Setting up test for " + _pageURL); // _webDriver = AllTests.getWebDriverPool().borrowObject(); // try { // _webDriver.get(_pageURL); // _jsExecutor = (JavascriptExecutor) _webDriver; // _jsExecutor.executeScript("localStorage.setItem('sdsat_debug', true);"); // _jsExecutor.executeScript("if (typeof _satellite !== 'undefined') { _satellite.setDebug(true); }"); // _webDriver.get(_pageURL); // // // Wait up to 10 seconds for jQuery to load // WebDriverWait waiting = new WebDriverWait(_webDriver, 10); // waiting.until(new Predicate<WebDriver>() { // public boolean apply(WebDriver driver) { // String testresult = (String) ((JavascriptExecutor) driver).executeScript("return typeof jQuery"); // LOGGER.log(Level.FINE, "Page " + _pageURL + " - jQuery status: " + testresult); // return testresult.equals("function"); // } // }); // } catch (Exception e) { // LOGGER.log(Level.SEVERE, e.getMessage()); // AllTests.getWebDriverPool().returnObject(_webDriver); // _webDriver = null; // } // // } // // @Override // protected void tearDown() throws Exception { // LOGGER.log(Level.FINE, "Tearing down test for " + _pageURL); // if (null != _webDriver) { // AllTests.getWebDriverPool().returnObject(_webDriver); // } // super.tearDown(); // } // // }
import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.Tools; import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests.WebDriverBasedTestCase;
package com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests.others; public class TealiumIQLoadedTestCase extends WebDriverBasedTestCase { public TealiumIQLoadedTestCase(String pageURL) { super(pageURL);
// Path: selenium-webdriver/GenericTests4AnalyticsProject/src/main/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/Tools.java // public class Tools { // // public static final String DTM = "Activation/DTM"; // public static final String AA = "Adobe Analytics"; // public static final String AT = "Adobe Target"; // public static final String AAM = "Adobe Audience Manager"; // public static final String MCVID = "Marketing Cloud Visitor ID Service"; // public static final String TEALIUM = "Tealium IQ"; // public static final String GA = "Google Analytics"; // public static final String GUA = "Google Universal Analytics"; // // public static boolean testVersionNotOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return true; // } else if (bvm > tvm) { // return false; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return true; // } else if (testVersionElements.length < baseVersionElements.length) { // return false; // } // // return true; // } // // public static boolean testVersionIsOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return false; // } else if (bvm > tvm) { // return true; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return false; // } else if (testVersionElements.length < baseVersionElements.length) { // return true; // } // // return false; // } // } // // Path: selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/WebDriverBasedTestCase.java // public abstract class WebDriverBasedTestCase extends TestCase { // private final static Logger LOGGER = Logger.getLogger(WebDriverBasedTestCase.class.getName()); // // protected final String _pageURL; // protected WebDriver _webDriver; // protected JavascriptExecutor _jsExecutor; // // protected WebDriverBasedTestCase(String pageURL) { // super(); // _pageURL = pageURL; // } // // @Override // protected void setUp() throws Exception { // super.setUp(); // LOGGER.log(Level.FINE, "Setting up test for " + _pageURL); // _webDriver = AllTests.getWebDriverPool().borrowObject(); // try { // _webDriver.get(_pageURL); // _jsExecutor = (JavascriptExecutor) _webDriver; // _jsExecutor.executeScript("localStorage.setItem('sdsat_debug', true);"); // _jsExecutor.executeScript("if (typeof _satellite !== 'undefined') { _satellite.setDebug(true); }"); // _webDriver.get(_pageURL); // // // Wait up to 10 seconds for jQuery to load // WebDriverWait waiting = new WebDriverWait(_webDriver, 10); // waiting.until(new Predicate<WebDriver>() { // public boolean apply(WebDriver driver) { // String testresult = (String) ((JavascriptExecutor) driver).executeScript("return typeof jQuery"); // LOGGER.log(Level.FINE, "Page " + _pageURL + " - jQuery status: " + testresult); // return testresult.equals("function"); // } // }); // } catch (Exception e) { // LOGGER.log(Level.SEVERE, e.getMessage()); // AllTests.getWebDriverPool().returnObject(_webDriver); // _webDriver = null; // } // // } // // @Override // protected void tearDown() throws Exception { // LOGGER.log(Level.FINE, "Tearing down test for " + _pageURL); // if (null != _webDriver) { // AllTests.getWebDriverPool().returnObject(_webDriver); // } // super.tearDown(); // } // // } // Path: selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/others/TealiumIQLoadedTestCase.java import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.Tools; import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests.WebDriverBasedTestCase; package com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests.others; public class TealiumIQLoadedTestCase extends WebDriverBasedTestCase { public TealiumIQLoadedTestCase(String pageURL) { super(pageURL);
setName(Tools.TEALIUM + " loaded - " + pageURL);
janexner/analytics-tests-test
selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/adobe/TargetCodeLoadedTestCase.java
// Path: selenium-webdriver/GenericTests4AnalyticsProject/src/main/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/Tools.java // public class Tools { // // public static final String DTM = "Activation/DTM"; // public static final String AA = "Adobe Analytics"; // public static final String AT = "Adobe Target"; // public static final String AAM = "Adobe Audience Manager"; // public static final String MCVID = "Marketing Cloud Visitor ID Service"; // public static final String TEALIUM = "Tealium IQ"; // public static final String GA = "Google Analytics"; // public static final String GUA = "Google Universal Analytics"; // // public static boolean testVersionNotOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return true; // } else if (bvm > tvm) { // return false; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return true; // } else if (testVersionElements.length < baseVersionElements.length) { // return false; // } // // return true; // } // // public static boolean testVersionIsOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return false; // } else if (bvm > tvm) { // return true; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return false; // } else if (testVersionElements.length < baseVersionElements.length) { // return true; // } // // return false; // } // } // // Path: selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/WebDriverBasedTestCase.java // public abstract class WebDriverBasedTestCase extends TestCase { // private final static Logger LOGGER = Logger.getLogger(WebDriverBasedTestCase.class.getName()); // // protected final String _pageURL; // protected WebDriver _webDriver; // protected JavascriptExecutor _jsExecutor; // // protected WebDriverBasedTestCase(String pageURL) { // super(); // _pageURL = pageURL; // } // // @Override // protected void setUp() throws Exception { // super.setUp(); // LOGGER.log(Level.FINE, "Setting up test for " + _pageURL); // _webDriver = AllTests.getWebDriverPool().borrowObject(); // try { // _webDriver.get(_pageURL); // _jsExecutor = (JavascriptExecutor) _webDriver; // _jsExecutor.executeScript("localStorage.setItem('sdsat_debug', true);"); // _jsExecutor.executeScript("if (typeof _satellite !== 'undefined') { _satellite.setDebug(true); }"); // _webDriver.get(_pageURL); // // // Wait up to 10 seconds for jQuery to load // WebDriverWait waiting = new WebDriverWait(_webDriver, 10); // waiting.until(new Predicate<WebDriver>() { // public boolean apply(WebDriver driver) { // String testresult = (String) ((JavascriptExecutor) driver).executeScript("return typeof jQuery"); // LOGGER.log(Level.FINE, "Page " + _pageURL + " - jQuery status: " + testresult); // return testresult.equals("function"); // } // }); // } catch (Exception e) { // LOGGER.log(Level.SEVERE, e.getMessage()); // AllTests.getWebDriverPool().returnObject(_webDriver); // _webDriver = null; // } // // } // // @Override // protected void tearDown() throws Exception { // LOGGER.log(Level.FINE, "Tearing down test for " + _pageURL); // if (null != _webDriver) { // AllTests.getWebDriverPool().returnObject(_webDriver); // } // super.tearDown(); // } // // }
import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.Tools; import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests.WebDriverBasedTestCase;
package com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests.adobe; public class TargetCodeLoadedTestCase extends WebDriverBasedTestCase { public TargetCodeLoadedTestCase(String pageURL, Object params) { super(pageURL);
// Path: selenium-webdriver/GenericTests4AnalyticsProject/src/main/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/Tools.java // public class Tools { // // public static final String DTM = "Activation/DTM"; // public static final String AA = "Adobe Analytics"; // public static final String AT = "Adobe Target"; // public static final String AAM = "Adobe Audience Manager"; // public static final String MCVID = "Marketing Cloud Visitor ID Service"; // public static final String TEALIUM = "Tealium IQ"; // public static final String GA = "Google Analytics"; // public static final String GUA = "Google Universal Analytics"; // // public static boolean testVersionNotOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return true; // } else if (bvm > tvm) { // return false; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return true; // } else if (testVersionElements.length < baseVersionElements.length) { // return false; // } // // return true; // } // // public static boolean testVersionIsOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return false; // } else if (bvm > tvm) { // return true; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return false; // } else if (testVersionElements.length < baseVersionElements.length) { // return true; // } // // return false; // } // } // // Path: selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/WebDriverBasedTestCase.java // public abstract class WebDriverBasedTestCase extends TestCase { // private final static Logger LOGGER = Logger.getLogger(WebDriverBasedTestCase.class.getName()); // // protected final String _pageURL; // protected WebDriver _webDriver; // protected JavascriptExecutor _jsExecutor; // // protected WebDriverBasedTestCase(String pageURL) { // super(); // _pageURL = pageURL; // } // // @Override // protected void setUp() throws Exception { // super.setUp(); // LOGGER.log(Level.FINE, "Setting up test for " + _pageURL); // _webDriver = AllTests.getWebDriverPool().borrowObject(); // try { // _webDriver.get(_pageURL); // _jsExecutor = (JavascriptExecutor) _webDriver; // _jsExecutor.executeScript("localStorage.setItem('sdsat_debug', true);"); // _jsExecutor.executeScript("if (typeof _satellite !== 'undefined') { _satellite.setDebug(true); }"); // _webDriver.get(_pageURL); // // // Wait up to 10 seconds for jQuery to load // WebDriverWait waiting = new WebDriverWait(_webDriver, 10); // waiting.until(new Predicate<WebDriver>() { // public boolean apply(WebDriver driver) { // String testresult = (String) ((JavascriptExecutor) driver).executeScript("return typeof jQuery"); // LOGGER.log(Level.FINE, "Page " + _pageURL + " - jQuery status: " + testresult); // return testresult.equals("function"); // } // }); // } catch (Exception e) { // LOGGER.log(Level.SEVERE, e.getMessage()); // AllTests.getWebDriverPool().returnObject(_webDriver); // _webDriver = null; // } // // } // // @Override // protected void tearDown() throws Exception { // LOGGER.log(Level.FINE, "Tearing down test for " + _pageURL); // if (null != _webDriver) { // AllTests.getWebDriverPool().returnObject(_webDriver); // } // super.tearDown(); // } // // } // Path: selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/adobe/TargetCodeLoadedTestCase.java import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.Tools; import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests.WebDriverBasedTestCase; package com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests.adobe; public class TargetCodeLoadedTestCase extends WebDriverBasedTestCase { public TargetCodeLoadedTestCase(String pageURL, Object params) { super(pageURL);
setName(Tools.AT + " mbox.js is loaded - " + pageURL);
janexner/analytics-tests-test
selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/adobe/VisitorIDServiceLoadedTestCase.java
// Path: selenium-webdriver/GenericTests4AnalyticsProject/src/main/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/Tools.java // public class Tools { // // public static final String DTM = "Activation/DTM"; // public static final String AA = "Adobe Analytics"; // public static final String AT = "Adobe Target"; // public static final String AAM = "Adobe Audience Manager"; // public static final String MCVID = "Marketing Cloud Visitor ID Service"; // public static final String TEALIUM = "Tealium IQ"; // public static final String GA = "Google Analytics"; // public static final String GUA = "Google Universal Analytics"; // // public static boolean testVersionNotOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return true; // } else if (bvm > tvm) { // return false; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return true; // } else if (testVersionElements.length < baseVersionElements.length) { // return false; // } // // return true; // } // // public static boolean testVersionIsOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return false; // } else if (bvm > tvm) { // return true; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return false; // } else if (testVersionElements.length < baseVersionElements.length) { // return true; // } // // return false; // } // } // // Path: selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/WebDriverBasedTestCase.java // public abstract class WebDriverBasedTestCase extends TestCase { // private final static Logger LOGGER = Logger.getLogger(WebDriverBasedTestCase.class.getName()); // // protected final String _pageURL; // protected WebDriver _webDriver; // protected JavascriptExecutor _jsExecutor; // // protected WebDriverBasedTestCase(String pageURL) { // super(); // _pageURL = pageURL; // } // // @Override // protected void setUp() throws Exception { // super.setUp(); // LOGGER.log(Level.FINE, "Setting up test for " + _pageURL); // _webDriver = AllTests.getWebDriverPool().borrowObject(); // try { // _webDriver.get(_pageURL); // _jsExecutor = (JavascriptExecutor) _webDriver; // _jsExecutor.executeScript("localStorage.setItem('sdsat_debug', true);"); // _jsExecutor.executeScript("if (typeof _satellite !== 'undefined') { _satellite.setDebug(true); }"); // _webDriver.get(_pageURL); // // // Wait up to 10 seconds for jQuery to load // WebDriverWait waiting = new WebDriverWait(_webDriver, 10); // waiting.until(new Predicate<WebDriver>() { // public boolean apply(WebDriver driver) { // String testresult = (String) ((JavascriptExecutor) driver).executeScript("return typeof jQuery"); // LOGGER.log(Level.FINE, "Page " + _pageURL + " - jQuery status: " + testresult); // return testresult.equals("function"); // } // }); // } catch (Exception e) { // LOGGER.log(Level.SEVERE, e.getMessage()); // AllTests.getWebDriverPool().returnObject(_webDriver); // _webDriver = null; // } // // } // // @Override // protected void tearDown() throws Exception { // LOGGER.log(Level.FINE, "Tearing down test for " + _pageURL); // if (null != _webDriver) { // AllTests.getWebDriverPool().returnObject(_webDriver); // } // super.tearDown(); // } // // }
import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.Tools; import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests.WebDriverBasedTestCase;
package com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests.adobe; public class VisitorIDServiceLoadedTestCase extends WebDriverBasedTestCase { public VisitorIDServiceLoadedTestCase(String pageURL, Object params) { super(pageURL);
// Path: selenium-webdriver/GenericTests4AnalyticsProject/src/main/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/Tools.java // public class Tools { // // public static final String DTM = "Activation/DTM"; // public static final String AA = "Adobe Analytics"; // public static final String AT = "Adobe Target"; // public static final String AAM = "Adobe Audience Manager"; // public static final String MCVID = "Marketing Cloud Visitor ID Service"; // public static final String TEALIUM = "Tealium IQ"; // public static final String GA = "Google Analytics"; // public static final String GUA = "Google Universal Analytics"; // // public static boolean testVersionNotOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return true; // } else if (bvm > tvm) { // return false; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return true; // } else if (testVersionElements.length < baseVersionElements.length) { // return false; // } // // return true; // } // // public static boolean testVersionIsOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return false; // } else if (bvm > tvm) { // return true; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return false; // } else if (testVersionElements.length < baseVersionElements.length) { // return true; // } // // return false; // } // } // // Path: selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/WebDriverBasedTestCase.java // public abstract class WebDriverBasedTestCase extends TestCase { // private final static Logger LOGGER = Logger.getLogger(WebDriverBasedTestCase.class.getName()); // // protected final String _pageURL; // protected WebDriver _webDriver; // protected JavascriptExecutor _jsExecutor; // // protected WebDriverBasedTestCase(String pageURL) { // super(); // _pageURL = pageURL; // } // // @Override // protected void setUp() throws Exception { // super.setUp(); // LOGGER.log(Level.FINE, "Setting up test for " + _pageURL); // _webDriver = AllTests.getWebDriverPool().borrowObject(); // try { // _webDriver.get(_pageURL); // _jsExecutor = (JavascriptExecutor) _webDriver; // _jsExecutor.executeScript("localStorage.setItem('sdsat_debug', true);"); // _jsExecutor.executeScript("if (typeof _satellite !== 'undefined') { _satellite.setDebug(true); }"); // _webDriver.get(_pageURL); // // // Wait up to 10 seconds for jQuery to load // WebDriverWait waiting = new WebDriverWait(_webDriver, 10); // waiting.until(new Predicate<WebDriver>() { // public boolean apply(WebDriver driver) { // String testresult = (String) ((JavascriptExecutor) driver).executeScript("return typeof jQuery"); // LOGGER.log(Level.FINE, "Page " + _pageURL + " - jQuery status: " + testresult); // return testresult.equals("function"); // } // }); // } catch (Exception e) { // LOGGER.log(Level.SEVERE, e.getMessage()); // AllTests.getWebDriverPool().returnObject(_webDriver); // _webDriver = null; // } // // } // // @Override // protected void tearDown() throws Exception { // LOGGER.log(Level.FINE, "Tearing down test for " + _pageURL); // if (null != _webDriver) { // AllTests.getWebDriverPool().returnObject(_webDriver); // } // super.tearDown(); // } // // } // Path: selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/adobe/VisitorIDServiceLoadedTestCase.java import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.Tools; import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests.WebDriverBasedTestCase; package com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests.adobe; public class VisitorIDServiceLoadedTestCase extends WebDriverBasedTestCase { public VisitorIDServiceLoadedTestCase(String pageURL, Object params) { super(pageURL);
setName(Tools.MCVID + " loaded - " + pageURL);
janexner/analytics-tests-test
selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/TestSuiteFactory.java
// Path: selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/WebDriverBasedTestCase.java // public abstract class WebDriverBasedTestCase extends TestCase { // private final static Logger LOGGER = Logger.getLogger(WebDriverBasedTestCase.class.getName()); // // protected final String _pageURL; // protected WebDriver _webDriver; // protected JavascriptExecutor _jsExecutor; // // protected WebDriverBasedTestCase(String pageURL) { // super(); // _pageURL = pageURL; // } // // @Override // protected void setUp() throws Exception { // super.setUp(); // LOGGER.log(Level.FINE, "Setting up test for " + _pageURL); // _webDriver = AllTests.getWebDriverPool().borrowObject(); // try { // _webDriver.get(_pageURL); // _jsExecutor = (JavascriptExecutor) _webDriver; // _jsExecutor.executeScript("localStorage.setItem('sdsat_debug', true);"); // _jsExecutor.executeScript("if (typeof _satellite !== 'undefined') { _satellite.setDebug(true); }"); // _webDriver.get(_pageURL); // // // Wait up to 10 seconds for jQuery to load // WebDriverWait waiting = new WebDriverWait(_webDriver, 10); // waiting.until(new Predicate<WebDriver>() { // public boolean apply(WebDriver driver) { // String testresult = (String) ((JavascriptExecutor) driver).executeScript("return typeof jQuery"); // LOGGER.log(Level.FINE, "Page " + _pageURL + " - jQuery status: " + testresult); // return testresult.equals("function"); // } // }); // } catch (Exception e) { // LOGGER.log(Level.SEVERE, e.getMessage()); // AllTests.getWebDriverPool().returnObject(_webDriver); // _webDriver = null; // } // // } // // @Override // protected void tearDown() throws Exception { // LOGGER.log(Level.FINE, "Tearing down test for " + _pageURL); // if (null != _webDriver) { // AllTests.getWebDriverPool().returnObject(_webDriver); // } // super.tearDown(); // } // // }
import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Set; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests.WebDriverBasedTestCase; import junit.framework.TestSuite;
package com.exner.tools.analyticstdd.GenericTests4AnalyticsProject; public class TestSuiteFactory { private Class[] _cArgs; public TestSuiteFactory() { _cArgs = new Class[2]; _cArgs[0] = String.class; _cArgs[1] = Object.class; } public TestSuite makeSuiteFromJSON(JSONObject jsonObject) { String testName = (String) jsonObject.get("name"); TestSuite suite = new TestSuite("Site test - " + testName); // loop through pages to test and add one test suite per page JSONArray pagesToTest = (JSONArray) jsonObject.get("pagesToTest"); for (Iterator<JSONObject> iterator = pagesToTest.iterator(); iterator.hasNext();) { suite.addTest(makeSuiteForPage(iterator.next())); } return suite; } private TestSuite makeSuiteForPage(JSONObject pageTests) { String pageURL = (String) pageTests.get("pageURL"); TestSuite pageSuite = new TestSuite("Page tests - " + pageURL); Set<String> keys = pageTests.keySet(); for (Iterator<String> iter2 = keys.iterator(); iter2.hasNext();) { String key = iter2.next(); if (!key.equals("pageURL")) { Object params = pageTests.get(key); String testClass = testNameFromKey(key); List<Object> testParams = parseTestParameters(params); try { for (Iterator<Object> iter4 = testParams.iterator(); iter4.hasNext();) {
// Path: selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/WebDriverBasedTestCase.java // public abstract class WebDriverBasedTestCase extends TestCase { // private final static Logger LOGGER = Logger.getLogger(WebDriverBasedTestCase.class.getName()); // // protected final String _pageURL; // protected WebDriver _webDriver; // protected JavascriptExecutor _jsExecutor; // // protected WebDriverBasedTestCase(String pageURL) { // super(); // _pageURL = pageURL; // } // // @Override // protected void setUp() throws Exception { // super.setUp(); // LOGGER.log(Level.FINE, "Setting up test for " + _pageURL); // _webDriver = AllTests.getWebDriverPool().borrowObject(); // try { // _webDriver.get(_pageURL); // _jsExecutor = (JavascriptExecutor) _webDriver; // _jsExecutor.executeScript("localStorage.setItem('sdsat_debug', true);"); // _jsExecutor.executeScript("if (typeof _satellite !== 'undefined') { _satellite.setDebug(true); }"); // _webDriver.get(_pageURL); // // // Wait up to 10 seconds for jQuery to load // WebDriverWait waiting = new WebDriverWait(_webDriver, 10); // waiting.until(new Predicate<WebDriver>() { // public boolean apply(WebDriver driver) { // String testresult = (String) ((JavascriptExecutor) driver).executeScript("return typeof jQuery"); // LOGGER.log(Level.FINE, "Page " + _pageURL + " - jQuery status: " + testresult); // return testresult.equals("function"); // } // }); // } catch (Exception e) { // LOGGER.log(Level.SEVERE, e.getMessage()); // AllTests.getWebDriverPool().returnObject(_webDriver); // _webDriver = null; // } // // } // // @Override // protected void tearDown() throws Exception { // LOGGER.log(Level.FINE, "Tearing down test for " + _pageURL); // if (null != _webDriver) { // AllTests.getWebDriverPool().returnObject(_webDriver); // } // super.tearDown(); // } // // } // Path: selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/TestSuiteFactory.java import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Set; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests.WebDriverBasedTestCase; import junit.framework.TestSuite; package com.exner.tools.analyticstdd.GenericTests4AnalyticsProject; public class TestSuiteFactory { private Class[] _cArgs; public TestSuiteFactory() { _cArgs = new Class[2]; _cArgs[0] = String.class; _cArgs[1] = Object.class; } public TestSuite makeSuiteFromJSON(JSONObject jsonObject) { String testName = (String) jsonObject.get("name"); TestSuite suite = new TestSuite("Site test - " + testName); // loop through pages to test and add one test suite per page JSONArray pagesToTest = (JSONArray) jsonObject.get("pagesToTest"); for (Iterator<JSONObject> iterator = pagesToTest.iterator(); iterator.hasNext();) { suite.addTest(makeSuiteForPage(iterator.next())); } return suite; } private TestSuite makeSuiteForPage(JSONObject pageTests) { String pageURL = (String) pageTests.get("pageURL"); TestSuite pageSuite = new TestSuite("Page tests - " + pageURL); Set<String> keys = pageTests.keySet(); for (Iterator<String> iter2 = keys.iterator(); iter2.hasNext();) { String key = iter2.next(); if (!key.equals("pageURL")) { Object params = pageTests.get(key); String testClass = testNameFromKey(key); List<Object> testParams = parseTestParameters(params); try { for (Iterator<Object> iter4 = testParams.iterator(); iter4.hasNext();) {
WebDriverBasedTestCase testCase = (WebDriverBasedTestCase) Class.forName(testClass)
janexner/analytics-tests-test
selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/JQueryVersionBelowTestCase.java
// Path: selenium-webdriver/GenericTests4AnalyticsProject/src/main/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/Tools.java // public class Tools { // // public static final String DTM = "Activation/DTM"; // public static final String AA = "Adobe Analytics"; // public static final String AT = "Adobe Target"; // public static final String AAM = "Adobe Audience Manager"; // public static final String MCVID = "Marketing Cloud Visitor ID Service"; // public static final String TEALIUM = "Tealium IQ"; // public static final String GA = "Google Analytics"; // public static final String GUA = "Google Universal Analytics"; // // public static boolean testVersionNotOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return true; // } else if (bvm > tvm) { // return false; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return true; // } else if (testVersionElements.length < baseVersionElements.length) { // return false; // } // // return true; // } // // public static boolean testVersionIsOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return false; // } else if (bvm > tvm) { // return true; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return false; // } else if (testVersionElements.length < baseVersionElements.length) { // return true; // } // // return false; // } // }
import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.Tools;
package com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests; public class JQueryVersionBelowTestCase extends WebDriverBasedTestCase { private final String _maxVersion; public JQueryVersionBelowTestCase(String pageURL, Object params) { super(pageURL); if (String.class.isAssignableFrom(params.getClass())) { _maxVersion = (String) params; } else if (int.class.isAssignableFrom(params.getClass())) { _maxVersion = String.valueOf((Integer) params); } else { _maxVersion = "0"; throw new IllegalArgumentException("Must define a max version!"); } setName("jQuery version before " + _maxVersion + " - " + pageURL); } @Override protected void runTest() throws Throwable { // check whether DTM has been loaded on the page Object response = _jsExecutor.executeScript( "if (typeof jQuery !== 'undefined') { return jQuery.fn.jquery } else { return 'unavailable' }"); // make sure the element exists if (String.class.isAssignableFrom(response.getClass())) {
// Path: selenium-webdriver/GenericTests4AnalyticsProject/src/main/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/Tools.java // public class Tools { // // public static final String DTM = "Activation/DTM"; // public static final String AA = "Adobe Analytics"; // public static final String AT = "Adobe Target"; // public static final String AAM = "Adobe Audience Manager"; // public static final String MCVID = "Marketing Cloud Visitor ID Service"; // public static final String TEALIUM = "Tealium IQ"; // public static final String GA = "Google Analytics"; // public static final String GUA = "Google Universal Analytics"; // // public static boolean testVersionNotOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return true; // } else if (bvm > tvm) { // return false; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return true; // } else if (testVersionElements.length < baseVersionElements.length) { // return false; // } // // return true; // } // // public static boolean testVersionIsOlderThanBaseVersion(String version, String versionBase) { // String[] testVersionElements = version.split("\\."); // String[] baseVersionElements = versionBase.split("\\."); // // int loops = Math.min(testVersionElements.length, baseVersionElements.length); // // // one special case: loops = 0 // if (null == version || version.isEmpty() || version.equals("unavailable")) { // return false; // } // // for (int i = 0; i < loops; i++) { // long tvm = Long.parseLong(testVersionElements[i]); // long bvm = Long.parseLong(baseVersionElements[i]); // if (tvm > bvm) { // return false; // } else if (bvm > tvm) { // return true; // } // } // // // hm... they are the same up to the length of the shorter one. what // // now? // if (testVersionElements.length > baseVersionElements.length) { // return false; // } else if (testVersionElements.length < baseVersionElements.length) { // return true; // } // // return false; // } // } // Path: selenium-webdriver/GenericTests4AnalyticsProject/src/test/java/com/exner/tools/analyticstdd/GenericTests4AnalyticsProject/tests/JQueryVersionBelowTestCase.java import com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.Tools; package com.exner.tools.analyticstdd.GenericTests4AnalyticsProject.tests; public class JQueryVersionBelowTestCase extends WebDriverBasedTestCase { private final String _maxVersion; public JQueryVersionBelowTestCase(String pageURL, Object params) { super(pageURL); if (String.class.isAssignableFrom(params.getClass())) { _maxVersion = (String) params; } else if (int.class.isAssignableFrom(params.getClass())) { _maxVersion = String.valueOf((Integer) params); } else { _maxVersion = "0"; throw new IllegalArgumentException("Must define a max version!"); } setName("jQuery version before " + _maxVersion + " - " + pageURL); } @Override protected void runTest() throws Throwable { // check whether DTM has been loaded on the page Object response = _jsExecutor.executeScript( "if (typeof jQuery !== 'undefined') { return jQuery.fn.jquery } else { return 'unavailable' }"); // make sure the element exists if (String.class.isAssignableFrom(response.getClass())) {
boolean result = Tools.testVersionIsOlderThanBaseVersion((String) response, _maxVersion);
forcedotcom/JavaChatterRESTApi
test/unit/src/com/salesforce/chatter/authentication/methods/AuthentificationMethodTest.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // }
import static org.junit.Assert.*; import org.junit.Test; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class AuthentificationMethodTest { @Test (expected=AuthenticationException.class) public void testInvalidProcessResponse() throws AuthenticationException { AuthentificationMethod auth = new UsernamePasswordAuthentication(null); String response = "400 Bad Request"; auth.processResponse(response); fail("We should have gotten a AuthenticationException by now"); } @Test public void testProcessResponse() throws AuthenticationException { AuthentificationMethod auth = new UsernamePasswordAuthentication(null); String response = "{ \"access_token\" : \"test\" }";
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // Path: test/unit/src/com/salesforce/chatter/authentication/methods/AuthentificationMethodTest.java import static org.junit.Assert.*; import org.junit.Test; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class AuthentificationMethodTest { @Test (expected=AuthenticationException.class) public void testInvalidProcessResponse() throws AuthenticationException { AuthentificationMethod auth = new UsernamePasswordAuthentication(null); String response = "400 Bad Request"; auth.processResponse(response); fail("We should have gotten a AuthenticationException by now"); } @Test public void testProcessResponse() throws AuthenticationException { AuthentificationMethod auth = new UsernamePasswordAuthentication(null); String response = "{ \"access_token\" : \"test\" }";
ChatterAuthToken token = auth.processResponse(response);
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/message/Message.java
// Path: src/com/salesforce/chatter/attachment/Attachment.java // public abstract class Attachment { // // public abstract String getAttachmentType(); // // }
import java.util.ArrayList; import java.util.List; import com.salesforce.chatter.attachment.Attachment;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.message; public class Message { private List<MessageSegment> segments = new ArrayList<MessageSegment>();
// Path: src/com/salesforce/chatter/attachment/Attachment.java // public abstract class Attachment { // // public abstract String getAttachmentType(); // // } // Path: src/com/salesforce/chatter/message/Message.java import java.util.ArrayList; import java.util.List; import com.salesforce.chatter.attachment.Attachment; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.message; public class Message { private List<MessageSegment> segments = new ArrayList<MessageSegment>();
private Attachment attachment;
forcedotcom/JavaChatterRESTApi
test/unit/src/com/salesforce/chatter/credentials/ChatterDataGenericTest.java
// Path: src/com/salesforce/chatter/authentication/ChatterAuthMethod.java // public enum ChatterAuthMethod { // // /** // * <p>This requires the user to visit a URL and return the authorization code to us.</p> // */ // INTERACTIVE, // /** // * <p>Uses username and password to authenticate.</p> // */ // PASSWORD, // /** // * <p>Uses client id, secret and code to authenticate.</p> // */ // CLIENT_SECRET, // /** // * <p>Uses a refresh token to authenticate.</p> // */ // REFRESH_TOKEN // }
import org.junit.Test; import com.salesforce.chatter.authentication.ChatterAuthMethod; import static org.junit.Assert.*;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.credentials; /** * <p>Making sure all the fields are correctly set, and the currently unused values return a null value.</p> * * @author jroel * @since 1.0 * */ public class ChatterDataGenericTest { private String apiVersion = "apiVersion"; private String instanceUrl = "instanceUrl"; private String authMethod = "password";
// Path: src/com/salesforce/chatter/authentication/ChatterAuthMethod.java // public enum ChatterAuthMethod { // // /** // * <p>This requires the user to visit a URL and return the authorization code to us.</p> // */ // INTERACTIVE, // /** // * <p>Uses username and password to authenticate.</p> // */ // PASSWORD, // /** // * <p>Uses client id, secret and code to authenticate.</p> // */ // CLIENT_SECRET, // /** // * <p>Uses a refresh token to authenticate.</p> // */ // REFRESH_TOKEN // } // Path: test/unit/src/com/salesforce/chatter/credentials/ChatterDataGenericTest.java import org.junit.Test; import com.salesforce.chatter.authentication.ChatterAuthMethod; import static org.junit.Assert.*; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.credentials; /** * <p>Making sure all the fields are correctly set, and the currently unused values return a null value.</p> * * @author jroel * @since 1.0 * */ public class ChatterDataGenericTest { private String apiVersion = "apiVersion"; private String instanceUrl = "instanceUrl"; private String authMethod = "password";
private ChatterAuthMethod authMethod2 = ChatterAuthMethod.PASSWORD;
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/authentication/methods/AuthentificationMethod.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.PropertyNamingStrategy; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import org.apache.commons.httpclient.HttpClient; import org.codehaus.jackson.JsonParseException; import org.codehaus.jackson.map.JsonMappingException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public abstract class AuthentificationMethod { /** * <p>The verification URL is used in interactive authentication, where the user copies and pastes the response code * to us.</p> */ public final static String VERIFICATION_URL = "https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=__CLIENTID__&redirect_uri=__REDIRECTURI__"; /** * <p>This URL is where the default Salesforce.com authentication is performed.</p> */ public final static String PRODUCTION_AUTHENTICATION_URL = "https://login.salesforce.com/services/oauth2/token"; /** * <p>This URL is where the Salesforce.com authentication is performed for test environments.</p> */ public final static String TEST_AUTHENTICATION_URL = "https://test.salesforce.com/services/oauth2/token"; private final static ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally static { mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); } private HttpClient client = new HttpClient();
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: src/com/salesforce/chatter/authentication/methods/AuthentificationMethod.java import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.PropertyNamingStrategy; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import org.apache.commons.httpclient.HttpClient; import org.codehaus.jackson.JsonParseException; import org.codehaus.jackson.map.JsonMappingException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public abstract class AuthentificationMethod { /** * <p>The verification URL is used in interactive authentication, where the user copies and pastes the response code * to us.</p> */ public final static String VERIFICATION_URL = "https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=__CLIENTID__&redirect_uri=__REDIRECTURI__"; /** * <p>This URL is where the default Salesforce.com authentication is performed.</p> */ public final static String PRODUCTION_AUTHENTICATION_URL = "https://login.salesforce.com/services/oauth2/token"; /** * <p>This URL is where the Salesforce.com authentication is performed for test environments.</p> */ public final static String TEST_AUTHENTICATION_URL = "https://test.salesforce.com/services/oauth2/token"; private final static ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally static { mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); } private HttpClient client = new HttpClient();
public abstract ChatterAuthToken authenticate() throws IOException, UnauthenticatedSessionException,
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/authentication/methods/AuthentificationMethod.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.PropertyNamingStrategy; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import org.apache.commons.httpclient.HttpClient; import org.codehaus.jackson.JsonParseException; import org.codehaus.jackson.map.JsonMappingException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public abstract class AuthentificationMethod { /** * <p>The verification URL is used in interactive authentication, where the user copies and pastes the response code * to us.</p> */ public final static String VERIFICATION_URL = "https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=__CLIENTID__&redirect_uri=__REDIRECTURI__"; /** * <p>This URL is where the default Salesforce.com authentication is performed.</p> */ public final static String PRODUCTION_AUTHENTICATION_URL = "https://login.salesforce.com/services/oauth2/token"; /** * <p>This URL is where the Salesforce.com authentication is performed for test environments.</p> */ public final static String TEST_AUTHENTICATION_URL = "https://test.salesforce.com/services/oauth2/token"; private final static ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally static { mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); } private HttpClient client = new HttpClient();
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: src/com/salesforce/chatter/authentication/methods/AuthentificationMethod.java import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.PropertyNamingStrategy; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import org.apache.commons.httpclient.HttpClient; import org.codehaus.jackson.JsonParseException; import org.codehaus.jackson.map.JsonMappingException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public abstract class AuthentificationMethod { /** * <p>The verification URL is used in interactive authentication, where the user copies and pastes the response code * to us.</p> */ public final static String VERIFICATION_URL = "https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=__CLIENTID__&redirect_uri=__REDIRECTURI__"; /** * <p>This URL is where the default Salesforce.com authentication is performed.</p> */ public final static String PRODUCTION_AUTHENTICATION_URL = "https://login.salesforce.com/services/oauth2/token"; /** * <p>This URL is where the Salesforce.com authentication is performed for test environments.</p> */ public final static String TEST_AUTHENTICATION_URL = "https://test.salesforce.com/services/oauth2/token"; private final static ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally static { mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); } private HttpClient client = new HttpClient();
public abstract ChatterAuthToken authenticate() throws IOException, UnauthenticatedSessionException,
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/authentication/methods/AuthentificationMethod.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.PropertyNamingStrategy; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import org.apache.commons.httpclient.HttpClient; import org.codehaus.jackson.JsonParseException; import org.codehaus.jackson.map.JsonMappingException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public abstract class AuthentificationMethod { /** * <p>The verification URL is used in interactive authentication, where the user copies and pastes the response code * to us.</p> */ public final static String VERIFICATION_URL = "https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=__CLIENTID__&redirect_uri=__REDIRECTURI__"; /** * <p>This URL is where the default Salesforce.com authentication is performed.</p> */ public final static String PRODUCTION_AUTHENTICATION_URL = "https://login.salesforce.com/services/oauth2/token"; /** * <p>This URL is where the Salesforce.com authentication is performed for test environments.</p> */ public final static String TEST_AUTHENTICATION_URL = "https://test.salesforce.com/services/oauth2/token"; private final static ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally static { mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); } private HttpClient client = new HttpClient(); public abstract ChatterAuthToken authenticate() throws IOException, UnauthenticatedSessionException,
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: src/com/salesforce/chatter/authentication/methods/AuthentificationMethod.java import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.PropertyNamingStrategy; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import org.apache.commons.httpclient.HttpClient; import org.codehaus.jackson.JsonParseException; import org.codehaus.jackson.map.JsonMappingException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public abstract class AuthentificationMethod { /** * <p>The verification URL is used in interactive authentication, where the user copies and pastes the response code * to us.</p> */ public final static String VERIFICATION_URL = "https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=__CLIENTID__&redirect_uri=__REDIRECTURI__"; /** * <p>This URL is where the default Salesforce.com authentication is performed.</p> */ public final static String PRODUCTION_AUTHENTICATION_URL = "https://login.salesforce.com/services/oauth2/token"; /** * <p>This URL is where the Salesforce.com authentication is performed for test environments.</p> */ public final static String TEST_AUTHENTICATION_URL = "https://test.salesforce.com/services/oauth2/token"; private final static ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally static { mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); } private HttpClient client = new HttpClient(); public abstract ChatterAuthToken authenticate() throws IOException, UnauthenticatedSessionException,
AuthenticationException;
forcedotcom/JavaChatterRESTApi
test/unit/src/com/salesforce/chatter/authentication/methods/ClientSecretTest.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class ClientSecretTest { @Test
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: test/unit/src/com/salesforce/chatter/authentication/methods/ClientSecretTest.java import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class ClientSecretTest { @Test
public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException,
forcedotcom/JavaChatterRESTApi
test/unit/src/com/salesforce/chatter/authentication/methods/ClientSecretTest.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class ClientSecretTest { @Test public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException,
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: test/unit/src/com/salesforce/chatter/authentication/methods/ClientSecretTest.java import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class ClientSecretTest { @Test public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException,
AuthenticationException {
forcedotcom/JavaChatterRESTApi
test/unit/src/com/salesforce/chatter/authentication/methods/ClientSecretTest.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class ClientSecretTest { @Test public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException, AuthenticationException {
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: test/unit/src/com/salesforce/chatter/authentication/methods/ClientSecretTest.java import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class ClientSecretTest { @Test public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException, AuthenticationException {
IChatterData data = getMockedChatterData();
forcedotcom/JavaChatterRESTApi
test/unit/src/com/salesforce/chatter/authentication/methods/ClientSecretTest.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class ClientSecretTest { @Test public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException, AuthenticationException { IChatterData data = getMockedChatterData(); ClientSecretAuthentication auth = new ClientSecretAuthentication(data, ""); HttpClient mockHttpClient = mock(HttpClient.class); when(mockHttpClient.executeMethod(any(PostMethod.class))).thenAnswer( new ExecuteMethodAnswer("{\"access_token\" : \"abc\" }")); auth.setHttpClient(mockHttpClient);
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: test/unit/src/com/salesforce/chatter/authentication/methods/ClientSecretTest.java import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class ClientSecretTest { @Test public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException, AuthenticationException { IChatterData data = getMockedChatterData(); ClientSecretAuthentication auth = new ClientSecretAuthentication(data, ""); HttpClient mockHttpClient = mock(HttpClient.class); when(mockHttpClient.executeMethod(any(PostMethod.class))).thenAnswer( new ExecuteMethodAnswer("{\"access_token\" : \"abc\" }")); auth.setHttpClient(mockHttpClient);
ChatterAuthToken token = auth.authenticate();
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/credentials/ChatterDataGeneric.java
// Path: src/com/salesforce/chatter/authentication/ChatterAuthMethod.java // public enum ChatterAuthMethod { // // /** // * <p>This requires the user to visit a URL and return the authorization code to us.</p> // */ // INTERACTIVE, // /** // * <p>Uses username and password to authenticate.</p> // */ // PASSWORD, // /** // * <p>Uses client id, secret and code to authenticate.</p> // */ // CLIENT_SECRET, // /** // * <p>Uses a refresh token to authenticate.</p> // */ // REFRESH_TOKEN // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // }
import com.salesforce.chatter.authentication.ChatterAuthMethod; import com.salesforce.chatter.authentication.IChatterData;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.credentials; /** * <p>This is a generic (blank) bean to initialize an instance of {@link IChatterData}.</p> * * @author jroel * @since 1.0 * */ public class ChatterDataGeneric implements IChatterData { private final String apiVersion; private final String instanceUrl;
// Path: src/com/salesforce/chatter/authentication/ChatterAuthMethod.java // public enum ChatterAuthMethod { // // /** // * <p>This requires the user to visit a URL and return the authorization code to us.</p> // */ // INTERACTIVE, // /** // * <p>Uses username and password to authenticate.</p> // */ // PASSWORD, // /** // * <p>Uses client id, secret and code to authenticate.</p> // */ // CLIENT_SECRET, // /** // * <p>Uses a refresh token to authenticate.</p> // */ // REFRESH_TOKEN // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // Path: src/com/salesforce/chatter/credentials/ChatterDataGeneric.java import com.salesforce.chatter.authentication.ChatterAuthMethod; import com.salesforce.chatter.authentication.IChatterData; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.credentials; /** * <p>This is a generic (blank) bean to initialize an instance of {@link IChatterData}.</p> * * @author jroel * @since 1.0 * */ public class ChatterDataGeneric implements IChatterData { private final String apiVersion; private final String instanceUrl;
private final ChatterAuthMethod authMethod;
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/authentication/methods/UsernamePasswordAuthentication.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import org.apache.commons.httpclient.methods.PostMethod; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import java.net.URLEncoder; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class UsernamePasswordAuthentication extends AuthentificationMethod { private final IChatterData chatterData; public UsernamePasswordAuthentication(IChatterData chatterData) { this.chatterData = chatterData; } /** * <p>Authenticate using a username and password. This is discouraged by the oauth flow, * but it allows for transparent (and non human-intervention) authentication).</p> * * @return The response retrieved from the REST API (usually an XML string with all the tokens) * @throws IOException * @throws UnauthenticatedSessionException * @throws AuthenticationException */
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: src/com/salesforce/chatter/authentication/methods/UsernamePasswordAuthentication.java import org.apache.commons.httpclient.methods.PostMethod; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import java.net.URLEncoder; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class UsernamePasswordAuthentication extends AuthentificationMethod { private final IChatterData chatterData; public UsernamePasswordAuthentication(IChatterData chatterData) { this.chatterData = chatterData; } /** * <p>Authenticate using a username and password. This is discouraged by the oauth flow, * but it allows for transparent (and non human-intervention) authentication).</p> * * @return The response retrieved from the REST API (usually an XML string with all the tokens) * @throws IOException * @throws UnauthenticatedSessionException * @throws AuthenticationException */
public ChatterAuthToken authenticate() throws IOException, UnauthenticatedSessionException, AuthenticationException {
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/authentication/methods/UsernamePasswordAuthentication.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import org.apache.commons.httpclient.methods.PostMethod; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import java.net.URLEncoder; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class UsernamePasswordAuthentication extends AuthentificationMethod { private final IChatterData chatterData; public UsernamePasswordAuthentication(IChatterData chatterData) { this.chatterData = chatterData; } /** * <p>Authenticate using a username and password. This is discouraged by the oauth flow, * but it allows for transparent (and non human-intervention) authentication).</p> * * @return The response retrieved from the REST API (usually an XML string with all the tokens) * @throws IOException * @throws UnauthenticatedSessionException * @throws AuthenticationException */
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: src/com/salesforce/chatter/authentication/methods/UsernamePasswordAuthentication.java import org.apache.commons.httpclient.methods.PostMethod; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import java.net.URLEncoder; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class UsernamePasswordAuthentication extends AuthentificationMethod { private final IChatterData chatterData; public UsernamePasswordAuthentication(IChatterData chatterData) { this.chatterData = chatterData; } /** * <p>Authenticate using a username and password. This is discouraged by the oauth flow, * but it allows for transparent (and non human-intervention) authentication).</p> * * @return The response retrieved from the REST API (usually an XML string with all the tokens) * @throws IOException * @throws UnauthenticatedSessionException * @throws AuthenticationException */
public ChatterAuthToken authenticate() throws IOException, UnauthenticatedSessionException, AuthenticationException {
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/authentication/methods/UsernamePasswordAuthentication.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import org.apache.commons.httpclient.methods.PostMethod; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import java.net.URLEncoder; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class UsernamePasswordAuthentication extends AuthentificationMethod { private final IChatterData chatterData; public UsernamePasswordAuthentication(IChatterData chatterData) { this.chatterData = chatterData; } /** * <p>Authenticate using a username and password. This is discouraged by the oauth flow, * but it allows for transparent (and non human-intervention) authentication).</p> * * @return The response retrieved from the REST API (usually an XML string with all the tokens) * @throws IOException * @throws UnauthenticatedSessionException * @throws AuthenticationException */
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: src/com/salesforce/chatter/authentication/methods/UsernamePasswordAuthentication.java import org.apache.commons.httpclient.methods.PostMethod; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import java.net.URLEncoder; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class UsernamePasswordAuthentication extends AuthentificationMethod { private final IChatterData chatterData; public UsernamePasswordAuthentication(IChatterData chatterData) { this.chatterData = chatterData; } /** * <p>Authenticate using a username and password. This is discouraged by the oauth flow, * but it allows for transparent (and non human-intervention) authentication).</p> * * @return The response retrieved from the REST API (usually an XML string with all the tokens) * @throws IOException * @throws UnauthenticatedSessionException * @throws AuthenticationException */
public ChatterAuthToken authenticate() throws IOException, UnauthenticatedSessionException, AuthenticationException {
forcedotcom/JavaChatterRESTApi
test/unit/src/com/salesforce/chatter/authentication/methods/RefreshTokenAuthenticationTest.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class RefreshTokenAuthenticationTest { @Test
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: test/unit/src/com/salesforce/chatter/authentication/methods/RefreshTokenAuthenticationTest.java import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class RefreshTokenAuthenticationTest { @Test
public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException,
forcedotcom/JavaChatterRESTApi
test/unit/src/com/salesforce/chatter/authentication/methods/RefreshTokenAuthenticationTest.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class RefreshTokenAuthenticationTest { @Test public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException,
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: test/unit/src/com/salesforce/chatter/authentication/methods/RefreshTokenAuthenticationTest.java import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class RefreshTokenAuthenticationTest { @Test public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException,
AuthenticationException {
forcedotcom/JavaChatterRESTApi
test/unit/src/com/salesforce/chatter/authentication/methods/RefreshTokenAuthenticationTest.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class RefreshTokenAuthenticationTest { @Test public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException, AuthenticationException {
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: test/unit/src/com/salesforce/chatter/authentication/methods/RefreshTokenAuthenticationTest.java import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class RefreshTokenAuthenticationTest { @Test public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException, AuthenticationException {
IChatterData data = getMockedChatterData();
forcedotcom/JavaChatterRESTApi
test/unit/src/com/salesforce/chatter/authentication/methods/RefreshTokenAuthenticationTest.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class RefreshTokenAuthenticationTest { @Test public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException, AuthenticationException { IChatterData data = getMockedChatterData(); RefreshTokenAuthentication auth = new RefreshTokenAuthentication(data); HttpClient mockHttpClient = mock(HttpClient.class); when(mockHttpClient.executeMethod(any(PostMethod.class))).thenAnswer( new ExecuteMethodAnswer("{\"access_token\" : \"abc\" }")); auth.setHttpClient(mockHttpClient);
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: test/unit/src/com/salesforce/chatter/authentication/methods/RefreshTokenAuthenticationTest.java import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class RefreshTokenAuthenticationTest { @Test public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException, AuthenticationException { IChatterData data = getMockedChatterData(); RefreshTokenAuthentication auth = new RefreshTokenAuthentication(data); HttpClient mockHttpClient = mock(HttpClient.class); when(mockHttpClient.executeMethod(any(PostMethod.class))).thenAnswer( new ExecuteMethodAnswer("{\"access_token\" : \"abc\" }")); auth.setHttpClient(mockHttpClient);
ChatterAuthToken token = auth.authenticate();
forcedotcom/JavaChatterRESTApi
test/integration/src/com/salesforce/chatter/ChatterAuthInteractive.java
// Path: src/com/salesforce/chatter/authentication/ChatterAuthMethod.java // public enum ChatterAuthMethod { // // /** // * <p>This requires the user to visit a URL and return the authorization code to us.</p> // */ // INTERACTIVE, // /** // * <p>Uses username and password to authenticate.</p> // */ // PASSWORD, // /** // * <p>Uses client id, secret and code to authenticate.</p> // */ // CLIENT_SECRET, // /** // * <p>Uses a refresh token to authenticate.</p> // */ // REFRESH_TOKEN // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // }
import com.salesforce.chatter.authentication.ChatterAuthMethod; import com.salesforce.chatter.authentication.IChatterData;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter; /** * <p>These credentials should be substituted for valid data for the integration tests to succeed.</p> * * <p>It assumes the INTERACTIVE ChatterAuthMethod, since it is used by the "testPostInteractiveLogin" test on * {@link TestChatterPost}.</p> * * @author jroel * @since 1.0 * */ public class ChatterAuthInteractive implements IChatterData { private final String apiVersion = "24.0"; private final String instanceUrl = "https://na8.salesforce.com";
// Path: src/com/salesforce/chatter/authentication/ChatterAuthMethod.java // public enum ChatterAuthMethod { // // /** // * <p>This requires the user to visit a URL and return the authorization code to us.</p> // */ // INTERACTIVE, // /** // * <p>Uses username and password to authenticate.</p> // */ // PASSWORD, // /** // * <p>Uses client id, secret and code to authenticate.</p> // */ // CLIENT_SECRET, // /** // * <p>Uses a refresh token to authenticate.</p> // */ // REFRESH_TOKEN // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // Path: test/integration/src/com/salesforce/chatter/ChatterAuthInteractive.java import com.salesforce.chatter.authentication.ChatterAuthMethod; import com.salesforce.chatter.authentication.IChatterData; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter; /** * <p>These credentials should be substituted for valid data for the integration tests to succeed.</p> * * <p>It assumes the INTERACTIVE ChatterAuthMethod, since it is used by the "testPostInteractiveLogin" test on * {@link TestChatterPost}.</p> * * @author jroel * @since 1.0 * */ public class ChatterAuthInteractive implements IChatterData { private final String apiVersion = "24.0"; private final String instanceUrl = "https://na8.salesforce.com";
private final ChatterAuthMethod authMethod = ChatterAuthMethod.INTERACTIVE;
forcedotcom/JavaChatterRESTApi
test/examples/src/com/salesforce/chatter/ExampleChatterServiceWithProxy.java
// Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/commands/ChatterCommand.java // public interface ChatterCommand { // public String getURI(); // }
import org.apache.commons.httpclient.HttpClient; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.commands.ChatterCommand;
package com.salesforce.chatter; /** * <p>This is not a real test, but a common example of working with a proxy.</p> * * <p>In this case, we create a HttpClient ourselves (which currently is the default for a ChatterService anyway) and * give that (with the proxy preconfigured) to the ChatterService.</p> * * @author jroel * */ public class ExampleChatterServiceWithProxy { /** * <p>This sets a proxy host and port in a default {@link HttpClient}, which we then pass into the * ChatterService.</p> * * <p>We can then reuse the chatterService, knowing it will use the proxy for every {@link ChatterCommand}. */ public void testChatterServiceWithProxy() { String proxyHost = "proxy-host.example.net"; int proxyPort = 8080; HttpClient httpClient = new HttpClient(); httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
// Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/commands/ChatterCommand.java // public interface ChatterCommand { // public String getURI(); // } // Path: test/examples/src/com/salesforce/chatter/ExampleChatterServiceWithProxy.java import org.apache.commons.httpclient.HttpClient; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.commands.ChatterCommand; package com.salesforce.chatter; /** * <p>This is not a real test, but a common example of working with a proxy.</p> * * <p>In this case, we create a HttpClient ourselves (which currently is the default for a ChatterService anyway) and * give that (with the proxy preconfigured) to the ChatterService.</p> * * @author jroel * */ public class ExampleChatterServiceWithProxy { /** * <p>This sets a proxy host and port in a default {@link HttpClient}, which we then pass into the * ChatterService.</p> * * <p>We can then reuse the chatterService, knowing it will use the proxy for every {@link ChatterCommand}. */ public void testChatterServiceWithProxy() { String proxyHost = "proxy-host.example.net"; int proxyPort = 8080; HttpClient httpClient = new HttpClient(); httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
IChatterData chatterData = null;
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/ChatterCommands.java
// Path: src/com/salesforce/chatter/attachment/ImageAttachment.java // public class ImageAttachment extends Attachment { // // // NewFile value is forced by API 27.0-31.0 // public static final String IMAGE_TYPE = "NewFile"; // private String attachmentType = IMAGE_TYPE; // private String title; // private String description; // private String fileName; // private File image; // private String contentType; // // /** // * Construct an ImageAttachment object with title, content type, description and File object. // * // * @param title // * @param description // * @param contentType // * @param image // */ // public ImageAttachment(String title, String description, String contentType, File image) { // this.title = title; // this.description = description; // this.image = image; // this.fileName = image.getName(); // this.contentType = contentType; // } // // public String getTitle() { return title; } // // public void setTitle(String title) { this.title = title; } // // public String getDescription() { return description; } // // public void setDescription(String description) { this.description = description; } // // public String getFileName() { return fileName; } // // public void setFileName(String fileName) { this.fileName = fileName; } // // public File retrieveObjectFile() { return image; } // // public String retrieveContentType() { return contentType; } // // @Override // public String getAttachmentType() { return attachmentType; } // } // // Path: src/com/salesforce/chatter/message/Message.java // public class Message { // // private List<MessageSegment> segments = new ArrayList<MessageSegment>(); // private Attachment attachment; // // public void addSegment(MessageSegment segment) { // segments.add(segment); // } // // public List<MessageSegment> getSegments() { // return segments; // } // // public void addAttachment(Attachment attachment) { // this.attachment = attachment; // } // // public Attachment getAttachment() { // return attachment; // } // // public boolean hasAttachment() { // return attachment != null; // } // } // // Path: src/com/salesforce/chatter/message/MessageSegment.java // public abstract class MessageSegment { // // public static final String TYPE_KEY = "type"; // // public abstract String getTypeValue(); // public abstract String getSegmentKey(); // public abstract String getSegmentValue(); // }
import java.io.IOException; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.StringRequestEntity; import org.apache.commons.httpclient.methods.multipart.FilePart; import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; import org.apache.commons.httpclient.methods.multipart.Part; import org.apache.commons.httpclient.methods.multipart.StringPart; import org.codehaus.jackson.JsonGenerationException; import org.codehaus.jackson.map.JsonMappingException; import org.codehaus.jackson.map.ObjectMapper; import com.salesforce.chatter.attachment.ImageAttachment; import com.salesforce.chatter.message.Message; import com.salesforce.chatter.message.MessageSegment;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter; public class ChatterCommands { /** * <p>This creates a HttpMethod with the message as its payload. The message should be a properly formatted JSON * String (No validation is done on this).</p> * * <p>The message can be easily created using the {@link #getJsonPayload(com.salesforce.chatter.message.Message)} method.</p> * * @param uri The full URI which we will post to * @param message A properly formatted JSON message. UTF-8 is expected * @throws IOException */ public HttpMethod getJsonPost(String uri, String message) throws IOException { PostMethod post = new PostMethod(uri); post.setRequestHeader("Content-type", "application/json"); post.setRequestEntity(new StringRequestEntity(message, "application/json", "UTF-8")); return post; } /** * <p>This creates a HttpMethod with the message as its payload and image attachment. The message should be a properly formatted JSON * String (No validation is done on this).</p> * * <p>The message can be easily created using the {@link #getJsonPayload(Message)} method.</p> * * @param uri The full URI which we will post to * @param message A properly formatted JSON message. UTF-8 is expected * @param image A complete instance of ImageAttachment object * @throws IOException */
// Path: src/com/salesforce/chatter/attachment/ImageAttachment.java // public class ImageAttachment extends Attachment { // // // NewFile value is forced by API 27.0-31.0 // public static final String IMAGE_TYPE = "NewFile"; // private String attachmentType = IMAGE_TYPE; // private String title; // private String description; // private String fileName; // private File image; // private String contentType; // // /** // * Construct an ImageAttachment object with title, content type, description and File object. // * // * @param title // * @param description // * @param contentType // * @param image // */ // public ImageAttachment(String title, String description, String contentType, File image) { // this.title = title; // this.description = description; // this.image = image; // this.fileName = image.getName(); // this.contentType = contentType; // } // // public String getTitle() { return title; } // // public void setTitle(String title) { this.title = title; } // // public String getDescription() { return description; } // // public void setDescription(String description) { this.description = description; } // // public String getFileName() { return fileName; } // // public void setFileName(String fileName) { this.fileName = fileName; } // // public File retrieveObjectFile() { return image; } // // public String retrieveContentType() { return contentType; } // // @Override // public String getAttachmentType() { return attachmentType; } // } // // Path: src/com/salesforce/chatter/message/Message.java // public class Message { // // private List<MessageSegment> segments = new ArrayList<MessageSegment>(); // private Attachment attachment; // // public void addSegment(MessageSegment segment) { // segments.add(segment); // } // // public List<MessageSegment> getSegments() { // return segments; // } // // public void addAttachment(Attachment attachment) { // this.attachment = attachment; // } // // public Attachment getAttachment() { // return attachment; // } // // public boolean hasAttachment() { // return attachment != null; // } // } // // Path: src/com/salesforce/chatter/message/MessageSegment.java // public abstract class MessageSegment { // // public static final String TYPE_KEY = "type"; // // public abstract String getTypeValue(); // public abstract String getSegmentKey(); // public abstract String getSegmentValue(); // } // Path: src/com/salesforce/chatter/ChatterCommands.java import java.io.IOException; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.StringRequestEntity; import org.apache.commons.httpclient.methods.multipart.FilePart; import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; import org.apache.commons.httpclient.methods.multipart.Part; import org.apache.commons.httpclient.methods.multipart.StringPart; import org.codehaus.jackson.JsonGenerationException; import org.codehaus.jackson.map.JsonMappingException; import org.codehaus.jackson.map.ObjectMapper; import com.salesforce.chatter.attachment.ImageAttachment; import com.salesforce.chatter.message.Message; import com.salesforce.chatter.message.MessageSegment; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter; public class ChatterCommands { /** * <p>This creates a HttpMethod with the message as its payload. The message should be a properly formatted JSON * String (No validation is done on this).</p> * * <p>The message can be easily created using the {@link #getJsonPayload(com.salesforce.chatter.message.Message)} method.</p> * * @param uri The full URI which we will post to * @param message A properly formatted JSON message. UTF-8 is expected * @throws IOException */ public HttpMethod getJsonPost(String uri, String message) throws IOException { PostMethod post = new PostMethod(uri); post.setRequestHeader("Content-type", "application/json"); post.setRequestEntity(new StringRequestEntity(message, "application/json", "UTF-8")); return post; } /** * <p>This creates a HttpMethod with the message as its payload and image attachment. The message should be a properly formatted JSON * String (No validation is done on this).</p> * * <p>The message can be easily created using the {@link #getJsonPayload(Message)} method.</p> * * @param uri The full URI which we will post to * @param message A properly formatted JSON message. UTF-8 is expected * @param image A complete instance of ImageAttachment object * @throws IOException */
public HttpMethod getJsonPostForMultipartRequestEntity(String uri, String message, ImageAttachment image) throws IOException {
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/ChatterTools.java
// Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // }
import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import java.io.IOException; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethod;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter; public class ChatterTools { private final IChatterData chatterData; private HttpClient httpClient = new HttpClient(); public ChatterTools(IChatterData chatterData) { this.chatterData = chatterData; } public void setHttpClient(HttpClient httpClient) { this.httpClient = httpClient; } /* Private helper methods */ private String getServiceUri() { return "/services/data/v" + chatterData.getApiVersion(); } public String getChatterUri(String command) { return chatterData.getInstanceUrl() + getServiceUri() + command; }
// Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // Path: src/com/salesforce/chatter/ChatterTools.java import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import java.io.IOException; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethod; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter; public class ChatterTools { private final IChatterData chatterData; private HttpClient httpClient = new HttpClient(); public ChatterTools(IChatterData chatterData) { this.chatterData = chatterData; } public void setHttpClient(HttpClient httpClient) { this.httpClient = httpClient; } /* Private helper methods */ private String getServiceUri() { return "/services/data/v" + chatterData.getApiVersion(); } public String getChatterUri(String command) { return chatterData.getInstanceUrl() + getServiceUri() + command; }
public HttpMethod addHeaders(HttpMethod method, ChatterAuthToken token) {
forcedotcom/JavaChatterRESTApi
test/integration/src/com/salesforce/chatter/ChatterFindTest.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // // Path: src/com/salesforce/chatter/commands/ChatterCommand.java // public interface ChatterCommand { // public String getURI(); // } // // Path: src/com/salesforce/chatter/commands/FindUserCommand.java // public class FindUserCommand implements ChatterCommand { // // public static final String URI = "/chatter/users?q="; // // /** // * <p>Any URL encoded String. Allows wildcards (like "Jasp*").</p> // */ // private final String username; // // /** // * <p>Username needs to be URL encoded, you're free to use wildcards ("Jasp*").</p> // * // * @param username // */ // public FindUserCommand(String username) { // if (username == null) { // throw new InvalidParameterException( // "Unable to find a user without specifying the username in question. Please pass a valid username."); // } // this.username = username; // } // // /** // * <p>Returns the username.</p> // * // * @return String username // */ // public String getUsername() { // return username; // } // // /** // * <p>Returns the URI prefix used to search for users.</p> // * // * @return String URI // */ // @Override // public String getURI() { // return URI + username; // } // } // // Path: src/com/salesforce/chatter/message/Message.java // public class Message { // // private List<MessageSegment> segments = new ArrayList<MessageSegment>(); // private Attachment attachment; // // public void addSegment(MessageSegment segment) { // segments.add(segment); // } // // public List<MessageSegment> getSegments() { // return segments; // } // // public void addAttachment(Attachment attachment) { // this.attachment = attachment; // } // // public Attachment getAttachment() { // return attachment; // } // // public boolean hasAttachment() { // return attachment != null; // } // }
import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import com.salesforce.chatter.commands.ChatterCommand; import com.salesforce.chatter.commands.FindUserCommand; import com.salesforce.chatter.message.Message; import java.io.IOException; import org.junit.Test; import com.salesforce.chatter.authentication.AuthenticationException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter; /** * <p>A quick example of how to look up a user in your Salesforce.com environment via the Chatter API.</p> * * <p> The {@link ChatterData} object has to contain valid data for this test to succeed.</li> * * @author jroel * @since 1.0 * */ public class ChatterFindTest { @Test
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // // Path: src/com/salesforce/chatter/commands/ChatterCommand.java // public interface ChatterCommand { // public String getURI(); // } // // Path: src/com/salesforce/chatter/commands/FindUserCommand.java // public class FindUserCommand implements ChatterCommand { // // public static final String URI = "/chatter/users?q="; // // /** // * <p>Any URL encoded String. Allows wildcards (like "Jasp*").</p> // */ // private final String username; // // /** // * <p>Username needs to be URL encoded, you're free to use wildcards ("Jasp*").</p> // * // * @param username // */ // public FindUserCommand(String username) { // if (username == null) { // throw new InvalidParameterException( // "Unable to find a user without specifying the username in question. Please pass a valid username."); // } // this.username = username; // } // // /** // * <p>Returns the username.</p> // * // * @return String username // */ // public String getUsername() { // return username; // } // // /** // * <p>Returns the URI prefix used to search for users.</p> // * // * @return String URI // */ // @Override // public String getURI() { // return URI + username; // } // } // // Path: src/com/salesforce/chatter/message/Message.java // public class Message { // // private List<MessageSegment> segments = new ArrayList<MessageSegment>(); // private Attachment attachment; // // public void addSegment(MessageSegment segment) { // segments.add(segment); // } // // public List<MessageSegment> getSegments() { // return segments; // } // // public void addAttachment(Attachment attachment) { // this.attachment = attachment; // } // // public Attachment getAttachment() { // return attachment; // } // // public boolean hasAttachment() { // return attachment != null; // } // } // Path: test/integration/src/com/salesforce/chatter/ChatterFindTest.java import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import com.salesforce.chatter.commands.ChatterCommand; import com.salesforce.chatter.commands.FindUserCommand; import com.salesforce.chatter.message.Message; import java.io.IOException; import org.junit.Test; import com.salesforce.chatter.authentication.AuthenticationException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter; /** * <p>A quick example of how to look up a user in your Salesforce.com environment via the Chatter API.</p> * * <p> The {@link ChatterData} object has to contain valid data for this test to succeed.</li> * * @author jroel * @since 1.0 * */ public class ChatterFindTest { @Test
public void testUpdateStatus() throws IOException, UnauthenticatedSessionException, AuthenticationException {
forcedotcom/JavaChatterRESTApi
test/integration/src/com/salesforce/chatter/ChatterFindTest.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // // Path: src/com/salesforce/chatter/commands/ChatterCommand.java // public interface ChatterCommand { // public String getURI(); // } // // Path: src/com/salesforce/chatter/commands/FindUserCommand.java // public class FindUserCommand implements ChatterCommand { // // public static final String URI = "/chatter/users?q="; // // /** // * <p>Any URL encoded String. Allows wildcards (like "Jasp*").</p> // */ // private final String username; // // /** // * <p>Username needs to be URL encoded, you're free to use wildcards ("Jasp*").</p> // * // * @param username // */ // public FindUserCommand(String username) { // if (username == null) { // throw new InvalidParameterException( // "Unable to find a user without specifying the username in question. Please pass a valid username."); // } // this.username = username; // } // // /** // * <p>Returns the username.</p> // * // * @return String username // */ // public String getUsername() { // return username; // } // // /** // * <p>Returns the URI prefix used to search for users.</p> // * // * @return String URI // */ // @Override // public String getURI() { // return URI + username; // } // } // // Path: src/com/salesforce/chatter/message/Message.java // public class Message { // // private List<MessageSegment> segments = new ArrayList<MessageSegment>(); // private Attachment attachment; // // public void addSegment(MessageSegment segment) { // segments.add(segment); // } // // public List<MessageSegment> getSegments() { // return segments; // } // // public void addAttachment(Attachment attachment) { // this.attachment = attachment; // } // // public Attachment getAttachment() { // return attachment; // } // // public boolean hasAttachment() { // return attachment != null; // } // }
import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import com.salesforce.chatter.commands.ChatterCommand; import com.salesforce.chatter.commands.FindUserCommand; import com.salesforce.chatter.message.Message; import java.io.IOException; import org.junit.Test; import com.salesforce.chatter.authentication.AuthenticationException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter; /** * <p>A quick example of how to look up a user in your Salesforce.com environment via the Chatter API.</p> * * <p> The {@link ChatterData} object has to contain valid data for this test to succeed.</li> * * @author jroel * @since 1.0 * */ public class ChatterFindTest { @Test
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // // Path: src/com/salesforce/chatter/commands/ChatterCommand.java // public interface ChatterCommand { // public String getURI(); // } // // Path: src/com/salesforce/chatter/commands/FindUserCommand.java // public class FindUserCommand implements ChatterCommand { // // public static final String URI = "/chatter/users?q="; // // /** // * <p>Any URL encoded String. Allows wildcards (like "Jasp*").</p> // */ // private final String username; // // /** // * <p>Username needs to be URL encoded, you're free to use wildcards ("Jasp*").</p> // * // * @param username // */ // public FindUserCommand(String username) { // if (username == null) { // throw new InvalidParameterException( // "Unable to find a user without specifying the username in question. Please pass a valid username."); // } // this.username = username; // } // // /** // * <p>Returns the username.</p> // * // * @return String username // */ // public String getUsername() { // return username; // } // // /** // * <p>Returns the URI prefix used to search for users.</p> // * // * @return String URI // */ // @Override // public String getURI() { // return URI + username; // } // } // // Path: src/com/salesforce/chatter/message/Message.java // public class Message { // // private List<MessageSegment> segments = new ArrayList<MessageSegment>(); // private Attachment attachment; // // public void addSegment(MessageSegment segment) { // segments.add(segment); // } // // public List<MessageSegment> getSegments() { // return segments; // } // // public void addAttachment(Attachment attachment) { // this.attachment = attachment; // } // // public Attachment getAttachment() { // return attachment; // } // // public boolean hasAttachment() { // return attachment != null; // } // } // Path: test/integration/src/com/salesforce/chatter/ChatterFindTest.java import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import com.salesforce.chatter.commands.ChatterCommand; import com.salesforce.chatter.commands.FindUserCommand; import com.salesforce.chatter.message.Message; import java.io.IOException; import org.junit.Test; import com.salesforce.chatter.authentication.AuthenticationException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter; /** * <p>A quick example of how to look up a user in your Salesforce.com environment via the Chatter API.</p> * * <p> The {@link ChatterData} object has to contain valid data for this test to succeed.</li> * * @author jroel * @since 1.0 * */ public class ChatterFindTest { @Test
public void testUpdateStatus() throws IOException, UnauthenticatedSessionException, AuthenticationException {
forcedotcom/JavaChatterRESTApi
test/integration/src/com/salesforce/chatter/ChatterFindTest.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // // Path: src/com/salesforce/chatter/commands/ChatterCommand.java // public interface ChatterCommand { // public String getURI(); // } // // Path: src/com/salesforce/chatter/commands/FindUserCommand.java // public class FindUserCommand implements ChatterCommand { // // public static final String URI = "/chatter/users?q="; // // /** // * <p>Any URL encoded String. Allows wildcards (like "Jasp*").</p> // */ // private final String username; // // /** // * <p>Username needs to be URL encoded, you're free to use wildcards ("Jasp*").</p> // * // * @param username // */ // public FindUserCommand(String username) { // if (username == null) { // throw new InvalidParameterException( // "Unable to find a user without specifying the username in question. Please pass a valid username."); // } // this.username = username; // } // // /** // * <p>Returns the username.</p> // * // * @return String username // */ // public String getUsername() { // return username; // } // // /** // * <p>Returns the URI prefix used to search for users.</p> // * // * @return String URI // */ // @Override // public String getURI() { // return URI + username; // } // } // // Path: src/com/salesforce/chatter/message/Message.java // public class Message { // // private List<MessageSegment> segments = new ArrayList<MessageSegment>(); // private Attachment attachment; // // public void addSegment(MessageSegment segment) { // segments.add(segment); // } // // public List<MessageSegment> getSegments() { // return segments; // } // // public void addAttachment(Attachment attachment) { // this.attachment = attachment; // } // // public Attachment getAttachment() { // return attachment; // } // // public boolean hasAttachment() { // return attachment != null; // } // }
import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import com.salesforce.chatter.commands.ChatterCommand; import com.salesforce.chatter.commands.FindUserCommand; import com.salesforce.chatter.message.Message; import java.io.IOException; import org.junit.Test; import com.salesforce.chatter.authentication.AuthenticationException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter; /** * <p>A quick example of how to look up a user in your Salesforce.com environment via the Chatter API.</p> * * <p> The {@link ChatterData} object has to contain valid data for this test to succeed.</li> * * @author jroel * @since 1.0 * */ public class ChatterFindTest { @Test public void testUpdateStatus() throws IOException, UnauthenticatedSessionException, AuthenticationException {
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // // Path: src/com/salesforce/chatter/commands/ChatterCommand.java // public interface ChatterCommand { // public String getURI(); // } // // Path: src/com/salesforce/chatter/commands/FindUserCommand.java // public class FindUserCommand implements ChatterCommand { // // public static final String URI = "/chatter/users?q="; // // /** // * <p>Any URL encoded String. Allows wildcards (like "Jasp*").</p> // */ // private final String username; // // /** // * <p>Username needs to be URL encoded, you're free to use wildcards ("Jasp*").</p> // * // * @param username // */ // public FindUserCommand(String username) { // if (username == null) { // throw new InvalidParameterException( // "Unable to find a user without specifying the username in question. Please pass a valid username."); // } // this.username = username; // } // // /** // * <p>Returns the username.</p> // * // * @return String username // */ // public String getUsername() { // return username; // } // // /** // * <p>Returns the URI prefix used to search for users.</p> // * // * @return String URI // */ // @Override // public String getURI() { // return URI + username; // } // } // // Path: src/com/salesforce/chatter/message/Message.java // public class Message { // // private List<MessageSegment> segments = new ArrayList<MessageSegment>(); // private Attachment attachment; // // public void addSegment(MessageSegment segment) { // segments.add(segment); // } // // public List<MessageSegment> getSegments() { // return segments; // } // // public void addAttachment(Attachment attachment) { // this.attachment = attachment; // } // // public Attachment getAttachment() { // return attachment; // } // // public boolean hasAttachment() { // return attachment != null; // } // } // Path: test/integration/src/com/salesforce/chatter/ChatterFindTest.java import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import com.salesforce.chatter.commands.ChatterCommand; import com.salesforce.chatter.commands.FindUserCommand; import com.salesforce.chatter.message.Message; import java.io.IOException; import org.junit.Test; import com.salesforce.chatter.authentication.AuthenticationException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter; /** * <p>A quick example of how to look up a user in your Salesforce.com environment via the Chatter API.</p> * * <p> The {@link ChatterData} object has to contain valid data for this test to succeed.</li> * * @author jroel * @since 1.0 * */ public class ChatterFindTest { @Test public void testUpdateStatus() throws IOException, UnauthenticatedSessionException, AuthenticationException {
ChatterCommand cmd = new FindUserCommand("Jasper+Roel");
forcedotcom/JavaChatterRESTApi
test/integration/src/com/salesforce/chatter/ChatterFindTest.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // // Path: src/com/salesforce/chatter/commands/ChatterCommand.java // public interface ChatterCommand { // public String getURI(); // } // // Path: src/com/salesforce/chatter/commands/FindUserCommand.java // public class FindUserCommand implements ChatterCommand { // // public static final String URI = "/chatter/users?q="; // // /** // * <p>Any URL encoded String. Allows wildcards (like "Jasp*").</p> // */ // private final String username; // // /** // * <p>Username needs to be URL encoded, you're free to use wildcards ("Jasp*").</p> // * // * @param username // */ // public FindUserCommand(String username) { // if (username == null) { // throw new InvalidParameterException( // "Unable to find a user without specifying the username in question. Please pass a valid username."); // } // this.username = username; // } // // /** // * <p>Returns the username.</p> // * // * @return String username // */ // public String getUsername() { // return username; // } // // /** // * <p>Returns the URI prefix used to search for users.</p> // * // * @return String URI // */ // @Override // public String getURI() { // return URI + username; // } // } // // Path: src/com/salesforce/chatter/message/Message.java // public class Message { // // private List<MessageSegment> segments = new ArrayList<MessageSegment>(); // private Attachment attachment; // // public void addSegment(MessageSegment segment) { // segments.add(segment); // } // // public List<MessageSegment> getSegments() { // return segments; // } // // public void addAttachment(Attachment attachment) { // this.attachment = attachment; // } // // public Attachment getAttachment() { // return attachment; // } // // public boolean hasAttachment() { // return attachment != null; // } // }
import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import com.salesforce.chatter.commands.ChatterCommand; import com.salesforce.chatter.commands.FindUserCommand; import com.salesforce.chatter.message.Message; import java.io.IOException; import org.junit.Test; import com.salesforce.chatter.authentication.AuthenticationException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter; /** * <p>A quick example of how to look up a user in your Salesforce.com environment via the Chatter API.</p> * * <p> The {@link ChatterData} object has to contain valid data for this test to succeed.</li> * * @author jroel * @since 1.0 * */ public class ChatterFindTest { @Test public void testUpdateStatus() throws IOException, UnauthenticatedSessionException, AuthenticationException {
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // // Path: src/com/salesforce/chatter/commands/ChatterCommand.java // public interface ChatterCommand { // public String getURI(); // } // // Path: src/com/salesforce/chatter/commands/FindUserCommand.java // public class FindUserCommand implements ChatterCommand { // // public static final String URI = "/chatter/users?q="; // // /** // * <p>Any URL encoded String. Allows wildcards (like "Jasp*").</p> // */ // private final String username; // // /** // * <p>Username needs to be URL encoded, you're free to use wildcards ("Jasp*").</p> // * // * @param username // */ // public FindUserCommand(String username) { // if (username == null) { // throw new InvalidParameterException( // "Unable to find a user without specifying the username in question. Please pass a valid username."); // } // this.username = username; // } // // /** // * <p>Returns the username.</p> // * // * @return String username // */ // public String getUsername() { // return username; // } // // /** // * <p>Returns the URI prefix used to search for users.</p> // * // * @return String URI // */ // @Override // public String getURI() { // return URI + username; // } // } // // Path: src/com/salesforce/chatter/message/Message.java // public class Message { // // private List<MessageSegment> segments = new ArrayList<MessageSegment>(); // private Attachment attachment; // // public void addSegment(MessageSegment segment) { // segments.add(segment); // } // // public List<MessageSegment> getSegments() { // return segments; // } // // public void addAttachment(Attachment attachment) { // this.attachment = attachment; // } // // public Attachment getAttachment() { // return attachment; // } // // public boolean hasAttachment() { // return attachment != null; // } // } // Path: test/integration/src/com/salesforce/chatter/ChatterFindTest.java import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import com.salesforce.chatter.commands.ChatterCommand; import com.salesforce.chatter.commands.FindUserCommand; import com.salesforce.chatter.message.Message; import java.io.IOException; import org.junit.Test; import com.salesforce.chatter.authentication.AuthenticationException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter; /** * <p>A quick example of how to look up a user in your Salesforce.com environment via the Chatter API.</p> * * <p> The {@link ChatterData} object has to contain valid data for this test to succeed.</li> * * @author jroel * @since 1.0 * */ public class ChatterFindTest { @Test public void testUpdateStatus() throws IOException, UnauthenticatedSessionException, AuthenticationException {
ChatterCommand cmd = new FindUserCommand("Jasper+Roel");
forcedotcom/JavaChatterRESTApi
test/integration/src/com/salesforce/chatter/ChatterFindTest.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // // Path: src/com/salesforce/chatter/commands/ChatterCommand.java // public interface ChatterCommand { // public String getURI(); // } // // Path: src/com/salesforce/chatter/commands/FindUserCommand.java // public class FindUserCommand implements ChatterCommand { // // public static final String URI = "/chatter/users?q="; // // /** // * <p>Any URL encoded String. Allows wildcards (like "Jasp*").</p> // */ // private final String username; // // /** // * <p>Username needs to be URL encoded, you're free to use wildcards ("Jasp*").</p> // * // * @param username // */ // public FindUserCommand(String username) { // if (username == null) { // throw new InvalidParameterException( // "Unable to find a user without specifying the username in question. Please pass a valid username."); // } // this.username = username; // } // // /** // * <p>Returns the username.</p> // * // * @return String username // */ // public String getUsername() { // return username; // } // // /** // * <p>Returns the URI prefix used to search for users.</p> // * // * @return String URI // */ // @Override // public String getURI() { // return URI + username; // } // } // // Path: src/com/salesforce/chatter/message/Message.java // public class Message { // // private List<MessageSegment> segments = new ArrayList<MessageSegment>(); // private Attachment attachment; // // public void addSegment(MessageSegment segment) { // segments.add(segment); // } // // public List<MessageSegment> getSegments() { // return segments; // } // // public void addAttachment(Attachment attachment) { // this.attachment = attachment; // } // // public Attachment getAttachment() { // return attachment; // } // // public boolean hasAttachment() { // return attachment != null; // } // }
import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import com.salesforce.chatter.commands.ChatterCommand; import com.salesforce.chatter.commands.FindUserCommand; import com.salesforce.chatter.message.Message; import java.io.IOException; import org.junit.Test; import com.salesforce.chatter.authentication.AuthenticationException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter; /** * <p>A quick example of how to look up a user in your Salesforce.com environment via the Chatter API.</p> * * <p> The {@link ChatterData} object has to contain valid data for this test to succeed.</li> * * @author jroel * @since 1.0 * */ public class ChatterFindTest { @Test public void testUpdateStatus() throws IOException, UnauthenticatedSessionException, AuthenticationException { ChatterCommand cmd = new FindUserCommand("Jasper+Roel");
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // // Path: src/com/salesforce/chatter/commands/ChatterCommand.java // public interface ChatterCommand { // public String getURI(); // } // // Path: src/com/salesforce/chatter/commands/FindUserCommand.java // public class FindUserCommand implements ChatterCommand { // // public static final String URI = "/chatter/users?q="; // // /** // * <p>Any URL encoded String. Allows wildcards (like "Jasp*").</p> // */ // private final String username; // // /** // * <p>Username needs to be URL encoded, you're free to use wildcards ("Jasp*").</p> // * // * @param username // */ // public FindUserCommand(String username) { // if (username == null) { // throw new InvalidParameterException( // "Unable to find a user without specifying the username in question. Please pass a valid username."); // } // this.username = username; // } // // /** // * <p>Returns the username.</p> // * // * @return String username // */ // public String getUsername() { // return username; // } // // /** // * <p>Returns the URI prefix used to search for users.</p> // * // * @return String URI // */ // @Override // public String getURI() { // return URI + username; // } // } // // Path: src/com/salesforce/chatter/message/Message.java // public class Message { // // private List<MessageSegment> segments = new ArrayList<MessageSegment>(); // private Attachment attachment; // // public void addSegment(MessageSegment segment) { // segments.add(segment); // } // // public List<MessageSegment> getSegments() { // return segments; // } // // public void addAttachment(Attachment attachment) { // this.attachment = attachment; // } // // public Attachment getAttachment() { // return attachment; // } // // public boolean hasAttachment() { // return attachment != null; // } // } // Path: test/integration/src/com/salesforce/chatter/ChatterFindTest.java import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import com.salesforce.chatter.commands.ChatterCommand; import com.salesforce.chatter.commands.FindUserCommand; import com.salesforce.chatter.message.Message; import java.io.IOException; import org.junit.Test; import com.salesforce.chatter.authentication.AuthenticationException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter; /** * <p>A quick example of how to look up a user in your Salesforce.com environment via the Chatter API.</p> * * <p> The {@link ChatterData} object has to contain valid data for this test to succeed.</li> * * @author jroel * @since 1.0 * */ public class ChatterFindTest { @Test public void testUpdateStatus() throws IOException, UnauthenticatedSessionException, AuthenticationException { ChatterCommand cmd = new FindUserCommand("Jasper+Roel");
Message msg = new Message();
forcedotcom/JavaChatterRESTApi
test/unit/src/com/salesforce/chatter/authentication/methods/InteractiveAuthenticationTest.java
// Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import java.io.InputStream; import org.apache.commons.io.IOUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; @RunWith(PowerMockRunner.class) @PrepareForTest(InteractiveAuthentication.class) public class InteractiveAuthenticationTest { @Test public void testNormalFlow() throws Exception { InputStream orig = System.in; try {
// Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: test/unit/src/com/salesforce/chatter/authentication/methods/InteractiveAuthenticationTest.java import java.io.InputStream; import org.apache.commons.io.IOUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; @RunWith(PowerMockRunner.class) @PrepareForTest(InteractiveAuthentication.class) public class InteractiveAuthenticationTest { @Test public void testNormalFlow() throws Exception { InputStream orig = System.in; try {
IChatterData data = getMockedChatterData();
forcedotcom/JavaChatterRESTApi
test/unit/src/com/salesforce/chatter/authentication/methods/InteractiveAuthenticationTest.java
// Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import java.io.InputStream; import org.apache.commons.io.IOUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; @RunWith(PowerMockRunner.class) @PrepareForTest(InteractiveAuthentication.class) public class InteractiveAuthenticationTest { @Test public void testNormalFlow() throws Exception { InputStream orig = System.in; try { IChatterData data = getMockedChatterData(); String validVerificationCode = "aPrxb0v8x4SoqfmZmKMRPKgxoKDEL5d5ZdPaYVxdpVSywTCIFBw_cfpyNB3Whit5GYWZhwzI7Q=="; InputStream in = IOUtils.toInputStream(validVerificationCode); ClientSecretAuthentication auth2 = mock(ClientSecretAuthentication.class);
// Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: test/unit/src/com/salesforce/chatter/authentication/methods/InteractiveAuthenticationTest.java import java.io.InputStream; import org.apache.commons.io.IOUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; @RunWith(PowerMockRunner.class) @PrepareForTest(InteractiveAuthentication.class) public class InteractiveAuthenticationTest { @Test public void testNormalFlow() throws Exception { InputStream orig = System.in; try { IChatterData data = getMockedChatterData(); String validVerificationCode = "aPrxb0v8x4SoqfmZmKMRPKgxoKDEL5d5ZdPaYVxdpVSywTCIFBw_cfpyNB3Whit5GYWZhwzI7Q=="; InputStream in = IOUtils.toInputStream(validVerificationCode); ClientSecretAuthentication auth2 = mock(ClientSecretAuthentication.class);
when(auth2.authenticate()).thenReturn(new ChatterAuthToken("abc"));
forcedotcom/JavaChatterRESTApi
test/unit/src/com/salesforce/chatter/authentication/methods/InteractiveAuthenticationTest.java
// Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import java.io.InputStream; import org.apache.commons.io.IOUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; @RunWith(PowerMockRunner.class) @PrepareForTest(InteractiveAuthentication.class) public class InteractiveAuthenticationTest { @Test public void testNormalFlow() throws Exception { InputStream orig = System.in; try { IChatterData data = getMockedChatterData(); String validVerificationCode = "aPrxb0v8x4SoqfmZmKMRPKgxoKDEL5d5ZdPaYVxdpVSywTCIFBw_cfpyNB3Whit5GYWZhwzI7Q=="; InputStream in = IOUtils.toInputStream(validVerificationCode); ClientSecretAuthentication auth2 = mock(ClientSecretAuthentication.class); when(auth2.authenticate()).thenReturn(new ChatterAuthToken("abc")); PowerMockito.whenNew(ClientSecretAuthentication.class).withArguments(any(), anyString()).thenReturn(auth2); System.setIn(in); InteractiveAuthentication auth = new InteractiveAuthentication(data); ChatterAuthToken token = auth.authenticate(); assertEquals("abc", token.getAccessToken()); } finally { System.setIn(orig); } }
// Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: test/unit/src/com/salesforce/chatter/authentication/methods/InteractiveAuthenticationTest.java import java.io.InputStream; import org.apache.commons.io.IOUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; @RunWith(PowerMockRunner.class) @PrepareForTest(InteractiveAuthentication.class) public class InteractiveAuthenticationTest { @Test public void testNormalFlow() throws Exception { InputStream orig = System.in; try { IChatterData data = getMockedChatterData(); String validVerificationCode = "aPrxb0v8x4SoqfmZmKMRPKgxoKDEL5d5ZdPaYVxdpVSywTCIFBw_cfpyNB3Whit5GYWZhwzI7Q=="; InputStream in = IOUtils.toInputStream(validVerificationCode); ClientSecretAuthentication auth2 = mock(ClientSecretAuthentication.class); when(auth2.authenticate()).thenReturn(new ChatterAuthToken("abc")); PowerMockito.whenNew(ClientSecretAuthentication.class).withArguments(any(), anyString()).thenReturn(auth2); System.setIn(in); InteractiveAuthentication auth = new InteractiveAuthentication(data); ChatterAuthToken token = auth.authenticate(); assertEquals("abc", token.getAccessToken()); } finally { System.setIn(orig); } }
@Test(expected = UnauthenticatedSessionException.class)
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/authentication/methods/ClientSecretAuthentication.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.PostMethod;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class ClientSecretAuthentication extends AuthentificationMethod { private final IChatterData chatterData; private final String clientCode; /** * * @param chatterData * @param clientCode If null, the clientCode from chatterData is used */ public ClientSecretAuthentication(IChatterData chatterData, String clientCode) { this.chatterData = chatterData; this.clientCode = clientCode; } /** * <p>Authenticate using a client Secret. This is usually gotten by either asking the user, * or by using a callback. This allows for transparent (and non human-intervention) authentication.</p> * * @return The response retrieved from the REST API (usually an XML string with all the tokens) * @throws IOException * @throws UnauthenticatedSessionException * @throws AuthenticationException */
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: src/com/salesforce/chatter/authentication/methods/ClientSecretAuthentication.java import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.PostMethod; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class ClientSecretAuthentication extends AuthentificationMethod { private final IChatterData chatterData; private final String clientCode; /** * * @param chatterData * @param clientCode If null, the clientCode from chatterData is used */ public ClientSecretAuthentication(IChatterData chatterData, String clientCode) { this.chatterData = chatterData; this.clientCode = clientCode; } /** * <p>Authenticate using a client Secret. This is usually gotten by either asking the user, * or by using a callback. This allows for transparent (and non human-intervention) authentication.</p> * * @return The response retrieved from the REST API (usually an XML string with all the tokens) * @throws IOException * @throws UnauthenticatedSessionException * @throws AuthenticationException */
public ChatterAuthToken authenticate() throws IOException, UnauthenticatedSessionException, AuthenticationException {
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/authentication/methods/ClientSecretAuthentication.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.PostMethod;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class ClientSecretAuthentication extends AuthentificationMethod { private final IChatterData chatterData; private final String clientCode; /** * * @param chatterData * @param clientCode If null, the clientCode from chatterData is used */ public ClientSecretAuthentication(IChatterData chatterData, String clientCode) { this.chatterData = chatterData; this.clientCode = clientCode; } /** * <p>Authenticate using a client Secret. This is usually gotten by either asking the user, * or by using a callback. This allows for transparent (and non human-intervention) authentication.</p> * * @return The response retrieved from the REST API (usually an XML string with all the tokens) * @throws IOException * @throws UnauthenticatedSessionException * @throws AuthenticationException */
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: src/com/salesforce/chatter/authentication/methods/ClientSecretAuthentication.java import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.PostMethod; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class ClientSecretAuthentication extends AuthentificationMethod { private final IChatterData chatterData; private final String clientCode; /** * * @param chatterData * @param clientCode If null, the clientCode from chatterData is used */ public ClientSecretAuthentication(IChatterData chatterData, String clientCode) { this.chatterData = chatterData; this.clientCode = clientCode; } /** * <p>Authenticate using a client Secret. This is usually gotten by either asking the user, * or by using a callback. This allows for transparent (and non human-intervention) authentication.</p> * * @return The response retrieved from the REST API (usually an XML string with all the tokens) * @throws IOException * @throws UnauthenticatedSessionException * @throws AuthenticationException */
public ChatterAuthToken authenticate() throws IOException, UnauthenticatedSessionException, AuthenticationException {
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/authentication/methods/ClientSecretAuthentication.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.PostMethod;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class ClientSecretAuthentication extends AuthentificationMethod { private final IChatterData chatterData; private final String clientCode; /** * * @param chatterData * @param clientCode If null, the clientCode from chatterData is used */ public ClientSecretAuthentication(IChatterData chatterData, String clientCode) { this.chatterData = chatterData; this.clientCode = clientCode; } /** * <p>Authenticate using a client Secret. This is usually gotten by either asking the user, * or by using a callback. This allows for transparent (and non human-intervention) authentication.</p> * * @return The response retrieved from the REST API (usually an XML string with all the tokens) * @throws IOException * @throws UnauthenticatedSessionException * @throws AuthenticationException */
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: src/com/salesforce/chatter/authentication/methods/ClientSecretAuthentication.java import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.PostMethod; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class ClientSecretAuthentication extends AuthentificationMethod { private final IChatterData chatterData; private final String clientCode; /** * * @param chatterData * @param clientCode If null, the clientCode from chatterData is used */ public ClientSecretAuthentication(IChatterData chatterData, String clientCode) { this.chatterData = chatterData; this.clientCode = clientCode; } /** * <p>Authenticate using a client Secret. This is usually gotten by either asking the user, * or by using a callback. This allows for transparent (and non human-intervention) authentication.</p> * * @return The response retrieved from the REST API (usually an XML string with all the tokens) * @throws IOException * @throws UnauthenticatedSessionException * @throws AuthenticationException */
public ChatterAuthToken authenticate() throws IOException, UnauthenticatedSessionException, AuthenticationException {
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/authentication/methods/InteractiveAuthentication.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import com.salesforce.chatter.authentication.AuthenticationException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; /** * <p>Asks the user to get the verificationCode (clientSecret) and use {@link ClientSecretAuthentication} to complete the * authentication.</p> * * @author jroel * @since 1.0 * */ public class InteractiveAuthentication extends AuthentificationMethod { private static final String TEST_VERIFICATION_URL = "https://test.salesforce.com/services/oauth2/authorize?response_type=code&client_id=__CLIENTID__&redirect_uri=__REDIRECTURI__"; private int attempts = 3;
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: src/com/salesforce/chatter/authentication/methods/InteractiveAuthentication.java import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import com.salesforce.chatter.authentication.AuthenticationException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; /** * <p>Asks the user to get the verificationCode (clientSecret) and use {@link ClientSecretAuthentication} to complete the * authentication.</p> * * @author jroel * @since 1.0 * */ public class InteractiveAuthentication extends AuthentificationMethod { private static final String TEST_VERIFICATION_URL = "https://test.salesforce.com/services/oauth2/authorize?response_type=code&client_id=__CLIENTID__&redirect_uri=__REDIRECTURI__"; private int attempts = 3;
private final IChatterData chatterData;
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/authentication/methods/InteractiveAuthentication.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import com.salesforce.chatter.authentication.AuthenticationException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; /** * <p>Asks the user to get the verificationCode (clientSecret) and use {@link ClientSecretAuthentication} to complete the * authentication.</p> * * @author jroel * @since 1.0 * */ public class InteractiveAuthentication extends AuthentificationMethod { private static final String TEST_VERIFICATION_URL = "https://test.salesforce.com/services/oauth2/authorize?response_type=code&client_id=__CLIENTID__&redirect_uri=__REDIRECTURI__"; private int attempts = 3; private final IChatterData chatterData; public InteractiveAuthentication(IChatterData chatterData) { this.chatterData = chatterData; } /** * <p>Start the interactive authentication. It will ask the user to visit the authentication page and report back * the verification code.</p> * * @return ChatterAuthToken When authenticated with success, the ChatterAuthToken will be returned * @throws IOException Thrown when a problem during I/O occurs * @throws AuthenticationException in case we got a String that looked like a Verification code, but was the wrong * one * @throws UnauthenticatedSessionException Thrown if after several attempts no valid authentication token was * created */
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: src/com/salesforce/chatter/authentication/methods/InteractiveAuthentication.java import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import com.salesforce.chatter.authentication.AuthenticationException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; /** * <p>Asks the user to get the verificationCode (clientSecret) and use {@link ClientSecretAuthentication} to complete the * authentication.</p> * * @author jroel * @since 1.0 * */ public class InteractiveAuthentication extends AuthentificationMethod { private static final String TEST_VERIFICATION_URL = "https://test.salesforce.com/services/oauth2/authorize?response_type=code&client_id=__CLIENTID__&redirect_uri=__REDIRECTURI__"; private int attempts = 3; private final IChatterData chatterData; public InteractiveAuthentication(IChatterData chatterData) { this.chatterData = chatterData; } /** * <p>Start the interactive authentication. It will ask the user to visit the authentication page and report back * the verification code.</p> * * @return ChatterAuthToken When authenticated with success, the ChatterAuthToken will be returned * @throws IOException Thrown when a problem during I/O occurs * @throws AuthenticationException in case we got a String that looked like a Verification code, but was the wrong * one * @throws UnauthenticatedSessionException Thrown if after several attempts no valid authentication token was * created */
public ChatterAuthToken authenticate() throws IOException, UnauthenticatedSessionException, AuthenticationException {
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/authentication/methods/InteractiveAuthentication.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import com.salesforce.chatter.authentication.AuthenticationException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; /** * <p>Asks the user to get the verificationCode (clientSecret) and use {@link ClientSecretAuthentication} to complete the * authentication.</p> * * @author jroel * @since 1.0 * */ public class InteractiveAuthentication extends AuthentificationMethod { private static final String TEST_VERIFICATION_URL = "https://test.salesforce.com/services/oauth2/authorize?response_type=code&client_id=__CLIENTID__&redirect_uri=__REDIRECTURI__"; private int attempts = 3; private final IChatterData chatterData; public InteractiveAuthentication(IChatterData chatterData) { this.chatterData = chatterData; } /** * <p>Start the interactive authentication. It will ask the user to visit the authentication page and report back * the verification code.</p> * * @return ChatterAuthToken When authenticated with success, the ChatterAuthToken will be returned * @throws IOException Thrown when a problem during I/O occurs * @throws AuthenticationException in case we got a String that looked like a Verification code, but was the wrong * one * @throws UnauthenticatedSessionException Thrown if after several attempts no valid authentication token was * created */
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: src/com/salesforce/chatter/authentication/methods/InteractiveAuthentication.java import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import com.salesforce.chatter.authentication.AuthenticationException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; /** * <p>Asks the user to get the verificationCode (clientSecret) and use {@link ClientSecretAuthentication} to complete the * authentication.</p> * * @author jroel * @since 1.0 * */ public class InteractiveAuthentication extends AuthentificationMethod { private static final String TEST_VERIFICATION_URL = "https://test.salesforce.com/services/oauth2/authorize?response_type=code&client_id=__CLIENTID__&redirect_uri=__REDIRECTURI__"; private int attempts = 3; private final IChatterData chatterData; public InteractiveAuthentication(IChatterData chatterData) { this.chatterData = chatterData; } /** * <p>Start the interactive authentication. It will ask the user to visit the authentication page and report back * the verification code.</p> * * @return ChatterAuthToken When authenticated with success, the ChatterAuthToken will be returned * @throws IOException Thrown when a problem during I/O occurs * @throws AuthenticationException in case we got a String that looked like a Verification code, but was the wrong * one * @throws UnauthenticatedSessionException Thrown if after several attempts no valid authentication token was * created */
public ChatterAuthToken authenticate() throws IOException, UnauthenticatedSessionException, AuthenticationException {
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/authentication/methods/InteractiveAuthentication.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import com.salesforce.chatter.authentication.AuthenticationException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; /** * <p>Asks the user to get the verificationCode (clientSecret) and use {@link ClientSecretAuthentication} to complete the * authentication.</p> * * @author jroel * @since 1.0 * */ public class InteractiveAuthentication extends AuthentificationMethod { private static final String TEST_VERIFICATION_URL = "https://test.salesforce.com/services/oauth2/authorize?response_type=code&client_id=__CLIENTID__&redirect_uri=__REDIRECTURI__"; private int attempts = 3; private final IChatterData chatterData; public InteractiveAuthentication(IChatterData chatterData) { this.chatterData = chatterData; } /** * <p>Start the interactive authentication. It will ask the user to visit the authentication page and report back * the verification code.</p> * * @return ChatterAuthToken When authenticated with success, the ChatterAuthToken will be returned * @throws IOException Thrown when a problem during I/O occurs * @throws AuthenticationException in case we got a String that looked like a Verification code, but was the wrong * one * @throws UnauthenticatedSessionException Thrown if after several attempts no valid authentication token was * created */
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: src/com/salesforce/chatter/authentication/methods/InteractiveAuthentication.java import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import com.salesforce.chatter.authentication.AuthenticationException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; /** * <p>Asks the user to get the verificationCode (clientSecret) and use {@link ClientSecretAuthentication} to complete the * authentication.</p> * * @author jroel * @since 1.0 * */ public class InteractiveAuthentication extends AuthentificationMethod { private static final String TEST_VERIFICATION_URL = "https://test.salesforce.com/services/oauth2/authorize?response_type=code&client_id=__CLIENTID__&redirect_uri=__REDIRECTURI__"; private int attempts = 3; private final IChatterData chatterData; public InteractiveAuthentication(IChatterData chatterData) { this.chatterData = chatterData; } /** * <p>Start the interactive authentication. It will ask the user to visit the authentication page and report back * the verification code.</p> * * @return ChatterAuthToken When authenticated with success, the ChatterAuthToken will be returned * @throws IOException Thrown when a problem during I/O occurs * @throws AuthenticationException in case we got a String that looked like a Verification code, but was the wrong * one * @throws UnauthenticatedSessionException Thrown if after several attempts no valid authentication token was * created */
public ChatterAuthToken authenticate() throws IOException, UnauthenticatedSessionException, AuthenticationException {
forcedotcom/JavaChatterRESTApi
test/unit/src/com/salesforce/chatter/authentication/methods/UsernamePasswordAuthenticationTest.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class UsernamePasswordAuthenticationTest { @Test
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: test/unit/src/com/salesforce/chatter/authentication/methods/UsernamePasswordAuthenticationTest.java import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class UsernamePasswordAuthenticationTest { @Test
public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException,
forcedotcom/JavaChatterRESTApi
test/unit/src/com/salesforce/chatter/authentication/methods/UsernamePasswordAuthenticationTest.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class UsernamePasswordAuthenticationTest { @Test public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException,
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: test/unit/src/com/salesforce/chatter/authentication/methods/UsernamePasswordAuthenticationTest.java import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class UsernamePasswordAuthenticationTest { @Test public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException,
AuthenticationException {
forcedotcom/JavaChatterRESTApi
test/unit/src/com/salesforce/chatter/authentication/methods/UsernamePasswordAuthenticationTest.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class UsernamePasswordAuthenticationTest { @Test public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException, AuthenticationException {
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: test/unit/src/com/salesforce/chatter/authentication/methods/UsernamePasswordAuthenticationTest.java import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class UsernamePasswordAuthenticationTest { @Test public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException, AuthenticationException {
IChatterData data = getMockedChatterData();
forcedotcom/JavaChatterRESTApi
test/unit/src/com/salesforce/chatter/authentication/methods/UsernamePasswordAuthenticationTest.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class UsernamePasswordAuthenticationTest { @Test public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException, AuthenticationException { IChatterData data = getMockedChatterData(); UsernamePasswordAuthentication auth = new UsernamePasswordAuthentication(data); HttpClient mockHttpClient = mock(HttpClient.class); when(mockHttpClient.executeMethod(any(PostMethod.class))).thenAnswer( new ExecuteMethodAnswer("{\"access_token\" : \"abc\" }")); auth.setHttpClient(mockHttpClient);
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: test/unit/src/com/salesforce/chatter/authentication/methods/UsernamePasswordAuthenticationTest.java import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.*; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class UsernamePasswordAuthenticationTest { @Test public void testNormalFlow() throws HttpException, IOException, UnauthenticatedSessionException, AuthenticationException { IChatterData data = getMockedChatterData(); UsernamePasswordAuthentication auth = new UsernamePasswordAuthentication(data); HttpClient mockHttpClient = mock(HttpClient.class); when(mockHttpClient.executeMethod(any(PostMethod.class))).thenAnswer( new ExecuteMethodAnswer("{\"access_token\" : \"abc\" }")); auth.setHttpClient(mockHttpClient);
ChatterAuthToken token = auth.authenticate();
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/authentication/methods/RefreshTokenAuthentication.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import org.apache.commons.httpclient.methods.PostMethod; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import java.net.URLEncoder; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class RefreshTokenAuthentication extends AuthentificationMethod { private final IChatterData chatterData; public RefreshTokenAuthentication(IChatterData chatterData) { this.chatterData = chatterData; } /** * <p>Using a valid Refresh token we can get a new accessToken.</p> * * @return The response retrieved from the REST API (usually an XML string with all the tokens) * @throws IOException * @throws UnauthenticatedSessionException */ @Override
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: src/com/salesforce/chatter/authentication/methods/RefreshTokenAuthentication.java import org.apache.commons.httpclient.methods.PostMethod; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import java.net.URLEncoder; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class RefreshTokenAuthentication extends AuthentificationMethod { private final IChatterData chatterData; public RefreshTokenAuthentication(IChatterData chatterData) { this.chatterData = chatterData; } /** * <p>Using a valid Refresh token we can get a new accessToken.</p> * * @return The response retrieved from the REST API (usually an XML string with all the tokens) * @throws IOException * @throws UnauthenticatedSessionException */ @Override
public ChatterAuthToken authenticate() throws IOException, UnauthenticatedSessionException, AuthenticationException {
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/authentication/methods/RefreshTokenAuthentication.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import org.apache.commons.httpclient.methods.PostMethod; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import java.net.URLEncoder; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class RefreshTokenAuthentication extends AuthentificationMethod { private final IChatterData chatterData; public RefreshTokenAuthentication(IChatterData chatterData) { this.chatterData = chatterData; } /** * <p>Using a valid Refresh token we can get a new accessToken.</p> * * @return The response retrieved from the REST API (usually an XML string with all the tokens) * @throws IOException * @throws UnauthenticatedSessionException */ @Override
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: src/com/salesforce/chatter/authentication/methods/RefreshTokenAuthentication.java import org.apache.commons.httpclient.methods.PostMethod; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import java.net.URLEncoder; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class RefreshTokenAuthentication extends AuthentificationMethod { private final IChatterData chatterData; public RefreshTokenAuthentication(IChatterData chatterData) { this.chatterData = chatterData; } /** * <p>Using a valid Refresh token we can get a new accessToken.</p> * * @return The response retrieved from the REST API (usually an XML string with all the tokens) * @throws IOException * @throws UnauthenticatedSessionException */ @Override
public ChatterAuthToken authenticate() throws IOException, UnauthenticatedSessionException, AuthenticationException {
forcedotcom/JavaChatterRESTApi
src/com/salesforce/chatter/authentication/methods/RefreshTokenAuthentication.java
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // }
import org.apache.commons.httpclient.methods.PostMethod; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import java.net.URLEncoder; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class RefreshTokenAuthentication extends AuthentificationMethod { private final IChatterData chatterData; public RefreshTokenAuthentication(IChatterData chatterData) { this.chatterData = chatterData; } /** * <p>Using a valid Refresh token we can get a new accessToken.</p> * * @return The response retrieved from the REST API (usually an XML string with all the tokens) * @throws IOException * @throws UnauthenticatedSessionException */ @Override
// Path: src/com/salesforce/chatter/authentication/AuthenticationException.java // public class AuthenticationException extends Exception { // // private static final long serialVersionUID = -4301971480963574988L; // // public AuthenticationException(Exception e) { // super(e); // } // // public AuthenticationException(String e) { // super(e); // } // // } // // Path: src/com/salesforce/chatter/authentication/ChatterAuthToken.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class ChatterAuthToken { // // private String accessToken; // private String id; // private String issuedAt; // private String scope; // private String refreshToken; // private String instanceUrl; // private String signature; // // public ChatterAuthToken(String accessToken) { // this.accessToken = accessToken; // } // // /** // * <p>This constructor is mostly used by bean-like structures (currently the // * JSON parser uses this).</p> // */ // public ChatterAuthToken() { // // } // // public String getAccessToken() { // return accessToken; // } // // public String getId() { // return id; // } // // public String getIssuedAt() { // return issuedAt; // } // // public String getScope() { // return scope; // } // // public String getRefreshToken() { // return refreshToken; // } // // public String getInstanceUrl() { // return instanceUrl; // } // // public String getSignature() { // return signature; // } // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // // Path: src/com/salesforce/chatter/authentication/UnauthenticatedSessionException.java // public class UnauthenticatedSessionException extends Exception { // // private static final long serialVersionUID = -827912609041441511L; // // public UnauthenticatedSessionException(String message) { // super(message); // } // // } // Path: src/com/salesforce/chatter/authentication/methods/RefreshTokenAuthentication.java import org.apache.commons.httpclient.methods.PostMethod; import com.salesforce.chatter.authentication.AuthenticationException; import com.salesforce.chatter.authentication.ChatterAuthToken; import com.salesforce.chatter.authentication.IChatterData; import com.salesforce.chatter.authentication.UnauthenticatedSessionException; import java.io.IOException; import java.net.URLEncoder; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter.authentication.methods; public class RefreshTokenAuthentication extends AuthentificationMethod { private final IChatterData chatterData; public RefreshTokenAuthentication(IChatterData chatterData) { this.chatterData = chatterData; } /** * <p>Using a valid Refresh token we can get a new accessToken.</p> * * @return The response retrieved from the REST API (usually an XML string with all the tokens) * @throws IOException * @throws UnauthenticatedSessionException */ @Override
public ChatterAuthToken authenticate() throws IOException, UnauthenticatedSessionException, AuthenticationException {
forcedotcom/JavaChatterRESTApi
test/integration/src/com/salesforce/chatter/ChatterData.java
// Path: src/com/salesforce/chatter/authentication/ChatterAuthMethod.java // public enum ChatterAuthMethod { // // /** // * <p>This requires the user to visit a URL and return the authorization code to us.</p> // */ // INTERACTIVE, // /** // * <p>Uses username and password to authenticate.</p> // */ // PASSWORD, // /** // * <p>Uses client id, secret and code to authenticate.</p> // */ // CLIENT_SECRET, // /** // * <p>Uses a refresh token to authenticate.</p> // */ // REFRESH_TOKEN // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // }
import com.salesforce.chatter.authentication.ChatterAuthMethod; import com.salesforce.chatter.authentication.IChatterData;
/******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter; /** * <p>These credentials should be substituted for valid data for the integration tests to succeed.</p> * * <p>Currently it assumes the PASSWORD ChatterAuthMethod, but this can be substituted for any valid method, * as long as it contains valid credentials.</p> * * @author jroel * @since 1.0 * */ public class ChatterData implements IChatterData { private final String apiVersion = "24.0"; private final String instanceUrl = "https://naX.salesforce.com";
// Path: src/com/salesforce/chatter/authentication/ChatterAuthMethod.java // public enum ChatterAuthMethod { // // /** // * <p>This requires the user to visit a URL and return the authorization code to us.</p> // */ // INTERACTIVE, // /** // * <p>Uses username and password to authenticate.</p> // */ // PASSWORD, // /** // * <p>Uses client id, secret and code to authenticate.</p> // */ // CLIENT_SECRET, // /** // * <p>Uses a refresh token to authenticate.</p> // */ // REFRESH_TOKEN // } // // Path: src/com/salesforce/chatter/authentication/IChatterData.java // public interface IChatterData { // // /** // * @return String Something like "24.0" // */ // public String getApiVersion(); // // /** // * // * @return String Something like "https://na10.salesforce.com" // */ // public String getInstanceUrl(); // // public ChatterAuthMethod getAuthMethod(); // // public String getRefreshToken(); // // public String getClientCode(); // // public String getClientKey(); // // public String getClientSecret(); // // public String getUsername(); // // public String getPassword(); // // public String getClientCallback(); // // /** // * The Salesforce.com environment in which to perform authentication. // * Either PRODUCTION or TEST. // * // * @return // */ // public String getEnvironment(); // } // Path: test/integration/src/com/salesforce/chatter/ChatterData.java import com.salesforce.chatter.authentication.ChatterAuthMethod; import com.salesforce.chatter.authentication.IChatterData; /******************************************************************************* * Copyright (c) 2013, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.salesforce.chatter; /** * <p>These credentials should be substituted for valid data for the integration tests to succeed.</p> * * <p>Currently it assumes the PASSWORD ChatterAuthMethod, but this can be substituted for any valid method, * as long as it contains valid credentials.</p> * * @author jroel * @since 1.0 * */ public class ChatterData implements IChatterData { private final String apiVersion = "24.0"; private final String instanceUrl = "https://naX.salesforce.com";
private final ChatterAuthMethod authMethod = ChatterAuthMethod.PASSWORD;
immopoly/android
src/org/immopoly/android/model/Flats.java
// Path: src/org/immopoly/android/constants/Const.java // public class Const { // // public static final String LOG_TAG = "IMPO"; // // // Intents // // // Intent open webview // public static final String EXPOSE_ID = "exposeID"; // public static final String EXPOSE_NAME = "exposeName"; // public static final String EXPOSE_DESC = "exposeDescription"; // public static final String EXPOSE_URL = "exposeURL"; // public static final String EXPOSE_IN_PORTOFOLIO = "exposeInPortfolio"; // // // public static final String EXPOSE_OWNED = "exposeOwned"; // // // Intent add portofolio // public static final String EXPOSE_ADD_PORTIFOLIO = "addToPortifolio"; // public static final String EXPOSE_RELEASE_PORTIFOLIO = "releaseFromPortifolio"; // // public static final String SOURCE = "source"; // // // immopoly // public static final String EXPOSE_PICTURE_SMALL = "exposeDescription"; // // public static final String SHARED_PREF_EXPOSE_WEBVIEW = "exposeWebView"; // public static final String KEY_VISITED = "visited"; // // public static final String AUTH_URL = "oauth_url"; // public static final long EXPOSE_THRESHOLD_OLD = 1000L * 60L * 60L * 24L // * 30L; // public static final long EXPOSE_THRESHOLD_NEW = 1000L * 60L * 60L * 24L // * 7L; // // public static final String MESSAGE_IMMOPOLY_EXCEPTION = "org.immopoly.common.ImmopolyException"; // // public static final String IMMOPOLY_EMAIL = "immopolyteam@gmail.com"; // public static final int ANALYTICS_INTERVAL = 20; // // public static final int USER_SIGNUP = 110; // // // IS24 search control - search different radii until at least SEARCH_MIN_RESULTS flats are found // public static final float[] SEARCH_RADII = { 1, 3, 10 }; // in km // public static final int SEARCH_MIN_RESULTS = 50; // ignored for last search radius // public static final int SEARCH_MAX_RESULTS = 80; // forced result limit. fernglas me, baby! // }
import java.util.ArrayList; import org.immopoly.android.constants.Const; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.util.Log;
/* * This is the Android component of Immopoly * http://immopoly.appspot.com * Copyright (C) 2011 Tobias Sasse * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see http://www.gnu.org/licenses/. */ package org.immopoly.android.model; public class Flats extends ArrayList<Flat> { /** * Make sure when adding fields to add them in write to Parcel as well */ private static final long serialVersionUID = 4642208262846389104L; public Flats() {} public Flats( int capacity ) { super( capacity ); } public void parse(JSONObject obj) { try { Flat item; JSONObject resultList = obj.getJSONObject("resultlist.resultlist"); JSONArray resultEntries = resultList .optJSONArray("resultlistEntries"); if (resultEntries != null && resultEntries.length() > 0) { JSONObject flatsObj = resultEntries.getJSONObject(0); JSONArray resultEntry = flatsObj.optJSONArray("resultlistEntry"); if(resultEntry == null){ JSONObject flatObj = flatsObj.optJSONObject("resultlistEntry"); if ( flatObj != null) { item = new Flat(flatObj); add(item); if ( flatObj.has("distance") )
// Path: src/org/immopoly/android/constants/Const.java // public class Const { // // public static final String LOG_TAG = "IMPO"; // // // Intents // // // Intent open webview // public static final String EXPOSE_ID = "exposeID"; // public static final String EXPOSE_NAME = "exposeName"; // public static final String EXPOSE_DESC = "exposeDescription"; // public static final String EXPOSE_URL = "exposeURL"; // public static final String EXPOSE_IN_PORTOFOLIO = "exposeInPortfolio"; // // // public static final String EXPOSE_OWNED = "exposeOwned"; // // // Intent add portofolio // public static final String EXPOSE_ADD_PORTIFOLIO = "addToPortifolio"; // public static final String EXPOSE_RELEASE_PORTIFOLIO = "releaseFromPortifolio"; // // public static final String SOURCE = "source"; // // // immopoly // public static final String EXPOSE_PICTURE_SMALL = "exposeDescription"; // // public static final String SHARED_PREF_EXPOSE_WEBVIEW = "exposeWebView"; // public static final String KEY_VISITED = "visited"; // // public static final String AUTH_URL = "oauth_url"; // public static final long EXPOSE_THRESHOLD_OLD = 1000L * 60L * 60L * 24L // * 30L; // public static final long EXPOSE_THRESHOLD_NEW = 1000L * 60L * 60L * 24L // * 7L; // // public static final String MESSAGE_IMMOPOLY_EXCEPTION = "org.immopoly.common.ImmopolyException"; // // public static final String IMMOPOLY_EMAIL = "immopolyteam@gmail.com"; // public static final int ANALYTICS_INTERVAL = 20; // // public static final int USER_SIGNUP = 110; // // // IS24 search control - search different radii until at least SEARCH_MIN_RESULTS flats are found // public static final float[] SEARCH_RADII = { 1, 3, 10 }; // in km // public static final int SEARCH_MIN_RESULTS = 50; // ignored for last search radius // public static final int SEARCH_MAX_RESULTS = 80; // forced result limit. fernglas me, baby! // } // Path: src/org/immopoly/android/model/Flats.java import java.util.ArrayList; import org.immopoly.android.constants.Const; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.util.Log; /* * This is the Android component of Immopoly * http://immopoly.appspot.com * Copyright (C) 2011 Tobias Sasse * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see http://www.gnu.org/licenses/. */ package org.immopoly.android.model; public class Flats extends ArrayList<Flat> { /** * Make sure when adding fields to add them in write to Parcel as well */ private static final long serialVersionUID = 4642208262846389104L; public Flats() {} public Flats( int capacity ) { super( capacity ); } public void parse(JSONObject obj) { try { Flat item; JSONObject resultList = obj.getJSONObject("resultlist.resultlist"); JSONArray resultEntries = resultList .optJSONArray("resultlistEntries"); if (resultEntries != null && resultEntries.length() > 0) { JSONObject flatsObj = resultEntries.getJSONObject(0); JSONArray resultEntry = flatsObj.optJSONArray("resultlistEntry"); if(resultEntry == null){ JSONObject flatObj = flatsObj.optJSONObject("resultlistEntry"); if ( flatObj != null) { item = new Flat(flatObj); add(item); if ( flatObj.has("distance") )
Log.d( Const.LOG_TAG, "Parsed 1 flat. Max distance: " + flatObj.get( "distance" ) );
immopoly/android
src/org/immopoly/android/widget/ViewPager.java
// Path: src/org/immopoly/android/constants/Const.java // public class Const { // // public static final String LOG_TAG = "IMPO"; // // // Intents // // // Intent open webview // public static final String EXPOSE_ID = "exposeID"; // public static final String EXPOSE_NAME = "exposeName"; // public static final String EXPOSE_DESC = "exposeDescription"; // public static final String EXPOSE_URL = "exposeURL"; // public static final String EXPOSE_IN_PORTOFOLIO = "exposeInPortfolio"; // // // public static final String EXPOSE_OWNED = "exposeOwned"; // // // Intent add portofolio // public static final String EXPOSE_ADD_PORTIFOLIO = "addToPortifolio"; // public static final String EXPOSE_RELEASE_PORTIFOLIO = "releaseFromPortifolio"; // // public static final String SOURCE = "source"; // // // immopoly // public static final String EXPOSE_PICTURE_SMALL = "exposeDescription"; // // public static final String SHARED_PREF_EXPOSE_WEBVIEW = "exposeWebView"; // public static final String KEY_VISITED = "visited"; // // public static final String AUTH_URL = "oauth_url"; // public static final long EXPOSE_THRESHOLD_OLD = 1000L * 60L * 60L * 24L // * 30L; // public static final long EXPOSE_THRESHOLD_NEW = 1000L * 60L * 60L * 24L // * 7L; // // public static final String MESSAGE_IMMOPOLY_EXCEPTION = "org.immopoly.common.ImmopolyException"; // // public static final String IMMOPOLY_EMAIL = "immopolyteam@gmail.com"; // public static final int ANALYTICS_INTERVAL = 20; // // public static final int USER_SIGNUP = 110; // // // IS24 search control - search different radii until at least SEARCH_MIN_RESULTS flats are found // public static final float[] SEARCH_RADII = { 1, 3, 10 }; // in km // public static final int SEARCH_MIN_RESULTS = 50; // ignored for last search radius // public static final int SEARCH_MAX_RESULTS = 80; // forced result limit. fernglas me, baby! // }
import android.content.Context; import android.content.res.TypedArray; import android.database.DataSetObserver; import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Parcel; import android.os.Parcelable; import android.os.SystemClock; import android.support.v4.os.ParcelableCompat; import android.support.v4.os.ParcelableCompatCreatorCallbacks; import android.support.v4.view.KeyEventCompat; import android.support.v4.view.MotionEventCompat; import android.support.v4.view.VelocityTrackerCompat; import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewConfigurationCompat; import android.support.v4.widget.EdgeEffectCompat; import android.util.AttributeSet; import android.util.Log; import android.view.FocusFinder; import android.view.Gravity; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.SoundEffectConstants; import android.view.VelocityTracker; import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; import android.view.ViewParent; import android.view.accessibility.AccessibilityEvent; import android.view.animation.Interpolator; import android.widget.Scroller; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import org.immopoly.android.constants.Const;
if (!always && mCurItem == item && mItems.size() != 0) { setScrollingCacheEnabled(false); return; } int itemCount = mAdapter.getCount(); if (item < 0) { item = 0; } else if (item >= itemCount ) { item = itemCount - 1; } final int pageLimit = mOffscreenPageLimit; if (item > (mCurItem + pageLimit) || item < (mCurItem - pageLimit)) { // We are doing a jump by more than one page. To avoid // glitches, we want to keep all current pages in the view // until the scroll ends. for (int i=0; i<mItems.size(); i++) { mItems.get(i).scrolling = true; } } final boolean dispatchSelected = mCurItem != item; mCurItem = item; populate(); int destX; if ( forcedChildWidth > 0 ) { int width = getWidth() - (getPaddingLeft() + getPaddingRight()); destX = (forcedChildWidth + mPageMargin) * item; if ( item == itemCount-1) destX -= width - forcedChildWidth; else if ( item != 0 ) destX -= (width - (forcedChildWidth + mPageMargin))/2;
// Path: src/org/immopoly/android/constants/Const.java // public class Const { // // public static final String LOG_TAG = "IMPO"; // // // Intents // // // Intent open webview // public static final String EXPOSE_ID = "exposeID"; // public static final String EXPOSE_NAME = "exposeName"; // public static final String EXPOSE_DESC = "exposeDescription"; // public static final String EXPOSE_URL = "exposeURL"; // public static final String EXPOSE_IN_PORTOFOLIO = "exposeInPortfolio"; // // // public static final String EXPOSE_OWNED = "exposeOwned"; // // // Intent add portofolio // public static final String EXPOSE_ADD_PORTIFOLIO = "addToPortifolio"; // public static final String EXPOSE_RELEASE_PORTIFOLIO = "releaseFromPortifolio"; // // public static final String SOURCE = "source"; // // // immopoly // public static final String EXPOSE_PICTURE_SMALL = "exposeDescription"; // // public static final String SHARED_PREF_EXPOSE_WEBVIEW = "exposeWebView"; // public static final String KEY_VISITED = "visited"; // // public static final String AUTH_URL = "oauth_url"; // public static final long EXPOSE_THRESHOLD_OLD = 1000L * 60L * 60L * 24L // * 30L; // public static final long EXPOSE_THRESHOLD_NEW = 1000L * 60L * 60L * 24L // * 7L; // // public static final String MESSAGE_IMMOPOLY_EXCEPTION = "org.immopoly.common.ImmopolyException"; // // public static final String IMMOPOLY_EMAIL = "immopolyteam@gmail.com"; // public static final int ANALYTICS_INTERVAL = 20; // // public static final int USER_SIGNUP = 110; // // // IS24 search control - search different radii until at least SEARCH_MIN_RESULTS flats are found // public static final float[] SEARCH_RADII = { 1, 3, 10 }; // in km // public static final int SEARCH_MIN_RESULTS = 50; // ignored for last search radius // public static final int SEARCH_MAX_RESULTS = 80; // forced result limit. fernglas me, baby! // } // Path: src/org/immopoly/android/widget/ViewPager.java import android.content.Context; import android.content.res.TypedArray; import android.database.DataSetObserver; import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Parcel; import android.os.Parcelable; import android.os.SystemClock; import android.support.v4.os.ParcelableCompat; import android.support.v4.os.ParcelableCompatCreatorCallbacks; import android.support.v4.view.KeyEventCompat; import android.support.v4.view.MotionEventCompat; import android.support.v4.view.VelocityTrackerCompat; import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewConfigurationCompat; import android.support.v4.widget.EdgeEffectCompat; import android.util.AttributeSet; import android.util.Log; import android.view.FocusFinder; import android.view.Gravity; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.SoundEffectConstants; import android.view.VelocityTracker; import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; import android.view.ViewParent; import android.view.accessibility.AccessibilityEvent; import android.view.animation.Interpolator; import android.widget.Scroller; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import org.immopoly.android.constants.Const; if (!always && mCurItem == item && mItems.size() != 0) { setScrollingCacheEnabled(false); return; } int itemCount = mAdapter.getCount(); if (item < 0) { item = 0; } else if (item >= itemCount ) { item = itemCount - 1; } final int pageLimit = mOffscreenPageLimit; if (item > (mCurItem + pageLimit) || item < (mCurItem - pageLimit)) { // We are doing a jump by more than one page. To avoid // glitches, we want to keep all current pages in the view // until the scroll ends. for (int i=0; i<mItems.size(); i++) { mItems.get(i).scrolling = true; } } final boolean dispatchSelected = mCurItem != item; mCurItem = item; populate(); int destX; if ( forcedChildWidth > 0 ) { int width = getWidth() - (getPaddingLeft() + getPaddingRight()); destX = (forcedChildWidth + mPageMargin) * item; if ( item == itemCount-1) destX -= width - forcedChildWidth; else if ( item != 0 ) destX -= (width - (forcedChildWidth + mPageMargin))/2;
Log.i( Const.LOG_TAG, "Item: " + item + "/" + itemCount + " forced: " + forcedChildWidth + " margin: " + mPageMargin + " DestX: " + destX + " width: " + width + "/" + getWidth());
immopoly/android
src/org/immopoly/android/tasks/Result.java
// Path: src/org/immopoly/android/model/ImmopolyException.java // public class ImmopolyException extends org.immopoly.common.ImmopolyException { // // public ImmopolyException(Exception t) { // super(t); // } // // public ImmopolyException(String msg,Exception t) { // super(t); // message=msg; // } // // public ImmopolyException(String msg) { // super(); // message=msg; // } // // // public ImmopolyException(Context context, JSONObject jsonObject) { // super(jsonObject); // switch (errorCode) { // case USERNAME_NOT_FOUND: // message = context.getString(R.string.account_not_found); // break; // case 201: // message = context.getString(R.string.flat_already_in_portifolio); // break; // case 301: // message = context.getString(R.string.flat_does_not_exist_anymore); // break; // case 302: // message = context.getString(R.string.flat_has_no_raw_rent); // break; // case 441: // message = context.getString(R.string.expose_location_spoofing); // break; // case USER_SEND_PASSWORDMAIL_NOEMAIL: // message = context.getString(R.string.account_has_no_email);; // break; // case USER_SEND_PASSWORDMAIL_EMAIL_NOMATCH: // message = context.getString(R.string.account_has_different_email);; // break; // default: // Log.i( Const.LOG_TAG, "not yet translated ImmopolyException errorCode: " + errorCode ); // } // } // } // // Path: src/org/immopoly/android/model/ImmopolyHistory.java // public class ImmopolyHistory extends History{ // // // mandatory // private String text; // private long time; // private int type; // // // optional // private Double amount; // private long exposeId; // // // public ImmopolyHistory(JSONObject obj) { // super(obj); // } // // @Override // public void setText(String text) { // this.text = text; // } // // @Override // public void setTime(long time) { // this.time = time; // } // // /** // * Wird im Client nicht mehr serialisiert. // */ // @Override // public JSONObject toJSON() throws JSONException { // throw new UnsupportedOperationException(); // } // // @Override // public void setType(int type) { // this.type = type; // } // // // @Override // public void setAmount(double amount) { // this.amount = amount; // } // // @Override // public void setExposeId(long exposeId) { // this.exposeId = exposeId; // } // // // TODO method should exist in base interface // public long getExposeId() { // return exposeId; // } // // public int getType() { // return type; // } // // public Double getAmount() { // return amount; // } // // public String getText() { // return text; // } // // public long getTime() { // return time; // } // // }
import org.immopoly.android.model.ImmopolyException; import org.immopoly.android.model.ImmopolyHistory;
package org.immopoly.android.tasks; public class Result { public boolean success = false;
// Path: src/org/immopoly/android/model/ImmopolyException.java // public class ImmopolyException extends org.immopoly.common.ImmopolyException { // // public ImmopolyException(Exception t) { // super(t); // } // // public ImmopolyException(String msg,Exception t) { // super(t); // message=msg; // } // // public ImmopolyException(String msg) { // super(); // message=msg; // } // // // public ImmopolyException(Context context, JSONObject jsonObject) { // super(jsonObject); // switch (errorCode) { // case USERNAME_NOT_FOUND: // message = context.getString(R.string.account_not_found); // break; // case 201: // message = context.getString(R.string.flat_already_in_portifolio); // break; // case 301: // message = context.getString(R.string.flat_does_not_exist_anymore); // break; // case 302: // message = context.getString(R.string.flat_has_no_raw_rent); // break; // case 441: // message = context.getString(R.string.expose_location_spoofing); // break; // case USER_SEND_PASSWORDMAIL_NOEMAIL: // message = context.getString(R.string.account_has_no_email);; // break; // case USER_SEND_PASSWORDMAIL_EMAIL_NOMATCH: // message = context.getString(R.string.account_has_different_email);; // break; // default: // Log.i( Const.LOG_TAG, "not yet translated ImmopolyException errorCode: " + errorCode ); // } // } // } // // Path: src/org/immopoly/android/model/ImmopolyHistory.java // public class ImmopolyHistory extends History{ // // // mandatory // private String text; // private long time; // private int type; // // // optional // private Double amount; // private long exposeId; // // // public ImmopolyHistory(JSONObject obj) { // super(obj); // } // // @Override // public void setText(String text) { // this.text = text; // } // // @Override // public void setTime(long time) { // this.time = time; // } // // /** // * Wird im Client nicht mehr serialisiert. // */ // @Override // public JSONObject toJSON() throws JSONException { // throw new UnsupportedOperationException(); // } // // @Override // public void setType(int type) { // this.type = type; // } // // // @Override // public void setAmount(double amount) { // this.amount = amount; // } // // @Override // public void setExposeId(long exposeId) { // this.exposeId = exposeId; // } // // // TODO method should exist in base interface // public long getExposeId() { // return exposeId; // } // // public int getType() { // return type; // } // // public Double getAmount() { // return amount; // } // // public String getText() { // return text; // } // // public long getTime() { // return time; // } // // } // Path: src/org/immopoly/android/tasks/Result.java import org.immopoly.android.model.ImmopolyException; import org.immopoly.android.model.ImmopolyHistory; package org.immopoly.android.tasks; public class Result { public boolean success = false;
public ImmopolyHistory history = null;
immopoly/android
src/org/immopoly/android/tasks/Result.java
// Path: src/org/immopoly/android/model/ImmopolyException.java // public class ImmopolyException extends org.immopoly.common.ImmopolyException { // // public ImmopolyException(Exception t) { // super(t); // } // // public ImmopolyException(String msg,Exception t) { // super(t); // message=msg; // } // // public ImmopolyException(String msg) { // super(); // message=msg; // } // // // public ImmopolyException(Context context, JSONObject jsonObject) { // super(jsonObject); // switch (errorCode) { // case USERNAME_NOT_FOUND: // message = context.getString(R.string.account_not_found); // break; // case 201: // message = context.getString(R.string.flat_already_in_portifolio); // break; // case 301: // message = context.getString(R.string.flat_does_not_exist_anymore); // break; // case 302: // message = context.getString(R.string.flat_has_no_raw_rent); // break; // case 441: // message = context.getString(R.string.expose_location_spoofing); // break; // case USER_SEND_PASSWORDMAIL_NOEMAIL: // message = context.getString(R.string.account_has_no_email);; // break; // case USER_SEND_PASSWORDMAIL_EMAIL_NOMATCH: // message = context.getString(R.string.account_has_different_email);; // break; // default: // Log.i( Const.LOG_TAG, "not yet translated ImmopolyException errorCode: " + errorCode ); // } // } // } // // Path: src/org/immopoly/android/model/ImmopolyHistory.java // public class ImmopolyHistory extends History{ // // // mandatory // private String text; // private long time; // private int type; // // // optional // private Double amount; // private long exposeId; // // // public ImmopolyHistory(JSONObject obj) { // super(obj); // } // // @Override // public void setText(String text) { // this.text = text; // } // // @Override // public void setTime(long time) { // this.time = time; // } // // /** // * Wird im Client nicht mehr serialisiert. // */ // @Override // public JSONObject toJSON() throws JSONException { // throw new UnsupportedOperationException(); // } // // @Override // public void setType(int type) { // this.type = type; // } // // // @Override // public void setAmount(double amount) { // this.amount = amount; // } // // @Override // public void setExposeId(long exposeId) { // this.exposeId = exposeId; // } // // // TODO method should exist in base interface // public long getExposeId() { // return exposeId; // } // // public int getType() { // return type; // } // // public Double getAmount() { // return amount; // } // // public String getText() { // return text; // } // // public long getTime() { // return time; // } // // }
import org.immopoly.android.model.ImmopolyException; import org.immopoly.android.model.ImmopolyHistory;
package org.immopoly.android.tasks; public class Result { public boolean success = false; public ImmopolyHistory history = null;
// Path: src/org/immopoly/android/model/ImmopolyException.java // public class ImmopolyException extends org.immopoly.common.ImmopolyException { // // public ImmopolyException(Exception t) { // super(t); // } // // public ImmopolyException(String msg,Exception t) { // super(t); // message=msg; // } // // public ImmopolyException(String msg) { // super(); // message=msg; // } // // // public ImmopolyException(Context context, JSONObject jsonObject) { // super(jsonObject); // switch (errorCode) { // case USERNAME_NOT_FOUND: // message = context.getString(R.string.account_not_found); // break; // case 201: // message = context.getString(R.string.flat_already_in_portifolio); // break; // case 301: // message = context.getString(R.string.flat_does_not_exist_anymore); // break; // case 302: // message = context.getString(R.string.flat_has_no_raw_rent); // break; // case 441: // message = context.getString(R.string.expose_location_spoofing); // break; // case USER_SEND_PASSWORDMAIL_NOEMAIL: // message = context.getString(R.string.account_has_no_email);; // break; // case USER_SEND_PASSWORDMAIL_EMAIL_NOMATCH: // message = context.getString(R.string.account_has_different_email);; // break; // default: // Log.i( Const.LOG_TAG, "not yet translated ImmopolyException errorCode: " + errorCode ); // } // } // } // // Path: src/org/immopoly/android/model/ImmopolyHistory.java // public class ImmopolyHistory extends History{ // // // mandatory // private String text; // private long time; // private int type; // // // optional // private Double amount; // private long exposeId; // // // public ImmopolyHistory(JSONObject obj) { // super(obj); // } // // @Override // public void setText(String text) { // this.text = text; // } // // @Override // public void setTime(long time) { // this.time = time; // } // // /** // * Wird im Client nicht mehr serialisiert. // */ // @Override // public JSONObject toJSON() throws JSONException { // throw new UnsupportedOperationException(); // } // // @Override // public void setType(int type) { // this.type = type; // } // // // @Override // public void setAmount(double amount) { // this.amount = amount; // } // // @Override // public void setExposeId(long exposeId) { // this.exposeId = exposeId; // } // // // TODO method should exist in base interface // public long getExposeId() { // return exposeId; // } // // public int getType() { // return type; // } // // public Double getAmount() { // return amount; // } // // public String getText() { // return text; // } // // public long getTime() { // return time; // } // // } // Path: src/org/immopoly/android/tasks/Result.java import org.immopoly.android.model.ImmopolyException; import org.immopoly.android.model.ImmopolyHistory; package org.immopoly.android.tasks; public class Result { public boolean success = false; public ImmopolyHistory history = null;
public ImmopolyException exception = null;
immopoly/android
src/org/immopoly/android/model/Flat.java
// Path: src/org/immopoly/android/constants/Const.java // public class Const { // // public static final String LOG_TAG = "IMPO"; // // // Intents // // // Intent open webview // public static final String EXPOSE_ID = "exposeID"; // public static final String EXPOSE_NAME = "exposeName"; // public static final String EXPOSE_DESC = "exposeDescription"; // public static final String EXPOSE_URL = "exposeURL"; // public static final String EXPOSE_IN_PORTOFOLIO = "exposeInPortfolio"; // // // public static final String EXPOSE_OWNED = "exposeOwned"; // // // Intent add portofolio // public static final String EXPOSE_ADD_PORTIFOLIO = "addToPortifolio"; // public static final String EXPOSE_RELEASE_PORTIFOLIO = "releaseFromPortifolio"; // // public static final String SOURCE = "source"; // // // immopoly // public static final String EXPOSE_PICTURE_SMALL = "exposeDescription"; // // public static final String SHARED_PREF_EXPOSE_WEBVIEW = "exposeWebView"; // public static final String KEY_VISITED = "visited"; // // public static final String AUTH_URL = "oauth_url"; // public static final long EXPOSE_THRESHOLD_OLD = 1000L * 60L * 60L * 24L // * 30L; // public static final long EXPOSE_THRESHOLD_NEW = 1000L * 60L * 60L * 24L // * 7L; // // public static final String MESSAGE_IMMOPOLY_EXCEPTION = "org.immopoly.common.ImmopolyException"; // // public static final String IMMOPOLY_EMAIL = "immopolyteam@gmail.com"; // public static final int ANALYTICS_INTERVAL = 20; // // public static final int USER_SIGNUP = 110; // // // IS24 search control - search different radii until at least SEARCH_MIN_RESULTS flats are found // public static final float[] SEARCH_RADII = { 1, 3, 10 }; // in km // public static final int SEARCH_MIN_RESULTS = 50; // ignored for last search radius // public static final int SEARCH_MAX_RESULTS = 80; // forced result limit. fernglas me, baby! // }
import android.os.Parcel; import android.os.Parcelable; import android.util.Log; import java.sql.SQLData; import java.sql.SQLException; import java.sql.SQLInput; import java.sql.SQLOutput; import java.text.ParseException; import java.text.SimpleDateFormat; import org.immopoly.android.constants.Const; import org.json.JSONException; import org.json.JSONObject;
dest.writeString(currency); dest.writeString(priceIntervaleType); dest.writeDouble(lat); dest.writeDouble(lng); dest.writeLong(creationDate); } public static final Parcelable.Creator<Flat> CREATOR = new Parcelable.Creator<Flat>() { public Flat createFromParcel(Parcel in) { return new Flat(in); } public Flat[] newArray(int size) { return new Flat[size]; } }; public Flat(Parcel in) { uid = in.readInt(); name = in.readString(); description = in.readString(); city = in.readString(); titlePictureSmall = in.readString(); priceValue = in.readString(); currency = in.readString(); priceIntervaleType = in.readString(); lat = in.readDouble(); lng = in.readDouble(); creationDate=in.readLong(); long ageMs = System.currentTimeMillis() - creationDate;
// Path: src/org/immopoly/android/constants/Const.java // public class Const { // // public static final String LOG_TAG = "IMPO"; // // // Intents // // // Intent open webview // public static final String EXPOSE_ID = "exposeID"; // public static final String EXPOSE_NAME = "exposeName"; // public static final String EXPOSE_DESC = "exposeDescription"; // public static final String EXPOSE_URL = "exposeURL"; // public static final String EXPOSE_IN_PORTOFOLIO = "exposeInPortfolio"; // // // public static final String EXPOSE_OWNED = "exposeOwned"; // // // Intent add portofolio // public static final String EXPOSE_ADD_PORTIFOLIO = "addToPortifolio"; // public static final String EXPOSE_RELEASE_PORTIFOLIO = "releaseFromPortifolio"; // // public static final String SOURCE = "source"; // // // immopoly // public static final String EXPOSE_PICTURE_SMALL = "exposeDescription"; // // public static final String SHARED_PREF_EXPOSE_WEBVIEW = "exposeWebView"; // public static final String KEY_VISITED = "visited"; // // public static final String AUTH_URL = "oauth_url"; // public static final long EXPOSE_THRESHOLD_OLD = 1000L * 60L * 60L * 24L // * 30L; // public static final long EXPOSE_THRESHOLD_NEW = 1000L * 60L * 60L * 24L // * 7L; // // public static final String MESSAGE_IMMOPOLY_EXCEPTION = "org.immopoly.common.ImmopolyException"; // // public static final String IMMOPOLY_EMAIL = "immopolyteam@gmail.com"; // public static final int ANALYTICS_INTERVAL = 20; // // public static final int USER_SIGNUP = 110; // // // IS24 search control - search different radii until at least SEARCH_MIN_RESULTS flats are found // public static final float[] SEARCH_RADII = { 1, 3, 10 }; // in km // public static final int SEARCH_MIN_RESULTS = 50; // ignored for last search radius // public static final int SEARCH_MAX_RESULTS = 80; // forced result limit. fernglas me, baby! // } // Path: src/org/immopoly/android/model/Flat.java import android.os.Parcel; import android.os.Parcelable; import android.util.Log; import java.sql.SQLData; import java.sql.SQLException; import java.sql.SQLInput; import java.sql.SQLOutput; import java.text.ParseException; import java.text.SimpleDateFormat; import org.immopoly.android.constants.Const; import org.json.JSONException; import org.json.JSONObject; dest.writeString(currency); dest.writeString(priceIntervaleType); dest.writeDouble(lat); dest.writeDouble(lng); dest.writeLong(creationDate); } public static final Parcelable.Creator<Flat> CREATOR = new Parcelable.Creator<Flat>() { public Flat createFromParcel(Parcel in) { return new Flat(in); } public Flat[] newArray(int size) { return new Flat[size]; } }; public Flat(Parcel in) { uid = in.readInt(); name = in.readString(); description = in.readString(); city = in.readString(); titlePictureSmall = in.readString(); priceValue = in.readString(); currency = in.readString(); priceIntervaleType = in.readString(); lat = in.readDouble(); lng = in.readDouble(); creationDate=in.readLong(); long ageMs = System.currentTimeMillis() - creationDate;
age = ageMs < Const.EXPOSE_THRESHOLD_NEW ? AGE_NEW
immopoly/android
src/org/immopoly/android/app/OauthLoginActivity.java
// Path: src/org/immopoly/android/model/OAuthData.java // public class OAuthData { // // public static final String SERVER = "http://rest.immobilienscout24.de"; // public static final String OAUTH_SECURITY_PREFIX = "/restapi/security/oauth/"; // // public static final String AUTHORIZATION_ENDPOINT = SERVER // + OAUTH_SECURITY_PREFIX + "confirm_access"; // public static final String ACCESS_TOKEN_ENDPOINT = SERVER // + OAUTH_SECURITY_PREFIX + "access_token"; // public static final String REQUEST_TOKEN_ENDPOINT = SERVER // + OAUTH_SECURITY_PREFIX + "request_token"; // // public static String CONSUMER_KEY = ""; // e. g. a system // // identifier // public static String CONSUMER_SECRET = ""; // // // technical and business context of the search webservice // public static final String SEARCH_PREFIX = "/restapi/api" + "/search/v1.0/"; // // public OAuthConsumer consumer = new DefaultOAuthConsumer(CONSUMER_KEY, // CONSUMER_SECRET); // // public OAuthProvider provider = new DefaultOAuthProvider( // REQUEST_TOKEN_ENDPOINT, ACCESS_TOKEN_ENDPOINT, // AUTHORIZATION_ENDPOINT); // // public String accessToken = ""; // public boolean signedIn = false; // // public static String sExposeUrl = "http://mobil.immobilienscout24.de" // + "/expose/"; // public static String sExposeUrlWeb = "http://immobilienscout24.de" // + "/expose/"; // private static OAuthData mInstance = null; // // private OAuthData() { // } // // private OAuthData(Context context) { // /** // * AN ERROR HERE IS NORMAL, we don't commit these properties, just // * create them in you project as resources in the string.xml or create a // * new file for that // */ // CONSUMER_KEY = context // .getString(org.immopoly.android.R.string.consumer_key); // CONSUMER_SECRET = context // .getString(org.immopoly.android.R.string.consumer_secret); // accessToken = context // .getString(org.immopoly.android.R.string.is24_access_token); // consumer = new DefaultOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); // provider = new DefaultOAuthProvider(REQUEST_TOKEN_ENDPOINT, // ACCESS_TOKEN_ENDPOINT, AUTHORIZATION_ENDPOINT); // } // // public static OAuthData getInstance(Context context) { // if (mInstance == null) { // mInstance = new OAuthData(context); // } // return mInstance; // } // }
import org.immopoly.android.R; import org.immopoly.android.model.OAuthData; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; import android.webkit.WebView; import android.webkit.WebViewClient;
/* * This is the Android component of Immopoly * http://immopoly.appspot.com * Copyright (C) 2011 Tobias Sasse * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see http://www.gnu.org/licenses/. */ package org.immopoly.android.app; public class OauthLoginActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.oauth_login_activity); Intent intent = getIntent(); if (intent != null) { String url = intent.getExtras().getString("oauth_url"); WebView webView = (WebView) findViewById(R.id.webview); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); // check url if (url.matches(".+?state=authorized")) { SharedPreferences shared = getSharedPreferences( "oauth", 0); SharedPreferences.Editor editor = shared.edit(); Uri uri = Uri.parse(url); String access_token = uri .getQueryParameter("oauth_token"); editor.putString("oauth_token", access_token); editor.commit();
// Path: src/org/immopoly/android/model/OAuthData.java // public class OAuthData { // // public static final String SERVER = "http://rest.immobilienscout24.de"; // public static final String OAUTH_SECURITY_PREFIX = "/restapi/security/oauth/"; // // public static final String AUTHORIZATION_ENDPOINT = SERVER // + OAUTH_SECURITY_PREFIX + "confirm_access"; // public static final String ACCESS_TOKEN_ENDPOINT = SERVER // + OAUTH_SECURITY_PREFIX + "access_token"; // public static final String REQUEST_TOKEN_ENDPOINT = SERVER // + OAUTH_SECURITY_PREFIX + "request_token"; // // public static String CONSUMER_KEY = ""; // e. g. a system // // identifier // public static String CONSUMER_SECRET = ""; // // // technical and business context of the search webservice // public static final String SEARCH_PREFIX = "/restapi/api" + "/search/v1.0/"; // // public OAuthConsumer consumer = new DefaultOAuthConsumer(CONSUMER_KEY, // CONSUMER_SECRET); // // public OAuthProvider provider = new DefaultOAuthProvider( // REQUEST_TOKEN_ENDPOINT, ACCESS_TOKEN_ENDPOINT, // AUTHORIZATION_ENDPOINT); // // public String accessToken = ""; // public boolean signedIn = false; // // public static String sExposeUrl = "http://mobil.immobilienscout24.de" // + "/expose/"; // public static String sExposeUrlWeb = "http://immobilienscout24.de" // + "/expose/"; // private static OAuthData mInstance = null; // // private OAuthData() { // } // // private OAuthData(Context context) { // /** // * AN ERROR HERE IS NORMAL, we don't commit these properties, just // * create them in you project as resources in the string.xml or create a // * new file for that // */ // CONSUMER_KEY = context // .getString(org.immopoly.android.R.string.consumer_key); // CONSUMER_SECRET = context // .getString(org.immopoly.android.R.string.consumer_secret); // accessToken = context // .getString(org.immopoly.android.R.string.is24_access_token); // consumer = new DefaultOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); // provider = new DefaultOAuthProvider(REQUEST_TOKEN_ENDPOINT, // ACCESS_TOKEN_ENDPOINT, AUTHORIZATION_ENDPOINT); // } // // public static OAuthData getInstance(Context context) { // if (mInstance == null) { // mInstance = new OAuthData(context); // } // return mInstance; // } // } // Path: src/org/immopoly/android/app/OauthLoginActivity.java import org.immopoly.android.R; import org.immopoly.android.model.OAuthData; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; import android.webkit.WebView; import android.webkit.WebViewClient; /* * This is the Android component of Immopoly * http://immopoly.appspot.com * Copyright (C) 2011 Tobias Sasse * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see http://www.gnu.org/licenses/. */ package org.immopoly.android.app; public class OauthLoginActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.oauth_login_activity); Intent intent = getIntent(); if (intent != null) { String url = intent.getExtras().getString("oauth_url"); WebView webView = (WebView) findViewById(R.id.webview); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); // check url if (url.matches(".+?state=authorized")) { SharedPreferences shared = getSharedPreferences( "oauth", 0); SharedPreferences.Editor editor = shared.edit(); Uri uri = Uri.parse(url); String access_token = uri .getQueryParameter("oauth_token"); editor.putString("oauth_token", access_token); editor.commit();
OAuthData.getInstance(OauthLoginActivity.this).accessToken = access_token;
immopoly/android
src/org/immopoly/android/helper/Settings.java
// Path: src/org/immopoly/android/model/OAuthData.java // public class OAuthData { // // public static final String SERVER = "http://rest.immobilienscout24.de"; // public static final String OAUTH_SECURITY_PREFIX = "/restapi/security/oauth/"; // // public static final String AUTHORIZATION_ENDPOINT = SERVER // + OAUTH_SECURITY_PREFIX + "confirm_access"; // public static final String ACCESS_TOKEN_ENDPOINT = SERVER // + OAUTH_SECURITY_PREFIX + "access_token"; // public static final String REQUEST_TOKEN_ENDPOINT = SERVER // + OAUTH_SECURITY_PREFIX + "request_token"; // // public static String CONSUMER_KEY = ""; // e. g. a system // // identifier // public static String CONSUMER_SECRET = ""; // // // technical and business context of the search webservice // public static final String SEARCH_PREFIX = "/restapi/api" + "/search/v1.0/"; // // public OAuthConsumer consumer = new DefaultOAuthConsumer(CONSUMER_KEY, // CONSUMER_SECRET); // // public OAuthProvider provider = new DefaultOAuthProvider( // REQUEST_TOKEN_ENDPOINT, ACCESS_TOKEN_ENDPOINT, // AUTHORIZATION_ENDPOINT); // // public String accessToken = ""; // public boolean signedIn = false; // // public static String sExposeUrl = "http://mobil.immobilienscout24.de" // + "/expose/"; // public static String sExposeUrlWeb = "http://immobilienscout24.de" // + "/expose/"; // private static OAuthData mInstance = null; // // private OAuthData() { // } // // private OAuthData(Context context) { // /** // * AN ERROR HERE IS NORMAL, we don't commit these properties, just // * create them in you project as resources in the string.xml or create a // * new file for that // */ // CONSUMER_KEY = context // .getString(org.immopoly.android.R.string.consumer_key); // CONSUMER_SECRET = context // .getString(org.immopoly.android.R.string.consumer_secret); // accessToken = context // .getString(org.immopoly.android.R.string.is24_access_token); // consumer = new DefaultOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); // provider = new DefaultOAuthProvider(REQUEST_TOKEN_ENDPOINT, // ACCESS_TOKEN_ENDPOINT, AUTHORIZATION_ENDPOINT); // } // // public static OAuthData getInstance(Context context) { // if (mInstance == null) { // mInstance = new OAuthData(context); // } // return mInstance; // } // }
import android.view.animation.Animation; import android.view.animation.AnimationUtils; import org.immopoly.android.R; import org.immopoly.android.model.OAuthData; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.ConnectivityManager; import android.util.DisplayMetrics;
/* * This is the Android component of Immopoly * http://immopoly.appspot.com * Copyright (C) 2011 Tobias Sasse * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see http://www.gnu.org/licenses/. */ package org.immopoly.android.helper; public class Settings { private static ImageListDownloader exposeImageDownloader; private static float screenDesity; public static void shareMessage(Context context, String title, String message, String link) { final String tag = "@immopoly"; /* * This code can limit the size of the messages which will be shared, * not needed at the moment final int maxMessage = 140; int overhead = maxMessage - message.length() - link.length() - 1 - tag.length() - 1 - title.length() - 1; if (overhead < 0) { message = message.substring((-1)*overhead, message.length() - 1); } message = title + message; */ message += " " + link + " " + tag; final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, title); intent.putExtra(Intent.EXTRA_TEXT, message); context.startActivity(Intent.createChooser(intent, "Share")); } public static boolean isOnline(Context context) { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (cm.getActiveNetworkInfo() == null) { return false; } return cm.getActiveNetworkInfo().isConnectedOrConnecting(); } public static String getFlatLink(String exposeID, boolean mobile) { if(mobile)
// Path: src/org/immopoly/android/model/OAuthData.java // public class OAuthData { // // public static final String SERVER = "http://rest.immobilienscout24.de"; // public static final String OAUTH_SECURITY_PREFIX = "/restapi/security/oauth/"; // // public static final String AUTHORIZATION_ENDPOINT = SERVER // + OAUTH_SECURITY_PREFIX + "confirm_access"; // public static final String ACCESS_TOKEN_ENDPOINT = SERVER // + OAUTH_SECURITY_PREFIX + "access_token"; // public static final String REQUEST_TOKEN_ENDPOINT = SERVER // + OAUTH_SECURITY_PREFIX + "request_token"; // // public static String CONSUMER_KEY = ""; // e. g. a system // // identifier // public static String CONSUMER_SECRET = ""; // // // technical and business context of the search webservice // public static final String SEARCH_PREFIX = "/restapi/api" + "/search/v1.0/"; // // public OAuthConsumer consumer = new DefaultOAuthConsumer(CONSUMER_KEY, // CONSUMER_SECRET); // // public OAuthProvider provider = new DefaultOAuthProvider( // REQUEST_TOKEN_ENDPOINT, ACCESS_TOKEN_ENDPOINT, // AUTHORIZATION_ENDPOINT); // // public String accessToken = ""; // public boolean signedIn = false; // // public static String sExposeUrl = "http://mobil.immobilienscout24.de" // + "/expose/"; // public static String sExposeUrlWeb = "http://immobilienscout24.de" // + "/expose/"; // private static OAuthData mInstance = null; // // private OAuthData() { // } // // private OAuthData(Context context) { // /** // * AN ERROR HERE IS NORMAL, we don't commit these properties, just // * create them in you project as resources in the string.xml or create a // * new file for that // */ // CONSUMER_KEY = context // .getString(org.immopoly.android.R.string.consumer_key); // CONSUMER_SECRET = context // .getString(org.immopoly.android.R.string.consumer_secret); // accessToken = context // .getString(org.immopoly.android.R.string.is24_access_token); // consumer = new DefaultOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); // provider = new DefaultOAuthProvider(REQUEST_TOKEN_ENDPOINT, // ACCESS_TOKEN_ENDPOINT, AUTHORIZATION_ENDPOINT); // } // // public static OAuthData getInstance(Context context) { // if (mInstance == null) { // mInstance = new OAuthData(context); // } // return mInstance; // } // } // Path: src/org/immopoly/android/helper/Settings.java import android.view.animation.Animation; import android.view.animation.AnimationUtils; import org.immopoly.android.R; import org.immopoly.android.model.OAuthData; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.ConnectivityManager; import android.util.DisplayMetrics; /* * This is the Android component of Immopoly * http://immopoly.appspot.com * Copyright (C) 2011 Tobias Sasse * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see http://www.gnu.org/licenses/. */ package org.immopoly.android.helper; public class Settings { private static ImageListDownloader exposeImageDownloader; private static float screenDesity; public static void shareMessage(Context context, String title, String message, String link) { final String tag = "@immopoly"; /* * This code can limit the size of the messages which will be shared, * not needed at the moment final int maxMessage = 140; int overhead = maxMessage - message.length() - link.length() - 1 - tag.length() - 1 - title.length() - 1; if (overhead < 0) { message = message.substring((-1)*overhead, message.length() - 1); } message = title + message; */ message += " " + link + " " + tag; final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, title); intent.putExtra(Intent.EXTRA_TEXT, message); context.startActivity(Intent.createChooser(intent, "Share")); } public static boolean isOnline(Context context) { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (cm.getActiveNetworkInfo() == null) { return false; } return cm.getActiveNetworkInfo().isConnectedOrConnecting(); } public static String getFlatLink(String exposeID, boolean mobile) { if(mobile)
return OAuthData.sExposeUrl + exposeID;
immopoly/android
src/org/immopoly/android/c2dm/C2DMessaging.java
// Path: src/org/immopoly/android/constants/Const.java // public class Const { // // public static final String LOG_TAG = "IMPO"; // // // Intents // // // Intent open webview // public static final String EXPOSE_ID = "exposeID"; // public static final String EXPOSE_NAME = "exposeName"; // public static final String EXPOSE_DESC = "exposeDescription"; // public static final String EXPOSE_URL = "exposeURL"; // public static final String EXPOSE_IN_PORTOFOLIO = "exposeInPortfolio"; // // // public static final String EXPOSE_OWNED = "exposeOwned"; // // // Intent add portofolio // public static final String EXPOSE_ADD_PORTIFOLIO = "addToPortifolio"; // public static final String EXPOSE_RELEASE_PORTIFOLIO = "releaseFromPortifolio"; // // public static final String SOURCE = "source"; // // // immopoly // public static final String EXPOSE_PICTURE_SMALL = "exposeDescription"; // // public static final String SHARED_PREF_EXPOSE_WEBVIEW = "exposeWebView"; // public static final String KEY_VISITED = "visited"; // // public static final String AUTH_URL = "oauth_url"; // public static final long EXPOSE_THRESHOLD_OLD = 1000L * 60L * 60L * 24L // * 30L; // public static final long EXPOSE_THRESHOLD_NEW = 1000L * 60L * 60L * 24L // * 7L; // // public static final String MESSAGE_IMMOPOLY_EXCEPTION = "org.immopoly.common.ImmopolyException"; // // public static final String IMMOPOLY_EMAIL = "immopolyteam@gmail.com"; // public static final int ANALYTICS_INTERVAL = 20; // // public static final int USER_SIGNUP = 110; // // // IS24 search control - search different radii until at least SEARCH_MIN_RESULTS flats are found // public static final float[] SEARCH_RADII = { 1, 3, 10 }; // in km // public static final int SEARCH_MIN_RESULTS = 50; // ignored for last search radius // public static final int SEARCH_MAX_RESULTS = 80; // forced result limit. fernglas me, baby! // }
import org.immopoly.android.constants.Const; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.preference.PreferenceManager;
package org.immopoly.android.c2dm; /* * Copyright 2010 Google 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. */ /** * Utilities for device registration. * * Will keep track of the registration token in a private preference. */ public class C2DMessaging { public static final String EXTRA_SENDER = "sender"; public static final String EXTRA_APPLICATION_PENDING_INTENT = "app"; public static final String REQUEST_UNREGISTRATION_INTENT = "com.google.android.c2dm.intent.UNREGISTER"; public static final String REQUEST_REGISTRATION_INTENT = "com.google.android.c2dm.intent.REGISTER"; public static final String LAST_REGISTRATION_CHANGE = "last_registration_change"; public static final String BACKOFF = "backoff"; public static final String GSF_PACKAGE = "com.google.android.gsf"; // package static final String PREFERENCE = "com.google.android.c2dm"; private static final long DEFAULT_BACKOFF = 30000; /** * Initiate c2d messaging registration for the current application */ public static void register(Context context, String senderId) { // only if wanted SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean notification = sharedPreferences.getBoolean("notification", true); if (!notification) return; Intent registrationIntent = new Intent(REQUEST_REGISTRATION_INTENT); registrationIntent.setPackage(GSF_PACKAGE); registrationIntent.putExtra(EXTRA_APPLICATION_PENDING_INTENT, PendingIntent.getBroadcast(context, 0, new Intent(), 0));
// Path: src/org/immopoly/android/constants/Const.java // public class Const { // // public static final String LOG_TAG = "IMPO"; // // // Intents // // // Intent open webview // public static final String EXPOSE_ID = "exposeID"; // public static final String EXPOSE_NAME = "exposeName"; // public static final String EXPOSE_DESC = "exposeDescription"; // public static final String EXPOSE_URL = "exposeURL"; // public static final String EXPOSE_IN_PORTOFOLIO = "exposeInPortfolio"; // // // public static final String EXPOSE_OWNED = "exposeOwned"; // // // Intent add portofolio // public static final String EXPOSE_ADD_PORTIFOLIO = "addToPortifolio"; // public static final String EXPOSE_RELEASE_PORTIFOLIO = "releaseFromPortifolio"; // // public static final String SOURCE = "source"; // // // immopoly // public static final String EXPOSE_PICTURE_SMALL = "exposeDescription"; // // public static final String SHARED_PREF_EXPOSE_WEBVIEW = "exposeWebView"; // public static final String KEY_VISITED = "visited"; // // public static final String AUTH_URL = "oauth_url"; // public static final long EXPOSE_THRESHOLD_OLD = 1000L * 60L * 60L * 24L // * 30L; // public static final long EXPOSE_THRESHOLD_NEW = 1000L * 60L * 60L * 24L // * 7L; // // public static final String MESSAGE_IMMOPOLY_EXCEPTION = "org.immopoly.common.ImmopolyException"; // // public static final String IMMOPOLY_EMAIL = "immopolyteam@gmail.com"; // public static final int ANALYTICS_INTERVAL = 20; // // public static final int USER_SIGNUP = 110; // // // IS24 search control - search different radii until at least SEARCH_MIN_RESULTS flats are found // public static final float[] SEARCH_RADII = { 1, 3, 10 }; // in km // public static final int SEARCH_MIN_RESULTS = 50; // ignored for last search radius // public static final int SEARCH_MAX_RESULTS = 80; // forced result limit. fernglas me, baby! // } // Path: src/org/immopoly/android/c2dm/C2DMessaging.java import org.immopoly.android.constants.Const; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.preference.PreferenceManager; package org.immopoly.android.c2dm; /* * Copyright 2010 Google 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. */ /** * Utilities for device registration. * * Will keep track of the registration token in a private preference. */ public class C2DMessaging { public static final String EXTRA_SENDER = "sender"; public static final String EXTRA_APPLICATION_PENDING_INTENT = "app"; public static final String REQUEST_UNREGISTRATION_INTENT = "com.google.android.c2dm.intent.UNREGISTER"; public static final String REQUEST_REGISTRATION_INTENT = "com.google.android.c2dm.intent.REGISTER"; public static final String LAST_REGISTRATION_CHANGE = "last_registration_change"; public static final String BACKOFF = "backoff"; public static final String GSF_PACKAGE = "com.google.android.gsf"; // package static final String PREFERENCE = "com.google.android.c2dm"; private static final long DEFAULT_BACKOFF = 30000; /** * Initiate c2d messaging registration for the current application */ public static void register(Context context, String senderId) { // only if wanted SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean notification = sharedPreferences.getBoolean("notification", true); if (!notification) return; Intent registrationIntent = new Intent(REQUEST_REGISTRATION_INTENT); registrationIntent.setPackage(GSF_PACKAGE); registrationIntent.putExtra(EXTRA_APPLICATION_PENDING_INTENT, PendingIntent.getBroadcast(context, 0, new Intent(), 0));
registrationIntent.putExtra(EXTRA_SENDER, Const.IMMOPOLY_EMAIL);
immopoly/android
src/org/immopoly/android/model/ImmopolyException.java
// Path: src/org/immopoly/android/constants/Const.java // public class Const { // // public static final String LOG_TAG = "IMPO"; // // // Intents // // // Intent open webview // public static final String EXPOSE_ID = "exposeID"; // public static final String EXPOSE_NAME = "exposeName"; // public static final String EXPOSE_DESC = "exposeDescription"; // public static final String EXPOSE_URL = "exposeURL"; // public static final String EXPOSE_IN_PORTOFOLIO = "exposeInPortfolio"; // // // public static final String EXPOSE_OWNED = "exposeOwned"; // // // Intent add portofolio // public static final String EXPOSE_ADD_PORTIFOLIO = "addToPortifolio"; // public static final String EXPOSE_RELEASE_PORTIFOLIO = "releaseFromPortifolio"; // // public static final String SOURCE = "source"; // // // immopoly // public static final String EXPOSE_PICTURE_SMALL = "exposeDescription"; // // public static final String SHARED_PREF_EXPOSE_WEBVIEW = "exposeWebView"; // public static final String KEY_VISITED = "visited"; // // public static final String AUTH_URL = "oauth_url"; // public static final long EXPOSE_THRESHOLD_OLD = 1000L * 60L * 60L * 24L // * 30L; // public static final long EXPOSE_THRESHOLD_NEW = 1000L * 60L * 60L * 24L // * 7L; // // public static final String MESSAGE_IMMOPOLY_EXCEPTION = "org.immopoly.common.ImmopolyException"; // // public static final String IMMOPOLY_EMAIL = "immopolyteam@gmail.com"; // public static final int ANALYTICS_INTERVAL = 20; // // public static final int USER_SIGNUP = 110; // // // IS24 search control - search different radii until at least SEARCH_MIN_RESULTS flats are found // public static final float[] SEARCH_RADII = { 1, 3, 10 }; // in km // public static final int SEARCH_MIN_RESULTS = 50; // ignored for last search radius // public static final int SEARCH_MAX_RESULTS = 80; // forced result limit. fernglas me, baby! // }
import org.immopoly.android.R; import org.immopoly.android.constants.Const; import org.json.JSONObject; import android.content.Context; import android.util.Log; import android.widget.Toast;
super(); message=msg; } public ImmopolyException(Context context, JSONObject jsonObject) { super(jsonObject); switch (errorCode) { case USERNAME_NOT_FOUND: message = context.getString(R.string.account_not_found); break; case 201: message = context.getString(R.string.flat_already_in_portifolio); break; case 301: message = context.getString(R.string.flat_does_not_exist_anymore); break; case 302: message = context.getString(R.string.flat_has_no_raw_rent); break; case 441: message = context.getString(R.string.expose_location_spoofing); break; case USER_SEND_PASSWORDMAIL_NOEMAIL: message = context.getString(R.string.account_has_no_email);; break; case USER_SEND_PASSWORDMAIL_EMAIL_NOMATCH: message = context.getString(R.string.account_has_different_email);; break; default:
// Path: src/org/immopoly/android/constants/Const.java // public class Const { // // public static final String LOG_TAG = "IMPO"; // // // Intents // // // Intent open webview // public static final String EXPOSE_ID = "exposeID"; // public static final String EXPOSE_NAME = "exposeName"; // public static final String EXPOSE_DESC = "exposeDescription"; // public static final String EXPOSE_URL = "exposeURL"; // public static final String EXPOSE_IN_PORTOFOLIO = "exposeInPortfolio"; // // // public static final String EXPOSE_OWNED = "exposeOwned"; // // // Intent add portofolio // public static final String EXPOSE_ADD_PORTIFOLIO = "addToPortifolio"; // public static final String EXPOSE_RELEASE_PORTIFOLIO = "releaseFromPortifolio"; // // public static final String SOURCE = "source"; // // // immopoly // public static final String EXPOSE_PICTURE_SMALL = "exposeDescription"; // // public static final String SHARED_PREF_EXPOSE_WEBVIEW = "exposeWebView"; // public static final String KEY_VISITED = "visited"; // // public static final String AUTH_URL = "oauth_url"; // public static final long EXPOSE_THRESHOLD_OLD = 1000L * 60L * 60L * 24L // * 30L; // public static final long EXPOSE_THRESHOLD_NEW = 1000L * 60L * 60L * 24L // * 7L; // // public static final String MESSAGE_IMMOPOLY_EXCEPTION = "org.immopoly.common.ImmopolyException"; // // public static final String IMMOPOLY_EMAIL = "immopolyteam@gmail.com"; // public static final int ANALYTICS_INTERVAL = 20; // // public static final int USER_SIGNUP = 110; // // // IS24 search control - search different radii until at least SEARCH_MIN_RESULTS flats are found // public static final float[] SEARCH_RADII = { 1, 3, 10 }; // in km // public static final int SEARCH_MIN_RESULTS = 50; // ignored for last search radius // public static final int SEARCH_MAX_RESULTS = 80; // forced result limit. fernglas me, baby! // } // Path: src/org/immopoly/android/model/ImmopolyException.java import org.immopoly.android.R; import org.immopoly.android.constants.Const; import org.json.JSONObject; import android.content.Context; import android.util.Log; import android.widget.Toast; super(); message=msg; } public ImmopolyException(Context context, JSONObject jsonObject) { super(jsonObject); switch (errorCode) { case USERNAME_NOT_FOUND: message = context.getString(R.string.account_not_found); break; case 201: message = context.getString(R.string.flat_already_in_portifolio); break; case 301: message = context.getString(R.string.flat_does_not_exist_anymore); break; case 302: message = context.getString(R.string.flat_has_no_raw_rent); break; case 441: message = context.getString(R.string.expose_location_spoofing); break; case USER_SEND_PASSWORDMAIL_NOEMAIL: message = context.getString(R.string.account_has_no_email);; break; case USER_SEND_PASSWORDMAIL_EMAIL_NOMATCH: message = context.getString(R.string.account_has_different_email);; break; default:
Log.i( Const.LOG_TAG, "not yet translated ImmopolyException errorCode: " + errorCode );
Chat-Wane/LSEQ
src/main/java/alma/fr/strategychoicecomponents/SingleStrategyChoice.java
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/IIdProviderStrategy.java // public interface IIdProviderStrategy { // // /** // * Generate N identifier between p & q // * // * @param p // * previous identifier // * @param q // * next identifier // * @param N // * number of line inserted // * @param rep // * replica informations to store // * @return list of unique identifiers which can be used in logoot // */ // public Iterator<Positions> generateIdentifiers(Positions p, Positions q, // Integer N, Replica rep, BigInteger interval, int index); // }
import java.math.BigInteger; import java.util.HashMap; import java.util.Iterator; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.IIdProviderStrategy; import com.google.inject.Inject;
package alma.fr.strategychoicecomponents; public class SingleStrategyChoice implements IStrategyChoice { private HashMap<Positions, FakeListNode> spectrum = new HashMap<Positions, FakeListNode>(); private Integer date = 0; @Inject
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/IIdProviderStrategy.java // public interface IIdProviderStrategy { // // /** // * Generate N identifier between p & q // * // * @param p // * previous identifier // * @param q // * next identifier // * @param N // * number of line inserted // * @param rep // * replica informations to store // * @return list of unique identifiers which can be used in logoot // */ // public Iterator<Positions> generateIdentifiers(Positions p, Positions q, // Integer N, Replica rep, BigInteger interval, int index); // } // Path: src/main/java/alma/fr/strategychoicecomponents/SingleStrategyChoice.java import java.math.BigInteger; import java.util.HashMap; import java.util.Iterator; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.IIdProviderStrategy; import com.google.inject.Inject; package alma.fr.strategychoicecomponents; public class SingleStrategyChoice implements IStrategyChoice { private HashMap<Positions, FakeListNode> spectrum = new HashMap<Positions, FakeListNode>(); private Integer date = 0; @Inject
IIdProviderStrategy strategy;
Chat-Wane/LSEQ
src/main/java/alma/fr/strategychoicecomponents/SingleStrategyChoice.java
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/IIdProviderStrategy.java // public interface IIdProviderStrategy { // // /** // * Generate N identifier between p & q // * // * @param p // * previous identifier // * @param q // * next identifier // * @param N // * number of line inserted // * @param rep // * replica informations to store // * @return list of unique identifiers which can be used in logoot // */ // public Iterator<Positions> generateIdentifiers(Positions p, Positions q, // Integer N, Replica rep, BigInteger interval, int index); // }
import java.math.BigInteger; import java.util.HashMap; import java.util.Iterator; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.IIdProviderStrategy; import com.google.inject.Inject;
package alma.fr.strategychoicecomponents; public class SingleStrategyChoice implements IStrategyChoice { private HashMap<Positions, FakeListNode> spectrum = new HashMap<Positions, FakeListNode>(); private Integer date = 0; @Inject IIdProviderStrategy strategy; @Inject
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/IIdProviderStrategy.java // public interface IIdProviderStrategy { // // /** // * Generate N identifier between p & q // * // * @param p // * previous identifier // * @param q // * next identifier // * @param N // * number of line inserted // * @param rep // * replica informations to store // * @return list of unique identifiers which can be used in logoot // */ // public Iterator<Positions> generateIdentifiers(Positions p, Positions q, // Integer N, Replica rep, BigInteger interval, int index); // } // Path: src/main/java/alma/fr/strategychoicecomponents/SingleStrategyChoice.java import java.math.BigInteger; import java.util.HashMap; import java.util.Iterator; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.IIdProviderStrategy; import com.google.inject.Inject; package alma.fr.strategychoicecomponents; public class SingleStrategyChoice implements IStrategyChoice { private HashMap<Positions, FakeListNode> spectrum = new HashMap<Positions, FakeListNode>(); private Integer date = 0; @Inject IIdProviderStrategy strategy; @Inject
IBase base;
Chat-Wane/LSEQ
src/main/java/alma/fr/strategychoicecomponents/SingleStrategyChoice.java
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/IIdProviderStrategy.java // public interface IIdProviderStrategy { // // /** // * Generate N identifier between p & q // * // * @param p // * previous identifier // * @param q // * next identifier // * @param N // * number of line inserted // * @param rep // * replica informations to store // * @return list of unique identifiers which can be used in logoot // */ // public Iterator<Positions> generateIdentifiers(Positions p, Positions q, // Integer N, Replica rep, BigInteger interval, int index); // }
import java.math.BigInteger; import java.util.HashMap; import java.util.Iterator; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.IIdProviderStrategy; import com.google.inject.Inject;
package alma.fr.strategychoicecomponents; public class SingleStrategyChoice implements IStrategyChoice { private HashMap<Positions, FakeListNode> spectrum = new HashMap<Positions, FakeListNode>(); private Integer date = 0; @Inject IIdProviderStrategy strategy; @Inject IBase base; @Inject public SingleStrategyChoice(IIdProviderStrategy strategy, IBase base) { this.strategy = strategy; } public Iterator<Positions> generateIdentifiers(Positions p, Positions q,
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/IIdProviderStrategy.java // public interface IIdProviderStrategy { // // /** // * Generate N identifier between p & q // * // * @param p // * previous identifier // * @param q // * next identifier // * @param N // * number of line inserted // * @param rep // * replica informations to store // * @return list of unique identifiers which can be used in logoot // */ // public Iterator<Positions> generateIdentifiers(Positions p, Positions q, // Integer N, Replica rep, BigInteger interval, int index); // } // Path: src/main/java/alma/fr/strategychoicecomponents/SingleStrategyChoice.java import java.math.BigInteger; import java.util.HashMap; import java.util.Iterator; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.IIdProviderStrategy; import com.google.inject.Inject; package alma.fr.strategychoicecomponents; public class SingleStrategyChoice implements IStrategyChoice { private HashMap<Positions, FakeListNode> spectrum = new HashMap<Positions, FakeListNode>(); private Integer date = 0; @Inject IIdProviderStrategy strategy; @Inject IBase base; @Inject public SingleStrategyChoice(IIdProviderStrategy strategy, IBase base) { this.strategy = strategy; } public Iterator<Positions> generateIdentifiers(Positions p, Positions q,
Integer N, Replica rep) {
Chat-Wane/LSEQ
src/main/java/alma/fr/strategychoicecomponents/RoundRobinStrategyChoice.java
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/IIdProviderStrategy.java // public interface IIdProviderStrategy { // // /** // * Generate N identifier between p & q // * // * @param p // * previous identifier // * @param q // * next identifier // * @param N // * number of line inserted // * @param rep // * replica informations to store // * @return list of unique identifiers which can be used in logoot // */ // public Iterator<Positions> generateIdentifiers(Positions p, Positions q, // Integer N, Replica rep, BigInteger interval, int index); // }
import java.math.BigInteger; import java.util.HashMap; import java.util.Iterator; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.IIdProviderStrategy; import com.google.inject.Inject;
package alma.fr.strategychoicecomponents; public class RoundRobinStrategyChoice implements IStrategyChoice { private HashMap<Positions, FakeListNode> spectrum = new HashMap<Positions, FakeListNode>(); private Integer date = 0; @Inject
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/IIdProviderStrategy.java // public interface IIdProviderStrategy { // // /** // * Generate N identifier between p & q // * // * @param p // * previous identifier // * @param q // * next identifier // * @param N // * number of line inserted // * @param rep // * replica informations to store // * @return list of unique identifiers which can be used in logoot // */ // public Iterator<Positions> generateIdentifiers(Positions p, Positions q, // Integer N, Replica rep, BigInteger interval, int index); // } // Path: src/main/java/alma/fr/strategychoicecomponents/RoundRobinStrategyChoice.java import java.math.BigInteger; import java.util.HashMap; import java.util.Iterator; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.IIdProviderStrategy; import com.google.inject.Inject; package alma.fr.strategychoicecomponents; public class RoundRobinStrategyChoice implements IStrategyChoice { private HashMap<Positions, FakeListNode> spectrum = new HashMap<Positions, FakeListNode>(); private Integer date = 0; @Inject
IBase base;
Chat-Wane/LSEQ
src/main/java/alma/fr/strategychoicecomponents/RoundRobinStrategyChoice.java
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/IIdProviderStrategy.java // public interface IIdProviderStrategy { // // /** // * Generate N identifier between p & q // * // * @param p // * previous identifier // * @param q // * next identifier // * @param N // * number of line inserted // * @param rep // * replica informations to store // * @return list of unique identifiers which can be used in logoot // */ // public Iterator<Positions> generateIdentifiers(Positions p, Positions q, // Integer N, Replica rep, BigInteger interval, int index); // }
import java.math.BigInteger; import java.util.HashMap; import java.util.Iterator; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.IIdProviderStrategy; import com.google.inject.Inject;
package alma.fr.strategychoicecomponents; public class RoundRobinStrategyChoice implements IStrategyChoice { private HashMap<Positions, FakeListNode> spectrum = new HashMap<Positions, FakeListNode>(); private Integer date = 0; @Inject IBase base;
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/IIdProviderStrategy.java // public interface IIdProviderStrategy { // // /** // * Generate N identifier between p & q // * // * @param p // * previous identifier // * @param q // * next identifier // * @param N // * number of line inserted // * @param rep // * replica informations to store // * @return list of unique identifiers which can be used in logoot // */ // public Iterator<Positions> generateIdentifiers(Positions p, Positions q, // Integer N, Replica rep, BigInteger interval, int index); // } // Path: src/main/java/alma/fr/strategychoicecomponents/RoundRobinStrategyChoice.java import java.math.BigInteger; import java.util.HashMap; import java.util.Iterator; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.IIdProviderStrategy; import com.google.inject.Inject; package alma.fr.strategychoicecomponents; public class RoundRobinStrategyChoice implements IStrategyChoice { private HashMap<Positions, FakeListNode> spectrum = new HashMap<Positions, FakeListNode>(); private Integer date = 0; @Inject IBase base;
private IIdProviderStrategy strategy1;
Chat-Wane/LSEQ
src/main/java/alma/fr/strategychoicecomponents/IStrategyChoice.java
// Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // }
import java.util.HashMap; import java.util.Iterator; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica;
package alma.fr.strategychoicecomponents; public interface IStrategyChoice { /** * Function which will defer the creation of identifiers to a bunch of * IdProviders * * @param p * previous identifier * @param q * next identifier * @param N * number of line inserted * @param rep * replica informations to store * @return list of unique identifiers which can be used in logoot */ public Iterator<Positions> generateIdentifiers(Positions p,
// Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // Path: src/main/java/alma/fr/strategychoicecomponents/IStrategyChoice.java import java.util.HashMap; import java.util.Iterator; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; package alma.fr.strategychoicecomponents; public interface IStrategyChoice { /** * Function which will defer the creation of identifiers to a bunch of * IdProviders * * @param p * previous identifier * @param q * next identifier * @param N * number of line inserted * @param rep * replica informations to store * @return list of unique identifiers which can be used in logoot */ public Iterator<Positions> generateIdentifiers(Positions p,
Positions q, Integer N, Replica rep);
Chat-Wane/LSEQ
src/main/java/alma/fr/strategiescomponents/BeginningBoundaryIdProvider.java
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/boundary/IBoundary.java // public interface IBoundary { // // /** // * Return the boundary value at the specified depth. // * @param depth // * @return // */ // BigInteger getBoundary(Integer depth); // // // }
import java.math.BigInteger; import java.util.ArrayList; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.boundary.IBoundary; import com.google.inject.Inject;
package alma.fr.strategiescomponents; public class BeginningBoundaryIdProvider implements IIdProviderStrategy { private Random rand = new Random(); @Inject
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/boundary/IBoundary.java // public interface IBoundary { // // /** // * Return the boundary value at the specified depth. // * @param depth // * @return // */ // BigInteger getBoundary(Integer depth); // // // } // Path: src/main/java/alma/fr/strategiescomponents/BeginningBoundaryIdProvider.java import java.math.BigInteger; import java.util.ArrayList; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.boundary.IBoundary; import com.google.inject.Inject; package alma.fr.strategiescomponents; public class BeginningBoundaryIdProvider implements IIdProviderStrategy { private Random rand = new Random(); @Inject
private IBase base;
Chat-Wane/LSEQ
src/main/java/alma/fr/strategiescomponents/BeginningBoundaryIdProvider.java
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/boundary/IBoundary.java // public interface IBoundary { // // /** // * Return the boundary value at the specified depth. // * @param depth // * @return // */ // BigInteger getBoundary(Integer depth); // // // }
import java.math.BigInteger; import java.util.ArrayList; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.boundary.IBoundary; import com.google.inject.Inject;
package alma.fr.strategiescomponents; public class BeginningBoundaryIdProvider implements IIdProviderStrategy { private Random rand = new Random(); @Inject private IBase base; @Inject
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/boundary/IBoundary.java // public interface IBoundary { // // /** // * Return the boundary value at the specified depth. // * @param depth // * @return // */ // BigInteger getBoundary(Integer depth); // // // } // Path: src/main/java/alma/fr/strategiescomponents/BeginningBoundaryIdProvider.java import java.math.BigInteger; import java.util.ArrayList; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.boundary.IBoundary; import com.google.inject.Inject; package alma.fr.strategiescomponents; public class BeginningBoundaryIdProvider implements IIdProviderStrategy { private Random rand = new Random(); @Inject private IBase base; @Inject
private IBoundary boundary;
Chat-Wane/LSEQ
src/main/java/alma/fr/strategiescomponents/BeginningBoundaryIdProvider.java
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/boundary/IBoundary.java // public interface IBoundary { // // /** // * Return the boundary value at the specified depth. // * @param depth // * @return // */ // BigInteger getBoundary(Integer depth); // // // }
import java.math.BigInteger; import java.util.ArrayList; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.boundary.IBoundary; import com.google.inject.Inject;
package alma.fr.strategiescomponents; public class BeginningBoundaryIdProvider implements IIdProviderStrategy { private Random rand = new Random(); @Inject private IBase base; @Inject private IBoundary boundary; @Inject public BeginningBoundaryIdProvider(IBase base, IBoundary boundary) { this.base = base; this.boundary = boundary; }
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/boundary/IBoundary.java // public interface IBoundary { // // /** // * Return the boundary value at the specified depth. // * @param depth // * @return // */ // BigInteger getBoundary(Integer depth); // // // } // Path: src/main/java/alma/fr/strategiescomponents/BeginningBoundaryIdProvider.java import java.math.BigInteger; import java.util.ArrayList; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.boundary.IBoundary; import com.google.inject.Inject; package alma.fr.strategiescomponents; public class BeginningBoundaryIdProvider implements IIdProviderStrategy { private Random rand = new Random(); @Inject private IBase base; @Inject private IBoundary boundary; @Inject public BeginningBoundaryIdProvider(IBase base, IBoundary boundary) { this.base = base; this.boundary = boundary; }
public Iterator<Positions> generateIdentifiers(Positions p, Positions q,
Chat-Wane/LSEQ
src/main/java/alma/fr/strategiescomponents/BeginningBoundaryIdProvider.java
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/boundary/IBoundary.java // public interface IBoundary { // // /** // * Return the boundary value at the specified depth. // * @param depth // * @return // */ // BigInteger getBoundary(Integer depth); // // // }
import java.math.BigInteger; import java.util.ArrayList; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.boundary.IBoundary; import com.google.inject.Inject;
package alma.fr.strategiescomponents; public class BeginningBoundaryIdProvider implements IIdProviderStrategy { private Random rand = new Random(); @Inject private IBase base; @Inject private IBoundary boundary; @Inject public BeginningBoundaryIdProvider(IBase base, IBoundary boundary) { this.base = base; this.boundary = boundary; } public Iterator<Positions> generateIdentifiers(Positions p, Positions q,
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/boundary/IBoundary.java // public interface IBoundary { // // /** // * Return the boundary value at the specified depth. // * @param depth // * @return // */ // BigInteger getBoundary(Integer depth); // // // } // Path: src/main/java/alma/fr/strategiescomponents/BeginningBoundaryIdProvider.java import java.math.BigInteger; import java.util.ArrayList; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.boundary.IBoundary; import com.google.inject.Inject; package alma.fr.strategiescomponents; public class BeginningBoundaryIdProvider implements IIdProviderStrategy { private Random rand = new Random(); @Inject private IBase base; @Inject private IBoundary boundary; @Inject public BeginningBoundaryIdProvider(IBase base, IBoundary boundary) { this.base = base; this.boundary = boundary; } public Iterator<Positions> generateIdentifiers(Positions p, Positions q,
Integer N, Replica rep, BigInteger interval, int index) {
Chat-Wane/LSEQ
src/main/java/alma/fr/strategychoicecomponents/RandomStrategyChoice.java
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/IIdProviderStrategy.java // public interface IIdProviderStrategy { // // /** // * Generate N identifier between p & q // * // * @param p // * previous identifier // * @param q // * next identifier // * @param N // * number of line inserted // * @param rep // * replica informations to store // * @return list of unique identifiers which can be used in logoot // */ // public Iterator<Positions> generateIdentifiers(Positions p, Positions q, // Integer N, Replica rep, BigInteger interval, int index); // }
import java.math.BigInteger; import java.util.BitSet; import java.util.HashMap; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.IIdProviderStrategy; import com.google.inject.Inject;
package alma.fr.strategychoicecomponents; public class RandomStrategyChoice implements IStrategyChoice { private HashMap<Positions, FakeListNode> spectrum = new HashMap<Positions, FakeListNode>(); private Integer date = 0; BitSet strategies; static final Random r = new Random(); @Inject
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/IIdProviderStrategy.java // public interface IIdProviderStrategy { // // /** // * Generate N identifier between p & q // * // * @param p // * previous identifier // * @param q // * next identifier // * @param N // * number of line inserted // * @param rep // * replica informations to store // * @return list of unique identifiers which can be used in logoot // */ // public Iterator<Positions> generateIdentifiers(Positions p, Positions q, // Integer N, Replica rep, BigInteger interval, int index); // } // Path: src/main/java/alma/fr/strategychoicecomponents/RandomStrategyChoice.java import java.math.BigInteger; import java.util.BitSet; import java.util.HashMap; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.IIdProviderStrategy; import com.google.inject.Inject; package alma.fr.strategychoicecomponents; public class RandomStrategyChoice implements IStrategyChoice { private HashMap<Positions, FakeListNode> spectrum = new HashMap<Positions, FakeListNode>(); private Integer date = 0; BitSet strategies; static final Random r = new Random(); @Inject
IBase base;
Chat-Wane/LSEQ
src/main/java/alma/fr/strategychoicecomponents/RandomStrategyChoice.java
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/IIdProviderStrategy.java // public interface IIdProviderStrategy { // // /** // * Generate N identifier between p & q // * // * @param p // * previous identifier // * @param q // * next identifier // * @param N // * number of line inserted // * @param rep // * replica informations to store // * @return list of unique identifiers which can be used in logoot // */ // public Iterator<Positions> generateIdentifiers(Positions p, Positions q, // Integer N, Replica rep, BigInteger interval, int index); // }
import java.math.BigInteger; import java.util.BitSet; import java.util.HashMap; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.IIdProviderStrategy; import com.google.inject.Inject;
package alma.fr.strategychoicecomponents; public class RandomStrategyChoice implements IStrategyChoice { private HashMap<Positions, FakeListNode> spectrum = new HashMap<Positions, FakeListNode>(); private Integer date = 0; BitSet strategies; static final Random r = new Random(); @Inject IBase base;
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/IIdProviderStrategy.java // public interface IIdProviderStrategy { // // /** // * Generate N identifier between p & q // * // * @param p // * previous identifier // * @param q // * next identifier // * @param N // * number of line inserted // * @param rep // * replica informations to store // * @return list of unique identifiers which can be used in logoot // */ // public Iterator<Positions> generateIdentifiers(Positions p, Positions q, // Integer N, Replica rep, BigInteger interval, int index); // } // Path: src/main/java/alma/fr/strategychoicecomponents/RandomStrategyChoice.java import java.math.BigInteger; import java.util.BitSet; import java.util.HashMap; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.IIdProviderStrategy; import com.google.inject.Inject; package alma.fr.strategychoicecomponents; public class RandomStrategyChoice implements IStrategyChoice { private HashMap<Positions, FakeListNode> spectrum = new HashMap<Positions, FakeListNode>(); private Integer date = 0; BitSet strategies; static final Random r = new Random(); @Inject IBase base;
private IIdProviderStrategy strategy1;
Chat-Wane/LSEQ
src/main/java/alma/fr/logootenginecomponents/MyDelta.java
// Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // }
import alma.fr.data.Positions;
package alma.fr.logootenginecomponents; public class MyDelta { private Operation type;
// Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // Path: src/main/java/alma/fr/logootenginecomponents/MyDelta.java import alma.fr.data.Positions; package alma.fr.logootenginecomponents; public class MyDelta { private Operation type;
private Positions id;
Chat-Wane/LSEQ
src/main/java/alma/fr/logootenginecomponents/LogootEngine.java
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/strategychoicecomponents/IStrategyChoice.java // public interface IStrategyChoice { // // /** // * Function which will defer the creation of identifiers to a bunch of // * IdProviders // * // * @param p // * previous identifier // * @param q // * next identifier // * @param N // * number of line inserted // * @param rep // * replica informations to store // * @return list of unique identifiers which can be used in logoot // */ // public Iterator<Positions> generateIdentifiers(Positions p, // Positions q, Integer N, Replica rep); // // /** // * Add data to the strategy choice // * // * @param p // * previous Id // * @param id // * inserted // * @param q // * next Id // */ // public void add(Positions p, Positions id, Positions q); // // // public void del(Positions id); // // public void incDate(); // // public HashMap<Positions, FakeListNode> getSpectrum(); // }
import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.strategychoicecomponents.IStrategyChoice; import com.google.inject.Inject; import difflib.Delta;
package alma.fr.logootenginecomponents; public class LogootEngine implements ILogootEngine { private ArrayList<Positions> idTable; private ArrayList<String> doc; @Inject
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/strategychoicecomponents/IStrategyChoice.java // public interface IStrategyChoice { // // /** // * Function which will defer the creation of identifiers to a bunch of // * IdProviders // * // * @param p // * previous identifier // * @param q // * next identifier // * @param N // * number of line inserted // * @param rep // * replica informations to store // * @return list of unique identifiers which can be used in logoot // */ // public Iterator<Positions> generateIdentifiers(Positions p, // Positions q, Integer N, Replica rep); // // /** // * Add data to the strategy choice // * // * @param p // * previous Id // * @param id // * inserted // * @param q // * next Id // */ // public void add(Positions p, Positions id, Positions q); // // // public void del(Positions id); // // public void incDate(); // // public HashMap<Positions, FakeListNode> getSpectrum(); // } // Path: src/main/java/alma/fr/logootenginecomponents/LogootEngine.java import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.strategychoicecomponents.IStrategyChoice; import com.google.inject.Inject; import difflib.Delta; package alma.fr.logootenginecomponents; public class LogootEngine implements ILogootEngine { private ArrayList<Positions> idTable; private ArrayList<String> doc; @Inject
private IBase base;
Chat-Wane/LSEQ
src/main/java/alma/fr/logootenginecomponents/LogootEngine.java
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/strategychoicecomponents/IStrategyChoice.java // public interface IStrategyChoice { // // /** // * Function which will defer the creation of identifiers to a bunch of // * IdProviders // * // * @param p // * previous identifier // * @param q // * next identifier // * @param N // * number of line inserted // * @param rep // * replica informations to store // * @return list of unique identifiers which can be used in logoot // */ // public Iterator<Positions> generateIdentifiers(Positions p, // Positions q, Integer N, Replica rep); // // /** // * Add data to the strategy choice // * // * @param p // * previous Id // * @param id // * inserted // * @param q // * next Id // */ // public void add(Positions p, Positions id, Positions q); // // // public void del(Positions id); // // public void incDate(); // // public HashMap<Positions, FakeListNode> getSpectrum(); // }
import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.strategychoicecomponents.IStrategyChoice; import com.google.inject.Inject; import difflib.Delta;
package alma.fr.logootenginecomponents; public class LogootEngine implements ILogootEngine { private ArrayList<Positions> idTable; private ArrayList<String> doc; @Inject private IBase base; private Replica replica; @Inject
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/strategychoicecomponents/IStrategyChoice.java // public interface IStrategyChoice { // // /** // * Function which will defer the creation of identifiers to a bunch of // * IdProviders // * // * @param p // * previous identifier // * @param q // * next identifier // * @param N // * number of line inserted // * @param rep // * replica informations to store // * @return list of unique identifiers which can be used in logoot // */ // public Iterator<Positions> generateIdentifiers(Positions p, // Positions q, Integer N, Replica rep); // // /** // * Add data to the strategy choice // * // * @param p // * previous Id // * @param id // * inserted // * @param q // * next Id // */ // public void add(Positions p, Positions id, Positions q); // // // public void del(Positions id); // // public void incDate(); // // public HashMap<Positions, FakeListNode> getSpectrum(); // } // Path: src/main/java/alma/fr/logootenginecomponents/LogootEngine.java import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.strategychoicecomponents.IStrategyChoice; import com.google.inject.Inject; import difflib.Delta; package alma.fr.logootenginecomponents; public class LogootEngine implements ILogootEngine { private ArrayList<Positions> idTable; private ArrayList<String> doc; @Inject private IBase base; private Replica replica; @Inject
private IStrategyChoice strategyChoice;
Chat-Wane/LSEQ
src/main/java/alma/fr/data/Positions.java
// Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // }
import java.math.BigInteger; import alma.fr.logootenginecomponents.Replica;
package alma.fr.data; public class Positions implements Comparable<Positions> { private final BigInteger d; private final Integer s; private final Integer c;
// Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // Path: src/main/java/alma/fr/data/Positions.java import java.math.BigInteger; import alma.fr.logootenginecomponents.Replica; package alma.fr.data; public class Positions implements Comparable<Positions> { private final BigInteger d; private final Integer s; private final Integer c;
public Positions(BigInteger r, int bitSize, Replica rep) {
Chat-Wane/LSEQ
src/main/java/alma/fr/strategiescomponents/EndingBoundaryIdProvider.java
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/boundary/IBoundary.java // public interface IBoundary { // // /** // * Return the boundary value at the specified depth. // * @param depth // * @return // */ // BigInteger getBoundary(Integer depth); // // // }
import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.boundary.IBoundary; import com.google.inject.Inject;
package alma.fr.strategiescomponents; public class EndingBoundaryIdProvider implements IIdProviderStrategy { private Random rand = new Random(); @Inject
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/boundary/IBoundary.java // public interface IBoundary { // // /** // * Return the boundary value at the specified depth. // * @param depth // * @return // */ // BigInteger getBoundary(Integer depth); // // // } // Path: src/main/java/alma/fr/strategiescomponents/EndingBoundaryIdProvider.java import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.boundary.IBoundary; import com.google.inject.Inject; package alma.fr.strategiescomponents; public class EndingBoundaryIdProvider implements IIdProviderStrategy { private Random rand = new Random(); @Inject
private IBase base;
Chat-Wane/LSEQ
src/main/java/alma/fr/strategiescomponents/EndingBoundaryIdProvider.java
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/boundary/IBoundary.java // public interface IBoundary { // // /** // * Return the boundary value at the specified depth. // * @param depth // * @return // */ // BigInteger getBoundary(Integer depth); // // // }
import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.boundary.IBoundary; import com.google.inject.Inject;
package alma.fr.strategiescomponents; public class EndingBoundaryIdProvider implements IIdProviderStrategy { private Random rand = new Random(); @Inject private IBase base; @Inject
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/boundary/IBoundary.java // public interface IBoundary { // // /** // * Return the boundary value at the specified depth. // * @param depth // * @return // */ // BigInteger getBoundary(Integer depth); // // // } // Path: src/main/java/alma/fr/strategiescomponents/EndingBoundaryIdProvider.java import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.boundary.IBoundary; import com.google.inject.Inject; package alma.fr.strategiescomponents; public class EndingBoundaryIdProvider implements IIdProviderStrategy { private Random rand = new Random(); @Inject private IBase base; @Inject
private IBoundary boundary;
Chat-Wane/LSEQ
src/main/java/alma/fr/strategiescomponents/EndingBoundaryIdProvider.java
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/boundary/IBoundary.java // public interface IBoundary { // // /** // * Return the boundary value at the specified depth. // * @param depth // * @return // */ // BigInteger getBoundary(Integer depth); // // // }
import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.boundary.IBoundary; import com.google.inject.Inject;
package alma.fr.strategiescomponents; public class EndingBoundaryIdProvider implements IIdProviderStrategy { private Random rand = new Random(); @Inject private IBase base; @Inject private IBoundary boundary; @Inject public EndingBoundaryIdProvider(IBase base, IBoundary boundary) { this.base = base; this.boundary = boundary; }
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/boundary/IBoundary.java // public interface IBoundary { // // /** // * Return the boundary value at the specified depth. // * @param depth // * @return // */ // BigInteger getBoundary(Integer depth); // // // } // Path: src/main/java/alma/fr/strategiescomponents/EndingBoundaryIdProvider.java import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.boundary.IBoundary; import com.google.inject.Inject; package alma.fr.strategiescomponents; public class EndingBoundaryIdProvider implements IIdProviderStrategy { private Random rand = new Random(); @Inject private IBase base; @Inject private IBoundary boundary; @Inject public EndingBoundaryIdProvider(IBase base, IBoundary boundary) { this.base = base; this.boundary = boundary; }
public Iterator<Positions> generateIdentifiers(Positions p, Positions q,
Chat-Wane/LSEQ
src/main/java/alma/fr/strategiescomponents/EndingBoundaryIdProvider.java
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/boundary/IBoundary.java // public interface IBoundary { // // /** // * Return the boundary value at the specified depth. // * @param depth // * @return // */ // BigInteger getBoundary(Integer depth); // // // }
import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.boundary.IBoundary; import com.google.inject.Inject;
package alma.fr.strategiescomponents; public class EndingBoundaryIdProvider implements IIdProviderStrategy { private Random rand = new Random(); @Inject private IBase base; @Inject private IBoundary boundary; @Inject public EndingBoundaryIdProvider(IBase base, IBoundary boundary) { this.base = base; this.boundary = boundary; } public Iterator<Positions> generateIdentifiers(Positions p, Positions q,
// Path: src/main/java/alma/fr/basecomponents/IBase.java // public interface IBase { // // /** // * Return the number of bit to a depth // * // * @param depth // * @return bit number // */ // public Integer getSumBit(Integer depth); // // /** // * The number of bit used at a given depth // * // * @param depth // * @return bit number // */ // Integer getBitBase(Integer depth); // // /** // * the number of bit at depth 1 // * // * @return bit number // */ // Integer getBaseBase(); // // /** // * Substract value to r // * // * @param r // * @param value // * @return r-value // */ // BigInteger sub(BigInteger r, BigInteger value); // // /** // * Add value to r // * // * @param r // * @param value // * @return r+value // */ // BigInteger add(BigInteger r, BigInteger value); // // /** // * Process the interval (i.e. number of id possible) between p and q, p <_id // * q. // * // * @param p // * previous digit // * @param q // * next digit // * @param index // * depth of processing // * @return the interval at given depth // */ // BigInteger interval(BigInteger p, BigInteger q, Integer index); // // } // // Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // // Path: src/main/java/alma/fr/strategiescomponents/boundary/IBoundary.java // public interface IBoundary { // // /** // * Return the boundary value at the specified depth. // * @param depth // * @return // */ // BigInteger getBoundary(Integer depth); // // // } // Path: src/main/java/alma/fr/strategiescomponents/EndingBoundaryIdProvider.java import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.Random; import alma.fr.basecomponents.IBase; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; import alma.fr.strategiescomponents.boundary.IBoundary; import com.google.inject.Inject; package alma.fr.strategiescomponents; public class EndingBoundaryIdProvider implements IIdProviderStrategy { private Random rand = new Random(); @Inject private IBase base; @Inject private IBoundary boundary; @Inject public EndingBoundaryIdProvider(IBase base, IBoundary boundary) { this.base = base; this.boundary = boundary; } public Iterator<Positions> generateIdentifiers(Positions p, Positions q,
Integer N, Replica rep, BigInteger interval, int index) {
Chat-Wane/LSEQ
src/main/java/alma/fr/strategiescomponents/IIdProviderStrategy.java
// Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // }
import java.math.BigInteger; import java.util.Iterator; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica;
package alma.fr.strategiescomponents; public interface IIdProviderStrategy { /** * Generate N identifier between p & q * * @param p * previous identifier * @param q * next identifier * @param N * number of line inserted * @param rep * replica informations to store * @return list of unique identifiers which can be used in logoot */ public Iterator<Positions> generateIdentifiers(Positions p, Positions q,
// Path: src/main/java/alma/fr/data/Positions.java // public class Positions implements Comparable<Positions> { // // private final BigInteger d; // private final Integer s; // private final Integer c; // // public Positions(BigInteger r, int bitSize, Replica rep) { // d = r.setBit(bitSize); // set the departure bit to 1. Thus the 0 in // // front won't be automatically truncated by // // BigInteger // s = rep.getId(); // c = rep.getClock(); // } // // public BigInteger getD() { // return d; // } // // public Integer getC() { // return c; // } // // public Integer getS() { // return s; // } // // public int compareTo(Positions o) { // // #1 truncate // int myBitLength = d.bitLength(); // int otBitLength = o.d.bitLength(); // // int difBitLength = myBitLength - otBitLength; // // BigInteger other; // BigInteger mine; // if (difBitLength > 0) { // mine > other (in size) // other = o.d; // mine = d.shiftRight(difBitLength); // } else { // other = o.d.shiftRight(-difBitLength); // mine = d; // } // // #2 compare digit // int comp = mine.compareTo(other); // if (comp != 0) { // return comp; // } // // // #3 compare s and c // comp = s.compareTo(o.s); // if (comp != 0) { // s != o.s // return comp; // } else { // comp = c.compareTo(o.c); // if (comp != 0) { // C != o.C // return comp; // } // } // // // #4 compare size // if (myBitLength > otBitLength) { // return 1; // } else if (myBitLength < otBitLength) { // return -1; // } // // return 0; // } // // @Override // public String toString() { // return "<d" + d.toString() + "; s " + s + "; c " + c.toString() + ">"; // } // // } // // Path: src/main/java/alma/fr/logootenginecomponents/Replica.java // public class Replica { // // private Integer id; // Id of replica // private Integer clock; // clock of replica // // public Replica() { // id = 0; // clock = 0; // } // // public void setClock(Integer clock) { // this.clock = clock; // } // // public void setId(Integer id) { // this.id = id; // } // // public Integer getClock() { // return clock; // } // // public Integer getId() { // return id; // } // // } // Path: src/main/java/alma/fr/strategiescomponents/IIdProviderStrategy.java import java.math.BigInteger; import java.util.Iterator; import alma.fr.data.Positions; import alma.fr.logootenginecomponents.Replica; package alma.fr.strategiescomponents; public interface IIdProviderStrategy { /** * Generate N identifier between p & q * * @param p * previous identifier * @param q * next identifier * @param N * number of line inserted * @param rep * replica informations to store * @return list of unique identifiers which can be used in logoot */ public Iterator<Positions> generateIdentifiers(Positions p, Positions q,
Integer N, Replica rep, BigInteger interval, int index);
JHK/jLange
src/main/java/org/jlange/proxy/Http.java
// Path: src/main/java/org/jlange/proxy/inbound/HttpPipelineFactory.java // public class HttpPipelineFactory implements ChannelPipelineFactory { // @Override // public ChannelPipeline getPipeline() { // final ChannelPipeline pipeline = Channels.pipeline(); // // pipeline.addLast("decoder", new HttpRequestDecoder()); // pipeline.addLast("encoder", new HttpResponseEncoder()); // pipeline.addLast("deflater", new HttpContentCompressor(Config.COMPRESSION_LEVEL)); // pipeline.addLast("idle", new IdleShutdownHandler(300, 0)); // pipeline.addLast("mapping", new HttpRequestResponseHandler()); // pipeline.addLast("proxy", new ProxyHandler()); // // return pipeline; // } // } // // Path: src/main/java/org/jlange/proxy/util/Config.java // public class Config { // // public static final Integer OUTBOUND_TIMEOUT = getConfig().getInteger("org.jlange.outbound.connection_timeout", 30); // public static final Integer MAX_USED_CONNECTIONS = getConfig().getInteger("org.jlange.outbound.max_used_connections", 12); // public static final RemoteAddress PROXY_CHAIN = buildProxyChain(); // // public static final Boolean HTTP_ENABLED = getConfig().getBoolean("org.jlange.proxy.http.enabled", true); // public static final Integer HTTP_PORT = getConfig().getInteger("org.jlange.proxy.http.port", 8080); // // public static final Boolean SPDY_ENABLED = getConfig().getBoolean("org.jlange.proxy.spdy.enabled", false); // public static final Integer SPDY_PORT = getConfig().getInteger("org.jlange.proxy.spdy.port", 8443); // public static final String SPDY_KEY_STORE = getConfig().getString("org.jlange.proxy.spdy.ssl.store"); // public static final String SPDY_KEY_PASS = getConfig().getString("org.jlange.proxy.spdy.ssl.key"); // // public static final String VIA_HOSTNAME = getConfig().getString("org.jlange.proxy.via.hostname", "jLange"); // public static final String VIA_COMMENT = getConfig().getString("org.jlange.proxy.via.comment", null); // public static final Integer COMPRESSION_LEVEL = getConfig().getInteger("org.jlange.proxy.compression_level", 7); // public static final Integer CHUNK_SIZE = getConfig().getInteger("org.jlange.proxy.chunk_size", 8196); // public static final File TMP_DIRECTORY = buildTmpDirectory(); // // public static final String[] PLUGINS_RESPONSE = getConfig().getStringArray("org.jlange.plugin.response"); // public static final String[] PLUGINS_PREDEFINED = getConfig().getStringArray("org.jlange.plugin.predefined"); // // public static Configuration getPluginConfig(Class<?> plugin) { // if (pluginConfig.get(plugin) == null) { // try { // pluginConfig.put(plugin, new PropertiesConfiguration(plugin.getName() + ".properties")); // } catch (ConfigurationException e) { // pluginConfig.put(plugin, new PropertiesConfiguration()); // } // } // // return pluginConfig.get(plugin); // } // // private static File buildTmpDirectory() { // File tmpBase = new File(getConfig().getString("org.jlange.proxy.tmp", "/tmp")); // // if (!tmpBase.isDirectory()) // throw new IllegalArgumentException("tmp is no directory"); // // File tmpDir = new File(tmpBase, "jLange-" + HTTP_PORT + "-" + SPDY_PORT); // tmpDir.mkdirs(); // tmpDir.deleteOnExit(); // // return tmpDir; // } // // private static RemoteAddress buildProxyChain() { // String host = getConfig().getString("org.jlange.outbound.proxy.host"); // Integer port = getConfig().getInteger("org.jlange.outbound.proxy.port", null); // // if (host != null && port != null) // return new RemoteAddress(host, port); // else // return null; // } // // private static Configuration config; // private static Map<Class<?>, Configuration> pluginConfig = new HashMap<Class<?>, Configuration>(); // // private static Configuration getConfig() { // if (config == null) { // try { // config = new PropertiesConfiguration("jLange.properties"); // } catch (ConfigurationException e) { // e.printStackTrace(); // System.exit(1); // } // } // return config; // } // }
import org.jlange.proxy.inbound.HttpPipelineFactory; import org.jlange.proxy.util.Config; import org.jboss.netty.channel.ChannelPipelineFactory;
/* * Copyright (C) 2012 Julian Knocke * * This file is part of jLange. * * jLange is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * jLange is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with jLange. If not, see <http://www.gnu.org/licenses/>. */ package org.jlange.proxy; public class Http extends Proxy { public Http(int port) { super(port); } @Override protected ChannelPipelineFactory getChannelPipelineFactory() {
// Path: src/main/java/org/jlange/proxy/inbound/HttpPipelineFactory.java // public class HttpPipelineFactory implements ChannelPipelineFactory { // @Override // public ChannelPipeline getPipeline() { // final ChannelPipeline pipeline = Channels.pipeline(); // // pipeline.addLast("decoder", new HttpRequestDecoder()); // pipeline.addLast("encoder", new HttpResponseEncoder()); // pipeline.addLast("deflater", new HttpContentCompressor(Config.COMPRESSION_LEVEL)); // pipeline.addLast("idle", new IdleShutdownHandler(300, 0)); // pipeline.addLast("mapping", new HttpRequestResponseHandler()); // pipeline.addLast("proxy", new ProxyHandler()); // // return pipeline; // } // } // // Path: src/main/java/org/jlange/proxy/util/Config.java // public class Config { // // public static final Integer OUTBOUND_TIMEOUT = getConfig().getInteger("org.jlange.outbound.connection_timeout", 30); // public static final Integer MAX_USED_CONNECTIONS = getConfig().getInteger("org.jlange.outbound.max_used_connections", 12); // public static final RemoteAddress PROXY_CHAIN = buildProxyChain(); // // public static final Boolean HTTP_ENABLED = getConfig().getBoolean("org.jlange.proxy.http.enabled", true); // public static final Integer HTTP_PORT = getConfig().getInteger("org.jlange.proxy.http.port", 8080); // // public static final Boolean SPDY_ENABLED = getConfig().getBoolean("org.jlange.proxy.spdy.enabled", false); // public static final Integer SPDY_PORT = getConfig().getInteger("org.jlange.proxy.spdy.port", 8443); // public static final String SPDY_KEY_STORE = getConfig().getString("org.jlange.proxy.spdy.ssl.store"); // public static final String SPDY_KEY_PASS = getConfig().getString("org.jlange.proxy.spdy.ssl.key"); // // public static final String VIA_HOSTNAME = getConfig().getString("org.jlange.proxy.via.hostname", "jLange"); // public static final String VIA_COMMENT = getConfig().getString("org.jlange.proxy.via.comment", null); // public static final Integer COMPRESSION_LEVEL = getConfig().getInteger("org.jlange.proxy.compression_level", 7); // public static final Integer CHUNK_SIZE = getConfig().getInteger("org.jlange.proxy.chunk_size", 8196); // public static final File TMP_DIRECTORY = buildTmpDirectory(); // // public static final String[] PLUGINS_RESPONSE = getConfig().getStringArray("org.jlange.plugin.response"); // public static final String[] PLUGINS_PREDEFINED = getConfig().getStringArray("org.jlange.plugin.predefined"); // // public static Configuration getPluginConfig(Class<?> plugin) { // if (pluginConfig.get(plugin) == null) { // try { // pluginConfig.put(plugin, new PropertiesConfiguration(plugin.getName() + ".properties")); // } catch (ConfigurationException e) { // pluginConfig.put(plugin, new PropertiesConfiguration()); // } // } // // return pluginConfig.get(plugin); // } // // private static File buildTmpDirectory() { // File tmpBase = new File(getConfig().getString("org.jlange.proxy.tmp", "/tmp")); // // if (!tmpBase.isDirectory()) // throw new IllegalArgumentException("tmp is no directory"); // // File tmpDir = new File(tmpBase, "jLange-" + HTTP_PORT + "-" + SPDY_PORT); // tmpDir.mkdirs(); // tmpDir.deleteOnExit(); // // return tmpDir; // } // // private static RemoteAddress buildProxyChain() { // String host = getConfig().getString("org.jlange.outbound.proxy.host"); // Integer port = getConfig().getInteger("org.jlange.outbound.proxy.port", null); // // if (host != null && port != null) // return new RemoteAddress(host, port); // else // return null; // } // // private static Configuration config; // private static Map<Class<?>, Configuration> pluginConfig = new HashMap<Class<?>, Configuration>(); // // private static Configuration getConfig() { // if (config == null) { // try { // config = new PropertiesConfiguration("jLange.properties"); // } catch (ConfigurationException e) { // e.printStackTrace(); // System.exit(1); // } // } // return config; // } // } // Path: src/main/java/org/jlange/proxy/Http.java import org.jlange.proxy.inbound.HttpPipelineFactory; import org.jlange.proxy.util.Config; import org.jboss.netty.channel.ChannelPipelineFactory; /* * Copyright (C) 2012 Julian Knocke * * This file is part of jLange. * * jLange is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * jLange is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with jLange. If not, see <http://www.gnu.org/licenses/>. */ package org.jlange.proxy; public class Http extends Proxy { public Http(int port) { super(port); } @Override protected ChannelPipelineFactory getChannelPipelineFactory() {
return new HttpPipelineFactory();
JHK/jLange
src/main/java/org/jlange/proxy/Http.java
// Path: src/main/java/org/jlange/proxy/inbound/HttpPipelineFactory.java // public class HttpPipelineFactory implements ChannelPipelineFactory { // @Override // public ChannelPipeline getPipeline() { // final ChannelPipeline pipeline = Channels.pipeline(); // // pipeline.addLast("decoder", new HttpRequestDecoder()); // pipeline.addLast("encoder", new HttpResponseEncoder()); // pipeline.addLast("deflater", new HttpContentCompressor(Config.COMPRESSION_LEVEL)); // pipeline.addLast("idle", new IdleShutdownHandler(300, 0)); // pipeline.addLast("mapping", new HttpRequestResponseHandler()); // pipeline.addLast("proxy", new ProxyHandler()); // // return pipeline; // } // } // // Path: src/main/java/org/jlange/proxy/util/Config.java // public class Config { // // public static final Integer OUTBOUND_TIMEOUT = getConfig().getInteger("org.jlange.outbound.connection_timeout", 30); // public static final Integer MAX_USED_CONNECTIONS = getConfig().getInteger("org.jlange.outbound.max_used_connections", 12); // public static final RemoteAddress PROXY_CHAIN = buildProxyChain(); // // public static final Boolean HTTP_ENABLED = getConfig().getBoolean("org.jlange.proxy.http.enabled", true); // public static final Integer HTTP_PORT = getConfig().getInteger("org.jlange.proxy.http.port", 8080); // // public static final Boolean SPDY_ENABLED = getConfig().getBoolean("org.jlange.proxy.spdy.enabled", false); // public static final Integer SPDY_PORT = getConfig().getInteger("org.jlange.proxy.spdy.port", 8443); // public static final String SPDY_KEY_STORE = getConfig().getString("org.jlange.proxy.spdy.ssl.store"); // public static final String SPDY_KEY_PASS = getConfig().getString("org.jlange.proxy.spdy.ssl.key"); // // public static final String VIA_HOSTNAME = getConfig().getString("org.jlange.proxy.via.hostname", "jLange"); // public static final String VIA_COMMENT = getConfig().getString("org.jlange.proxy.via.comment", null); // public static final Integer COMPRESSION_LEVEL = getConfig().getInteger("org.jlange.proxy.compression_level", 7); // public static final Integer CHUNK_SIZE = getConfig().getInteger("org.jlange.proxy.chunk_size", 8196); // public static final File TMP_DIRECTORY = buildTmpDirectory(); // // public static final String[] PLUGINS_RESPONSE = getConfig().getStringArray("org.jlange.plugin.response"); // public static final String[] PLUGINS_PREDEFINED = getConfig().getStringArray("org.jlange.plugin.predefined"); // // public static Configuration getPluginConfig(Class<?> plugin) { // if (pluginConfig.get(plugin) == null) { // try { // pluginConfig.put(plugin, new PropertiesConfiguration(plugin.getName() + ".properties")); // } catch (ConfigurationException e) { // pluginConfig.put(plugin, new PropertiesConfiguration()); // } // } // // return pluginConfig.get(plugin); // } // // private static File buildTmpDirectory() { // File tmpBase = new File(getConfig().getString("org.jlange.proxy.tmp", "/tmp")); // // if (!tmpBase.isDirectory()) // throw new IllegalArgumentException("tmp is no directory"); // // File tmpDir = new File(tmpBase, "jLange-" + HTTP_PORT + "-" + SPDY_PORT); // tmpDir.mkdirs(); // tmpDir.deleteOnExit(); // // return tmpDir; // } // // private static RemoteAddress buildProxyChain() { // String host = getConfig().getString("org.jlange.outbound.proxy.host"); // Integer port = getConfig().getInteger("org.jlange.outbound.proxy.port", null); // // if (host != null && port != null) // return new RemoteAddress(host, port); // else // return null; // } // // private static Configuration config; // private static Map<Class<?>, Configuration> pluginConfig = new HashMap<Class<?>, Configuration>(); // // private static Configuration getConfig() { // if (config == null) { // try { // config = new PropertiesConfiguration("jLange.properties"); // } catch (ConfigurationException e) { // e.printStackTrace(); // System.exit(1); // } // } // return config; // } // }
import org.jlange.proxy.inbound.HttpPipelineFactory; import org.jlange.proxy.util.Config; import org.jboss.netty.channel.ChannelPipelineFactory;
/* * Copyright (C) 2012 Julian Knocke * * This file is part of jLange. * * jLange is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * jLange is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with jLange. If not, see <http://www.gnu.org/licenses/>. */ package org.jlange.proxy; public class Http extends Proxy { public Http(int port) { super(port); } @Override protected ChannelPipelineFactory getChannelPipelineFactory() { return new HttpPipelineFactory(); } @Override protected Boolean isEnabled() {
// Path: src/main/java/org/jlange/proxy/inbound/HttpPipelineFactory.java // public class HttpPipelineFactory implements ChannelPipelineFactory { // @Override // public ChannelPipeline getPipeline() { // final ChannelPipeline pipeline = Channels.pipeline(); // // pipeline.addLast("decoder", new HttpRequestDecoder()); // pipeline.addLast("encoder", new HttpResponseEncoder()); // pipeline.addLast("deflater", new HttpContentCompressor(Config.COMPRESSION_LEVEL)); // pipeline.addLast("idle", new IdleShutdownHandler(300, 0)); // pipeline.addLast("mapping", new HttpRequestResponseHandler()); // pipeline.addLast("proxy", new ProxyHandler()); // // return pipeline; // } // } // // Path: src/main/java/org/jlange/proxy/util/Config.java // public class Config { // // public static final Integer OUTBOUND_TIMEOUT = getConfig().getInteger("org.jlange.outbound.connection_timeout", 30); // public static final Integer MAX_USED_CONNECTIONS = getConfig().getInteger("org.jlange.outbound.max_used_connections", 12); // public static final RemoteAddress PROXY_CHAIN = buildProxyChain(); // // public static final Boolean HTTP_ENABLED = getConfig().getBoolean("org.jlange.proxy.http.enabled", true); // public static final Integer HTTP_PORT = getConfig().getInteger("org.jlange.proxy.http.port", 8080); // // public static final Boolean SPDY_ENABLED = getConfig().getBoolean("org.jlange.proxy.spdy.enabled", false); // public static final Integer SPDY_PORT = getConfig().getInteger("org.jlange.proxy.spdy.port", 8443); // public static final String SPDY_KEY_STORE = getConfig().getString("org.jlange.proxy.spdy.ssl.store"); // public static final String SPDY_KEY_PASS = getConfig().getString("org.jlange.proxy.spdy.ssl.key"); // // public static final String VIA_HOSTNAME = getConfig().getString("org.jlange.proxy.via.hostname", "jLange"); // public static final String VIA_COMMENT = getConfig().getString("org.jlange.proxy.via.comment", null); // public static final Integer COMPRESSION_LEVEL = getConfig().getInteger("org.jlange.proxy.compression_level", 7); // public static final Integer CHUNK_SIZE = getConfig().getInteger("org.jlange.proxy.chunk_size", 8196); // public static final File TMP_DIRECTORY = buildTmpDirectory(); // // public static final String[] PLUGINS_RESPONSE = getConfig().getStringArray("org.jlange.plugin.response"); // public static final String[] PLUGINS_PREDEFINED = getConfig().getStringArray("org.jlange.plugin.predefined"); // // public static Configuration getPluginConfig(Class<?> plugin) { // if (pluginConfig.get(plugin) == null) { // try { // pluginConfig.put(plugin, new PropertiesConfiguration(plugin.getName() + ".properties")); // } catch (ConfigurationException e) { // pluginConfig.put(plugin, new PropertiesConfiguration()); // } // } // // return pluginConfig.get(plugin); // } // // private static File buildTmpDirectory() { // File tmpBase = new File(getConfig().getString("org.jlange.proxy.tmp", "/tmp")); // // if (!tmpBase.isDirectory()) // throw new IllegalArgumentException("tmp is no directory"); // // File tmpDir = new File(tmpBase, "jLange-" + HTTP_PORT + "-" + SPDY_PORT); // tmpDir.mkdirs(); // tmpDir.deleteOnExit(); // // return tmpDir; // } // // private static RemoteAddress buildProxyChain() { // String host = getConfig().getString("org.jlange.outbound.proxy.host"); // Integer port = getConfig().getInteger("org.jlange.outbound.proxy.port", null); // // if (host != null && port != null) // return new RemoteAddress(host, port); // else // return null; // } // // private static Configuration config; // private static Map<Class<?>, Configuration> pluginConfig = new HashMap<Class<?>, Configuration>(); // // private static Configuration getConfig() { // if (config == null) { // try { // config = new PropertiesConfiguration("jLange.properties"); // } catch (ConfigurationException e) { // e.printStackTrace(); // System.exit(1); // } // } // return config; // } // } // Path: src/main/java/org/jlange/proxy/Http.java import org.jlange.proxy.inbound.HttpPipelineFactory; import org.jlange.proxy.util.Config; import org.jboss.netty.channel.ChannelPipelineFactory; /* * Copyright (C) 2012 Julian Knocke * * This file is part of jLange. * * jLange is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * jLange is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with jLange. If not, see <http://www.gnu.org/licenses/>. */ package org.jlange.proxy; public class Http extends Proxy { public Http(int port) { super(port); } @Override protected ChannelPipelineFactory getChannelPipelineFactory() { return new HttpPipelineFactory(); } @Override protected Boolean isEnabled() {
return Config.HTTP_ENABLED;
JHK/jLange
src/main/java/org/jlange/proxy/plugin/PluginProvider.java
// Path: src/main/java/org/jlange/proxy/util/Config.java // public class Config { // // public static final Integer OUTBOUND_TIMEOUT = getConfig().getInteger("org.jlange.outbound.connection_timeout", 30); // public static final Integer MAX_USED_CONNECTIONS = getConfig().getInteger("org.jlange.outbound.max_used_connections", 12); // public static final RemoteAddress PROXY_CHAIN = buildProxyChain(); // // public static final Boolean HTTP_ENABLED = getConfig().getBoolean("org.jlange.proxy.http.enabled", true); // public static final Integer HTTP_PORT = getConfig().getInteger("org.jlange.proxy.http.port", 8080); // // public static final Boolean SPDY_ENABLED = getConfig().getBoolean("org.jlange.proxy.spdy.enabled", false); // public static final Integer SPDY_PORT = getConfig().getInteger("org.jlange.proxy.spdy.port", 8443); // public static final String SPDY_KEY_STORE = getConfig().getString("org.jlange.proxy.spdy.ssl.store"); // public static final String SPDY_KEY_PASS = getConfig().getString("org.jlange.proxy.spdy.ssl.key"); // // public static final String VIA_HOSTNAME = getConfig().getString("org.jlange.proxy.via.hostname", "jLange"); // public static final String VIA_COMMENT = getConfig().getString("org.jlange.proxy.via.comment", null); // public static final Integer COMPRESSION_LEVEL = getConfig().getInteger("org.jlange.proxy.compression_level", 7); // public static final Integer CHUNK_SIZE = getConfig().getInteger("org.jlange.proxy.chunk_size", 8196); // public static final File TMP_DIRECTORY = buildTmpDirectory(); // // public static final String[] PLUGINS_RESPONSE = getConfig().getStringArray("org.jlange.plugin.response"); // public static final String[] PLUGINS_PREDEFINED = getConfig().getStringArray("org.jlange.plugin.predefined"); // // public static Configuration getPluginConfig(Class<?> plugin) { // if (pluginConfig.get(plugin) == null) { // try { // pluginConfig.put(plugin, new PropertiesConfiguration(plugin.getName() + ".properties")); // } catch (ConfigurationException e) { // pluginConfig.put(plugin, new PropertiesConfiguration()); // } // } // // return pluginConfig.get(plugin); // } // // private static File buildTmpDirectory() { // File tmpBase = new File(getConfig().getString("org.jlange.proxy.tmp", "/tmp")); // // if (!tmpBase.isDirectory()) // throw new IllegalArgumentException("tmp is no directory"); // // File tmpDir = new File(tmpBase, "jLange-" + HTTP_PORT + "-" + SPDY_PORT); // tmpDir.mkdirs(); // tmpDir.deleteOnExit(); // // return tmpDir; // } // // private static RemoteAddress buildProxyChain() { // String host = getConfig().getString("org.jlange.outbound.proxy.host"); // Integer port = getConfig().getInteger("org.jlange.outbound.proxy.port", null); // // if (host != null && port != null) // return new RemoteAddress(host, port); // else // return null; // } // // private static Configuration config; // private static Map<Class<?>, Configuration> pluginConfig = new HashMap<Class<?>, Configuration>(); // // private static Configuration getConfig() { // if (config == null) { // try { // config = new PropertiesConfiguration("jLange.properties"); // } catch (ConfigurationException e) { // e.printStackTrace(); // System.exit(1); // } // } // return config; // } // }
import java.util.ArrayList; import java.util.List; import org.jlange.proxy.util.Config; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
/* * Copyright (C) 2012 Julian Knocke * * This file is part of jLange. * * jLange is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * jLange is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with jLange. If not, see <http://www.gnu.org/licenses/>. */ package org.jlange.proxy.plugin; public class PluginProvider { private final static Logger log = LoggerFactory.getLogger(PluginProvider.class); private final static PluginProvider instance = new PluginProvider(); public static PluginProvider getInstance() { return instance; } private final List<ResponsePlugin> responsePlugins; private final List<PredefinedResponsePlugin> predefinedResponsePlugins; private PluginProvider() { responsePlugins = new ArrayList<ResponsePlugin>();
// Path: src/main/java/org/jlange/proxy/util/Config.java // public class Config { // // public static final Integer OUTBOUND_TIMEOUT = getConfig().getInteger("org.jlange.outbound.connection_timeout", 30); // public static final Integer MAX_USED_CONNECTIONS = getConfig().getInteger("org.jlange.outbound.max_used_connections", 12); // public static final RemoteAddress PROXY_CHAIN = buildProxyChain(); // // public static final Boolean HTTP_ENABLED = getConfig().getBoolean("org.jlange.proxy.http.enabled", true); // public static final Integer HTTP_PORT = getConfig().getInteger("org.jlange.proxy.http.port", 8080); // // public static final Boolean SPDY_ENABLED = getConfig().getBoolean("org.jlange.proxy.spdy.enabled", false); // public static final Integer SPDY_PORT = getConfig().getInteger("org.jlange.proxy.spdy.port", 8443); // public static final String SPDY_KEY_STORE = getConfig().getString("org.jlange.proxy.spdy.ssl.store"); // public static final String SPDY_KEY_PASS = getConfig().getString("org.jlange.proxy.spdy.ssl.key"); // // public static final String VIA_HOSTNAME = getConfig().getString("org.jlange.proxy.via.hostname", "jLange"); // public static final String VIA_COMMENT = getConfig().getString("org.jlange.proxy.via.comment", null); // public static final Integer COMPRESSION_LEVEL = getConfig().getInteger("org.jlange.proxy.compression_level", 7); // public static final Integer CHUNK_SIZE = getConfig().getInteger("org.jlange.proxy.chunk_size", 8196); // public static final File TMP_DIRECTORY = buildTmpDirectory(); // // public static final String[] PLUGINS_RESPONSE = getConfig().getStringArray("org.jlange.plugin.response"); // public static final String[] PLUGINS_PREDEFINED = getConfig().getStringArray("org.jlange.plugin.predefined"); // // public static Configuration getPluginConfig(Class<?> plugin) { // if (pluginConfig.get(plugin) == null) { // try { // pluginConfig.put(plugin, new PropertiesConfiguration(plugin.getName() + ".properties")); // } catch (ConfigurationException e) { // pluginConfig.put(plugin, new PropertiesConfiguration()); // } // } // // return pluginConfig.get(plugin); // } // // private static File buildTmpDirectory() { // File tmpBase = new File(getConfig().getString("org.jlange.proxy.tmp", "/tmp")); // // if (!tmpBase.isDirectory()) // throw new IllegalArgumentException("tmp is no directory"); // // File tmpDir = new File(tmpBase, "jLange-" + HTTP_PORT + "-" + SPDY_PORT); // tmpDir.mkdirs(); // tmpDir.deleteOnExit(); // // return tmpDir; // } // // private static RemoteAddress buildProxyChain() { // String host = getConfig().getString("org.jlange.outbound.proxy.host"); // Integer port = getConfig().getInteger("org.jlange.outbound.proxy.port", null); // // if (host != null && port != null) // return new RemoteAddress(host, port); // else // return null; // } // // private static Configuration config; // private static Map<Class<?>, Configuration> pluginConfig = new HashMap<Class<?>, Configuration>(); // // private static Configuration getConfig() { // if (config == null) { // try { // config = new PropertiesConfiguration("jLange.properties"); // } catch (ConfigurationException e) { // e.printStackTrace(); // System.exit(1); // } // } // return config; // } // } // Path: src/main/java/org/jlange/proxy/plugin/PluginProvider.java import java.util.ArrayList; import java.util.List; import org.jlange.proxy.util.Config; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /* * Copyright (C) 2012 Julian Knocke * * This file is part of jLange. * * jLange is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * jLange is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with jLange. If not, see <http://www.gnu.org/licenses/>. */ package org.jlange.proxy.plugin; public class PluginProvider { private final static Logger log = LoggerFactory.getLogger(PluginProvider.class); private final static PluginProvider instance = new PluginProvider(); public static PluginProvider getInstance() { return instance; } private final List<ResponsePlugin> responsePlugins; private final List<PredefinedResponsePlugin> predefinedResponsePlugins; private PluginProvider() { responsePlugins = new ArrayList<ResponsePlugin>();
for (String plugin : Config.PLUGINS_RESPONSE) {
JHK/jLange
src/main/java/org/jlange/proxy/outbound/PluginHandler.java
// Path: src/main/java/org/jlange/proxy/plugin/PluginProvider.java // public class PluginProvider { // // private final static Logger log = LoggerFactory.getLogger(PluginProvider.class); // private final static PluginProvider instance = new PluginProvider(); // // public static PluginProvider getInstance() { // return instance; // } // // private final List<ResponsePlugin> responsePlugins; // private final List<PredefinedResponsePlugin> predefinedResponsePlugins; // // private PluginProvider() { // responsePlugins = new ArrayList<ResponsePlugin>(); // // for (String plugin : Config.PLUGINS_RESPONSE) { // try { // Class<?> className = Class.forName(plugin); // responsePlugins.add((ResponsePlugin) className.newInstance()); // log.info("Plugin loaded: {}", plugin); // } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { // log.error("Could not load plugin: {}", e.getMessage()); // } // } // // predefinedResponsePlugins = new ArrayList<PredefinedResponsePlugin>(); // // for (String plugin : Config.PLUGINS_PREDEFINED) { // try { // Class<?> className = Class.forName(plugin); // predefinedResponsePlugins.add((PredefinedResponsePlugin) className.newInstance()); // log.info("Plugin loaded: {}", plugin); // } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { // log.error("Could not load plugin: {}", e.getMessage()); // } // } // } // // public List<ResponsePlugin> getResponsePlugins() { // return responsePlugins; // } // // public List<PredefinedResponsePlugin> getPredefinedResponsePlugins() { // return predefinedResponsePlugins; // } // } // // Path: src/main/java/org/jlange/proxy/plugin/PredefinedResponsePlugin.java // public interface PredefinedResponsePlugin { // // /** // * If the plugin is able to define a {@link HttpResponse} for the given {@link HttpRequest} this method will return it. Otherwise // * {@code null} is returned. // * // * @param request {@link HttpRequest} // * @return a {@link HttpResponse} or {@code null} // */ // public HttpResponse getPredefinedResponse(final HttpRequest request); // } // // Path: src/main/java/org/jlange/proxy/plugin/ResponsePlugin.java // public interface ResponsePlugin { // // /** // * Decides if the plugin is applicable for the given request // * // * @param request {@link HttpRequest} // * @return is the plugin applicable // */ // public Boolean isApplicable(final HttpRequest request); // // /** // * Decides if the plugin is applicable for the given response // * // * @param request {@link HttpRequest} // * @return is the plugin applicable // */ // public Boolean isApplicable(final HttpResponse response); // // /** // * Run the main code of the plugin. The response will be updated in here. For read and changing responses content the code must be // * marked as <code>synchronized</code>, because these plugins are intended to run in parallel. // * // * @param request {@link HttpRequest} // * @param response matching {@link HttpResponse} // */ // public void run(final HttpRequest request, final HttpResponse response); // // /** // * Run the main code of the plugin for a given chunk. // * // * @param request {@link HttpRequest} // * @param chunk {@link HttpChunk} // */ // public void run(HttpRequest request, HttpChunk chunk); // }
import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.Channels; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; import org.jboss.netty.handler.codec.http.HttpChunk; import org.jboss.netty.handler.codec.http.HttpRequest; import org.jboss.netty.handler.codec.http.HttpResponse; import org.jlange.proxy.plugin.PluginProvider; import org.jlange.proxy.plugin.PredefinedResponsePlugin; import org.jlange.proxy.plugin.ResponsePlugin; import org.slf4j.Logger;
/* * Copyright (C) 2012 Julian Knocke * * This file is part of jLange. * * jLange is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * jLange is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with jLange. If not, see <http://www.gnu.org/licenses/>. */ package org.jlange.proxy.outbound; public class PluginHandler extends SimpleChannelHandler { private final static Map<String, Long> pluginStats = new HashMap<String, Long>(); private final static Logger log = LoggerFactory.getLogger(PluginHandler.class);
// Path: src/main/java/org/jlange/proxy/plugin/PluginProvider.java // public class PluginProvider { // // private final static Logger log = LoggerFactory.getLogger(PluginProvider.class); // private final static PluginProvider instance = new PluginProvider(); // // public static PluginProvider getInstance() { // return instance; // } // // private final List<ResponsePlugin> responsePlugins; // private final List<PredefinedResponsePlugin> predefinedResponsePlugins; // // private PluginProvider() { // responsePlugins = new ArrayList<ResponsePlugin>(); // // for (String plugin : Config.PLUGINS_RESPONSE) { // try { // Class<?> className = Class.forName(plugin); // responsePlugins.add((ResponsePlugin) className.newInstance()); // log.info("Plugin loaded: {}", plugin); // } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { // log.error("Could not load plugin: {}", e.getMessage()); // } // } // // predefinedResponsePlugins = new ArrayList<PredefinedResponsePlugin>(); // // for (String plugin : Config.PLUGINS_PREDEFINED) { // try { // Class<?> className = Class.forName(plugin); // predefinedResponsePlugins.add((PredefinedResponsePlugin) className.newInstance()); // log.info("Plugin loaded: {}", plugin); // } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { // log.error("Could not load plugin: {}", e.getMessage()); // } // } // } // // public List<ResponsePlugin> getResponsePlugins() { // return responsePlugins; // } // // public List<PredefinedResponsePlugin> getPredefinedResponsePlugins() { // return predefinedResponsePlugins; // } // } // // Path: src/main/java/org/jlange/proxy/plugin/PredefinedResponsePlugin.java // public interface PredefinedResponsePlugin { // // /** // * If the plugin is able to define a {@link HttpResponse} for the given {@link HttpRequest} this method will return it. Otherwise // * {@code null} is returned. // * // * @param request {@link HttpRequest} // * @return a {@link HttpResponse} or {@code null} // */ // public HttpResponse getPredefinedResponse(final HttpRequest request); // } // // Path: src/main/java/org/jlange/proxy/plugin/ResponsePlugin.java // public interface ResponsePlugin { // // /** // * Decides if the plugin is applicable for the given request // * // * @param request {@link HttpRequest} // * @return is the plugin applicable // */ // public Boolean isApplicable(final HttpRequest request); // // /** // * Decides if the plugin is applicable for the given response // * // * @param request {@link HttpRequest} // * @return is the plugin applicable // */ // public Boolean isApplicable(final HttpResponse response); // // /** // * Run the main code of the plugin. The response will be updated in here. For read and changing responses content the code must be // * marked as <code>synchronized</code>, because these plugins are intended to run in parallel. // * // * @param request {@link HttpRequest} // * @param response matching {@link HttpResponse} // */ // public void run(final HttpRequest request, final HttpResponse response); // // /** // * Run the main code of the plugin for a given chunk. // * // * @param request {@link HttpRequest} // * @param chunk {@link HttpChunk} // */ // public void run(HttpRequest request, HttpChunk chunk); // } // Path: src/main/java/org/jlange/proxy/outbound/PluginHandler.java import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.Channels; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; import org.jboss.netty.handler.codec.http.HttpChunk; import org.jboss.netty.handler.codec.http.HttpRequest; import org.jboss.netty.handler.codec.http.HttpResponse; import org.jlange.proxy.plugin.PluginProvider; import org.jlange.proxy.plugin.PredefinedResponsePlugin; import org.jlange.proxy.plugin.ResponsePlugin; import org.slf4j.Logger; /* * Copyright (C) 2012 Julian Knocke * * This file is part of jLange. * * jLange is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * jLange is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with jLange. If not, see <http://www.gnu.org/licenses/>. */ package org.jlange.proxy.outbound; public class PluginHandler extends SimpleChannelHandler { private final static Map<String, Long> pluginStats = new HashMap<String, Long>(); private final static Logger log = LoggerFactory.getLogger(PluginHandler.class);
private List<ResponsePlugin> responsePlugins;
JHK/jLange
src/main/java/org/jlange/proxy/outbound/PluginHandler.java
// Path: src/main/java/org/jlange/proxy/plugin/PluginProvider.java // public class PluginProvider { // // private final static Logger log = LoggerFactory.getLogger(PluginProvider.class); // private final static PluginProvider instance = new PluginProvider(); // // public static PluginProvider getInstance() { // return instance; // } // // private final List<ResponsePlugin> responsePlugins; // private final List<PredefinedResponsePlugin> predefinedResponsePlugins; // // private PluginProvider() { // responsePlugins = new ArrayList<ResponsePlugin>(); // // for (String plugin : Config.PLUGINS_RESPONSE) { // try { // Class<?> className = Class.forName(plugin); // responsePlugins.add((ResponsePlugin) className.newInstance()); // log.info("Plugin loaded: {}", plugin); // } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { // log.error("Could not load plugin: {}", e.getMessage()); // } // } // // predefinedResponsePlugins = new ArrayList<PredefinedResponsePlugin>(); // // for (String plugin : Config.PLUGINS_PREDEFINED) { // try { // Class<?> className = Class.forName(plugin); // predefinedResponsePlugins.add((PredefinedResponsePlugin) className.newInstance()); // log.info("Plugin loaded: {}", plugin); // } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { // log.error("Could not load plugin: {}", e.getMessage()); // } // } // } // // public List<ResponsePlugin> getResponsePlugins() { // return responsePlugins; // } // // public List<PredefinedResponsePlugin> getPredefinedResponsePlugins() { // return predefinedResponsePlugins; // } // } // // Path: src/main/java/org/jlange/proxy/plugin/PredefinedResponsePlugin.java // public interface PredefinedResponsePlugin { // // /** // * If the plugin is able to define a {@link HttpResponse} for the given {@link HttpRequest} this method will return it. Otherwise // * {@code null} is returned. // * // * @param request {@link HttpRequest} // * @return a {@link HttpResponse} or {@code null} // */ // public HttpResponse getPredefinedResponse(final HttpRequest request); // } // // Path: src/main/java/org/jlange/proxy/plugin/ResponsePlugin.java // public interface ResponsePlugin { // // /** // * Decides if the plugin is applicable for the given request // * // * @param request {@link HttpRequest} // * @return is the plugin applicable // */ // public Boolean isApplicable(final HttpRequest request); // // /** // * Decides if the plugin is applicable for the given response // * // * @param request {@link HttpRequest} // * @return is the plugin applicable // */ // public Boolean isApplicable(final HttpResponse response); // // /** // * Run the main code of the plugin. The response will be updated in here. For read and changing responses content the code must be // * marked as <code>synchronized</code>, because these plugins are intended to run in parallel. // * // * @param request {@link HttpRequest} // * @param response matching {@link HttpResponse} // */ // public void run(final HttpRequest request, final HttpResponse response); // // /** // * Run the main code of the plugin for a given chunk. // * // * @param request {@link HttpRequest} // * @param chunk {@link HttpChunk} // */ // public void run(HttpRequest request, HttpChunk chunk); // }
import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.Channels; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; import org.jboss.netty.handler.codec.http.HttpChunk; import org.jboss.netty.handler.codec.http.HttpRequest; import org.jboss.netty.handler.codec.http.HttpResponse; import org.jlange.proxy.plugin.PluginProvider; import org.jlange.proxy.plugin.PredefinedResponsePlugin; import org.jlange.proxy.plugin.ResponsePlugin; import org.slf4j.Logger;
if (!iter.next().isApplicable(response)) iter.remove(); // apply response plugins for (ResponsePlugin plugin : responsePlugins) { long start = System.currentTimeMillis(); plugin.run(request, response); logStats(plugin, start); } } else if (e.getMessage() instanceof HttpChunk) { HttpChunk chunk = (HttpChunk) e.getMessage(); // apply response plugins for (ResponsePlugin plugin : responsePlugins) { long start = System.currentTimeMillis(); plugin.run(request, chunk); logStats(plugin, start); } } super.messageReceived(ctx, e); } @Override public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception { HttpRequest request = (HttpRequest) e.getMessage(); // apply request to predefined response plugins HttpResponse response;
// Path: src/main/java/org/jlange/proxy/plugin/PluginProvider.java // public class PluginProvider { // // private final static Logger log = LoggerFactory.getLogger(PluginProvider.class); // private final static PluginProvider instance = new PluginProvider(); // // public static PluginProvider getInstance() { // return instance; // } // // private final List<ResponsePlugin> responsePlugins; // private final List<PredefinedResponsePlugin> predefinedResponsePlugins; // // private PluginProvider() { // responsePlugins = new ArrayList<ResponsePlugin>(); // // for (String plugin : Config.PLUGINS_RESPONSE) { // try { // Class<?> className = Class.forName(plugin); // responsePlugins.add((ResponsePlugin) className.newInstance()); // log.info("Plugin loaded: {}", plugin); // } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { // log.error("Could not load plugin: {}", e.getMessage()); // } // } // // predefinedResponsePlugins = new ArrayList<PredefinedResponsePlugin>(); // // for (String plugin : Config.PLUGINS_PREDEFINED) { // try { // Class<?> className = Class.forName(plugin); // predefinedResponsePlugins.add((PredefinedResponsePlugin) className.newInstance()); // log.info("Plugin loaded: {}", plugin); // } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { // log.error("Could not load plugin: {}", e.getMessage()); // } // } // } // // public List<ResponsePlugin> getResponsePlugins() { // return responsePlugins; // } // // public List<PredefinedResponsePlugin> getPredefinedResponsePlugins() { // return predefinedResponsePlugins; // } // } // // Path: src/main/java/org/jlange/proxy/plugin/PredefinedResponsePlugin.java // public interface PredefinedResponsePlugin { // // /** // * If the plugin is able to define a {@link HttpResponse} for the given {@link HttpRequest} this method will return it. Otherwise // * {@code null} is returned. // * // * @param request {@link HttpRequest} // * @return a {@link HttpResponse} or {@code null} // */ // public HttpResponse getPredefinedResponse(final HttpRequest request); // } // // Path: src/main/java/org/jlange/proxy/plugin/ResponsePlugin.java // public interface ResponsePlugin { // // /** // * Decides if the plugin is applicable for the given request // * // * @param request {@link HttpRequest} // * @return is the plugin applicable // */ // public Boolean isApplicable(final HttpRequest request); // // /** // * Decides if the plugin is applicable for the given response // * // * @param request {@link HttpRequest} // * @return is the plugin applicable // */ // public Boolean isApplicable(final HttpResponse response); // // /** // * Run the main code of the plugin. The response will be updated in here. For read and changing responses content the code must be // * marked as <code>synchronized</code>, because these plugins are intended to run in parallel. // * // * @param request {@link HttpRequest} // * @param response matching {@link HttpResponse} // */ // public void run(final HttpRequest request, final HttpResponse response); // // /** // * Run the main code of the plugin for a given chunk. // * // * @param request {@link HttpRequest} // * @param chunk {@link HttpChunk} // */ // public void run(HttpRequest request, HttpChunk chunk); // } // Path: src/main/java/org/jlange/proxy/outbound/PluginHandler.java import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.Channels; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; import org.jboss.netty.handler.codec.http.HttpChunk; import org.jboss.netty.handler.codec.http.HttpRequest; import org.jboss.netty.handler.codec.http.HttpResponse; import org.jlange.proxy.plugin.PluginProvider; import org.jlange.proxy.plugin.PredefinedResponsePlugin; import org.jlange.proxy.plugin.ResponsePlugin; import org.slf4j.Logger; if (!iter.next().isApplicable(response)) iter.remove(); // apply response plugins for (ResponsePlugin plugin : responsePlugins) { long start = System.currentTimeMillis(); plugin.run(request, response); logStats(plugin, start); } } else if (e.getMessage() instanceof HttpChunk) { HttpChunk chunk = (HttpChunk) e.getMessage(); // apply response plugins for (ResponsePlugin plugin : responsePlugins) { long start = System.currentTimeMillis(); plugin.run(request, chunk); logStats(plugin, start); } } super.messageReceived(ctx, e); } @Override public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception { HttpRequest request = (HttpRequest) e.getMessage(); // apply request to predefined response plugins HttpResponse response;
for (PredefinedResponsePlugin plugin : PluginProvider.getInstance().getPredefinedResponsePlugins()) {
JHK/jLange
src/main/java/org/jlange/proxy/outbound/PluginHandler.java
// Path: src/main/java/org/jlange/proxy/plugin/PluginProvider.java // public class PluginProvider { // // private final static Logger log = LoggerFactory.getLogger(PluginProvider.class); // private final static PluginProvider instance = new PluginProvider(); // // public static PluginProvider getInstance() { // return instance; // } // // private final List<ResponsePlugin> responsePlugins; // private final List<PredefinedResponsePlugin> predefinedResponsePlugins; // // private PluginProvider() { // responsePlugins = new ArrayList<ResponsePlugin>(); // // for (String plugin : Config.PLUGINS_RESPONSE) { // try { // Class<?> className = Class.forName(plugin); // responsePlugins.add((ResponsePlugin) className.newInstance()); // log.info("Plugin loaded: {}", plugin); // } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { // log.error("Could not load plugin: {}", e.getMessage()); // } // } // // predefinedResponsePlugins = new ArrayList<PredefinedResponsePlugin>(); // // for (String plugin : Config.PLUGINS_PREDEFINED) { // try { // Class<?> className = Class.forName(plugin); // predefinedResponsePlugins.add((PredefinedResponsePlugin) className.newInstance()); // log.info("Plugin loaded: {}", plugin); // } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { // log.error("Could not load plugin: {}", e.getMessage()); // } // } // } // // public List<ResponsePlugin> getResponsePlugins() { // return responsePlugins; // } // // public List<PredefinedResponsePlugin> getPredefinedResponsePlugins() { // return predefinedResponsePlugins; // } // } // // Path: src/main/java/org/jlange/proxy/plugin/PredefinedResponsePlugin.java // public interface PredefinedResponsePlugin { // // /** // * If the plugin is able to define a {@link HttpResponse} for the given {@link HttpRequest} this method will return it. Otherwise // * {@code null} is returned. // * // * @param request {@link HttpRequest} // * @return a {@link HttpResponse} or {@code null} // */ // public HttpResponse getPredefinedResponse(final HttpRequest request); // } // // Path: src/main/java/org/jlange/proxy/plugin/ResponsePlugin.java // public interface ResponsePlugin { // // /** // * Decides if the plugin is applicable for the given request // * // * @param request {@link HttpRequest} // * @return is the plugin applicable // */ // public Boolean isApplicable(final HttpRequest request); // // /** // * Decides if the plugin is applicable for the given response // * // * @param request {@link HttpRequest} // * @return is the plugin applicable // */ // public Boolean isApplicable(final HttpResponse response); // // /** // * Run the main code of the plugin. The response will be updated in here. For read and changing responses content the code must be // * marked as <code>synchronized</code>, because these plugins are intended to run in parallel. // * // * @param request {@link HttpRequest} // * @param response matching {@link HttpResponse} // */ // public void run(final HttpRequest request, final HttpResponse response); // // /** // * Run the main code of the plugin for a given chunk. // * // * @param request {@link HttpRequest} // * @param chunk {@link HttpChunk} // */ // public void run(HttpRequest request, HttpChunk chunk); // }
import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.Channels; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; import org.jboss.netty.handler.codec.http.HttpChunk; import org.jboss.netty.handler.codec.http.HttpRequest; import org.jboss.netty.handler.codec.http.HttpResponse; import org.jlange.proxy.plugin.PluginProvider; import org.jlange.proxy.plugin.PredefinedResponsePlugin; import org.jlange.proxy.plugin.ResponsePlugin; import org.slf4j.Logger;
if (!iter.next().isApplicable(response)) iter.remove(); // apply response plugins for (ResponsePlugin plugin : responsePlugins) { long start = System.currentTimeMillis(); plugin.run(request, response); logStats(plugin, start); } } else if (e.getMessage() instanceof HttpChunk) { HttpChunk chunk = (HttpChunk) e.getMessage(); // apply response plugins for (ResponsePlugin plugin : responsePlugins) { long start = System.currentTimeMillis(); plugin.run(request, chunk); logStats(plugin, start); } } super.messageReceived(ctx, e); } @Override public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception { HttpRequest request = (HttpRequest) e.getMessage(); // apply request to predefined response plugins HttpResponse response;
// Path: src/main/java/org/jlange/proxy/plugin/PluginProvider.java // public class PluginProvider { // // private final static Logger log = LoggerFactory.getLogger(PluginProvider.class); // private final static PluginProvider instance = new PluginProvider(); // // public static PluginProvider getInstance() { // return instance; // } // // private final List<ResponsePlugin> responsePlugins; // private final List<PredefinedResponsePlugin> predefinedResponsePlugins; // // private PluginProvider() { // responsePlugins = new ArrayList<ResponsePlugin>(); // // for (String plugin : Config.PLUGINS_RESPONSE) { // try { // Class<?> className = Class.forName(plugin); // responsePlugins.add((ResponsePlugin) className.newInstance()); // log.info("Plugin loaded: {}", plugin); // } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { // log.error("Could not load plugin: {}", e.getMessage()); // } // } // // predefinedResponsePlugins = new ArrayList<PredefinedResponsePlugin>(); // // for (String plugin : Config.PLUGINS_PREDEFINED) { // try { // Class<?> className = Class.forName(plugin); // predefinedResponsePlugins.add((PredefinedResponsePlugin) className.newInstance()); // log.info("Plugin loaded: {}", plugin); // } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { // log.error("Could not load plugin: {}", e.getMessage()); // } // } // } // // public List<ResponsePlugin> getResponsePlugins() { // return responsePlugins; // } // // public List<PredefinedResponsePlugin> getPredefinedResponsePlugins() { // return predefinedResponsePlugins; // } // } // // Path: src/main/java/org/jlange/proxy/plugin/PredefinedResponsePlugin.java // public interface PredefinedResponsePlugin { // // /** // * If the plugin is able to define a {@link HttpResponse} for the given {@link HttpRequest} this method will return it. Otherwise // * {@code null} is returned. // * // * @param request {@link HttpRequest} // * @return a {@link HttpResponse} or {@code null} // */ // public HttpResponse getPredefinedResponse(final HttpRequest request); // } // // Path: src/main/java/org/jlange/proxy/plugin/ResponsePlugin.java // public interface ResponsePlugin { // // /** // * Decides if the plugin is applicable for the given request // * // * @param request {@link HttpRequest} // * @return is the plugin applicable // */ // public Boolean isApplicable(final HttpRequest request); // // /** // * Decides if the plugin is applicable for the given response // * // * @param request {@link HttpRequest} // * @return is the plugin applicable // */ // public Boolean isApplicable(final HttpResponse response); // // /** // * Run the main code of the plugin. The response will be updated in here. For read and changing responses content the code must be // * marked as <code>synchronized</code>, because these plugins are intended to run in parallel. // * // * @param request {@link HttpRequest} // * @param response matching {@link HttpResponse} // */ // public void run(final HttpRequest request, final HttpResponse response); // // /** // * Run the main code of the plugin for a given chunk. // * // * @param request {@link HttpRequest} // * @param chunk {@link HttpChunk} // */ // public void run(HttpRequest request, HttpChunk chunk); // } // Path: src/main/java/org/jlange/proxy/outbound/PluginHandler.java import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.Channels; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; import org.jboss.netty.handler.codec.http.HttpChunk; import org.jboss.netty.handler.codec.http.HttpRequest; import org.jboss.netty.handler.codec.http.HttpResponse; import org.jlange.proxy.plugin.PluginProvider; import org.jlange.proxy.plugin.PredefinedResponsePlugin; import org.jlange.proxy.plugin.ResponsePlugin; import org.slf4j.Logger; if (!iter.next().isApplicable(response)) iter.remove(); // apply response plugins for (ResponsePlugin plugin : responsePlugins) { long start = System.currentTimeMillis(); plugin.run(request, response); logStats(plugin, start); } } else if (e.getMessage() instanceof HttpChunk) { HttpChunk chunk = (HttpChunk) e.getMessage(); // apply response plugins for (ResponsePlugin plugin : responsePlugins) { long start = System.currentTimeMillis(); plugin.run(request, chunk); logStats(plugin, start); } } super.messageReceived(ctx, e); } @Override public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception { HttpRequest request = (HttpRequest) e.getMessage(); // apply request to predefined response plugins HttpResponse response;
for (PredefinedResponsePlugin plugin : PluginProvider.getInstance().getPredefinedResponsePlugins()) {
JHK/jLange
src/main/java/org/jlange/proxy/plugin/predefinedResponse/RequestPolicy.java
// Path: src/main/java/org/jlange/proxy/plugin/PredefinedResponsePlugin.java // public interface PredefinedResponsePlugin { // // /** // * If the plugin is able to define a {@link HttpResponse} for the given {@link HttpRequest} this method will return it. Otherwise // * {@code null} is returned. // * // * @param request {@link HttpRequest} // * @return a {@link HttpResponse} or {@code null} // */ // public HttpResponse getPredefinedResponse(final HttpRequest request); // } // // Path: src/main/java/org/jlange/proxy/util/RemoteAddress.java // public class RemoteAddress { // // public static RemoteAddress parseRequest(final HttpRequest request) { // final RemoteAddress address; // if (request.getMethod().equals(HttpMethod.CONNECT)) // address = parseString(request.getUri()); // else // address = parseString(HttpHeaders.getHost(request)); // return address; // } // // public static RemoteAddress parseString(final String uri) { // final RemoteAddress address; // if (uri.startsWith("http")) { // // consider string as url // try { // address = new RemoteAddress(new URL(uri)); // } catch (MalformedURLException e) { // e.printStackTrace(); // throw new RuntimeException(uri); // } // } else if (uri.contains(":")) { // // consider string host:port // String[] hostAndPort = uri.split(":"); // address = new RemoteAddress(hostAndPort[0], new Integer(hostAndPort[1])); // } else { // address = new RemoteAddress(uri, 80); // } // return address; // } // // private final String host; // private final Integer port; // // public RemoteAddress(final String host, final Integer port) { // this.host = host; // this.port = port; // } // // public RemoteAddress(final URL url) { // host = url.getHost(); // port = url.getPort() == -1 ? 80 : url.getPort(); // } // // public String getHost() { // return host; // } // // public Integer getPort() { // return port; // } // // @Override // public boolean equals(final Object obj) { // if (obj instanceof RemoteAddress) { // RemoteAddress other = (RemoteAddress) obj; // return other.getHost().equals(host) && other.getPort() == port; // } else // return false; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(); // return sb.append(host).append(":").append(port).toString(); // } // // @Override // public int hashCode() { // return toString().hashCode(); // } // }
import org.jboss.netty.handler.codec.http.DefaultHttpResponse; import org.jboss.netty.handler.codec.http.HttpHeaders; import org.jboss.netty.handler.codec.http.HttpRequest; import org.jboss.netty.handler.codec.http.HttpResponse; import org.jboss.netty.handler.codec.http.HttpResponseStatus; import org.jboss.netty.handler.codec.http.HttpVersion; import org.jlange.proxy.plugin.PredefinedResponsePlugin; import org.jlange.proxy.util.RemoteAddress;
/* * Copyright (C) 2012 Julian Knocke * * This file is part of jLange. * * jLange is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * jLange is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with jLange. If not, see <http://www.gnu.org/licenses/>. */ package org.jlange.proxy.plugin.predefinedResponse; public class RequestPolicy implements PredefinedResponsePlugin { private final static HttpResponse HTTP_FORBIDDEN = buildForbiddenHttpResponse(); private final static String[] HOST_BLACKLIST = new String[] { "localhost", "127.0.0.1", "127.0.1.1" }; @Override public HttpResponse getPredefinedResponse(final HttpRequest request) {
// Path: src/main/java/org/jlange/proxy/plugin/PredefinedResponsePlugin.java // public interface PredefinedResponsePlugin { // // /** // * If the plugin is able to define a {@link HttpResponse} for the given {@link HttpRequest} this method will return it. Otherwise // * {@code null} is returned. // * // * @param request {@link HttpRequest} // * @return a {@link HttpResponse} or {@code null} // */ // public HttpResponse getPredefinedResponse(final HttpRequest request); // } // // Path: src/main/java/org/jlange/proxy/util/RemoteAddress.java // public class RemoteAddress { // // public static RemoteAddress parseRequest(final HttpRequest request) { // final RemoteAddress address; // if (request.getMethod().equals(HttpMethod.CONNECT)) // address = parseString(request.getUri()); // else // address = parseString(HttpHeaders.getHost(request)); // return address; // } // // public static RemoteAddress parseString(final String uri) { // final RemoteAddress address; // if (uri.startsWith("http")) { // // consider string as url // try { // address = new RemoteAddress(new URL(uri)); // } catch (MalformedURLException e) { // e.printStackTrace(); // throw new RuntimeException(uri); // } // } else if (uri.contains(":")) { // // consider string host:port // String[] hostAndPort = uri.split(":"); // address = new RemoteAddress(hostAndPort[0], new Integer(hostAndPort[1])); // } else { // address = new RemoteAddress(uri, 80); // } // return address; // } // // private final String host; // private final Integer port; // // public RemoteAddress(final String host, final Integer port) { // this.host = host; // this.port = port; // } // // public RemoteAddress(final URL url) { // host = url.getHost(); // port = url.getPort() == -1 ? 80 : url.getPort(); // } // // public String getHost() { // return host; // } // // public Integer getPort() { // return port; // } // // @Override // public boolean equals(final Object obj) { // if (obj instanceof RemoteAddress) { // RemoteAddress other = (RemoteAddress) obj; // return other.getHost().equals(host) && other.getPort() == port; // } else // return false; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(); // return sb.append(host).append(":").append(port).toString(); // } // // @Override // public int hashCode() { // return toString().hashCode(); // } // } // Path: src/main/java/org/jlange/proxy/plugin/predefinedResponse/RequestPolicy.java import org.jboss.netty.handler.codec.http.DefaultHttpResponse; import org.jboss.netty.handler.codec.http.HttpHeaders; import org.jboss.netty.handler.codec.http.HttpRequest; import org.jboss.netty.handler.codec.http.HttpResponse; import org.jboss.netty.handler.codec.http.HttpResponseStatus; import org.jboss.netty.handler.codec.http.HttpVersion; import org.jlange.proxy.plugin.PredefinedResponsePlugin; import org.jlange.proxy.util.RemoteAddress; /* * Copyright (C) 2012 Julian Knocke * * This file is part of jLange. * * jLange is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * jLange is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with jLange. If not, see <http://www.gnu.org/licenses/>. */ package org.jlange.proxy.plugin.predefinedResponse; public class RequestPolicy implements PredefinedResponsePlugin { private final static HttpResponse HTTP_FORBIDDEN = buildForbiddenHttpResponse(); private final static String[] HOST_BLACKLIST = new String[] { "localhost", "127.0.0.1", "127.0.1.1" }; @Override public HttpResponse getPredefinedResponse(final HttpRequest request) {
final RemoteAddress address = RemoteAddress.parseRequest(request);
JHK/jLange
src/test/java/org/jlange/test/proxy/HeaderTest.java
// Path: src/main/java/org/jlange/proxy/util/HttpProxyHeaders.java // public class HttpProxyHeaders { // // private final static Pattern getIpFromAddress = Pattern.compile(".*?(\\d+(\\.\\d+){3}).*"); // // public static final class Names { // public final static String CONNECTION = "Proxy-Connection"; // public final static String X_FORWARDED_FOR = "X-Forwarded-For"; // } // // /** // * Adds a Via header to the given message. If there is already one the header will be appended. The parameter comment is optional and // * may be null. // * // * @param message HttpRequest or HttpResponse // * @param version the version of the incoming HttpRequest or HttpResponse to the proxy // * @param hostname a generic name or the IP of the proxy // * @param comment may be null, for further information // */ // public static void setVia(HttpMessage message, String hostname, String comment) { // HttpVersion version = message.getProtocolVersion(); // String currentVia = HttpHeaders.getHeader(message, HttpHeaders.Names.VIA); // String thisVia = version.getMajorVersion() + "." + version.getMinorVersion() + " " + hostname // + (comment == null ? "" : " (" + comment + ")"); // // String newVia; // if (currentVia == null) // newVia = thisVia; // else // newVia = currentVia + ", " + thisVia; // // HttpHeaders.setHeader(message, HttpHeaders.Names.VIA, newVia); // } // // public static void setForwardedFor(HttpMessage message, SocketAddress remoteAddress) { // Matcher m = getIpFromAddress.matcher(remoteAddress.toString()); // HttpHeaders.setHeader(message, Names.X_FORWARDED_FOR, m.replaceAll("$1")); // } // }
import static org.junit.Assert.assertEquals; import org.jboss.netty.handler.codec.http.DefaultHttpRequest; import org.jboss.netty.handler.codec.http.HttpHeaders; import org.jboss.netty.handler.codec.http.HttpMethod; import org.jboss.netty.handler.codec.http.HttpRequest; import org.jboss.netty.handler.codec.http.HttpVersion; import org.jlange.proxy.util.HttpProxyHeaders; import org.junit.Test;
package org.jlange.test.proxy; public class HeaderTest { @Test public void testVia() { HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost:8000/"); assertEquals(null, HttpHeaders.getHeader(request, HttpHeaders.Names.VIA));
// Path: src/main/java/org/jlange/proxy/util/HttpProxyHeaders.java // public class HttpProxyHeaders { // // private final static Pattern getIpFromAddress = Pattern.compile(".*?(\\d+(\\.\\d+){3}).*"); // // public static final class Names { // public final static String CONNECTION = "Proxy-Connection"; // public final static String X_FORWARDED_FOR = "X-Forwarded-For"; // } // // /** // * Adds a Via header to the given message. If there is already one the header will be appended. The parameter comment is optional and // * may be null. // * // * @param message HttpRequest or HttpResponse // * @param version the version of the incoming HttpRequest or HttpResponse to the proxy // * @param hostname a generic name or the IP of the proxy // * @param comment may be null, for further information // */ // public static void setVia(HttpMessage message, String hostname, String comment) { // HttpVersion version = message.getProtocolVersion(); // String currentVia = HttpHeaders.getHeader(message, HttpHeaders.Names.VIA); // String thisVia = version.getMajorVersion() + "." + version.getMinorVersion() + " " + hostname // + (comment == null ? "" : " (" + comment + ")"); // // String newVia; // if (currentVia == null) // newVia = thisVia; // else // newVia = currentVia + ", " + thisVia; // // HttpHeaders.setHeader(message, HttpHeaders.Names.VIA, newVia); // } // // public static void setForwardedFor(HttpMessage message, SocketAddress remoteAddress) { // Matcher m = getIpFromAddress.matcher(remoteAddress.toString()); // HttpHeaders.setHeader(message, Names.X_FORWARDED_FOR, m.replaceAll("$1")); // } // } // Path: src/test/java/org/jlange/test/proxy/HeaderTest.java import static org.junit.Assert.assertEquals; import org.jboss.netty.handler.codec.http.DefaultHttpRequest; import org.jboss.netty.handler.codec.http.HttpHeaders; import org.jboss.netty.handler.codec.http.HttpMethod; import org.jboss.netty.handler.codec.http.HttpRequest; import org.jboss.netty.handler.codec.http.HttpVersion; import org.jlange.proxy.util.HttpProxyHeaders; import org.junit.Test; package org.jlange.test.proxy; public class HeaderTest { @Test public void testVia() { HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost:8000/"); assertEquals(null, HttpHeaders.getHeader(request, HttpHeaders.Names.VIA));
HttpProxyHeaders.setVia(request, "hostname", null);
JHK/jLange
src/main/java/org/jlange/proxy/inbound/HttpPipelineFactory.java
// Path: src/main/java/org/jlange/proxy/util/Config.java // public class Config { // // public static final Integer OUTBOUND_TIMEOUT = getConfig().getInteger("org.jlange.outbound.connection_timeout", 30); // public static final Integer MAX_USED_CONNECTIONS = getConfig().getInteger("org.jlange.outbound.max_used_connections", 12); // public static final RemoteAddress PROXY_CHAIN = buildProxyChain(); // // public static final Boolean HTTP_ENABLED = getConfig().getBoolean("org.jlange.proxy.http.enabled", true); // public static final Integer HTTP_PORT = getConfig().getInteger("org.jlange.proxy.http.port", 8080); // // public static final Boolean SPDY_ENABLED = getConfig().getBoolean("org.jlange.proxy.spdy.enabled", false); // public static final Integer SPDY_PORT = getConfig().getInteger("org.jlange.proxy.spdy.port", 8443); // public static final String SPDY_KEY_STORE = getConfig().getString("org.jlange.proxy.spdy.ssl.store"); // public static final String SPDY_KEY_PASS = getConfig().getString("org.jlange.proxy.spdy.ssl.key"); // // public static final String VIA_HOSTNAME = getConfig().getString("org.jlange.proxy.via.hostname", "jLange"); // public static final String VIA_COMMENT = getConfig().getString("org.jlange.proxy.via.comment", null); // public static final Integer COMPRESSION_LEVEL = getConfig().getInteger("org.jlange.proxy.compression_level", 7); // public static final Integer CHUNK_SIZE = getConfig().getInteger("org.jlange.proxy.chunk_size", 8196); // public static final File TMP_DIRECTORY = buildTmpDirectory(); // // public static final String[] PLUGINS_RESPONSE = getConfig().getStringArray("org.jlange.plugin.response"); // public static final String[] PLUGINS_PREDEFINED = getConfig().getStringArray("org.jlange.plugin.predefined"); // // public static Configuration getPluginConfig(Class<?> plugin) { // if (pluginConfig.get(plugin) == null) { // try { // pluginConfig.put(plugin, new PropertiesConfiguration(plugin.getName() + ".properties")); // } catch (ConfigurationException e) { // pluginConfig.put(plugin, new PropertiesConfiguration()); // } // } // // return pluginConfig.get(plugin); // } // // private static File buildTmpDirectory() { // File tmpBase = new File(getConfig().getString("org.jlange.proxy.tmp", "/tmp")); // // if (!tmpBase.isDirectory()) // throw new IllegalArgumentException("tmp is no directory"); // // File tmpDir = new File(tmpBase, "jLange-" + HTTP_PORT + "-" + SPDY_PORT); // tmpDir.mkdirs(); // tmpDir.deleteOnExit(); // // return tmpDir; // } // // private static RemoteAddress buildProxyChain() { // String host = getConfig().getString("org.jlange.outbound.proxy.host"); // Integer port = getConfig().getInteger("org.jlange.outbound.proxy.port", null); // // if (host != null && port != null) // return new RemoteAddress(host, port); // else // return null; // } // // private static Configuration config; // private static Map<Class<?>, Configuration> pluginConfig = new HashMap<Class<?>, Configuration>(); // // private static Configuration getConfig() { // if (config == null) { // try { // config = new PropertiesConfiguration("jLange.properties"); // } catch (ConfigurationException e) { // e.printStackTrace(); // System.exit(1); // } // } // return config; // } // } // // Path: src/main/java/org/jlange/proxy/util/IdleShutdownHandler.java // public class IdleShutdownHandler extends IdleStateHandler implements ChannelHandler { // // public final static Timer timer = new HashedWheelTimer(); // // private final Logger log = LoggerFactory.getLogger(getClass()); // // public IdleShutdownHandler(final int readerIdleTimeSeconds, final int writerIdleTimeSeconds) { // super(timer, readerIdleTimeSeconds, writerIdleTimeSeconds, 0); // } // // @Override // protected void channelIdle(final ChannelHandlerContext ctx, final IdleState state, final long lastActivityTimeMillis) { // log.info("Channel {} - shutdown due idle time exceeded", ctx.getChannel().getId()); // ctx.getChannel().close(); // } // // }
import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelPipelineFactory; import org.jboss.netty.channel.Channels; import org.jboss.netty.handler.codec.http.HttpRequestDecoder; import org.jboss.netty.handler.codec.http.HttpResponseEncoder; import org.jlange.proxy.util.Config; import org.jlange.proxy.util.IdleShutdownHandler;
/* * Copyright (C) 2012 Julian Knocke * * This file is part of jLange. * * jLange is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * jLange is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with jLange. If not, see <http://www.gnu.org/licenses/>. */ package org.jlange.proxy.inbound; public class HttpPipelineFactory implements ChannelPipelineFactory { @Override public ChannelPipeline getPipeline() { final ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("decoder", new HttpRequestDecoder()); pipeline.addLast("encoder", new HttpResponseEncoder());
// Path: src/main/java/org/jlange/proxy/util/Config.java // public class Config { // // public static final Integer OUTBOUND_TIMEOUT = getConfig().getInteger("org.jlange.outbound.connection_timeout", 30); // public static final Integer MAX_USED_CONNECTIONS = getConfig().getInteger("org.jlange.outbound.max_used_connections", 12); // public static final RemoteAddress PROXY_CHAIN = buildProxyChain(); // // public static final Boolean HTTP_ENABLED = getConfig().getBoolean("org.jlange.proxy.http.enabled", true); // public static final Integer HTTP_PORT = getConfig().getInteger("org.jlange.proxy.http.port", 8080); // // public static final Boolean SPDY_ENABLED = getConfig().getBoolean("org.jlange.proxy.spdy.enabled", false); // public static final Integer SPDY_PORT = getConfig().getInteger("org.jlange.proxy.spdy.port", 8443); // public static final String SPDY_KEY_STORE = getConfig().getString("org.jlange.proxy.spdy.ssl.store"); // public static final String SPDY_KEY_PASS = getConfig().getString("org.jlange.proxy.spdy.ssl.key"); // // public static final String VIA_HOSTNAME = getConfig().getString("org.jlange.proxy.via.hostname", "jLange"); // public static final String VIA_COMMENT = getConfig().getString("org.jlange.proxy.via.comment", null); // public static final Integer COMPRESSION_LEVEL = getConfig().getInteger("org.jlange.proxy.compression_level", 7); // public static final Integer CHUNK_SIZE = getConfig().getInteger("org.jlange.proxy.chunk_size", 8196); // public static final File TMP_DIRECTORY = buildTmpDirectory(); // // public static final String[] PLUGINS_RESPONSE = getConfig().getStringArray("org.jlange.plugin.response"); // public static final String[] PLUGINS_PREDEFINED = getConfig().getStringArray("org.jlange.plugin.predefined"); // // public static Configuration getPluginConfig(Class<?> plugin) { // if (pluginConfig.get(plugin) == null) { // try { // pluginConfig.put(plugin, new PropertiesConfiguration(plugin.getName() + ".properties")); // } catch (ConfigurationException e) { // pluginConfig.put(plugin, new PropertiesConfiguration()); // } // } // // return pluginConfig.get(plugin); // } // // private static File buildTmpDirectory() { // File tmpBase = new File(getConfig().getString("org.jlange.proxy.tmp", "/tmp")); // // if (!tmpBase.isDirectory()) // throw new IllegalArgumentException("tmp is no directory"); // // File tmpDir = new File(tmpBase, "jLange-" + HTTP_PORT + "-" + SPDY_PORT); // tmpDir.mkdirs(); // tmpDir.deleteOnExit(); // // return tmpDir; // } // // private static RemoteAddress buildProxyChain() { // String host = getConfig().getString("org.jlange.outbound.proxy.host"); // Integer port = getConfig().getInteger("org.jlange.outbound.proxy.port", null); // // if (host != null && port != null) // return new RemoteAddress(host, port); // else // return null; // } // // private static Configuration config; // private static Map<Class<?>, Configuration> pluginConfig = new HashMap<Class<?>, Configuration>(); // // private static Configuration getConfig() { // if (config == null) { // try { // config = new PropertiesConfiguration("jLange.properties"); // } catch (ConfigurationException e) { // e.printStackTrace(); // System.exit(1); // } // } // return config; // } // } // // Path: src/main/java/org/jlange/proxy/util/IdleShutdownHandler.java // public class IdleShutdownHandler extends IdleStateHandler implements ChannelHandler { // // public final static Timer timer = new HashedWheelTimer(); // // private final Logger log = LoggerFactory.getLogger(getClass()); // // public IdleShutdownHandler(final int readerIdleTimeSeconds, final int writerIdleTimeSeconds) { // super(timer, readerIdleTimeSeconds, writerIdleTimeSeconds, 0); // } // // @Override // protected void channelIdle(final ChannelHandlerContext ctx, final IdleState state, final long lastActivityTimeMillis) { // log.info("Channel {} - shutdown due idle time exceeded", ctx.getChannel().getId()); // ctx.getChannel().close(); // } // // } // Path: src/main/java/org/jlange/proxy/inbound/HttpPipelineFactory.java import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelPipelineFactory; import org.jboss.netty.channel.Channels; import org.jboss.netty.handler.codec.http.HttpRequestDecoder; import org.jboss.netty.handler.codec.http.HttpResponseEncoder; import org.jlange.proxy.util.Config; import org.jlange.proxy.util.IdleShutdownHandler; /* * Copyright (C) 2012 Julian Knocke * * This file is part of jLange. * * jLange is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * jLange is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with jLange. If not, see <http://www.gnu.org/licenses/>. */ package org.jlange.proxy.inbound; public class HttpPipelineFactory implements ChannelPipelineFactory { @Override public ChannelPipeline getPipeline() { final ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("decoder", new HttpRequestDecoder()); pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("deflater", new HttpContentCompressor(Config.COMPRESSION_LEVEL));