Skip to content

Commit

Permalink
Fixes to make compiliation via maven work.
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewins committed Apr 17, 2012
1 parent f7d2eaa commit 809176d
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 44 deletions.
7 changes: 4 additions & 3 deletions src/main/java/org/neo4j/smack/api/NodeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public void getRoot(Invocation invocation, Output result) {
@DeserializeWith(ValueOrNullDeserializationStrategy.class)
@SerializeWith(RepresentationSerializationStrategy.class)
public void createNode(Invocation invocation, Output result) throws PropertyValueException, URISyntaxException {
Object payload = invocation.getDeserializedContent();
Map<String, Object> payload = invocation.getDeserializedContent();
if (payload==null) payload = Collections.emptyMap();
final NodeRepresentation node = actionsFor(invocation).createNode((Map<String, Object>) payload);
final NodeRepresentation node = actionsFor(invocation).createNode(payload);
final String location = createOutputFormat(invocation).format(node.selfUri());
result.createdAt(location, node);
}
Expand All @@ -73,11 +73,12 @@ public void deleteNode(Invocation invocation, Output result) throws PropertyValu
result.ok();
}

@SuppressWarnings("unchecked")
@PUT
@Path(PATH_NODE_PROPERTIES)
@DeserializeWith(PropertyMapDeserializationStrategy.class)
public void setAllNodeProperties(Invocation invocation, Output result) throws PropertyValueException, URISyntaxException, NodeNotFoundException, OperationFailureException {
actionsFor(invocation).setAllNodeProperties(getNodeId(invocation), (Map<String, Object>) invocation.getDeserializedContent());
actionsFor(invocation).setAllNodeProperties(getNodeId(invocation), invocation.getDeserializedContent(Map.class));
result.okNoContent();
}

Expand Down
69 changes: 43 additions & 26 deletions src/main/java/org/neo4j/smack/event/NettyChannelBackedOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@
public class NettyChannelBackedOutput implements Output {

private SerializationFactory serializationFactory;

private boolean outputStarted;
private Channel channel;
private SerializationStrategy<Object> defaultSerializationStrategy;
private boolean isPersistentConnection;

public NettyChannelBackedOutput(SerializationFactory serializationFactory) {
public NettyChannelBackedOutput(SerializationFactory serializationFactory)
{
this.serializationFactory = serializationFactory;
}

@Override
public void created()
{
Expand Down Expand Up @@ -100,64 +101,80 @@ protected boolean started()
{
return outputStarted;
}

@SuppressWarnings("unchecked")
protected void reset(Channel channel, SerializationStrategy<?> serializationStrategy, boolean isPersistentConnection) {
protected void reset(Channel channel,
SerializationStrategy<?> serializationStrategy,
boolean isPersistentConnection)
{
this.channel = channel;
this.defaultSerializationStrategy = (SerializationStrategy<Object>) serializationStrategy;
this.isPersistentConnection = isPersistentConnection;

outputStarted = false;
}

public void send(HttpResponseStatus status, Object data, String location) {

public void send(HttpResponseStatus status, Object data, String location)
{
send(status, data, location, defaultSerializationStrategy);
}

public void send(HttpResponseStatus status, Object data, String location, SerializationStrategy serializationStrategy) {
if(outputStarted) {
throw new RuntimeException("Response has already been sent, can only send once per invocation.");

@SuppressWarnings("unchecked")
public void send(
HttpResponseStatus status,
Object data,
String location,
@SuppressWarnings("rawtypes") SerializationStrategy serializationStrategy)
{
if (outputStarted)
{
throw new RuntimeException(
"Response has already been sent, can only send once per invocation.");
}

outputStarted = true;

DefaultHttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);

if (location != null)
{
response.addHeader(HttpHeaders.Names.LOCATION, location);
}
if (data == null)

if (data == null)
{
response.addHeader(HttpHeaders.Names.CONTENT_LENGTH, 0);
} else
} else
{
if(serializationStrategy.isStreaming())
if (serializationStrategy.isStreaming())
{
response.setChunked(true);
throw new RuntimeException("IMPLEMENT ME!");
} else
} else
{
final DynamicChannelBuffer content = new DynamicChannelBuffer(1000);
Serializer serializer = serializationFactory.getSerializer(content);
final DynamicChannelBuffer content = new DynamicChannelBuffer(
1000);
Serializer serializer = serializationFactory
.getSerializer(content);
serializationStrategy.serialize(data, serializer);
response.setHeader(HttpHeaders.Names.CONTENT_TYPE, serializer.getContentType().toString());
response.setHeader(HttpHeaders.Names.CONTENT_TYPE, serializer
.getContentType().toString());
response.setContent(content);
}
}

ChannelFuture future = channel.write(response);
if( ! isPersistentConnection )

if (!isPersistentConnection)
{
try
{
future.await().addListener(ChannelFutureListener.CLOSE);
} catch (InterruptedException e)
{
// TODO: Create specific exception?
throw new RuntimeException("Waiting for channel to be done to close it failed.", e);
throw new RuntimeException(
"Waiting for channel to be done to close it failed.", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ public class ExceptionOutputWriter {

private final SerializationStrategy<Throwable> exceptionSerializationStrategy;

private Map<Class<? extends Throwable>, HttpResponseStatus> exceptionToStatusMap = new HashMap<Class<? extends Throwable>, HttpResponseStatus>() {{
private Map<Class<? extends Throwable>, HttpResponseStatus> exceptionToStatusMap = new HashMap<Class<? extends Throwable>, HttpResponseStatus>()
{

private static final long serialVersionUID = -5937199711856466595L;

{
put(ResourceNotFoundException.class, HttpResponseStatus.NOT_FOUND);
put(NodeNotFoundException.class, HttpResponseStatus.NOT_FOUND);
put(RelationNotFoundException.class, HttpResponseStatus.NOT_FOUND);
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/org/neo4j/smack/routing/Router.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
*/
package org.neo4j.smack.routing;

import com.sun.jersey.server.impl.uri.PathPattern;
import com.sun.jersey.server.impl.uri.PathTemplate;
import org.apache.log4j.Logger;
import org.neo4j.smack.event.RequestEvent;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.regex.MatchResult;

import org.apache.log4j.Logger;
import org.neo4j.smack.event.RequestEvent;

import com.sun.jersey.server.impl.uri.PathPattern;
import com.sun.jersey.server.impl.uri.PathTemplate;

public class Router extends RoutingDefinition {

private RouteEntry [] routes;
Expand Down Expand Up @@ -74,7 +75,7 @@ public void compileRoutes() {
private RouteEntry createRoute(RouteDefinitionEntry definition) {
RouteEntry route = new RouteEntry();
final PathTemplate template = new PathTemplate(definition.getPath());
route.pattern = new PathPattern(template,"");
route.pattern = new PathPattern(template,"/");
return route;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
*/
package org.neo4j.smack.serialization;

import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.JsonParser;

import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.JsonParser;
public class JsonDeserializer implements Deserializer {

private JsonParser parser;
Expand Down Expand Up @@ -101,8 +101,8 @@ public Object readObjectOrNull() throws DeserializationException {
}
}


@Override
@SuppressWarnings("unchecked")
public Map<String, Object> readMap() throws DeserializationException {
try {
return parser.readValueAs(Map.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
* @author mh
* @since 27.11.11
*/
public class MapSerializationStrategy extends AbstractNonStreamingSerializationStrategy<Map> {
public class MapSerializationStrategy extends AbstractNonStreamingSerializationStrategy<Map<String,Object>> {

@Override
public void serialize(Map map, Serializer out) throws SerializationException {
public void serialize(Map<String,Object> map, Serializer out) throws SerializationException {
out.putMap(map);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void main(String [] args) {
private double test() {
try {

int numRequests = 10000;
int numRequests = 100000;

startServer();

Expand Down

0 comments on commit 809176d

Please sign in to comment.