Java Code Examples for java.net.HttpURLConnection#HTTP_NOT_FOUND

The following examples show how to use java.net.HttpURLConnection#HTTP_NOT_FOUND . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void log(SyncResult syncResult, String code) {
    int responseCode = Integer.parseInt(code);
    switch (responseCode) {
        case HttpURLConnection.HTTP_UNAUTHORIZED:
        case HttpURLConnection.HTTP_FORBIDDEN:
            syncResult.stats.numAuthExceptions++;
            break;
        case 1:
            syncResult.stats.numParseExceptions++;
            break;
        case 0:
        default:
        case HttpURLConnection.HTTP_NOT_FOUND:
        case HttpURLConnection.HTTP_INTERNAL_ERROR:
            syncResult.stats.numIoExceptions++;
            syncResult.stats.numEntries++;
            break;
    }
}
 
Example 2
Source File: DossierFileManagement.java    From opencps-v2 with GNU Affero General Public License v3.0 6 votes vote down vote up
@PUT
@Path("/{id}/files/{referenceUid}/resetformdata")
@ApiOperation(value = "update DossierFile")
@ApiResponses(value = {
	@ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Returns"),
	@ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized", response = ExceptionModel.class),
	@ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found", response = ExceptionModel.class),
	@ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = "Access denied", response = ExceptionModel.class)
})
public Response resetformdataDossierFileFormData(
	@Context HttpServletRequest request, @Context HttpHeaders header,
	@Context Company company, @Context Locale locale, @Context User user,
	@Context ServiceContext serviceContext,
	@ApiParam(value = "id of dossier", required = true) @PathParam("id") long id,
	@ApiParam(value = "referenceUid of dossierfile", required = true) @PathParam("referenceUid") String referenceUid,
	@ApiParam(value = "formdata of dossierfile", required = true) @FormParam("formdata") String formdata);
 
Example 3
Source File: DossierFileManagement.java    From opencps-v2 with GNU Affero General Public License v3.0 6 votes vote down vote up
@POST
@Path("/{id}/files/{referenceUid}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({
	MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON
})
@ApiOperation(value = "update DossierFile", response = String.class)
@ApiResponses(value = {
	@ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Returns the DossierFileModel was updated", response = DossierFileResultsModel.class),
	@ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized", response = ExceptionModel.class),
	@ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found", response = ExceptionModel.class),
	@ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = "Access denied", response = ExceptionModel.class)
})
public Response updateDossierFile(
	@Context HttpServletRequest request, @Context HttpHeaders header,
	@Context Company company, @Context Locale locale, @Context User user,
	@Context ServiceContext serviceContext,
	@ApiParam(value = "id of dossier", required = true) @PathParam("id") long id,
	@ApiParam(value = "reference of dossierfile", required = true) @PathParam("referenceUid") String referenceUid,
	@ApiParam(value = "Attachment files", required = true) @Multipart("file") Attachment file);
 
Example 4
Source File: ClusterOperationsImpl.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
public VersionInfo fetchVersion() {
  try {
    Response response = handleVersionGet(versionEndpoint);
    // Handle Openshift 4 version case
    if (HttpURLConnection.HTTP_NOT_FOUND == response.code() && versionEndpoint.equals(OPENSHIFT_VERSION_ENDPOINT)) {
      response.close();
      return fetchOpenshift4Version();
    }

    Map<String, String> myMap = objectMapper.readValue(response.body().string(), HashMap.class);
    return fetchVersionInfoFromResponse(myMap);
  } catch(Exception e) {
    KubernetesClientException.launderThrowable(e);
  }
  return null;
}
 
Example 5
Source File: StatusCodeMapper.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Creates an exception for an AMQP error condition.
 *
 * @param condition The error condition.
 * @param description The error description or {@code null} if not available.
 * @return The exception.
 * @throws NullPointerException if error is {@code null}.
 */
public static final ServiceInvocationException from(final Symbol condition, final String description) {

    Objects.requireNonNull(condition);

    if (AmqpError.RESOURCE_LIMIT_EXCEEDED.equals(condition)) {
        return new ClientErrorException(HttpURLConnection.HTTP_FORBIDDEN, description);
    } else if (AmqpError.UNAUTHORIZED_ACCESS.equals(condition)) {
        return new ClientErrorException(HttpURLConnection.HTTP_FORBIDDEN, description);
    } else if (AmqpError.INTERNAL_ERROR.equals(condition)) {
        return new ServerErrorException(HttpURLConnection.HTTP_INTERNAL_ERROR, description);
    } else if (Constants.AMQP_BAD_REQUEST.equals(condition)) {
        return new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST, description);
    } else {
        return new ClientErrorException(HttpURLConnection.HTTP_NOT_FOUND, description);
    }
}
 
Example 6
Source File: DossierFileManagement.java    From opencps-v2 with GNU Affero General Public License v3.0 6 votes vote down vote up
@POST
@Path("/import/files")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({
	MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON
})
@ApiOperation(value = "import file xml)", response = DossierFileModel.class)
@ApiResponses(value = {
	@ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Returns the DossierFileModel was updated", response = DossierFileResultsModel.class),
	@ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized", response = ExceptionModel.class),
	@ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found", response = ExceptionModel.class),
	@ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = "Access denied", response = ExceptionModel.class)
})
public Response uploadFileEntry(
	@Context HttpServletRequest request, @Context HttpHeaders header,
	@Context Company company, @Context Locale locale, @Context User user,
	@Context ServiceContext serviceContext,
	@ApiParam(value = "Attachment files", required = true) @Multipart("file") Attachment file);
 
Example 7
Source File: GrpcUtil.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
private static Status.Code httpStatusToGrpcCode(int httpStatusCode) {
  if (httpStatusCode >= 100 && httpStatusCode < 200) {
    // 1xx. These headers should have been ignored.
    return Status.Code.INTERNAL;
  }
  switch (httpStatusCode) {
    case HttpURLConnection.HTTP_BAD_REQUEST:  // 400
    case 431: // Request Header Fields Too Large
      // TODO(carl-mastrangelo): this should be added to the http-grpc-status-mapping.md doc.
      return Status.Code.INTERNAL;
    case HttpURLConnection.HTTP_UNAUTHORIZED:  // 401
      return Status.Code.UNAUTHENTICATED;
    case HttpURLConnection.HTTP_FORBIDDEN:  // 403
      return Status.Code.PERMISSION_DENIED;
    case HttpURLConnection.HTTP_NOT_FOUND:  // 404
      return Status.Code.UNIMPLEMENTED;
    case 429:  // Too Many Requests
    case HttpURLConnection.HTTP_BAD_GATEWAY:  // 502
    case HttpURLConnection.HTTP_UNAVAILABLE:  // 503
    case HttpURLConnection.HTTP_GATEWAY_TIMEOUT:  // 504
      return Status.Code.UNAVAILABLE;
    default:
      return Status.Code.UNKNOWN;
  }
}
 
Example 8
Source File: CloudFile.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes the file if it exists, using the specified access condition, request options, and operation context.
 * 
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the file.
 * @param options
 *            A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudFileClient}).
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 * 
 * @return <code>true</code> if the file existed and was deleted; otherwise, <code>false</code>
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 * @throws URISyntaxException 
 */
@DoesServiceRequest
public final boolean deleteIfExists(final AccessCondition accessCondition, FileRequestOptions options,
        OperationContext opContext) throws StorageException, URISyntaxException {
    options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
    this.getShare().assertNoSnapshot();

    boolean exists = this.exists(true, accessCondition, options, opContext);
    if (exists) {
        try {
            this.delete(accessCondition, options, opContext);
            return true;
        }
        catch (StorageException e) {
            if (e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND
                    && StorageErrorCodeStrings.RESOURCE_NOT_FOUND.equals(e.getErrorCode())) {
                return false;
            }
            else {
                throw e;
            }
        }

    }
    else {
        return false;
    }
}
 
Example 9
Source File: EFormManagement.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@GET
@Path("/{id}/report/{secret}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ApiOperation(value = "Get a formdata of Plugin", response = DossierResultsModel.class)
@ApiResponses(value = {
		@ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Returns a list of Plugins have been filtered", response = DossierResultsModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized", response = ExceptionModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found", response = ExceptionModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = "Access denied", response = ExceptionModel.class) })

public Response printEFormReport(@Context HttpServletRequest request, @Context HttpHeaders header,
		@Context Company company, @Context Locale locale, @Context User user,
		@Context ServiceContext serviceContext, @PathParam("id") String id,
		@PathParam("secret") String secret);
 
Example 10
Source File: ServerConfigManagement.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ApiOperation(value = "Get all ServerConfig", response = ServerConfigResultsModel.class)
@ApiResponses(value = {
		@ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Returns a list of all ServerConfig", response = ServerConfigResultsModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized", response = ExceptionModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found", response = ExceptionModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = "Access denied", response = ExceptionModel.class) })

public Response getServerConfigs(@Context HttpServletRequest request, @Context HttpHeaders header,
		@Context Company company, @Context Locale locale, @Context User user,
		@Context ServiceContext serviceContext, @BeanParam ServerConfigSearchModel query);
 
Example 11
Source File: DeliverableTypesManagement.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@GET
@Path("/{id}/formreport")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED })
@ApiOperation(value = "getFormReportByDeliverableTypeId", response = JSONObject.class)
@ApiResponses(value = {
		@ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Returns a formdata", response = JSONObject.class),
		@ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found", response = ExceptionModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = "Access denied", response = ExceptionModel.class) })
public Response getFormReportByDeliverableTypeId(@Context HttpServletRequest request,
		@Context HttpHeaders header, @Context Company company, @Context Locale locale, @Context User user,
		@Context ServiceContext serviceContext,
		@ApiParam(value = "id of dossier", required = true) @PathParam("id") long id);
 
Example 12
Source File: DossierTemplateManagement.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@GET
@Path("/{id}/parts/{partno}/formreport")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ApiOperation(value = "Get formreport of a DossierPart", response = DossierPartContentInputUpdateModel.class)
@ApiResponses(value = {
		@ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Returns the formreport", response = DossierPartContentInputUpdateModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized", response = ExceptionModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found", response = ExceptionModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = "Access denied", response = ExceptionModel.class) })

public Response getFormReport(@Context HttpServletRequest request, @Context HttpHeaders header,
		@Context Company company, @Context Locale locale, @Context User user,
		@Context ServiceContext serviceContext, @PathParam("id") long id, @PathParam("partno") String partNo);
 
Example 13
Source File: DossierActionManagement.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@GET
@Path("/{id}/rollback")
@ApiOperation(value = "rollback", response = String.class)
@ApiResponses(value = {
		@ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Returns rollback is success", response = String.class),
		@ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = "Access denied", response = ExceptionModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found", response = ExceptionModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal error", response = ExceptionModel.class) })
public Response getRollback(@Context HttpServletRequest request, @Context HttpHeaders header,
		@Context Company company, @Context Locale locale, @Context User user,
		@Context ServiceContext serviceContext, @PathParam("id") String id);
 
Example 14
Source File: DossierManagement.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@GET
@Path("/{id}/cancelling")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ApiOperation(value = "Owner requset cancalling for Dossier", response = DossierDetailModel.class)
@ApiResponses(value = {
		@ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Returns a Dossier has been cancelled", response = DossierDetailModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized", response = ExceptionModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found", response = ExceptionModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = "Access denied", response = ExceptionModel.class) })

public Response cancellingDossier(@Context HttpServletRequest request, @Context HttpHeaders header,
		@Context Company company, @Context Locale locale, @Context User user,
		@Context ServiceContext serviceContext, @PathParam("id") String id);
 
Example 15
Source File: MetacatController.java    From metacat with Apache License 2.0 5 votes vote down vote up
/**
 * List of metacat view names.
 *
 * @param catalogName  catalog name
 * @param databaseName database name
 * @param tableName    table name
 * @return List of metacat view names.
 */
@RequestMapping(
    method = RequestMethod.GET,
    path = "/catalog/{catalog-name}/database/{database-name}/table/{table-name}/mviews"
)
@ResponseStatus(HttpStatus.OK)
@ApiOperation(
    position = 1,
    value = "List of metacat views",
    notes = "List of metacat views for a catalog"
)
@ApiResponses(
    {
        @ApiResponse(
            code = HttpURLConnection.HTTP_OK,
            message = "The list of views is returned"
        ),
        @ApiResponse(
            code = HttpURLConnection.HTTP_NOT_FOUND,
            message = "The requested catalog cannot be located"
        )
    }
)
public List<NameDateDto> getMViews(
    @ApiParam(value = "The name of the catalog", required = true)
    @PathVariable("catalog-name") final String catalogName,
    @ApiParam(value = "The name of the database", required = true)
    @PathVariable("database-name") final String databaseName,
    @ApiParam(value = "The name of the table", required = true)
    @PathVariable("table-name") final String tableName
) {
    final QualifiedName name = this.requestWrapper.qualifyName(
        () -> QualifiedName.ofTable(catalogName, databaseName, tableName)
    );
    return this.requestWrapper.processRequest(
        name,
        "getMViews",
        () -> this.mViewService.list(name)
    );
}
 
Example 16
Source File: DossierManagement.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@POST
@Path("/{id}/fixDueDate")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ApiOperation(value = "Owner submitting Dossier", response = DossierDetailModel.class)
@ApiResponses(value = {
		@ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Returns a Dossier has been submitted", response = DossierDetailModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized", response = ExceptionModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found", response = ExceptionModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = "Access denied", response = ExceptionModel.class) })

public Response fixDueDateDossier(@Context HttpServletRequest request, @Context HttpHeaders header,
		@Context Company company, @Context Locale locale, @Context User user,
		@Context ServiceContext serviceContext, @PathParam("id") String id, @FormParam("receiveDate") String receiveDate);
 
Example 17
Source File: ApplicantManagement.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@GET
@Path("/ngsp/{applicantIdNo}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED })
@ApiOperation(value = "Get the profile of applicant", response = JSONObject.class)
@ApiResponses(value = {
		@ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Returns the profile of applicant", response = JSONObject.class),
		@ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized", response = ExceptionModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found", response = ExceptionModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = "Access denied", response = ExceptionModel.class) })
public Response ngspGetApplicantInfo(@Context HttpServletRequest request, @Context HttpHeaders header,
		@Context Company company, @Context Locale locale, @Context User user,
		@Context ServiceContext serviceContext, @PathParam("applicantIdNo") String applicantIdNo);
 
Example 18
Source File: PartitionController.java    From metacat with Apache License 2.0 4 votes vote down vote up
/**
 * Return list of partition names for a view.
 *
 * @param catalogName             catalog name
 * @param databaseName            database name
 * @param tableName               table name
 * @param viewName                view name
 * @param sortBy                  sort by this name
 * @param sortOrder               sort order to use
 * @param offset                  offset of the list
 * @param limit                   size of the list
 * @param getPartitionsRequestDto request
 * @return list of partition names for a view
 */
@RequestMapping(
    method = RequestMethod.POST,
    path = "/catalog/{catalog-name}/database/{database-name}/table/{table-name}/mview/{view-name}/keys-request",
    consumes = MediaType.APPLICATION_JSON_VALUE
)
@ResponseStatus(HttpStatus.OK)
@ApiOperation(
    value = "List of partition keys for a metacat view",
    notes = "List of partition keys for the given view name under the given catalog and database"
)
@ApiResponses(
    {
        @ApiResponse(
            code = HttpURLConnection.HTTP_OK,
            message = "The partitions keys were retrieved"
        ),
        @ApiResponse(
            code = HttpURLConnection.HTTP_NOT_FOUND,
            message = "The requested catalog or database or metacat view cannot be located"
        )
    }
)
public List<String> getPartitionKeysForRequest(
    @ApiParam(value = "The name of the catalog", required = true)
    @PathVariable("catalog-name") final String catalogName,
    @ApiParam(value = "The name of the database", required = true)
    @PathVariable("database-name") final String databaseName,
    @ApiParam(value = "The name of the table", required = true)
    @PathVariable("table-name") final String tableName,
    @ApiParam(value = "The name of the metacat view", required = true)
    @PathVariable("view-name") final String viewName,
    @ApiParam(value = "Sort the partition list by this value")
    @Nullable @RequestParam(name = "sortBy", required = false) final String sortBy,
    @ApiParam(value = "Sorting order to use")
    @Nullable @RequestParam(name = "sortOrder", required = false) final SortOrder sortOrder,
    @ApiParam(value = "Offset of the list returned")
    @Nullable @RequestParam(name = "offset", required = false) final Integer offset,
    @ApiParam(value = "Size of the partition list")
    @Nullable @RequestParam(name = "limit", required = false) final Integer limit,
    @ApiParam(value = "Request containing the filter expression for the partitions")
    @Nullable @RequestBody(required = false) final GetPartitionsRequestDto getPartitionsRequestDto
) {
    return this._getMViewPartitionKeys(
        catalogName,
        databaseName,
        tableName,
        viewName,
        sortBy,
        sortOrder,
        offset,
        limit,
        getPartitionsRequestDto
    );
}
 
Example 19
Source File: OpenWeatherMapUtils.java    From go-bees with GNU General Public License v3.0 4 votes vote down vote up
static MeteoRecord parseCurrentWeatherJson(String weatherJson) throws JSONException {
    // Get JSON
    JSONObject jsonObject = new JSONObject(weatherJson);

    // Check errors
    if (jsonObject.has(OWM_MESSAGE_CODE)) {
        int errorCode = jsonObject.getInt(OWM_MESSAGE_CODE);
        switch (errorCode) {
            case HttpURLConnection.HTTP_OK:
                break;
            case HttpURLConnection.HTTP_NOT_FOUND: // Location invalid
            default: // Server probably down
                return null;
        }
    }

    // Parse JSON
    Date timestamp = new Date();
    String cityName = null;
    int weatherCondition = 0;
    String weatherConditionIcon = null;
    double temperature = 0;
    double temperatureMin = 0;
    double temperatureMax = 0;
    int pressure = 0;
    int humidity = 0;
    double windSpeed = 0;
    double windDegrees = 0;
    int clouds = 0;
    double rain = 0;
    double snow = 0;

    // Get city
    if (jsonObject.has(OWM_CITY)) {
        cityName = jsonObject.getString(OWM_CITY);
    }

    // Get weather condition
    if (jsonObject.has(OWM_WEATHER)) {
        JSONArray jsonWeatherArray = jsonObject.getJSONArray(OWM_WEATHER);
        JSONObject jsonWeatherObject = jsonWeatherArray.getJSONObject(0);
        weatherCondition = jsonWeatherObject.has(OWM_WEATHER_ID) ?
                jsonWeatherObject.getInt(OWM_WEATHER_ID) : -1;
        weatherConditionIcon = jsonWeatherObject.has(OWM_WEATHER_ICON) ?
                jsonWeatherObject.getString(OWM_WEATHER_ICON) : "";
    }

    // Get main info
    if (jsonObject.has(OWM_MAIN)) {
        JSONObject jsonMainObject = jsonObject.getJSONObject(OWM_MAIN);
        temperature = jsonMainObject.has(OWM_MAIN_TEMPERATURE) ?
                jsonMainObject.getDouble(OWM_MAIN_TEMPERATURE) : 0;
        temperatureMin = jsonMainObject.has(OWM_MAIN_TEMPERATURE_MIN) ?
                jsonMainObject.getDouble(OWM_MAIN_TEMPERATURE_MIN) : 0;
        temperatureMax = jsonMainObject.has(OWM_MAIN_TEMPERATURE_MAX) ?
                jsonMainObject.getDouble(OWM_MAIN_TEMPERATURE_MAX) : 0;
        pressure = jsonMainObject.has(OWM_MAIN_PRESSURE) ?
                jsonMainObject.getInt(OWM_MAIN_PRESSURE) : 0;
        humidity = jsonMainObject.has(OWM_MAIN_HUMIDITY) ?
                jsonMainObject.getInt(OWM_MAIN_HUMIDITY) : 0;
    }

    // Get wind
    if (jsonObject.has(OWM_WIND)) {
        JSONObject jsonWindObject = jsonObject.getJSONObject(OWM_WIND);
        windSpeed = jsonWindObject.has(OWM_WIND_SPEED) ?
                jsonWindObject.getDouble(OWM_WIND_SPEED) : 0;
        windDegrees = jsonWindObject.has(OWM_WIND_DIRECTION) ?
                jsonWindObject.getDouble(OWM_WIND_DIRECTION) : 0;
    }

    // Get clouds
    if (jsonObject.has(OWM_CLOUDS)) {
        JSONObject jsonCloudsObject = jsonObject.getJSONObject(OWM_CLOUDS);
        clouds = jsonCloudsObject.has(OWM_CLOUDS_CLOUDINESS) ?
                jsonCloudsObject.getInt(OWM_CLOUDS_CLOUDINESS) : 0;
    }

    // Get rain
    if (jsonObject.has(OWM_RAIN)) {
        JSONObject jsonRainObject = jsonObject.getJSONObject(OWM_RAIN);
        rain = jsonRainObject.has(OWM_RAIN_3H) ?
                jsonRainObject.getDouble(OWM_RAIN_3H) : 0;
    }

    // Get snow
    if (jsonObject.has(OWM_SNOW)) {
        JSONObject jsonSnowObject = jsonObject.getJSONObject(OWM_SNOW);
        snow = jsonSnowObject.has(OWM_SNOW_3H) ?
                jsonSnowObject.getDouble(OWM_SNOW_3H) : 0;
    }

    return new MeteoRecord(timestamp, cityName, weatherCondition, weatherConditionIcon,
            temperature, temperatureMin, temperatureMax, pressure, humidity, windSpeed,
            windDegrees, clouds, rain, snow);
}
 
Example 20
Source File: GenieNotFoundException.java    From genie with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor.
 *
 * @param msg human readable message
 */
public GenieNotFoundException(final String msg) {
    super(HttpURLConnection.HTTP_NOT_FOUND, msg);
}