use of APJP.ANDROID.HTTP11.HTTPRequests in project apjp by jvansteirteghem.
the class Main method main.
public static void main(final String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
Security.addProvider(new IAIK());
Properties properties = new Properties();
properties.load(new FileInputStream("APJP_LOCAL.properties"));
APJP.APJP_KEY = properties.getProperty("APJP_KEY", "");
APJP.APJP_LOGGER_ID = "APJP";
APJP.APJP_LOGGER_LEVEL = 1;
APJP.APJP_LOCAL_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_PROXY_SERVER_ADDRESS", "");
try {
APJP.APJP_LOCAL_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_PROXY_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_LOCAL_PROXY_SERVER_PORT = 0;
}
APJP.APJP_LOCAL_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_PROXY_SERVER";
APJP.APJP_LOCAL_PROXY_SERVER_LOGGER_LEVEL = 1;
APJP.APJP_LOCAL_HTTP_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTP_PROXY_SERVER_ADDRESS", "");
try {
APJP.APJP_LOCAL_HTTP_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTP_PROXY_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_LOCAL_HTTP_PROXY_SERVER_PORT = 0;
}
APJP.APJP_LOCAL_HTTP_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_HTTP_PROXY_SERVER";
APJP.APJP_LOCAL_HTTP_PROXY_SERVER_LOGGER_LEVEL = 1;
APJP.APJP_LOCAL_HTTP_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTP_SERVER_ADDRESS", "");
try {
APJP.APJP_LOCAL_HTTP_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTP_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_LOCAL_HTTP_SERVER_PORT = 0;
}
APJP.APJP_LOCAL_HTTP_SERVER_LOGGER_ID = "APJP_LOCAL_HTTP_SERVER";
APJP.APJP_LOCAL_HTTP_SERVER_LOGGER_LEVEL = 1;
APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_URL = new String[10];
APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY = new String[10][5];
APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_VALUE = new String[10][5];
for (int i = 0; i < APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY.length; i = i + 1) {
APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_URL[i] = properties.getProperty("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_URL", "");
for (int j = 0; j < APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY[i].length; j = j + 1) {
APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY[i][j] = properties.getProperty("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_KEY", "");
APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_VALUE[i][j] = properties.getProperty("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_VALUE", "");
}
}
APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTPS_PROXY_SERVER_ADDRESS", "");
try {
APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTPS_PROXY_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_PORT = 0;
}
APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_HTTPS_PROXY_SERVER";
APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_LOGGER_LEVEL = 1;
APJP.APJP_LOCAL_HTTPS_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTPS_SERVER_ADDRESS", "");
try {
APJP.APJP_LOCAL_HTTPS_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTPS_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_LOCAL_HTTPS_SERVER_PORT = 0;
}
APJP.APJP_LOCAL_HTTPS_SERVER_LOGGER_ID = "APJP_LOCAL_HTTPS_SERVER";
APJP.APJP_LOCAL_HTTPS_SERVER_LOGGER_LEVEL = 1;
APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_URL = new String[10];
APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY = new String[10][5];
APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_VALUE = new String[10][5];
for (int i = 0; i < APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY.length; i = i + 1) {
APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_URL[i] = properties.getProperty("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_URL", "");
for (int j = 0; j < APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY[i].length; j = j + 1) {
APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY[i][j] = properties.getProperty("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_KEY", "");
APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_VALUE[i][j] = properties.getProperty("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_VALUE", "");
}
}
APJP.APJP_HTTP_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_HTTP_PROXY_SERVER_ADDRESS", "");
try {
APJP.APJP_HTTP_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_HTTP_PROXY_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_HTTP_PROXY_SERVER_PORT = 0;
}
APJP.APJP_HTTP_PROXY_SERVER_USERNAME = properties.getProperty("APJP_HTTP_PROXY_SERVER_USERNAME", "");
APJP.APJP_HTTP_PROXY_SERVER_PASSWORD = properties.getProperty("APJP_HTTP_PROXY_SERVER_PASSWORD", "");
APJP.APJP_HTTPS_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_HTTPS_PROXY_SERVER_ADDRESS", "");
try {
APJP.APJP_HTTPS_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_HTTPS_PROXY_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_HTTPS_PROXY_SERVER_PORT = 0;
}
APJP.APJP_HTTPS_PROXY_SERVER_USERNAME = properties.getProperty("APJP_HTTPS_PROXY_SERVER_USERNAME", "");
APJP.APJP_HTTPS_PROXY_SERVER_PASSWORD = properties.getProperty("APJP_HTTPS_PROXY_SERVER_PASSWORD", "");
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
PasswordAuthentication passwordAuthentication = null;
if (this.getRequestorType() == Authenticator.RequestorType.PROXY) {
if (this.getRequestingURL().getProtocol().equalsIgnoreCase("HTTP") == true) {
passwordAuthentication = new PasswordAuthentication(APJP.APJP_HTTP_PROXY_SERVER_USERNAME, APJP.APJP_HTTP_PROXY_SERVER_PASSWORD.toCharArray());
} else {
if (this.getRequestingURL().getProtocol().equalsIgnoreCase("HTTPS") == true) {
passwordAuthentication = new PasswordAuthentication(APJP.APJP_HTTPS_PROXY_SERVER_USERNAME, APJP.APJP_HTTPS_PROXY_SERVER_PASSWORD.toCharArray());
}
}
}
return passwordAuthentication;
}
});
logger = Logger.getLogger(APJP.APJP_LOGGER_ID);
final ProxyServer proxyServer = new ProxyServer();
final JTextArea outputTextArea = new JTextArea();
outputTextArea.setEditable(false);
outputTextArea.setLineWrap(true);
outputTextArea.setBackground(new Color(0, 0, 0));
outputTextArea.setForeground(new Color(255, 255, 255));
outputTextArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
final JScrollPane outputScrollPane = new JScrollPane(outputTextArea);
final OutputStream outputStream = new OutputStream() {
public void write(final int b) throws IOException {
outputTextArea.append(new String(new char[] { (char) b }));
}
public void write(final byte[] b, final int off, final int len) throws IOException {
outputTextArea.append(new String(b, off, len));
}
};
final PrintStream printStream = new PrintStream(outputStream, true);
System.setOut(printStream);
final JButton startButton = new JButton();
startButton.setText("Start");
startButton.setPreferredSize(new Dimension(100, 30));
startButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent actionEvent) {
outputTextArea.setText("");
logger.log(1, "START_PROXY_SERVER");
try {
proxyServer.start();
logger.log(1, "START_PROXY_SERVER: OK");
} catch (Exception e) {
logger.log(1, "START_PROXY_SERVER: EXCEPTION", e);
logger.log(1, "START_PROXY_SERVER: NOT OK");
}
HTTPRequests httpRequests = HTTPRequests.getHTTPRequests();
logger.log(1, "TEST_HTTP_REQUESTS");
try {
httpRequests.test();
logger.log(1, "TEST_HTTP_REQUESTS: OK");
} catch (Exception e) {
logger.log(1, "TEST_HTTP_REQUESTS: EXCEPTION", e);
logger.log(1, "TEST_HTTP_REQUESTS: NOT OK");
}
HTTPSRequests httpsRequests = HTTPSRequests.getHTTPSRequests();
logger.log(1, "TEST_HTTPS_REQUESTS");
try {
httpsRequests.test();
logger.log(1, "TEST_HTTPS_REQUESTS: OK");
} catch (Exception e) {
logger.log(1, "TEST_HTTPS_REQUESTS: EXCEPTION", e);
logger.log(1, "TEST_HTTPS_REQUESTS: NOT OK");
}
}
});
final JButton stopButton = new JButton();
stopButton.setText("Stop");
stopButton.setPreferredSize(new Dimension(100, 30));
stopButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent actionEvent) {
outputTextArea.setText("");
logger.log(1, "STOP_PROXY_SERVER");
try {
proxyServer.stop();
logger.log(1, "STOP_PROXY_SERVER: OK");
} catch (Exception e) {
logger.log(1, "STOP_PROXY_SERVER: EXCEPTION", e);
logger.log(1, "STOP_PROXY_SERVER: NOT OK");
}
}
});
final Panel buttonPanel = new Panel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
buttonPanel.add(startButton);
buttonPanel.add(stopButton);
final ImageIcon imageIcon = new ImageIcon("APJP_LOCAL.png");
final JFrame frame = new JFrame();
frame.setIconImage(imageIcon.getImage());
frame.setSize(675, 375);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(buttonPanel, BorderLayout.NORTH);
frame.add(outputScrollPane, BorderLayout.CENTER);
if (SystemTray.isSupported()) {
final TrayIcon trayIcon = new TrayIcon(imageIcon.getImage());
trayIcon.setImageAutoSize(true);
trayIcon.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent actionEvent) {
frame.setVisible(!frame.isVisible());
}
});
SystemTray.getSystemTray().add(trayIcon);
}
frame.setVisible(true);
} catch (Exception e) {
logger.log(1, "EXCEPTION", e);
}
}
});
}
use of APJP.ANDROID.HTTP11.HTTPRequests in project apjp by jvansteirteghem.
the class HTTPServerWorker method process.
protected void process() throws Exception {
InputStream inputSocketInputStream = inputSocket.getInputStream();
OutputStream inputSocketOutputStream = inputSocket.getOutputStream();
HTTPRequests httpRequests = HTTPRequests.getHTTPRequests();
HTTPRequestMessage httpRequestMessage1 = new HTTPRequestMessage(inputSocketInputStream);
httpRequestMessage1.read();
HTTPMessageHeader httpRequestMessage1Header1 = httpRequestMessage1.getHTTPMessageHeader("");
if (httpRequestMessage1Header1 == null) {
keepAlive = false;
return;
}
String httpRequestMessage1Header1Value1 = httpRequestMessage1Header1.getValue();
if (httpRequestMessage1Header1Value1.equalsIgnoreCase("")) {
keepAlive = false;
return;
}
processHTTPRequestMessage(httpRequestMessage1);
HTTPResponseMessage httpResponseMessage1 = null;
try {
HTTPRequest httpRequest1 = httpRequests.createHTTPRequest(httpRequestMessage1);
httpRequest1.open();
try {
httpResponseMessage1 = httpRequest1.getHTTPResponseMessage();
processHTTPResponseMessage(httpResponseMessage1);
HTTPMessageHeader[] httpResponseMessage1Headers1 = httpResponseMessage1.getHTTPMessageHeaders();
HTTPMessageHeader httpResponseMessage1Header1 = httpResponseMessage1Headers1[0];
String httpResponseMessage1Header1Key1 = httpResponseMessage1Header1.getKey();
String httpResponseMessage1Header1Value1 = httpResponseMessage1Header1.getValue();
inputSocketOutputStream.write((httpResponseMessage1Header1Value1 + "\r\n").getBytes());
for (int i = 1; i < httpResponseMessage1Headers1.length; i = i + 1) {
httpResponseMessage1Header1 = httpResponseMessage1Headers1[i];
httpResponseMessage1Header1Key1 = httpResponseMessage1Header1.getKey();
httpResponseMessage1Header1Value1 = httpResponseMessage1Header1.getValue();
inputSocketOutputStream.write((httpResponseMessage1Header1Key1 + ": " + httpResponseMessage1Header1Value1 + "\r\n").getBytes());
}
inputSocketOutputStream.write(("\r\n").getBytes());
httpResponseMessage1.read(inputSocketOutputStream);
} catch (Exception e) {
throw e;
} finally {
try {
httpRequest1.close();
} catch (Exception e) {
}
}
} catch (Exception e) {
logger.log(2, "HTTP_SERVER_WORKER/PROCESS: EXCEPTION", e);
if (httpResponseMessage1 == null) {
String[] httpRequestMessage1Header1Values1 = httpRequestMessage1Header1Value1.split(" ");
String httpRequestMessage1Header1Value2 = httpRequestMessage1Header1Values1[0];
if (!httpRequestMessage1Header1Value2.equalsIgnoreCase("GET")) {
throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: REQUEST/METHOD != \"GET\", REQUEST/METHOD == \"" + httpRequestMessage1Header1Value2 + "\"");
}
HTTPMessageHeader httpRequestMessage1Header2 = httpRequestMessage1.getHTTPMessageHeader("If-Range");
if (httpRequestMessage1Header2 != null) {
String httpRequestMessage1Header2Value1 = httpRequestMessage1Header2.getValue();
throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: REQUEST/IF_RANGE != \"\", REQUEST/IF_RANGE == \"" + httpRequestMessage1Header2Value1 + "\"");
}
HTTPMessageHeader httpRequestMessage1Header3 = httpRequestMessage1.getHTTPMessageHeader("Range");
if (httpRequestMessage1Header3 != null) {
String httpRequestMessage1Header3Value1 = httpRequestMessage1Header3.getValue();
throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: REQUEST/RANGE != \"\", REQUEST/RANGE == \"" + httpRequestMessage1Header3Value1 + "\"");
}
httpRequestMessage1Header1Values1[0] = "HEAD";
httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Values1[0];
for (int i = 1; i < httpRequestMessage1Header1Values1.length; i = i + 1) {
httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Value1 + " " + httpRequestMessage1Header1Values1[i];
}
httpRequestMessage1Header1.setValue(httpRequestMessage1Header1Value1);
HTTPRequest httpRequest1 = httpRequests.createHTTPRequest(httpRequestMessage1);
httpRequest1.open();
try {
httpResponseMessage1 = httpRequest1.getHTTPResponseMessage();
} catch (Exception e2) {
throw e2;
} finally {
try {
httpRequest1.close();
} catch (Exception e2) {
}
}
HTTPMessageHeader httpResponseMessage1Header1 = httpResponseMessage1.getHTTPMessageHeader("Accept-Ranges");
if (httpResponseMessage1Header1 == null) {
throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: RESPONSE/ACCEPT_RANGES != \"bytes\", RESPONSE/ACCEPT_RANGES == \"\"");
}
String httpResponseMessage1Header1Value1 = httpResponseMessage1Header1.getValue();
if (!httpResponseMessage1Header1Value1.equalsIgnoreCase("bytes")) {
throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: RESPONSE/ACCEPT_RANGES != \"bytes\", RESPONSE/ACCEPT_RANGES == \"" + httpResponseMessage1Header1Value1 + "\"");
}
processHTTPResponseMessage(httpResponseMessage1);
HTTPMessageHeader[] httpResponseMessage1Headers1 = httpResponseMessage1.getHTTPMessageHeaders();
HTTPMessageHeader httpResponseMessage1Header2 = httpResponseMessage1Headers1[0];
String httpResponseMessage1Header2Key1 = httpResponseMessage1Header2.getKey();
String httpResponseMessage1Header2Value1 = httpResponseMessage1Header2.getValue();
inputSocketOutputStream.write((httpResponseMessage1Header2Value1 + "\r\n").getBytes());
for (int i = 1; i < httpResponseMessage1Headers1.length; i = i + 1) {
httpResponseMessage1Header2 = httpResponseMessage1Headers1[i];
httpResponseMessage1Header2Key1 = httpResponseMessage1Header2.getKey();
httpResponseMessage1Header2Value1 = httpResponseMessage1Header2.getValue();
inputSocketOutputStream.write((httpResponseMessage1Header2Key1 + ": " + httpResponseMessage1Header2Value1 + "\r\n").getBytes());
}
inputSocketOutputStream.write(("\r\n").getBytes());
HTTPMessageHeader httpResponseMessage1Header3 = httpResponseMessage1.getHTTPMessageHeader("Content-Length");
int httpResponseMessage1Header3Value1 = 0;
if (httpResponseMessage1Header3 != null) {
try {
httpResponseMessage1Header3Value1 = new Integer(httpResponseMessage1Header3.getValue());
} catch (Exception e2) {
}
}
httpRequestMessage1Header1Values1[0] = "GET";
httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Values1[0];
for (int i = 1; i < httpRequestMessage1Header1Values1.length; i = i + 1) {
httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Value1 + " " + httpRequestMessage1Header1Values1[i];
}
httpRequestMessage1Header1.setValue(httpRequestMessage1Header1Value1);
long i = 0;
long j = 1048576;
if (j > httpResponseMessage1Header3Value1 - 1) {
j = httpResponseMessage1Header3Value1 - 1;
}
while (i < httpResponseMessage1Header3Value1 - 1) {
HTTPMessageHeader httpRequestMessage1Header4 = httpRequestMessage1.getHTTPMessageHeader("Range");
if (httpRequestMessage1Header4 != null) {
httpRequestMessage1.removeHTTPMessageHeader(httpRequestMessage1Header4);
}
httpRequestMessage1.addHTTPMessageHeader(new HTTPMessageHeader("Range", "bytes=" + i + "-" + j));
HTTPResponseMessage httpResponseMessage2 = null;
int k = 1;
while (k <= 5) {
try {
HTTPRequest httpRequest2 = httpRequests.createHTTPRequest(httpRequestMessage1);
httpRequest2.open();
try {
httpResponseMessage2 = httpRequest2.getHTTPResponseMessage();
HTTPMessageHeader httpResponseMessage2Header1 = httpResponseMessage2.getHTTPMessageHeader("Content-Range");
if (httpResponseMessage2Header1 == null) {
throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: RESPONSE/CONTENT_RANGE != \"bytes " + i + "-" + j + "/" + httpResponseMessage1Header3Value1 + "\", RESPONSE/CONTENT_RANGE == \"\"");
}
String httpResponseMessage2Header1Value1 = httpResponseMessage2Header1.getValue();
if (!httpResponseMessage2Header1Value1.equalsIgnoreCase("bytes " + i + "-" + j + "/" + httpResponseMessage1Header3Value1)) {
throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: RESPONSE/CONTENT_RANGE != \"bytes " + i + "-" + j + "/" + httpResponseMessage1Header3Value1 + "\", RESPONSE/CONTENT_RANGE == \"" + httpResponseMessage2Header1Value1 + "\"");
}
httpResponseMessage2.read(inputSocketOutputStream);
} catch (Exception e2) {
throw e;
} finally {
try {
httpRequest2.close();
} catch (Exception e2) {
}
}
k = 5;
} catch (Exception e2) {
logger.log(2, "HTTP_SERVER_WORKER/PROCESS: EXCEPTION", e2);
if (k == 5) {
throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS");
}
}
k = k + 1;
}
i = j + 1;
j = j + 1 + 1048576;
if (j > httpResponseMessage1Header3Value1 - 1) {
j = httpResponseMessage1Header3Value1 - 1;
}
}
}
}
}
use of APJP.ANDROID.HTTP11.HTTPRequests in project apjp by jvansteirteghem.
the class HTTPServerWorker method process.
protected void process() throws Exception {
InputStream inputSocketInputStream = inputSocket.getInputStream();
OutputStream inputSocketOutputStream = inputSocket.getOutputStream();
HTTPRequests httpRequests = HTTPRequests.getHTTPRequests();
HTTPRequestMessage httpRequestMessage1 = new HTTPRequestMessage(inputSocketInputStream);
httpRequestMessage1.read();
HTTPMessageHeader httpRequestMessage1Header1 = httpRequestMessage1.getHTTPMessageHeader("");
if (httpRequestMessage1Header1 == null) {
keepAlive = false;
return;
}
String httpRequestMessage1Header1Value1 = httpRequestMessage1Header1.getValue();
if (httpRequestMessage1Header1Value1.equalsIgnoreCase("")) {
keepAlive = false;
return;
}
processHTTPRequestMessage(httpRequestMessage1);
HTTPResponseMessage httpResponseMessage1 = null;
try {
HTTPRequest httpRequest1 = httpRequests.createHTTPRequest(httpRequestMessage1);
httpRequest1.open();
try {
httpResponseMessage1 = httpRequest1.getHTTPResponseMessage();
processHTTPResponseMessage(httpResponseMessage1);
HTTPMessageHeader[] httpResponseMessage1Headers1 = httpResponseMessage1.getHTTPMessageHeaders();
HTTPMessageHeader httpResponseMessage1Header1 = httpResponseMessage1Headers1[0];
String httpResponseMessage1Header1Key1 = httpResponseMessage1Header1.getKey();
String httpResponseMessage1Header1Value1 = httpResponseMessage1Header1.getValue();
inputSocketOutputStream.write((httpResponseMessage1Header1Value1 + "\r\n").getBytes());
for (int i = 1; i < httpResponseMessage1Headers1.length; i = i + 1) {
httpResponseMessage1Header1 = httpResponseMessage1Headers1[i];
httpResponseMessage1Header1Key1 = httpResponseMessage1Header1.getKey();
httpResponseMessage1Header1Value1 = httpResponseMessage1Header1.getValue();
inputSocketOutputStream.write((httpResponseMessage1Header1Key1 + ": " + httpResponseMessage1Header1Value1 + "\r\n").getBytes());
}
inputSocketOutputStream.write(("\r\n").getBytes());
httpResponseMessage1.read(inputSocketOutputStream);
} catch (Exception e) {
throw e;
} finally {
try {
httpRequest1.close();
} catch (Exception e) {
}
}
} catch (Exception e) {
logger.log(2, "HTTP_SERVER_WORKER/PROCESS: EXCEPTION", e);
if (httpResponseMessage1 == null) {
String[] httpRequestMessage1Header1Values1 = httpRequestMessage1Header1Value1.split(" ");
String httpRequestMessage1Header1Value2 = httpRequestMessage1Header1Values1[0];
if (!httpRequestMessage1Header1Value2.equalsIgnoreCase("GET")) {
throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: REQUEST/METHOD != \"GET\", REQUEST/METHOD == \"" + httpRequestMessage1Header1Value2 + "\"");
}
HTTPMessageHeader httpRequestMessage1Header2 = httpRequestMessage1.getHTTPMessageHeader("If-Range");
if (httpRequestMessage1Header2 != null) {
String httpRequestMessage1Header2Value1 = httpRequestMessage1Header2.getValue();
throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: REQUEST/IF_RANGE != \"\", REQUEST/IF_RANGE == \"" + httpRequestMessage1Header2Value1 + "\"");
}
HTTPMessageHeader httpRequestMessage1Header3 = httpRequestMessage1.getHTTPMessageHeader("Range");
if (httpRequestMessage1Header3 != null) {
String httpRequestMessage1Header3Value1 = httpRequestMessage1Header3.getValue();
throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: REQUEST/RANGE != \"\", REQUEST/RANGE == \"" + httpRequestMessage1Header3Value1 + "\"");
}
httpRequestMessage1Header1Values1[0] = "HEAD";
httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Values1[0];
for (int i = 1; i < httpRequestMessage1Header1Values1.length; i = i + 1) {
httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Value1 + " " + httpRequestMessage1Header1Values1[i];
}
httpRequestMessage1Header1.setValue(httpRequestMessage1Header1Value1);
HTTPRequest httpRequest1 = httpRequests.createHTTPRequest(httpRequestMessage1);
httpRequest1.open();
try {
httpResponseMessage1 = httpRequest1.getHTTPResponseMessage();
} catch (Exception e2) {
throw e2;
} finally {
try {
httpRequest1.close();
} catch (Exception e2) {
}
}
HTTPMessageHeader httpResponseMessage1Header1 = httpResponseMessage1.getHTTPMessageHeader("Accept-Ranges");
if (httpResponseMessage1Header1 == null) {
throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: RESPONSE/ACCEPT_RANGES != \"bytes\", RESPONSE/ACCEPT_RANGES == \"\"");
}
String httpResponseMessage1Header1Value1 = httpResponseMessage1Header1.getValue();
if (!httpResponseMessage1Header1Value1.equalsIgnoreCase("bytes")) {
throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: RESPONSE/ACCEPT_RANGES != \"bytes\", RESPONSE/ACCEPT_RANGES == \"" + httpResponseMessage1Header1Value1 + "\"");
}
processHTTPResponseMessage(httpResponseMessage1);
HTTPMessageHeader[] httpResponseMessage1Headers1 = httpResponseMessage1.getHTTPMessageHeaders();
HTTPMessageHeader httpResponseMessage1Header2 = httpResponseMessage1Headers1[0];
String httpResponseMessage1Header2Key1 = httpResponseMessage1Header2.getKey();
String httpResponseMessage1Header2Value1 = httpResponseMessage1Header2.getValue();
inputSocketOutputStream.write((httpResponseMessage1Header2Value1 + "\r\n").getBytes());
for (int i = 1; i < httpResponseMessage1Headers1.length; i = i + 1) {
httpResponseMessage1Header2 = httpResponseMessage1Headers1[i];
httpResponseMessage1Header2Key1 = httpResponseMessage1Header2.getKey();
httpResponseMessage1Header2Value1 = httpResponseMessage1Header2.getValue();
inputSocketOutputStream.write((httpResponseMessage1Header2Key1 + ": " + httpResponseMessage1Header2Value1 + "\r\n").getBytes());
}
inputSocketOutputStream.write(("\r\n").getBytes());
HTTPMessageHeader httpResponseMessage1Header3 = httpResponseMessage1.getHTTPMessageHeader("Content-Length");
int httpResponseMessage1Header3Value1 = 0;
if (httpResponseMessage1Header3 != null) {
try {
httpResponseMessage1Header3Value1 = new Integer(httpResponseMessage1Header3.getValue());
} catch (Exception e2) {
}
}
httpRequestMessage1Header1Values1[0] = "GET";
httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Values1[0];
for (int i = 1; i < httpRequestMessage1Header1Values1.length; i = i + 1) {
httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Value1 + " " + httpRequestMessage1Header1Values1[i];
}
httpRequestMessage1Header1.setValue(httpRequestMessage1Header1Value1);
long i = 0;
long j = 1048576;
if (j > httpResponseMessage1Header3Value1 - 1) {
j = httpResponseMessage1Header3Value1 - 1;
}
while (i < httpResponseMessage1Header3Value1 - 1) {
HTTPMessageHeader httpRequestMessage1Header4 = httpRequestMessage1.getHTTPMessageHeader("Range");
if (httpRequestMessage1Header4 != null) {
httpRequestMessage1.removeHTTPMessageHeader(httpRequestMessage1Header4);
}
httpRequestMessage1.addHTTPMessageHeader(new HTTPMessageHeader("Range", "bytes=" + i + "-" + j));
HTTPResponseMessage httpResponseMessage2 = null;
int k = 1;
while (k <= 5) {
try {
HTTPRequest httpRequest2 = httpRequests.createHTTPRequest(httpRequestMessage1);
httpRequest2.open();
try {
httpResponseMessage2 = httpRequest2.getHTTPResponseMessage();
HTTPMessageHeader httpResponseMessage2Header1 = httpResponseMessage2.getHTTPMessageHeader("Content-Range");
if (httpResponseMessage2Header1 == null) {
throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: RESPONSE/CONTENT_RANGE != \"bytes " + i + "-" + j + "/" + httpResponseMessage1Header3Value1 + "\", RESPONSE/CONTENT_RANGE == \"\"");
}
String httpResponseMessage2Header1Value1 = httpResponseMessage2Header1.getValue();
if (!httpResponseMessage2Header1Value1.equalsIgnoreCase("bytes " + i + "-" + j + "/" + httpResponseMessage1Header3Value1)) {
throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: RESPONSE/CONTENT_RANGE != \"bytes " + i + "-" + j + "/" + httpResponseMessage1Header3Value1 + "\", RESPONSE/CONTENT_RANGE == \"" + httpResponseMessage2Header1Value1 + "\"");
}
httpResponseMessage2.read(inputSocketOutputStream);
} catch (Exception e2) {
throw e;
} finally {
try {
httpRequest2.close();
} catch (Exception e2) {
}
}
k = 5;
} catch (Exception e2) {
logger.log(2, "HTTP_SERVER_WORKER/PROCESS: EXCEPTION", e2);
if (k == 5) {
throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS");
}
}
k = k + 1;
}
i = j + 1;
j = j + 1 + 1048576;
if (j > httpResponseMessage1Header3Value1 - 1) {
j = httpResponseMessage1Header3Value1 - 1;
}
}
}
}
}
Aggregations