Skip to content

Add Overload to OAuthParameters.toReference which Accepts an Existing Reference #1240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.logging.Logger;

import org.restlet.data.Form;
import org.restlet.data.Parameter;
import org.restlet.data.Reference;
import org.restlet.ext.oauth.internal.Scopes;
import org.restlet.representation.Representation;
Expand Down Expand Up @@ -118,6 +119,17 @@ public Reference toReference(String uri) {
reference.setQuery(query);
return reference;
}

public Reference toReference(Reference ref) {
Reference reference = new Reference(ref);

//Add each parameter to avoid overwriting existing parameters
for(Parameter param : form){
reference.addQueryParameter(param);
}

return reference;
}

public Representation toRepresentation() {
return form.getWebRepresentation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,16 @@ public void testToReference() {
assertEquals("val2", form.getFirstValue("bar"));
assertEquals("val3", form.getFirstValue("buz"));
}

@Test
public void testToReferenceFromReference() {
Reference originalReference = new Reference("http://localhost/test?existing=thing");

Reference reference = parameters.toReference(originalReference);
Form form = reference.getQueryAsForm();
assertEquals("thing", form.getFirstValue("existing"));
assertEquals("val1", form.getFirstValue("foo"));
assertEquals("val2", form.getFirstValue("bar"));
assertEquals("val3", form.getFirstValue("buz"));
}
}