Permalink
Browse files

Merge pull request #445 from patriot1burke/master

case, mediatype, and pathsegment optimizations
  • Loading branch information...
2 parents 1224663 + ce2670f commit 47c60c71f5bfa7e05dc45af45d8c5f686568fc44 @patriot1burke patriot1burke committed Jan 25, 2014
@@ -12,6 +12,7 @@
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
+import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import java.io.ByteArrayInputStream;
@@ -37,21 +38,29 @@ public String create(String cust)
}
+
@Test
public void testCleartext() throws Exception
{
- final int WARMUP = 10;
- final int INTERATIONS = 100;
- //final int WARMUP = 1000;
- //final int INTERATIONS = 100000;
+ //final int WARMUP = 10;
+ //final int INTERATIONS = 100;
+ final int WARMUP = 1000;
+ final int INTERATIONS = 1000000;
ResteasyDeployment deployment = new ResteasyDeployment();
deployment.start();
Registry registry = deployment.getRegistry();
registry.addPerRequestResource(CleartextResource.class);
MockHttpResponse response = new MockHttpResponse();
- MockHttpRequest request = MockHttpRequest.post("/test/create").contentType(MediaType.TEXT_PLAIN);
+ MockHttpRequest request = MockHttpRequest.post("/test/create")
+ .header(HttpHeaders.CONTENT_LANGUAGE, "en")
+ .header(HttpHeaders.USER_AGENT, "mozilla")
+ .header("Custom-Header1", "mozilla")
+ .header("Custom-Header2", "mozilla")
+ .header("Custom-Header3", "mozilla")
+ .header("Custom-Header4", "mozilla")
+ .contentType(MediaType.TEXT_PLAIN);
ByteArrayInputStream stream = new ByteArrayInputStream("hello".getBytes());
request.setInputStream(stream);
@@ -27,6 +27,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.util.List;
import java.util.Map;
import static java.lang.String.format;
@@ -51,7 +52,7 @@ protected ClientResponse(ClientConfiguration configuration)
public void setHeaders(MultivaluedMap<String, String> headers)
{
this.metadata = new Headers<Object>();
- this.metadata.putAll(headers);
+ this.metadata.putAll((Map)headers);
}
public void setProperties(Map<String, Object> properties)
@@ -18,7 +18,7 @@ public Object fromString(String type) throws IllegalArgumentException
return parse(type);
}
-
+ /*
public static MediaType parse(String type)
{
String params = null;
@@ -65,6 +65,62 @@ else if (paths.length == 2)
return new MediaType(major, subtype);
}
}
+ */
+
+ public static MediaType parse(String type)
+ {
+ int typeIndex = type.indexOf('/');
+ int paramIndex = type.indexOf(';');
+ String major = null;
+ String subtype = null;
+ if (typeIndex < 0) // possible "*"
+ {
+ major = type;
+ if (paramIndex > -1)
+ {
+ major = major.substring(0, paramIndex);
+ }
+ if (!MediaType.MEDIA_TYPE_WILDCARD.equals(major))
+ {
+ throw new IllegalArgumentException("Failure parsing MediaType string: " + type);
+ }
+ subtype = MediaType.MEDIA_TYPE_WILDCARD;
+ }
+ else
+ {
+ major = type.substring(0, typeIndex);
+ if (paramIndex > -1)
+ {
+ subtype = type.substring(typeIndex + 1, paramIndex);
+ }
+ else
+ {
+ subtype = type.substring(typeIndex + 1);
+ }
+ }
+ if (major.length() < 1 || subtype.length() < 1)
+ {
+ throw new IllegalArgumentException("Failure parsing MediaType string: " + type);
+ }
+ String params = null;
+ if (paramIndex > -1) params = type.substring(paramIndex + 1);
+ if (params != null && !params.equals(""))
+ {
+ HashMap<String, String> typeParams = new HashMap<String, String>();
+
+ int start = 0;
+
+ while (start < params.length())
+ {
+ start = HeaderParameterParser.setParam(typeParams, params, start);
+ }
+ return new MediaType(major, subtype, typeParams);
+ }
+ else
+ {
+ return new MediaType(major, subtype);
+ }
+ }
private static final char[] quotedChars = "()<>@,;:\\\"/[]?= \t\r\n".toCharArray();
@@ -396,6 +396,7 @@ public String getHeaderString(String name)
{
if (first) first = false;
else builder.append(",");
+ if (val == null) val = "";
val = toHeaderString(val);
if (val == null) val = "";
builder.append(val);
Oops, something went wrong.

0 comments on commit 47c60c7

Please sign in to comment.