List of usage examples for java.net HttpURLConnection HTTP_NOT_ACCEPTABLE
int HTTP_NOT_ACCEPTABLE
To view the source code for java.net HttpURLConnection HTTP_NOT_ACCEPTABLE.
Click Source Link
From source file:Main.java
public static void main(String[] argv) throws Exception { HttpURLConnection.setFollowRedirects(false); HttpURLConnection con = (HttpURLConnection) new URL("http://www.google.coom").openConnection(); con.setRequestMethod("HEAD"); System.out.println(con.getResponseCode() == HttpURLConnection.HTTP_NOT_ACCEPTABLE); }
From source file:com.mobile.godot.core.controller.CoreController.java
public synchronized void register(UserBean user) { String servlet = "AddUser"; List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add(new BasicNameValuePair("firstname", user.getFirstname())); params.add(new BasicNameValuePair("lastname", user.getLastname())); params.add(new BasicNameValuePair("mail", user.getMail())); params.add(new BasicNameValuePair("username", user.getUsername())); params.add(new BasicNameValuePair("password", user.getPassword())); SparseIntArray mMessageMap = new SparseIntArray(); mMessageMap.append(HttpURLConnection.HTTP_OK, GodotMessage.Session.REGISTERED); mMessageMap.append(HttpURLConnection.HTTP_CONFLICT, GodotMessage.Error.CONFLICT); mMessageMap.append(HttpURLConnection.HTTP_NOT_ACCEPTABLE, GodotMessage.Error.UNACCEPTABLE); GodotAction action = new GodotAction(servlet, params, mMessageMap, mHandler); Thread tAction = new Thread(action); tAction.start();/*from ww w . j a v a 2 s. co m*/ }
From source file:com.mobile.godot.core.controller.CoreController.java
public synchronized void addCar(CarBean car) { String servlet = "AddCar"; List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add(new BasicNameValuePair("carName", car.getName())); params.add(new BasicNameValuePair("username", car.getOwnerUsername())); SparseIntArray mMessageMap = new SparseIntArray(); mMessageMap.append(HttpURLConnection.HTTP_OK, GodotMessage.Entity.CAR_CREATED); mMessageMap.append(HttpURLConnection.HTTP_CONFLICT, GodotMessage.Error.CONFLICT); mMessageMap.append(HttpURLConnection.HTTP_NOT_ACCEPTABLE, GodotMessage.Error.UNACCEPTABLE); GodotAction action = new GodotAction(servlet, params, mMessageMap, mHandler); Thread tAction = new Thread(action); tAction.start();//from ww w . jav a2 s . co m }
From source file:co.cask.cdap.client.rest.RestStreamClientTest.java
@Test public void testNotAcceptableGetTTL() throws IOException { try {// w w w . j a v a2 s . co m streamClient.getTTL(TestUtils.NOT_ALLOWED_STREAM_NAME); Assert.fail("Expected HttpFailureException"); } catch (HttpFailureException e) { Assert.assertEquals(HttpURLConnection.HTTP_NOT_ACCEPTABLE, e.getStatusCode()); } }
From source file:org.eclipse.rdf4j.http.server.ProtocolTest.java
/** * Checks that a proper error (HTTP 406) is returned when accept header is set incorrectly on graph query. *///from www. j av a2 s. c o m @Test public void testContentTypeForGraphQuery2_GET() throws Exception { String query = "DESCRIBE <foo:bar>"; String location = TestServer.REPOSITORY_URL; location += "?query=" + URLEncoder.encode(query, "UTF-8"); URL url = new URL(location); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // incorrect mime-type for graph query results conn.setRequestProperty("Accept", TupleQueryResultFormat.SPARQL.getDefaultMIMEType()); conn.connect(); try { int responseCode = conn.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_NOT_ACCEPTABLE) { // do nothing, expected } else { String response = "location " + location + " responded: " + conn.getResponseMessage() + " (" + responseCode + ")"; fail(response); } } finally { conn.disconnect(); } }
From source file:co.cask.cdap.client.rest.RestStreamClientTest.java
@Test public void testNotAcceptableSetTTL() throws IOException { try {/*from w w w.ja va2s. c om*/ streamClient.setTTL(TestUtils.NOT_ALLOWED_STREAM_NAME, STREAM_TTL); Assert.fail("Expected HttpFailureException"); } catch (HttpFailureException e) { Assert.assertEquals(HttpURLConnection.HTTP_NOT_ACCEPTABLE, e.getStatusCode()); } }
From source file:co.cask.cdap.client.rest.RestStreamClientTest.java
@Test public void testNotAcceptableTruncate() throws IOException { try {//from w ww . ja v a 2 s . c o m streamClient.truncate(TestUtils.NOT_ALLOWED_STREAM_NAME); Assert.fail("Expected HttpFailureException"); } catch (HttpFailureException e) { Assert.assertEquals(HttpURLConnection.HTTP_NOT_ACCEPTABLE, e.getStatusCode()); } }
From source file:co.cask.cdap.client.rest.RestStreamClientTest.java
@Test public void testNotAcceptableCreate() throws IOException { try {//from w w w . j a v a 2s. co m streamClient.create(TestUtils.NOT_ALLOWED_STREAM_NAME); Assert.fail("Expected HttpFailureException"); } catch (HttpFailureException e) { Assert.assertEquals(HttpURLConnection.HTTP_NOT_ACCEPTABLE, e.getStatusCode()); } }
From source file:org.wso2.carbon.registry.app.RegistryAdapter.java
private ResponseContext processCommentsRequest(RequestContext request, String path) { final String method = request.getMethod(); if (method.equals(APPConstants.HTTP_GET)) { int colonIdx = request.getUri().toString().indexOf(':'); if (colonIdx > -1) { return getEntry(request); } else {//from w ww .ja v a2 s .c o m // Return comments feed return getFeed(request); } } else { try { final Registry secureRegistry = getSecureRegistry(request); if (method.equals(APPConstants.HTTP_POST)) { // Accept either Atom or plain text for comments org.wso2.carbon.registry.core.Comment comment = new org.wso2.carbon.registry.core.Comment(); final String contentType = request.getContentType().toString(); if (request.isAtom()) { Entry entry = (Entry) request.getDocument().getRoot(); comment.setText(entry.getContent()); comment.setUser(entry.getAuthor().getName()); if (entry.getUpdated() != null) { comment.setCreatedTime(entry.getUpdated()); } } else if (contentType.equals("text/plain")) { InputStream is = request.getInputStream(); String text = readToString(is); comment.setText(text); } String commentPath = secureRegistry.addComment(path, comment); EmptyResponseContext responseContext = new EmptyResponseContext(HttpURLConnection.HTTP_OK); try { responseContext.setLocation(URLDecoder.decode(getAtomURI(commentPath, request), RegistryConstants.DEFAULT_CHARSET_ENCODING).replaceAll(" ", "+")); } catch (UnsupportedEncodingException e) { // no action } return responseContext; } else if (method.equals(APPConstants.HTTP_PUT)) { Entry entry = (Entry) request.getDocument().getRoot(); String text = entry.getContent(); secureRegistry.editComment(path, text); return new EmptyResponseContext(HttpURLConnection.HTTP_OK); } else if (method.equals(APPConstants.HTTP_DELETE)) { secureRegistry.delete(path); return new EmptyResponseContext(HttpURLConnection.HTTP_OK); } } catch (Exception e) { return new StackTraceResponseContext(e); } } // unsupported method return new EmptyResponseContext(HttpURLConnection.HTTP_NOT_ACCEPTABLE); }