Java 类org.apache.http.MethodNotSupportedException 实例源码

项目:v20-java    文件:Context.java   
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 + "\""
    );
}
项目:lams    文件:HttpService.java   
/**
 * Handles the given exception and generates an HTTP response to be sent
 * back to the client to inform about the exceptional condition encountered
 * in the course of the request processing.
 *
 * @param ex the exception.
 * @param response the HTTP response.
 */
protected void handleException(final HttpException ex, final HttpResponse response) {
    if (ex instanceof MethodNotSupportedException) {
        response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
    } else if (ex instanceof UnsupportedHttpVersionException) {
        response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
    } else if (ex instanceof ProtocolException) {
        response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
    } else {
        response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }
    String message = ex.getMessage();
    if (message == null) {
        message = ex.toString();
    }
    byte[] msg = EncodingUtils.getAsciiBytes(message);
    ByteArrayEntity entity = new ByteArrayEntity(msg);
    entity.setContentType("text/plain; charset=US-ASCII");
    response.setEntity(entity);
}
项目:lams    文件:DefaultHttpRequestFactory.java   
public HttpRequest newHttpRequest(final RequestLine requestline)
        throws MethodNotSupportedException {
    if (requestline == null) {
        throw new IllegalArgumentException("Request line may not be null");
    }
    String method = requestline.getMethod();
    if (isOneOf(RFC2616_COMMON_METHODS, method)) {
        return new BasicHttpRequest(requestline);
    } else if (isOneOf(RFC2616_ENTITY_ENC_METHODS, method)) {
        return new BasicHttpEntityEnclosingRequest(requestline);
    } else if (isOneOf(RFC2616_SPECIAL_METHODS, method)) {
        return new BasicHttpRequest(requestline);
    } else {
        throw new MethodNotSupportedException(method +  " method not supported");
    }
}
项目:Android_CCTV    文件:ModInternationalization.java   
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);

}
项目:purecloud-iot    文件:TestStaleWhileRevalidationReleasesConnection.java   
/**
 * Handles a request by echoing the incoming request entity.
 * If there is no request entity, an empty document is returned.
 *
 * @param request   the request
 * @param response  the response
 * @param context   the context
 *
 * @throws org.apache.http.HttpException    in case of a problem
 * @throws java.io.IOException      in case of an IO problem
 */
@Override
public void handle(final HttpRequest request,
                   final HttpResponse response,
                   final HttpContext context)
        throws HttpException, IOException {

    final String method = request.getRequestLine().getMethod().toUpperCase(Locale.ROOT);
    if (!"GET".equals(method) &&
            !"POST".equals(method) &&
            !"PUT".equals(method)
            ) {
        throw new MethodNotSupportedException
                (method + " not supported by " + getClass().getName());
    }

    response.setStatusCode(org.apache.http.HttpStatus.SC_OK);
    response.addHeader("Cache-Control",getCacheContent(request));
    final byte[] content = getHeaderContent(request);
    final ByteArrayEntity bae = new ByteArrayEntity(content);
    response.setHeader("Connection","keep-alive");

    response.setEntity(bae);

}
项目:sana.mobile    文件:DispatchRequestFactory.java   
@Override
public HttpRequest newHttpRequest(String method, String uri)
        throws MethodNotSupportedException {
    RequestLine line = new BasicRequestLine(method, uri, HttpVersion.HTTP_1_1);

    HttpUriRequest request = null;
    if(method.equals(HttpGet.METHOD_NAME)){
        request = new HttpGet(uri);
    }else if(method.equals(HttpPost.METHOD_NAME)){
        request = new HttpPost(uri);
    }else if(method.equals(HttpPut.METHOD_NAME)){
        request = new HttpPut(uri);
    }else if(method.equals(HttpPut.METHOD_NAME)){
        request = new HttpDelete(uri);
    }
    return request;
}
项目:MAKEYOURFACE    文件:HttpService.java   
/**
 * Handles the given exception and generates an HTTP response to be sent
 * back to the client to inform about the exceptional condition encountered
 * in the course of the request processing.
 *
 * @param ex the exception.
 * @param response the HTTP response.
 */
protected void handleException(final HttpException ex, final HttpResponse response) {
    if (ex instanceof MethodNotSupportedException) {
        response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
    } else if (ex instanceof UnsupportedHttpVersionException) {
        response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
    } else if (ex instanceof ProtocolException) {
        response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
    } else {
        response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }
    String message = ex.getMessage();
    if (message == null) {
        message = ex.toString();
    }
    byte[] msg = EncodingUtils.getAsciiBytes(message);
    ByteArrayEntity entity = new ByteArrayEntity(msg);
    entity.setContentType("text/plain; charset=US-ASCII");
    response.setEntity(entity);
}
项目:spydroid-ipcamera    文件:ModInternationalization.java   
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);

}
项目:ecg_over_rtp    文件:ModInternationalization.java   
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);

}
项目:pcap-reconst    文件:RecordedHttpRequestFactory.java   
public HttpRequest newHttpRequest(final RequestLine requestline)
        throws MethodNotSupportedException {
    if (requestline == null) {
        throw new IllegalArgumentException("Request line may not be null");
    }
    String method = requestline.getMethod();
    if (isOneOf(RFC2616_COMMON_METHODS, method)) {
        return new RecordedHttpRequest(requestline, messdata);
    } else if (isOneOf(RFC2616_ENTITY_ENC_METHODS, method)) {
        return new RecordedHttpEntityEnclosingRequest(requestline, messdata);
    } else if (isOneOf(RFC2616_SPECIAL_METHODS, method)) {
        return new RecordedHttpRequest(requestline, messdata);
    } else {
        throw new MethodNotSupportedException(method +  " method not supported");
    }
}
项目:irond    文件:BasicAccessAuthenticationTest.java   
private HttpRequest getHttpRequest(String user, String pass){
    HttpRequestFactory factory = new DefaultHttpRequestFactory();
    HttpRequest req = null;
    String base64 = new String(Base64.encodeBase64(
            user.concat(":").concat(pass).getBytes()));
    try {
        req = factory.newHttpRequest(
                new BasicRequestLine("POST", "https://localhost:8444/",
                        HttpVersion.HTTP_1_1));
        req.addHeader("Accept-Encoding", "gzip,deflate");
        req.addHeader("Content-Type", "application/soap+xml;charset=UTF-8");
        req.addHeader("User-Agent", "IROND Testsuite/1.0");
        req.addHeader("Host", "localhost:8444");
        req.addHeader("Content-Length", "198");
        req.addHeader("Authorization", "Basic "+base64);
    } catch (MethodNotSupportedException e) {
        e.printStackTrace();
    }
    return req;
}
项目:lams    文件:DefaultHttpRequestFactory.java   
public HttpRequest newHttpRequest(final String method, final String uri)
        throws MethodNotSupportedException {
    if (isOneOf(RFC2616_COMMON_METHODS, method)) {
        return new BasicHttpRequest(method, uri);
    } else if (isOneOf(RFC2616_ENTITY_ENC_METHODS, method)) {
        return new BasicHttpEntityEnclosingRequest(method, uri);
    } else if (isOneOf(RFC2616_SPECIAL_METHODS, method)) {
        return new BasicHttpRequest(method, uri);
    } else {
        throw new MethodNotSupportedException(method
                + " method not supported");
    }
}
项目:InsanityRadio-Android    文件:SocializeActionProxy.java   
protected Object getBean() throws MethodNotSupportedException {
    Object bean = Socialize.getBean(delegateBean);

    if(bean != null) {
        return bean;
    }
    else {
        throw new MethodNotSupportedException("No bean with name [" +
                delegateBean +
                "] found");
    }       
}
项目:remote-files-sync    文件:DefaultHttpRequestFactoryHC4.java   
public HttpRequest newHttpRequest(final RequestLine requestline)
        throws MethodNotSupportedException {
    Args.notNull(requestline, "Request line");
    final String method = requestline.getMethod();
    if (isOneOf(RFC2616_COMMON_METHODS, method)) {
        return new BasicHttpRequest(requestline);
    } else if (isOneOf(RFC2616_ENTITY_ENC_METHODS, method)) {
        return new BasicHttpEntityEnclosingRequest(requestline);
    } else if (isOneOf(RFC2616_SPECIAL_METHODS, method)) {
        return new BasicHttpRequest(requestline);
    } else {
        throw new MethodNotSupportedException(method +  " method not supported");
    }
}
项目:remote-files-sync    文件:DefaultHttpRequestFactoryHC4.java   
public HttpRequest newHttpRequest(final String method, final String uri)
        throws MethodNotSupportedException {
    if (isOneOf(RFC2616_COMMON_METHODS, method)) {
        return new BasicHttpRequest(method, uri);
    } else if (isOneOf(RFC2616_ENTITY_ENC_METHODS, method)) {
        return new BasicHttpEntityEnclosingRequest(method, uri);
    } else if (isOneOf(RFC2616_SPECIAL_METHODS, method)) {
        return new BasicHttpRequest(method, uri);
    } else {
        throw new MethodNotSupportedException(method
                + " method not supported");
    }
}
项目:purecloud-iot    文件:EchoHandler.java   
/**
 * Handles a request by echoing the incoming request entity.
 * If there is no request entity, an empty document is returned.
 *
 * @param request   the request
 * @param response  the response
 * @param context   the context
 *
 * @throws HttpException    in case of a problem
 * @throws IOException      in case of an IO problem
 */
@Override
public void handle(final HttpRequest request,
                   final HttpResponse response,
                   final HttpContext context)
    throws HttpException, IOException {

    final String method = request.getRequestLine().getMethod().toUpperCase(Locale.ROOT);
    if (!"GET".equals(method) &&
        !"POST".equals(method) &&
        !"PUT".equals(method)
        ) {
        throw new MethodNotSupportedException
            (method + " not supported by " + getClass().getName());
    }

    HttpEntity entity = null;
    if (request instanceof HttpEntityEnclosingRequest) {
        entity = ((HttpEntityEnclosingRequest)request).getEntity();
    }

    // For some reason, just putting the incoming entity into
    // the response will not work. We have to buffer the message.
    byte[] data;
    if (entity == null) {
        data = new byte [0];
    } else {
        data = EntityUtils.toByteArray(entity);
    }

    final ByteArrayEntity bae = new ByteArrayEntity(data);
    if (entity != null) {
        bae.setContentType(entity.getContentType());
    }
    entity = bae;

    response.setStatusCode(HttpStatus.SC_OK);
    response.setEntity(entity);

}
项目:InsanityRadio-Android    文件:SocializeActionProxy.java   
protected Object getBean() throws MethodNotSupportedException {
    Object bean = Socialize.getBean(delegateBean);

    if(bean != null) {
        return bean;
    }
    else {
        throw new MethodNotSupportedException("No bean with name [" +
                delegateBean +
                "] found");
    }       
}
项目:gwt-syncproxy    文件:RemoteServiceInvocationHandler.java   
/**
 *
 * Handles method invocations to the {@link HasRpcToken} interface
 * implemented by the service. Also handles Annotation of service with
 * {@link RpcTokenImplementation}
 *
 * @throws ClassNotFoundException
 *             if base service interface class cannot be found if actual
 *             implemented interface is Async
 *
 * @since 0.5
 */
protected Object handleHasRpcToken(Object proxy, Method method,
        Object[] args) throws MethodNotSupportedException,
        NoSuchMethodException, ClassNotFoundException {
    if (HasRpcToken.class.getMethod("setRpcToken", RpcToken.class).equals(
            method)) {
        // Check if service has annotation defining the Token class and
        // that this token matches the specified class
        Class<?> srvcIntf = determineProxyServiceBaseInterface(proxy);
        if (srvcIntf != null) {
            RpcTokenImplementation rti = srvcIntf
                    .getAnnotation(RpcTokenImplementation.class);
            // Replace $ in class name in order to handle inner classes
            if (rti != null
                    && !args[0].getClass().getName().replace("$", ".")
                            .equals(rti.value())) {
                throw new RpcTokenException("Incorrect Token Class. Got "
                        + args[0].getClass().getName() + " but expected: "
                        + rti.value());
            }
        }

        this.token = (RpcToken) args[0];
        return null;
    } else if (HasRpcToken.class.getMethod("getRpcToken").equals(method)) {
        return this.token;
    } else if (HasRpcToken.class.getMethod("setRpcTokenExceptionHandler",
            RpcTokenExceptionHandler.class).equals(method)) {
        this.rpcTokenExceptionHandler = (RpcTokenExceptionHandler) args[0];
        return null;
    } else if (HasRpcToken.class.getMethod("setRpcTokenExceptionHandler",
            RpcTokenExceptionHandler.class).equals(method)) {
        return this.rpcTokenExceptionHandler;
    }
    throw new MethodNotSupportedException("Method: " + method.getName()
            + " in class: " + method.getDeclaringClass().getName()
            + " not defined for class: " + proxy.getClass().getName());
}
项目:gwt-syncproxy    文件:RemoteServiceInvocationHandler.java   
/**
 * Handles method invocations to the {@link ServiceDefTarget} interface
 * implemented by the service.
 */
protected Object handleServiceDefTarget(Object proxy, Method method,
        Object[] args) throws Throwable {
    if (ServiceDefTarget.class.getMethod("getSerializationPolicyName")
            .equals(method)) {
        return this.settings.getPolicyName();
    } else if (ServiceDefTarget.class.getMethod("setServiceEntryPoint",
            String.class).equals(method)) {
        this.serviceEntryPoint = (String) args[0];
        // Modify current base and relative Path to newly specific
        // serviceEntryPoint assuming that base path is part of
        // serviceEntryPoint
        // TODO May not be a valid assumption
        if (this.serviceEntryPoint.contains(this.settings
                .getModuleBaseUrl())) {
            this.settings
                    .setRemoteServiceRelativePath(this.serviceEntryPoint
                            .split(this.settings.getModuleBaseUrl())[1]);
        } else {
            this.logger.warning("Unable to determine base (orig: "
                    + this.settings.getModuleBaseUrl() + ") against: "
                    + this.serviceEntryPoint);
            throw new SyncProxyException(
                    determineProxyServiceBaseInterface(proxy),
                    InfoType.SERVICE_BASE_DELTA);
        }
        return null;
    } else if (ServiceDefTarget.class.getMethod("getServiceEntryPoint")
            .equals(method)) {
        return this.serviceEntryPoint;
    }
    // TODO handle all methods
    throw new MethodNotSupportedException("Method: " + method.getName()
            + " in class: " + method.getDeclaringClass().getName()
            + " not defined for class: " + proxy.getClass().getName());
}
项目:Visit    文件:DefaultHttpRequestFactoryHC4.java   
public HttpRequest newHttpRequest(final RequestLine requestline)
        throws MethodNotSupportedException {
    Args.notNull(requestline, "Request line");
    final String method = requestline.getMethod();
    if (isOneOf(RFC2616_COMMON_METHODS, method)) {
        return new BasicHttpRequest(requestline);
    } else if (isOneOf(RFC2616_ENTITY_ENC_METHODS, method)) {
        return new BasicHttpEntityEnclosingRequest(requestline);
    } else if (isOneOf(RFC2616_SPECIAL_METHODS, method)) {
        return new BasicHttpRequest(requestline);
    } else {
        throw new MethodNotSupportedException(method +  " method not supported");
    }
}
项目:Visit    文件:DefaultHttpRequestFactoryHC4.java   
public HttpRequest newHttpRequest(final String method, final String uri)
        throws MethodNotSupportedException {
    if (isOneOf(RFC2616_COMMON_METHODS, method)) {
        return new BasicHttpRequest(method, uri);
    } else if (isOneOf(RFC2616_ENTITY_ENC_METHODS, method)) {
        return new BasicHttpEntityEnclosingRequest(method, uri);
    } else if (isOneOf(RFC2616_SPECIAL_METHODS, method)) {
        return new BasicHttpRequest(method, uri);
    } else {
        throw new MethodNotSupportedException(method
                + " method not supported");
    }
}
项目:openhab-hdl    文件:StreamClientImpl.java   
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());
        }

    }
项目:DroidDLNA    文件:UpnpHttpRequestFactory.java   
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);
}
项目:DroidDLNA    文件:UpnpHttpRequestFactory.java   
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);
    }
}
项目:APICloud-Studio    文件:LocalWebServerHttpRequestHandler.java   
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));
    }
}
项目:geoar-app    文件:NewGridFeature.java   
@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();
    }
}
项目:Cherry    文件:MimeAndFileResourcesUtil.java   
static public String supported(final HttpRequest request) throws MethodNotSupportedException {
  assert null != request;

  final RequestLine requestLine = request.getRequestLine();
  final String method = requestLine.getMethod().toUpperCase(Locale.ENGLISH);

  switch (method) {
    case "GET":
    case "HEAD":
    case "POST":
      return requestLine.getUri();
  }

  throw new MethodNotSupportedException(method + " method not supported");
}
项目:wso2-axis2    文件:AxisHttpService.java   
protected void handleException(final HttpException ex, final HttpResponse response) {
    if (ex instanceof MethodNotSupportedException) {
        response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
    } else if (ex instanceof UnsupportedHttpVersionException) {
        response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
    } else if (ex instanceof ProtocolException) {
        response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
    } else {
        response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }
}
项目:sana.mobile    文件:HttpRequestBuilder.java   
public HttpRequest newHttpRequest(String method, String uri)
        throws MethodNotSupportedException {
    HttpUriRequest request = null;
    URI host = URI.create(uri);
    if(method.equals(HttpGet.METHOD_NAME)){
        request = new HttpGet(host);
    }else if(method.equals(HttpPost.METHOD_NAME)){
        request = new HttpPost(host);
    }else if(method.equals(HttpPut.METHOD_NAME)){
        request = new HttpPut(host);
    }else if(method.equals(HttpPut.METHOD_NAME)){
        request = new HttpDelete(host);
    }
    return request;
}
项目:sana.mobile    文件:DispatchRequestFactory.java   
@Override
public HttpRequest newHttpRequest(RequestLine requestLine)
        throws MethodNotSupportedException {
    String method = requestLine.getMethod();
    String uri = requestLine.getUri();
    return this.newHttpRequest(method, uri);
}
项目:ZTLib    文件:DefaultHttpRequestFactoryHC4.java   
public HttpRequest newHttpRequest(final RequestLine requestline)
        throws MethodNotSupportedException {
    Args.notNull(requestline, "Request line");
    final String method = requestline.getMethod();
    if (isOneOf(RFC2616_COMMON_METHODS, method)) {
        return new BasicHttpRequest(requestline);
    } else if (isOneOf(RFC2616_ENTITY_ENC_METHODS, method)) {
        return new BasicHttpEntityEnclosingRequest(requestline);
    } else if (isOneOf(RFC2616_SPECIAL_METHODS, method)) {
        return new BasicHttpRequest(requestline);
    } else {
        throw new MethodNotSupportedException(method +  " method not supported");
    }
}
项目:ZTLib    文件:DefaultHttpRequestFactoryHC4.java   
public HttpRequest newHttpRequest(final String method, final String uri)
        throws MethodNotSupportedException {
    if (isOneOf(RFC2616_COMMON_METHODS, method)) {
        return new BasicHttpRequest(method, uri);
    } else if (isOneOf(RFC2616_ENTITY_ENC_METHODS, method)) {
        return new BasicHttpEntityEnclosingRequest(method, uri);
    } else if (isOneOf(RFC2616_SPECIAL_METHODS, method)) {
        return new BasicHttpRequest(method, uri);
    } else {
        throw new MethodNotSupportedException(method
                + " method not supported");
    }
}
项目:prive-android    文件:OtrDataHandler.java   
public HttpRequest newHttpRequest(final RequestLine requestline)
        throws MethodNotSupportedException {
    if (requestline == null) {
        throw new IllegalArgumentException("Request line may not be null");
    }
    //String method = requestline.getMethod();
    return new BasicHttpRequest(requestline);
}
项目:dcl    文件:HttpRequestHandlerNew.java   
/**
 * Handles a HTTP-Request.
 * @param request
 * @param response
 * @param arg2 Blank {@link BasicHttpContext}
 */
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext arg2) throws HttpException, IOException {
    String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);
    if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST")) {
        throw new MethodNotSupportedException(method + " method not supported");
    }

    response.setStatusCode(HttpStatus.SC_CREATED);
    StringEntity entity = new StringEntity(writeTable(connectedAddressesProvider.getConnectedAddresses()),ContentType.create("text/html", "UTF-8"));
    response.setEntity(entity);
    System.out.println("Serving open Connections");
}
项目:pcap-reconst    文件:RecordedHttpRequestFactory.java   
public HttpRequest newHttpRequest(final String method, final String uri)
        throws MethodNotSupportedException {
    if (isOneOf(RFC2616_COMMON_METHODS, method)) {
        return new RecordedHttpRequest(method, uri, messdata);
    } else if (isOneOf(RFC2616_ENTITY_ENC_METHODS, method)) {
        return new RecordedHttpEntityEnclosingRequest(method, uri, messdata);
    } else if (isOneOf(RFC2616_SPECIAL_METHODS, method)) {
        return new RecordedHttpRequest(method, uri, messdata);
    } else {
        throw new MethodNotSupportedException(method
                + " method not supported");
    }
}
项目:openhab1-addons    文件:StreamClientImpl.java   
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());
    }

}
项目:Android-SimpleBlog    文件:SimpleBlogDBCacheService.java   
@Override
public void addCommentToBlog(Context ctx, Integer blogId, UIComment comment,
        IServiceTaskCompleteDelegate serviceCompleteDelegate) throws IOException
{

    throw new IOException("This method is not supported", new MethodNotSupportedException(
            "This method is not supported"));

}
项目:cameraserve    文件:SsdpAdvertiser.java   
private HttpMessage getHttpMessage(final byte[] data) {
    final HttpParams httpParams = new BasicHttpParams();
    final AbstractSessionInputBuffer inputBuffer = new AbstractSessionInputBuffer() {
        {
            init(new ByteArrayInputStream(data), 128, httpParams);
        }

        @Override
        public boolean isDataAvailable(int i) throws IOException {
            return this.hasBufferedData();
        }
    };
    final HttpRequestFactory msearchRequestFactory = new HttpRequestFactory() {
        @Override
        public HttpRequest newHttpRequest(RequestLine requestLine) throws MethodNotSupportedException {
            if (!requestLine.getMethod().equalsIgnoreCase("m-search"))
                throw new MethodNotSupportedException("Invalid method: " + requestLine.getMethod());
            if (!requestLine.getUri().equals("*"))
                throw new MethodNotSupportedException("Invalid URI: " + requestLine.getUri());

            return new BasicHttpRequest(requestLine);
        }

        @Override
        public HttpRequest newHttpRequest(String method, String uri) throws MethodNotSupportedException {
            if (!method.equalsIgnoreCase("m-search"))
                throw new MethodNotSupportedException("Invalid method: " + method);
            if (!uri.equals("*"))
                throw new MethodNotSupportedException("Invalid URI: " + uri);

            return new BasicHttpRequest(method, uri);
        }
    };

    HttpRequestParser requestParser = new HttpRequestParser(inputBuffer, null, msearchRequestFactory, httpParams);
    try {
        return requestParser.parse();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
项目:purecloud-iot    文件:RandomHandler.java   
/**
 * Handles a request by generating random data.
 * The length of the response can be specified in the request URI
 * as a number after the last /. For example /random/whatever/20
 * will generate 20 random bytes in the printable ASCII range.
 * If the request URI ends with /, a random number of random bytes
 * is generated, but at least one.
 *
 * @param request   the request
 * @param response  the response
 * @param context   the context
 *
 * @throws HttpException    in case of a problem
 * @throws IOException      in case of an IO problem
 */
@Override
public void handle(final HttpRequest request,
                   final HttpResponse response,
                   final HttpContext context)
    throws HttpException, IOException {

    final String method = request.getRequestLine().getMethod().toUpperCase(Locale.ROOT);
    if (!"GET".equals(method) && !"HEAD".equals(method)) {
        throw new MethodNotSupportedException
            (method + " not supported by " + getClass().getName());
    }

    final String uri = request.getRequestLine().getUri();
    final int  slash = uri.lastIndexOf('/');
    int length = -1;
    if (slash < uri.length()-1) {
        try {
            // no more than Integer, 2 GB ought to be enough for anybody
            length = Integer.parseInt(uri.substring(slash+1));

            if (length < 0) {
                response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
                response.setReasonPhrase("LENGTH " + length);
            }
        } catch (final NumberFormatException nfx) {
            response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
            response.setReasonPhrase(nfx.toString());
        }
    } else {
        // random length, but make sure at least something is sent
        length = 1 + (int)(Math.random() * 79.0);
    }

    if (length >= 0) {

        response.setStatusCode(HttpStatus.SC_OK);

        if (!"HEAD".equals(method)) {
            final RandomEntity entity = new RandomEntity(length);
            entity.setContentType("text/plain; charset=US-ASCII");
            response.setEntity(entity);
        } else {
            response.setHeader("Content-Type",
                               "text/plain; charset=US-ASCII");
            response.setHeader("Content-Length",
                               String.valueOf(length));
        }
    }

}
项目:neo4jena    文件:NeoGraph.java   
@Override
public void clear() {
    throw new RuntimeException(new MethodNotSupportedException("clear"));
}