下面列出了org.apache.http.message.BasicHttpEntityEnclosingRequest#org.apache.http.MethodNotSupportedException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private HttpUriRequest newHttpRequest(String method, URI uri)
throws MethodNotSupportedException
{
if (method == "GET")
return new HttpGet(uri);
if (method == "POST")
return new HttpPost(uri);
if (method == "PUT")
return new HttpPut(uri);
if (method == "DELETE")
return new HttpDelete(uri);
if (method == "PATCH")
return new HttpPatch(uri);
throw new MethodNotSupportedException(
"Invalid method \"" + method + "\""
);
}
public void handle(
final HttpRequest request,
final HttpResponse response,
final HttpContext context) throws HttpException, IOException {
final String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);
if (!method.equals("GET") && !method.equals("HEAD")) {
throw new MethodNotSupportedException(method + " method not supported");
}
final EntityTemplate body = new EntityTemplate(new ContentProducer() {
public void writeTo(final OutputStream outstream) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
writer.write(mJSON);
writer.flush();
}
});
response.setStatusCode(HttpStatus.SC_OK);
body.setContentType("text/json; charset=UTF-8");
response.setEntity(body);
}
public HttpRequest newHttpRequest(final RequestLine requestline)
throws MethodNotSupportedException {
if (requestline == null) {
throw new IllegalArgumentException("Request line may not be null");
}
String method = requestline.getMethod();
String uri = requestline.getUri();
return newHttpRequest(method, uri);
}
public HttpRequest newHttpRequest(final String method, final String uri) throws MethodNotSupportedException {
if (isOneOf(BASIC, method)) {
return new BasicHttpRequest(method, uri);
} else if (isOneOf(WITH_ENTITY, method)) {
return new BasicHttpEntityEnclosingRequest(method, uri);
} else {
return super.newHttpRequest(method, uri);
}
}
public HttpRequest newHttpRequest(final RequestLine requestline)
throws MethodNotSupportedException {
if (requestline == null) {
throw new IllegalArgumentException("Request line may not be null");
}
String method = requestline.getMethod();
String uri = requestline.getUri();
return newHttpRequest(method, uri);
}
public HttpRequest newHttpRequest(final String method, final String uri) throws MethodNotSupportedException {
if (isOneOf(BASIC, method)) {
return new BasicHttpRequest(method, uri);
} else if (isOneOf(WITH_ENTITY, method)) {
return new BasicHttpEntityEnclosingRequest(method, uri);
} else {
return super.newHttpRequest(method, uri);
}
}
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException,
IOException
{
try
{
String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);
if (METHOD_GET.equals(method) || METHOD_HEAD.equals(method))
{
handleRequest(request, response, METHOD_HEAD.equals(method));
}
else if (METHOD_POST.equals(method))
{
handleRequest(request, response, METHOD_HEAD.equals(method));
}
else
{
throw new MethodNotSupportedException(MessageFormat.format(
Messages.LocalWebServerHttpRequestHandler_UNSUPPORTED_METHOD, method));
}
}
catch (Exception e)
{
IdeLog.logError(WebServerCorePlugin.getDefault(), e);
response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
response.setEntity(createTextEntity(Messages.LocalWebServerHttpRequestHandler_INTERNAL_SERVER_ERROR));
}
}
@Override
public void setColor(float[] colorArray) {
try {
throw new MethodNotSupportedException(
"Setting Color array is not supported atm");
} catch (MethodNotSupportedException e) { // Lol...
LOG.debug("setColor array is not supported atm");
e.printStackTrace();
}
}
@Override
public HttpRequest newHttpRequest(RequestLine requestLine)
throws MethodNotSupportedException {
String method = requestLine.getMethod();
String uri = requestLine.getUri();
return this.newHttpRequest(method, uri);
}
protected HttpUriRequest createHttpRequest(UpnpMessage upnpMessage, UpnpRequest upnpRequestOperation)
throws MethodNotSupportedException {
switch (upnpRequestOperation.getMethod()) {
case GET:
return new HttpGet(upnpRequestOperation.getURI());
case SUBSCRIBE:
return new HttpGet(upnpRequestOperation.getURI()) {
@Override
public String getMethod() {
return UpnpRequest.Method.SUBSCRIBE.getHttpName();
}
};
case UNSUBSCRIBE:
return new HttpGet(upnpRequestOperation.getURI()) {
@Override
public String getMethod() {
return UpnpRequest.Method.UNSUBSCRIBE.getHttpName();
}
};
case POST:
HttpEntityEnclosingRequest post = new HttpPost(upnpRequestOperation.getURI());
post.setEntity(createHttpRequestEntity(upnpMessage));
return (HttpUriRequest) post; // Fantastic API
case NOTIFY:
HttpEntityEnclosingRequest notify = new HttpPost(upnpRequestOperation.getURI()) {
@Override
public String getMethod() {
return UpnpRequest.Method.NOTIFY.getHttpName();
}
};
notify.setEntity(createHttpRequestEntity(upnpMessage));
return (HttpUriRequest) notify; // Fantastic API
default:
throw new MethodNotSupportedException(upnpRequestOperation.getHttpMethodName());
}
}
@Override
public void clear() {
throw new RuntimeException(new MethodNotSupportedException("clear"));
}
@Override
public boolean dependsOn(Graph arg0) {
throw new RuntimeException(new MethodNotSupportedException("dependsOn"));
}
@Override
public BulkUpdateHandler getBulkUpdateHandler() {
throw new RuntimeException(new MethodNotSupportedException("getBulUpdate"));
}
@Override
public GraphStatisticsHandler getStatisticsHandler() {
throw new RuntimeException(new MethodNotSupportedException("getStatsHandler"));
}
@Override
public TransactionHandler getTransactionHandler() {
throw new RuntimeException(new MethodNotSupportedException("getTransactionHandler"));
}
@Override
public boolean isIsomorphicWith(Graph arg0) {
throw new RuntimeException(new MethodNotSupportedException("isIsomorphic"));
}
@Override
public void remove(Node arg0, Node arg1, Node arg2) {
throw new RuntimeException(new MethodNotSupportedException("remove"));
}
@Override
public int size() {
throw new RuntimeException(new MethodNotSupportedException("size"));
}
public HttpRequest newHttpRequest(RequestLine requestLine)
throws MethodNotSupportedException {
String method = requestLine.getMethod();
String uri = requestLine.getUri();
return newHttpRequest(method, uri);
}