mirror of
https://github.com/gnh1201/caterpillar.git
synced 2025-07-15 16:58:08 +00:00
fix
This commit is contained in:
parent
2b5c8e6daf
commit
4cd311cc24
|
@ -1,11 +1,8 @@
|
||||||
package com.catswords.caterpillar;
|
package com.catswords.caterpillar;
|
||||||
|
|
||||||
public class App {
|
public class App {
|
||||||
public String getGreeting() {
|
|
||||||
return "Hello World!";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println(new App().getGreeting());
|
// Stateful mode only
|
||||||
|
throw new UnsupportedOperationException("This method is not yet implemented.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class Worker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, String> parseHeaders(String str) {
|
private static Map<String, String> parseHeaders(String str) {
|
||||||
Map<String, String> headers = new HashMap<>();
|
Map<String, String> headers = new HashMap<>();
|
||||||
String[] lines = str.split("\r?\n");
|
String[] lines = str.split("\r?\n");
|
||||||
String firstLine = lines[0];
|
String firstLine = lines[0];
|
||||||
|
@ -87,6 +87,9 @@ public class Worker {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readFromRemoteServer(String remoteAddress, int remotePort, String scheme, byte[] requestData, object _out, int bufferSize, String id) {
|
private static readFromRemoteServer(String remoteAddress, int remotePort, String scheme, byte[] requestData, object _out, int bufferSize, String id) {
|
||||||
|
JspWriter jspWriterOut = (out instanceof JspWriter ? (JspWriter) _out : null);
|
||||||
|
Socket conn = (out instanceof Socket ? (Socket) _out : null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// connect to the remote server
|
// connect to the remote server
|
||||||
Socket sock = new Socket();
|
Socket sock = new Socket();
|
||||||
|
@ -97,21 +100,17 @@ public class Worker {
|
||||||
// send data to the remote server
|
// send data to the remote server
|
||||||
outToServer.write(requestData, 0, requestData.length);
|
outToServer.write(requestData, 0, requestData.length);
|
||||||
|
|
||||||
// receive a response
|
// receive a response and forward to the client
|
||||||
char[] buffer = new char[bufferSize];
|
char[] buffer = new char[bufferSize];
|
||||||
int bytesRead;
|
int bytesRead;
|
||||||
StringBuilder response = new StringBuilder();
|
|
||||||
while ((bytesRead = inFromServer.read(buffer, 0, bufferSize)) != -1) {
|
while ((bytesRead = inFromServer.read(buffer, 0, bufferSize)) != -1) {
|
||||||
response.append(buffer, 0, bytesRead);
|
if (jspWriterOut != null) {
|
||||||
}
|
out.write(buffer, 0, bytesRead);
|
||||||
|
} else if (conn != null) {
|
||||||
// send output to the client
|
char[] outBuffer = new char[bytesRead];
|
||||||
if (out instanceof JspWriter) {
|
System.arraycopy(buffer, 0, outBuffer, 0, bytesRead);
|
||||||
JspWriter out = (JspWriter) _out;
|
conn.getOutputStream().write(outBuffer);
|
||||||
out.println(response.toString());
|
}
|
||||||
} else if (out instanceof Socket) {
|
|
||||||
Socket conn = (Socket) _out;
|
|
||||||
conn.getOutputStream().write(response.toString().getBytes());
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// build a description of the error
|
// build a description of the error
|
||||||
|
@ -122,11 +121,9 @@ public class Worker {
|
||||||
String response = new JsonRpc2.Error(error, id);
|
String response = new JsonRpc2.Error(error, id);
|
||||||
|
|
||||||
// send output to the client
|
// send output to the client
|
||||||
if (out instanceof JspWriter) {
|
if (jspWriterOut != null) {
|
||||||
JspWriter out = (JspWriter) _out;
|
|
||||||
out.println(response.toString());
|
out.println(response.toString());
|
||||||
} else if (out instanceof Socket) {
|
} else if (conn != null) {
|
||||||
Socket conn = (Socket) _out;
|
|
||||||
conn.getOutputStream().write(response.toString().getBytes());
|
conn.getOutputStream().write(response.toString().getBytes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,14 +158,14 @@ public class Worker {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stateful (Servlet only)
|
// Stateful mode (Servlet only)
|
||||||
public static void relayConenct(Map<String, Object> params, String id, JspWriter out) {
|
public static void relayConenct(Map<String, Object> params, String id, JspWriter out) {
|
||||||
// todo
|
throw new UnsupportedOperationException("This method is not yet implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stateful (Socket only)
|
// Stateful mode (Socket only)
|
||||||
public static void relayConenct(Map<String, Object> params, String id, Socket connection) {
|
public static void relayConenct(Map<String, Object> params, String id, Socket connection) {
|
||||||
// todo
|
throw new UnsupportedOperationException("This method is not yet implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user