Example usage for java.net HttpURLConnection HTTP_INTERNAL_ERROR

List of usage examples for java.net HttpURLConnection HTTP_INTERNAL_ERROR

Introduction

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

Prototype

int HTTP_INTERNAL_ERROR

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

Click Source Link

Document

HTTP Status-Code 500: Internal Server Error.

Usage

From source file:reflex.DefaultReflexIOHandler.java

public static String getStreamAsString(InputStream is, String encoding) throws FileNotFoundException {
    String ret = null;//from   w w w  .  jav  a2s. c  o  m
    InputStreamReader isr = null;
    try {
        isr = new InputStreamReader(is, encoding);
        ret = CharStreams.toString(isr);
    } catch (IOException e) {
        throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Error with Reflex stream",
                e);
    } finally {
        try {
            if (isr != null) {
                isr.close();
            }
            is.close();
        } catch (IOException e) {
            throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Error closing stream",
                    e);
        }
    }
    return ret;
}

From source file:rapture.kernel.schedule.CronParser.java

private static Set<Integer> parseRangeParam(String param, int timeLength, int minLength, int lowestVal,
        int highestVal) {
    String[] paramArray;/*from  w  ww .j a  v  a2s. c o m*/
    Set<Integer> ret = new HashSet<Integer>();
    // Test for range
    if (param.indexOf('-') != -1) {
        paramArray = param.split("-");
        if (paramArray.length == 2) {
            ret = fillRange(Integer.parseInt(paramArray[0]), Integer.parseInt(paramArray[1]));
        } else {
            throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR,
                    "- range must have two values");
        }
    } else {
        if (param.indexOf(",") != -1) {
            paramArray = param.split(",");
        } else {
            paramArray = new String[] { param };
        }
        for (String p : paramArray) {
            if (p.indexOf("/") != -1) {
                int secondary = Integer.parseInt(p.substring(p.indexOf("/") + 1));
                for (int a = 1; a <= timeLength; a++) {
                    if (a % secondary == 0) {
                        if (a == timeLength) {
                            ret.add(minLength);
                        } else {
                            ret.add(a);
                        }
                    }
                }
            } else {
                if (p.equals("*")) {
                    ret.addAll(fillRange(minLength, timeLength));
                } else {
                    ret.add(Integer.parseInt(p));
                }
            }
        }
    }
    for (int x : ret) {
        if (x < lowestVal || x > highestVal) {
            throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR,
                    "Error value is out of bounds for cron spec");
        }
    }
    return ret;
}

From source file:rapture.kernel.plugin.ReflectionEncoder.java

@Override
public PluginTransportItem encode(CallingContext ctx, String uri) {
    try {/*from w  ww .j a  v  a 2 s . c om*/
        Object o = getReflectionObject(ctx, uri);
        MessageDigest md = MessageDigest.getInstance("MD5");
        PluginTransportItem item = new PluginTransportItem();
        item.setContent(JacksonUtil.bytesJsonFromObject(o));
        md.update(item.getContent());
        item.setHash(Hex.encodeHexString(md.digest()));
        item.setUri(uri);
        return item;
    } catch (NoSuchAlgorithmException e) {
        throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Error encoding item", e);
    }
}

From source file:io.jare.tk.TkAppFallback.java

/**
 * Make fatal error page./*from  ww  w  . j av a 2s  .co  m*/
 * @param req Request
 * @return Response
 * @throws IOException If fails
 */
private static Response fatal(final RqFallback req) throws IOException {
    return new RsWithStatus(
            new RsWithType(new RsVelocity(TkAppFallback.class.getResource("error.html.vm"),
                    new RsVelocity.Pair("err", ExceptionUtils.getStackTrace(req.throwable())),
                    new RsVelocity.Pair("rev", TkAppFallback.REV)), "text/html"),
            HttpURLConnection.HTTP_INTERNAL_ERROR);
}

From source file:org.jboss.test.web.test.WebProgrammaticLoginTestCase.java

/**
 * Test unsuccessful login//w  w  w  .  ja v a2s . c  o m
 * @throws Exception
 */
public void testUnsuccessfulLogin() throws Exception {
    String baseURLNoAuth = "http://" + getServerHost() + ":" + Integer.getInteger("web.port", 8080) + "/";
    String path = "war1/TestServlet";
    // try to perform programmatic auth without supplying login information.
    HttpMethod indexGet = null;
    try {
        indexGet = new GetMethod(baseURLNoAuth + path + "?operation=login");
        int responseCode = httpConn.executeMethod(indexGet);
        assertTrue("Get Error(" + responseCode + ")", responseCode == HttpURLConnection.HTTP_INTERNAL_ERROR);
        // assert access to the restricted area of the first application is denied.
        SSOBaseCase.checkAccessDenied(this.httpConn, baseURLNoAuth + "war1/restricted/restricted.html");
        // assert access to the second application is not granted, as no successful login
        // was performed (and therefore no ssoid has been set).
        SSOBaseCase.checkAccessDenied(this.httpConn, baseURLNoAuth + "war2/index.html");
    } finally {
        if (indexGet != null)
            indexGet.releaseConnection();
    }
    // try to perform programmatic auth with no valid username/password.
    path = path + "?operation=login&username=dummy&pass=dummy";
    try {
        indexGet = new GetMethod(baseURLNoAuth + path);
        int responseCode = httpConn.executeMethod(indexGet);
        assertTrue("Get Error(" + responseCode + ")", responseCode == HttpURLConnection.HTTP_INTERNAL_ERROR);
        // assert access to the restricted applications remains denied.
        SSOBaseCase.checkAccessDenied(this.httpConn, baseURLNoAuth + "war1/restricted/restricted.html");
        SSOBaseCase.checkAccessDenied(this.httpConn, baseURLNoAuth + "war2/index.html");
    } finally {
        if (indexGet != null)
            indexGet.releaseConnection();
    }
}

From source file:rapture.kernel.plugin.WorkflowEncoder.java

@Override
public PluginTransportItem encode(CallingContext ctx, String uri) {
    try {/* w w w. j a va 2s .  co  m*/
        MessageDigest md = MessageDigest.getInstance("MD5");
        StringBuilder buf = new StringBuilder();
        DecisionApi api = Kernel.getDecision();
        Workflow workflow = api.getWorkflow(ctx, uri);
        String json = JacksonUtil.jsonFromObject(workflow);
        buf.append(json);
        PluginTransportItem item = new PluginTransportItem();
        item.setContent(buf.toString().getBytes(Charsets.UTF_8));
        md.update(item.getContent());
        item.setHash(Hex.encodeHexString(md.digest()));
        item.setUri(uri);
        return item;
    } catch (NoSuchAlgorithmException e) {
        // this can only happen if we use a JRE without MD5 support
        throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Error encoding workflow",
                e);
    }
}

From source file:rapture.kernel.plugin.DocumentEncoder.java

@Override
public PluginTransportItem encode(CallingContext ctx, String uri) {
    try {//from  w w  w .j  av a2s.  c  o  m
        byte[] content;
        if (isRepository(uri)) {
            DocumentRepoConfig config = Kernel.getDoc().getDocRepoConfig(ctx, uri);
            content = JacksonUtil.bytesJsonFromObject(config);
        } else {
            String str = Kernel.getDoc().getDoc(ctx, uri);
            content = (str != null) ? str.getBytes(Charsets.UTF_8) : new byte[0];
        }
        MessageDigest md = MessageDigest.getInstance("MD5");
        PluginTransportItem item = new PluginTransportItem();
        item.setContent(content);
        md.update(item.getContent());
        item.setHash(Hex.encodeHexString(md.digest()));
        item.setUri(uri);
        return item;
    } catch (NoSuchAlgorithmException e) {
        throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Error encoding", e);
    }
}

From source file:rapture.kernel.plugin.StructuredEncoder.java

@Override
public PluginTransportItem encode(CallingContext ctx, String uriStr) {
    PluginTransportItem item = new PluginTransportItem();
    item.setUri(uriStr);//  w  ww.  j ava2 s. co  m
    StringBuilder contents = new StringBuilder();
    if (isRepository(uriStr)) {
        contents.append(JacksonUtil.prettyfy(
                JacksonUtil.jsonFromObject(Kernel.getStructured().getStructuredRepoConfig(ctx, uriStr))));
        contents.append("\n");
    } else {
        contents.append(Kernel.getStructured().getDdl(ctx, uriStr, true));
    }
    item.setContent(contents.toString().getBytes(Charsets.UTF_8));
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(item.getContent());
        item.setHash(Hex.encodeHexString(md.digest()));
    } catch (NoSuchAlgorithmException e) {
        throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR,
                "MD5 message digest not installed in JVM.  Can't encode plugin", e);
    }
    return item;
}

From source file:com.stackify.api.common.log.LogSender.java

/**
 * Sends a group of log messages to Stackify
 * @param group The log message group/*from  w ww  .ja v  a  2 s  .  c om*/
 * @return The HTTP status code returned from the HTTP POST
 * @throws IOException
 */
public int send(final LogMsgGroup group) throws IOException {
    Preconditions.checkNotNull(group);

    HttpClient httpClient = new HttpClient(apiConfig);

    // retransmit any logs on the resend queue

    resendQueue.drain(httpClient, LOG_SAVE_PATH, true);

    // convert to json bytes

    byte[] jsonBytes = objectMapper.writer().writeValueAsBytes(group);

    // post to stackify

    int statusCode = HttpURLConnection.HTTP_INTERNAL_ERROR;

    try {
        httpClient.post(LOG_SAVE_PATH, jsonBytes, true);
        statusCode = HttpURLConnection.HTTP_OK;
    } catch (IOException t) {
        LOGGER.info("Queueing logs for retransmission due to IOException");
        resendQueue.offer(jsonBytes, t);
        throw t;
    } catch (HttpException e) {
        statusCode = e.getStatusCode();
        LOGGER.info("Queueing logs for retransmission due to HttpException", e);
        resendQueue.offer(jsonBytes, e);
    }

    return statusCode;
}

From source file:i5.las2peer.services.userManagement.UserManagement.java

/**
 * //from   w w  w .ja va 2 s . c o m
 * createUser
 * 
 * 
 * @return HttpResponse
 * 
 */
@POST
@Path("/create")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.TEXT_PLAIN)
@ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = "userExists"),
        @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "authorizationNeeded"),
        @ApiResponse(code = HttpURLConnection.HTTP_CREATED, message = "userCreated"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "internal"),
        @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "malformedRequest") })
@ApiOperation(value = "createUser", notes = "")
public HttpResponse createUser() {
    // userExists
    boolean userExists_condition = true;
    if (userExists_condition) {
        String error = "Some String";
        HttpResponse userExists = new HttpResponse(error, HttpURLConnection.HTTP_CONFLICT);
        return userExists;
    }
    // authorizationNeeded
    boolean authorizationNeeded_condition = true;
    if (authorizationNeeded_condition) {
        String error = "Some String";
        HttpResponse authorizationNeeded = new HttpResponse(error, HttpURLConnection.HTTP_UNAUTHORIZED);
        return authorizationNeeded;
    }
    // userCreated
    boolean userCreated_condition = true;
    if (userCreated_condition) {
        JSONObject User = new JSONObject();
        HttpResponse userCreated = new HttpResponse(User.toJSONString(), HttpURLConnection.HTTP_CREATED);
        return userCreated;
    }
    // internal
    boolean internal_condition = true;
    if (internal_condition) {
        String error = "Some String";
        HttpResponse internal = new HttpResponse(error, HttpURLConnection.HTTP_INTERNAL_ERROR);
        return internal;
    }
    // malformedRequest
    boolean malformedRequest_condition = true;
    if (malformedRequest_condition) {
        String malformation = "Some String";
        HttpResponse malformedRequest = new HttpResponse(malformation, HttpURLConnection.HTTP_BAD_REQUEST);
        return malformedRequest;
    }
    return null;
}