Skip to content
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

Gae support #48

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Correções para suporte a encoding , e correções para funcionamento no
Google App Engine
jlemes committed Aug 2, 2012
commit eecca9a4ceccf7f1de419638cc8549abdcbc4a24
36 changes: 23 additions & 13 deletions client/.project
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
<projectDescription>
<name>restfulie</name>
<comment>Sonatype helps open source projects to set up maven repositories on http://oss.sonatype.org. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
<projects/>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>restfulie</name>
<comment>Sonatype helps open source projects to set up maven repositories on http://oss.sonatype.org. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
9 changes: 9 additions & 0 deletions client/src/main/java/br/com/caelum/restfulie/RestClient.java
Original file line number Diff line number Diff line change
@@ -66,5 +66,14 @@ public interface RestClient extends RequestEntry {
* Returns the required object for asynchronous requests of this client.
*/
ExecutorService getThreads();
/**
* Set custom charset
*/
RestClient withCharset(String charset);
/**
* Returns the default charset
*/
String charset();


}
Original file line number Diff line number Diff line change
@@ -49,6 +49,8 @@ public class DefaultRestClient implements RestClient {
private RequestDispatcher dispatcher;

private Pluralizer inflector;

private String charset = "UTF-8";

private URI lastURI = null;

@@ -129,4 +131,13 @@ public ExecutorService getThreads() {
return threads;
}

public RestClient withCharset(String charset) {
this.charset = charset;
return null;
}

public String charset() {
return charset;
}

}
Original file line number Diff line number Diff line change
@@ -59,24 +59,18 @@ public Response process(Request details, String method, URI uri,
"You should set a content type prior to sending some payload.");
}

// ContentProducer cp = new ContentProducer() {
// public void writeTo(OutputStream outstream) throws IOException {
// Writer writer = new OutputStreamWriter(outstream, "UTF-8");
// String type = headers.get("Content-type");
// handlerFor(type).marshal(payload, writer);
// writer.flush();
// }
// };

StringWriter writer = new StringWriter();
String type = headers.get("Content-type");
try {
type = type.split(";")[0];
handlerFor(type).marshal(payload, writer, client);
writer.flush();

HttpEntityEnclosingRequestBase verb = (HttpEntityEnclosingRequestBase) verbFor(method, uri);
add(verb, headers);
String string = writer.getBuffer().toString();
verb.setEntity(new StringEntity(string));
verb.setEntity(new StringEntity(string,client.charset()));
return execute(details, verb);
} catch (IOException e) {
throw new RestfulieException("Unable to marshal entity.", e);
Original file line number Diff line number Diff line change
@@ -17,11 +17,13 @@ public MapHeaders(Map<String, List<String>> fields) {
}

public List<String> get(String key) {
return fields.get(key);
List<String> values = fields.get(key);
if(values==null) values = fields.get(key.toLowerCase());
return values;
}

public String getMain(String key) {
if(!fields.containsKey(key)) {
if(!fields.containsKey(key)&&!fields.containsKey(key.toLowerCase())) {
throw new IllegalArgumentException("Unable to parse as field does not exist.");
}
return get(key).get(0).split(";")[0];
Original file line number Diff line number Diff line change
@@ -27,9 +27,9 @@ public <T> void marshal(T payload, Writer writer, RestClient client) throws IOEx
Map<String, String> params = (Map<String, String>) payload;
int at = 0;
for (String key : params.keySet()) {
writer.append(URLEncoder.encode(key));
writer.append(URLEncoder.encode(key,client.charset()));
writer.append("=");
writer.append(URLEncoder.encode(params.get(key)));
writer.append(URLEncoder.encode(params.get(key),client.charset()));
if (++at != params.size()) {
writer.append("&");
}
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ public class MediaTypes {
private final LinkedList<MediaType> types = new LinkedList<MediaType>();

public MediaType forContentType(String searching) {
searching = searching.split(";")[0];
for (MediaType type : types) {
if (type.answersTo(searching)) {
return type;
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
import br.com.caelum.restfulie.relation.Enhancer;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;
import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
import com.thoughtworks.xstream.converters.reflection.ReflectionProviderWrapper;
import com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider;
@@ -95,7 +96,7 @@ public XStreamHelper(HierarchicalStreamDriver driver, Enhancer enhancer) {
* @return
*/
protected ReflectionProvider getProvider() {
return new EnhancedLookupProvider(new Sun14ReflectionProvider());
return new EnhancedLookupProvider(new PureJavaReflectionProvider());
}

/**