Skip to content

Commit

Permalink
socket update
Browse files Browse the repository at this point in the history
  • Loading branch information
mirage22 committed May 11, 2018
1 parent 545dca7 commit e946f46
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 165 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public OutboundHttpSocketChannelHandler(ByteChannel byteChannel, HttpDecoratedRe
@Override
public void start() {
// FIXME: 1/24/18 (miro) -> client context
final ClientPathDTO pathMethod = new ClientPathDTO(message.getPath(), message.getMethod(),
final ClientPathDTO pathMethod = new ClientPathDTO(message.getPathMethod().getPath(), message.getPathMethod().getMethod(),
message.getCallbacks());

//@formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package com.robo4j.socket.http.message;

import com.robo4j.socket.http.HttpHeaderFieldNames;
import com.robo4j.socket.http.HttpMethod;
import com.robo4j.socket.http.units.PathHttpMethod;
import com.robo4j.socket.http.util.RoboHttpUtils;

import java.util.Map;
Expand Down Expand Up @@ -54,12 +54,8 @@ public HttpDenominator getDenominator() {
return denominator;
}

public HttpMethod getMethod() {
return denominator.getMethod();
}

public String getPath() {
return denominator.getPath();
public PathHttpMethod getPathMethod(){
return denominator.getPathHttpMethod();
}

public String getHost() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.robo4j.socket.http.HttpMethod;
import com.robo4j.socket.http.HttpVersion;
import com.robo4j.socket.http.units.PathHttpMethod;
import com.robo4j.util.Utf8Constant;

import static com.robo4j.util.Utf8Constant.UTF8_SOLIDUS;
Expand All @@ -30,8 +31,7 @@
public class HttpRequestDenominator implements HttpDenominator {

private final StringBuilder sb = new StringBuilder();
private final HttpMethod method;
private final String path;
private final PathHttpMethod pathHttpMethod;
private final HttpVersion version;

/**
Expand All @@ -43,8 +43,7 @@ public class HttpRequestDenominator implements HttpDenominator {
* http version
*/
public HttpRequestDenominator(HttpMethod method, HttpVersion version) {
this.method = method;
this.path = UTF8_SOLIDUS;
this.pathHttpMethod = new PathHttpMethod(UTF8_SOLIDUS, method);
this.version = version;
}

Expand All @@ -58,17 +57,12 @@ public HttpRequestDenominator(HttpMethod method, HttpVersion version) {
* http version
*/
public HttpRequestDenominator(HttpMethod method, String path, HttpVersion version) {
this.method = method;
this.path = path;
this.pathHttpMethod = new PathHttpMethod(path, method);
this.version = version;
}

public HttpMethod getMethod() {
return method;
}

public String getPath() {
return path;
public PathHttpMethod getPathHttpMethod() {
return pathHttpMethod;
}

@Override
Expand All @@ -83,15 +77,13 @@ public String getVersion() {
*/
@Override
public String generate() {
assert method != null;
assert path != null;
assert version != null;
return sb.append(method.getName()).append(Utf8Constant.UTF8_SPACE).append(path).append(Utf8Constant.UTF8_SPACE)
return sb.append(pathHttpMethod.getMethod().getName()).append(Utf8Constant.UTF8_SPACE).append(pathHttpMethod.getPath()).append(Utf8Constant.UTF8_SPACE)
.append(getVersion()).toString();
}

@Override
public String toString() {
return "HttpRequestDenominator{" + "method=" + method + ", path='" + path + '\'' + ", version=" + version + '}';
return "HttpRequestDenominator{" + "pathHttpMethod=" + pathHttpMethod + '\'' + ", version=" + version + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.robo4j.logging.SimpleLoggingUtil;
import com.robo4j.socket.http.enums.StatusCode;
import com.robo4j.socket.http.message.HttpDecoratedRequest;
import com.robo4j.socket.http.units.PathHttpMethod;
import com.robo4j.socket.http.units.ServerContext;
import com.robo4j.socket.http.units.ServerPathConfig;

Expand Down Expand Up @@ -55,7 +54,7 @@ public RoboRequestCallable(RoboContext context, ServerContext serverContext, Htt
public HttpResponseProcess call() throws Exception {

final HttpResponseProcessBuilder resultBuilder = HttpResponseProcessBuilder.Builder();
final ServerPathConfig pathConfig = serverContext.getPathConfig(new PathHttpMethod(decoratedRequest.getPath(), decoratedRequest.getMethod()));
final ServerPathConfig pathConfig = serverContext.getPathConfig(decoratedRequest.getPathMethod());

if (isValidPath(pathConfig)) {
resultBuilder.setMethod(pathConfig.getMethod());
Expand Down Expand Up @@ -89,7 +88,7 @@ public HttpResponseProcess call() throws Exception {
break;
default:
resultBuilder.setCode(StatusCode.BAD_REQUEST);
SimpleLoggingUtil.debug(getClass(), "not implemented method: " + decoratedRequest.getMethod());
SimpleLoggingUtil.debug(getClass(), "not implemented method: " + decoratedRequest.getPathMethod());
}
} else {
resultBuilder.setCode(StatusCode.BAD_REQUEST);
Expand All @@ -98,8 +97,8 @@ public HttpResponseProcess call() throws Exception {
}

private boolean isValidPath(ServerPathConfig pathConfig) {
return pathConfig != null && decoratedRequest.getMethod() != null
&& decoratedRequest.getMethod().equals(pathConfig.getMethod());
return pathConfig != null && decoratedRequest.getPathMethod() != null
&& decoratedRequest.getPathMethod().getMethod().equals(pathConfig.getMethod());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public HttpMethod getMethod() {
return method;
}

@Override
public String toString() {
return "PathHttpMethod{" +
"path='" + path + '\'' +
", method=" + method +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o)
Expand All @@ -55,7 +63,6 @@ public boolean equals(Object o) {

@Override
public int hashCode() {

return Objects.hash(path, method);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void byteBufferFromRequestTest() {

Assert.assertNotNull(postMessage);
Assert.assertTrue(postMessage.length() == decoratedRequest.getLength());
Assert.assertTrue(clientPath.equals(decoratedRequest.getPath()));
Assert.assertTrue(clientPath.equals(decoratedRequest.getPathMethod().getPath()));
Assert.assertTrue(bodyMessage.equals(decoratedRequest.getMessage()));
}

Expand Down

0 comments on commit e946f46

Please sign in to comment.