Example usage for java.net HttpURLConnection HTTP_BAD_METHOD

List of usage examples for java.net HttpURLConnection HTTP_BAD_METHOD

Introduction

In this page you can find the example usage for java.net HttpURLConnection HTTP_BAD_METHOD.

Prototype

int HTTP_BAD_METHOD

To view the source code for java.net HttpURLConnection HTTP_BAD_METHOD.

Click Source Link

Document

HTTP Status-Code 405: Method Not Allowed.

Usage

From source file:org.codehaus.mojo.mrm.servlet.FileSystemServlet.java

private void createDirectory(HttpServletResponse resp, String path) throws IOException {
    String[] parts = path.split("/");
    resp.sendError(HttpURLConnection.HTTP_BAD_METHOD);
}

From source file:org.codehaus.mojo.mrm.servlet.FileSystemServlet.java

/**
 * {@inheritDoc}//from   www  . j a  va 2 s. co m
 */
protected void _doDelete(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    String path = req.getPathInfo();
    String context;
    if (path == null) {
        path = req.getServletPath();
        context = req.getContextPath();
    } else {
        context = req.getContextPath() + req.getServletPath();
    }
    Entry entry = fileSystem.get(path);
    if (entry == null) {
        resp.setStatus(HttpURLConnection.HTTP_OK);
        return;
    }
    try {
        fileSystem.remove(entry);
        resp.setStatus(HttpURLConnection.HTTP_OK);
    } catch (UnsupportedOperationException e) {
        resp.sendError(HttpURLConnection.HTTP_BAD_METHOD);
    }
}

From source file:org.eclipse.orion.server.tests.prefs.PreferenceTest.java

/**
 * Tests whether a client can access workspace metadata via the preferences servlet.
 * @throws IOException //from  w w w.j  a  v a  2 s .c o m
 */
@Test
public void testAccessingMetadata() throws IOException {
    List<String> locations = getIllegalPreferenceNodes();
    for (String location : locations) {
        //get should return 405
        WebRequest request = new GetMethodWebRequest(location);
        setAuthentication(request);
        WebResponse response = webConversation.getResource(request);
        assertEquals(HttpURLConnection.HTTP_BAD_METHOD, response.getResponseCode());

        //put a value should be 403
        request = createSetPreferenceRequest(location, "Name", "Frodo");
        setAuthentication(request);
        response = webConversation.getResource(request);
        assertEquals(HttpURLConnection.HTTP_BAD_METHOD, response.getResponseCode());
    }
}

From source file:org.xwoot.xwootApp.web.XWootSite.java

/**
 * Checks that the XWiki connection configuration is good: the connection URL is a valid URL, and the username and
 * password are provided.//from  ww w .java 2 s.  com
 * 
 * @param properties The configuration to validate.
 * @return A list of error messages to display to the user, as a <code>String</code>. If the configuration is good,
 *         then an <string>empty <code>String</code></strong> is returned.
 * @todo Message localization.
 * @todo Make a simple call to the wiki to verify that there is a wiki at that address, and that the
 *       username/password are valid.
 */
private final String validateXWikiProperties(Properties properties) {
    String result = "";
    String xwikiEndpoint = properties.getProperty(XWootSite.XWIKI_ENDPOINT);
    String xwikiUserName = properties.getProperty(XWootSite.XWIKI_USERNAME);
    String xwikiPassword = properties.getProperty(XWootSite.XWIKI_PASSWORD);

    // Check that the XWiki endpoint is a valid URL.
    if (xwikiEndpoint == null || xwikiEndpoint.trim().length() == 0) {
        result += "Please enter a non-empty XWiki endpoint URL.\n";
    } else {
        try {
            new URL(xwikiEndpoint);
        } catch (MalformedURLException e) {
            result += "Please enter a valid XWiki endpoint URL (the given URL is malformed)\n";
        }

    }

    // Check that the username and password are provided.

    if (xwikiUserName == null || xwikiUserName.trim().length() == 0) {
        result += "Please enter a non-empty username.\n";
    }

    if (xwikiPassword == null || xwikiPassword.length() == 0) {
        result += "Please enter a non-empty password.\n";
    }

    if (result != null && result.length() == 0) {
        boolean connectionFailed = false;
        try {
            HttpURLConnection connection = (HttpURLConnection) (new URL(xwikiEndpoint).openConnection());
            connection.setConnectTimeout(15000);
            int responseCode = connection.getResponseCode();
            if (responseCode != HttpURLConnection.HTTP_BAD_METHOD) {
                result += "An XWiki server is not available at the provided address.";
                connectionFailed = true;
            }
        } catch (Exception e) {
            connectionFailed = true;
            result += "Failed to contact the remote XWiki server. Make sure XWiki is started at the provided address and that it is reachable.";
        }

        if (!connectionFailed) {
            try {
                if (!Utils.checkLogin(xwikiEndpoint, xwikiUserName, xwikiPassword)) {
                    result += "The remote XWiki server refused the provided username/password combination.\n";
                }
            } catch (Exception e) {
                result += "Please enter a valid XWiki endpoint URL (the given URL is malformed)\n";
            }
        }
    }

    return result;
}

From source file:jenkins.model.Jenkins.java

/**
 * @since 1.509.1//  w w w.  j av  a  2 s  .c o m
 */
public static void _doScript(StaplerRequest req, StaplerResponse rsp, RequestDispatcher view,
        VirtualChannel channel, ACL acl) throws IOException, ServletException {
    // ability to run arbitrary script is dangerous
    acl.checkPermission(RUN_SCRIPTS);

    String text = req.getParameter("script");
    if (text != null) {
        if (!"POST".equals(req.getMethod())) {
            throw HttpResponses.error(HttpURLConnection.HTTP_BAD_METHOD, "requires POST");
        }

        if (channel == null) {
            throw HttpResponses.error(HttpURLConnection.HTTP_NOT_FOUND, "Node is offline");
        }

        try {
            req.setAttribute("output", RemotingDiagnostics.executeGroovy(text, channel));
        } catch (InterruptedException e) {
            throw new ServletException(e);
        }
    }

    view.forward(req, rsp);
}