/** * Returns a resource object as a result of a get request. **/ public WebResource getGetResponse() throws IOException { throw new UnknownMethodException( "GET" ); }
private boolean respondToRequest( HttpRequest request, HttpResponseStream response ) { debug( "Server thread handling request: " + request ); boolean keepAlive = isKeepAlive( request ); WebResource resource = null; try { response.restart(); response.setProtocol( getResponseProtocol( request ) ); resource = getResource( request ); if (resource == null) { response.setResponse( HttpURLConnection.HTTP_NOT_FOUND, "unable to find " + request.getURI() ); } else { if (resource.closesConnection()) keepAlive = false; if (resource.getResponseCode() != HttpURLConnection.HTTP_OK) { response.setResponse( resource.getResponseCode(), "" ); } String[] headers = resource.getHeaders(); for (int i = 0; i < headers.length; i++) { debug( "Server thread sending header: " + headers[i] ); response.addHeader( headers[i] ); } } } catch (UnknownMethodException e) { response.setResponse( HttpURLConnection.HTTP_BAD_METHOD, "unsupported method: " + e.getMethod() ); } catch (Throwable t) { t.printStackTrace(); response.setResponse( HttpURLConnection.HTTP_INTERNAL_ERROR, t.toString() ); } try { response.write( resource ); } catch (IOException e) { System.out.println( "*** Failed to send reply: " + e ); } return keepAlive; }
private boolean respondToRequest( HttpRequest request, HttpResponseStream response ) { debug( "Server thread handling request: " + request ); boolean keepAlive = isKeepAlive( request ); WebResource resource = null; try { response.restart(); response.setProtocol( getResponseProtocol( request ) ); resource = getResource( request ); if (resource == null) { response.setResponse( HttpURLConnection.HTTP_NOT_FOUND, "unable to find " + request.getURI() ); } else { if (resource.closesConnection()) keepAlive = false; if (resource.getResponseCode() != HttpURLConnection.HTTP_OK) { response.setResponse( resource.getResponseCode(), "" ); } String[] headers = resource.getHeaders(); for (int i = 0; i < headers.length; i++) { debug( "Server thread sending header: " + headers[i] ); response.addHeader( headers[i] ); } } } catch (UnknownMethodException e) { response.setResponse( HttpURLConnection.HTTP_BAD_METHOD, "unsupported method: " + e.getMethod() ); } catch (Throwable t) { t.printStackTrace(); response.setResponse( HttpURLConnection.HTTP_INTERNAL_ERROR, t.toString() ); } try { response.write( resource ); } catch (IOException e) { System.out.println( "*** Failed to send reply: " + e ); } return keepAlive; }
/** * Returns a resource object as a result of a get request. **/ public WebResource getGetResponse() throws IOException { throw new UnknownMethodException( "GET" ); }
private boolean respondToRequest( HttpRequest request, HttpResponseStream response ) { debug( "Server thread handling request: " + request ); boolean keepAlive = isKeepAlive( request ); WebResource resource = null; try { response.restart(); response.setProtocol( getResponseProtocol( request ) ); resource = getResource( request ); if (resource == null) { response.setResponse( HttpURLConnection.HTTP_NOT_FOUND, "unable to find " + request.getURI() ); } else { if (resource.closesConnection()) keepAlive = false; if (resource.getResponseCode() != HttpURLConnection.HTTP_OK) { response.setResponse( resource.getResponseCode(), "" ); } String[] headers = resource.getHeaders(); for (int i = 0; i < headers.length; i++) { debug( "Server thread sending header: " + headers[i] ); response.addHeader( headers[i] ); } } } catch (UnknownMethodException e) { response.setResponse( HttpURLConnection.HTTP_BAD_METHOD, "unsupported method: " + e.getMethod() ); } catch (Throwable t) { t.printStackTrace(); response.setResponse( HttpURLConnection.HTTP_INTERNAL_ERROR, t.toString() ); } try { response.write( resource ); } catch (IOException e) { System.out.println( "*** Failed to send reply: " + e ); } return keepAlive; }
public WebResource getPostResponse() throws IOException { throw new UnknownMethodException( "POST" ); }
/** * Returns a resource object as a result of a get request. **/ public WebResource getGetResponse() throws IOException { throw new UnknownMethodException( "GET" ); }
public WebResource getPutResponse() throws IOException { throw new UnknownMethodException( "PUT" ); }
public WebResource getPostResponse() throws IOException { throw new UnknownMethodException( "POST" ); }
public WebResource getPutResponse() throws IOException { throw new UnknownMethodException( "PUT" ); }
public WebResource getPutResponse() throws IOException { throw new UnknownMethodException( "PUT" ); }
public WebResource getPostResponse() throws IOException { throw new UnknownMethodException( "POST" ); }
/** * Returns a resource object as a result of a get request. **/ public WebResource getResponse( String methodType ) throws IOException { if (methodType.equalsIgnoreCase( "GET" )) { return getGetResponse(); } else if (methodType.equalsIgnoreCase( "PUT" )) { return getPutResponse(); } else if (methodType.equalsIgnoreCase( "POST" )) { return getPostResponse(); } else { throw new UnknownMethodException( methodType ); } }
/** * Returns a resource object as a result of a get request. **/ public WebResource getResponse( String methodType ) throws IOException { if (methodType.equalsIgnoreCase( "GET" )) { return getGetResponse(); } else if (methodType.equalsIgnoreCase( "PUT" )) { return getPutResponse(); } else if (methodType.equalsIgnoreCase( "POST" )) { return getPostResponse(); } else { throw new UnknownMethodException( methodType ); } }
/** * Returns a resource object as a result of a get request. **/ public WebResource getResponse( String methodType ) throws IOException { if (methodType.equalsIgnoreCase( "GET" )) { return getGetResponse(); } else if (methodType.equalsIgnoreCase( "PUT" )) { return getPutResponse(); } else if (methodType.equalsIgnoreCase( "POST" )) { return getPostResponse(); } else { throw new UnknownMethodException( methodType ); } }