本文整理汇总了Java中java.net.HttpURLConnection.HTTP_OK属性的典型用法代码示例。如果您正苦于以下问题:Java HttpURLConnection.HTTP_OK属性的具体用法?Java HttpURLConnection.HTTP_OK怎么用?Java HttpURLConnection.HTTP_OK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.net.HttpURLConnection
的用法示例。
在下文中一共展示了HttpURLConnection.HTTP_OK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkConnection
/**
* @description 判断服务连通性
* @author yi.zhang
* @time 2017年4月19日 下午6:00:40
* @param url
* @param auth 认证信息(username+":"+password)
* @return (true:连接成功,false:连接失败)
*/
public static boolean checkConnection(String url,String auth){
boolean flag = false;
try {
HttpURLConnection connection = (HttpURLConnection)new URL(url).openConnection();
connection.setConnectTimeout(5*1000);
if(auth!=null&&!"".equals(auth)){
String authorization = "Basic "+new String(Base64.encodeBase64(auth.getBytes()));
connection.setRequestProperty("Authorization", authorization);
}
connection.connect();
if(connection.getResponseCode()==HttpURLConnection.HTTP_OK){
flag = true;
}
connection.disconnect();
}catch (Exception e) {
logger.error("--Server Connect Error !",e);
}
return flag;
}
示例2: updatePaymentFileConfirmNoAttachment
@PUT
@Path("/{id}/payments/{referenceUid}/confirm/noattachment")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED})
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED})
@ApiOperation(value = "Update PaymentFile")
@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 updatePaymentFileConfirmNoAttachment(@Context HttpServletRequest request, @Context HttpHeaders header,
@Context Company company, @Context Locale locale, @Context User user,
@Context ServiceContext serviceContext,
@ApiParam(value = "id of payments", required = true) @PathParam("id") String id,
@ApiParam(value = "reference of paymentFile", required = true) @PathParam("referenceUid") String referenceUid,
@BeanParam PaymentFileInputModel input);
示例3: finish
/**
* Completes the request and receives response from the server.
*
* @return a list of Strings as response in case the server returned status
* OK, otherwise an exception is thrown.
* @throws IOException
*/
public List<String> finish() throws IOException {
List<String> response = new ArrayList<String>();
writer.append(LINE_FEED).flush();
writer.append("--" + boundary + "--").append(LINE_FEED);
writer.close();
// checks server's status code first
int status = httpConn.getResponseCode();
if (status == HttpURLConnection.HTTP_OK) {
BufferedReader reader = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
response.add(line);
}
reader.close();
httpConn.disconnect();
} else {
throw new IOException("Server returned non-OK status: " + status);
}
return response;
}
示例4: isCacheable
/**
* Returns true if this response can be stored to later serve another
* request.
*/
public boolean isCacheable(RequestHeaders request) {
// Always go to network for uncacheable response codes (RFC 2616, 13.4),
// This implementation doesn't support caching partial content.
int responseCode = headers.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK
&& responseCode != HttpURLConnection.HTTP_NOT_AUTHORITATIVE
&& responseCode != HttpURLConnection.HTTP_MULT_CHOICE
&& responseCode != HttpURLConnection.HTTP_MOVED_PERM
&& responseCode != HttpURLConnection.HTTP_GONE) {
return false;
}
// Responses to authorized requests aren't cacheable unless they include
// a 'public', 'must-revalidate' or 's-maxage' directive.
if (request.hasAuthorization() && !isPublic && !mustRevalidate && sMaxAgeSeconds == -1) {
return false;
}
if (noStore) {
return false;
}
return true;
}
示例5: getDeliverableAction
@GET
@Path("/deliverables/{id}/update/{deliverableAction}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED })
@ApiOperation(value = "Update deliverableAction by deliverable id")
@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 defined", response = ExceptionModel.class) })
public Response getDeliverableAction(@Context HttpServletRequest request, @Context HttpHeaders header,
@Context Company company, @Context Locale locale, @Context User user, @Context ServiceContext serviceContext,
@ApiParam(value = "id of Deliverable", required = true) @PathParam("id") Long id,
@ApiParam(value = "deliverableAction", required = true) @PathParam("deliverableAction") String deliverableAction);
示例6: getPaymentFiles
@GET
@Path("/paymentfiles")
@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 info Payment files", response = PaymentFileSearchResultModel.class)
@ApiResponses(value = {
@ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Return a list of PaymentFile", response = PaymentFileSearchResultModel.class),
@ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "", response = ExceptionModel.class),
@ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "", response = ExceptionModel.class),
@ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = "", response = ExceptionModel.class) })
public Response getPaymentFiles(@Context HttpServletRequest request, @Context HttpHeaders header, @Context Company company,
@Context Locale locale, @Context User user, @Context ServiceContext serviceContext,
@ApiParam(value = "body params of post", required = true) @BeanParam PaymentFileSearchModel search);
示例7: fetch
public static GameProfile fetch(UUID uuid, boolean forceNew) throws IOException
{
if (!forceNew && cache.containsKey(uuid) && cache.get(uuid).isValid())
{
return cache.get(uuid).profile;
}
else
{
HttpURLConnection connection = (HttpURLConnection) new URL(String.format(SERVICE_URL, UUIDTypeAdapter.fromUUID(uuid))).openConnection();
connection.setReadTimeout(5000);
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK)
{
InputStreamReader response = new InputStreamReader(connection.getInputStream());
GameProfile result = gson.fromJson(new BufferedReader(response), GameProfile.class);
cache.put(uuid, new CachedProfile(result));
return result;
}
else
{
if (!forceNew && cache.containsKey(uuid))
{
return cache.get(uuid).profile;
}
JsonObject error = (JsonObject) new JsonParser().parse(new BufferedReader(new InputStreamReader(connection.getErrorStream())).readLine());
throw new IOException(error.get("error").getAsString() + ": " + error.get("errorMessage").getAsString());
}
}
}
示例8: getProcessSteps
@GET
@Path("/{id}/steps")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ApiOperation(value = "Get all ProcessSteps of a ServiceProcess", response = ProcessStepResultsModel.class)
@ApiResponses(value = {
@ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Returns a list of all ProcessSteps", response = ProcessStepResultsModel.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 getProcessSteps(@Context HttpServletRequest request, @Context HttpHeaders header,
@Context Company company, @Context Locale locale, @Context User user,
@Context ServiceContext serviceContext, @PathParam("id") long id, @BeanParam ProcessStepSearchModel query);
示例9: code
@GET
@Path("/{id}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ApiOperation(value = "Get detail ServiceInfo by code (or Id)", response = ServiceInfoDetailModel.class)
@ApiResponses(value = {
@ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Returns the detail of ServiceInfo", response = ServiceInfoDetailModel.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 getDetailServiceInfo(@Context HttpServletRequest request, @Context HttpHeaders header,
@Context Company company, @Context Locale locale, @Context User user,
@Context ServiceContext serviceContext,
@ApiParam(value = "id (or code) of ServiceInfo that need to be get detail", required = true) @PathParam("id") String id);
示例10: respondToRequest
private boolean respondToRequest( HttpRequest request, HttpResponseStream response ) {
if (_debug) System.out.println( "** Server thread " + hashCode() + " handling request: " + request );
boolean keepAlive = isKeepAlive( request );
try {
response.restart();
response.setProtocol( getResponseProtocol( request ) );
WebResource resource = getResource( request );
if (resource == null) {
response.setResponse( HttpURLConnection.HTTP_NOT_FOUND, "unable to find " + request.getURI() );
} else {
if (resource.closesConnection()) keepAlive = false;
if (resource.getResponseCode() != HttpURLConnection.HTTP_OK) {
response.setResponse( resource.getResponseCode(), "" );
}
String[] headers = resource.getHeaders();
for (int i = 0; i < headers.length; i++) {
if (_debug) System.out.println( "** Server thread " + hashCode() + " sending header: " + headers[i] );
response.addHeader( headers[i] );
}
response.write( resource );
}
} catch (UnknownMethodException e) {
response.setResponse( HttpURLConnection.HTTP_BAD_METHOD, "unsupported method: " + e.getMethod() );
} catch (Throwable t) {
t.printStackTrace();
response.setResponse( HttpURLConnection.HTTP_INTERNAL_ERROR, t.toString() );
}
return keepAlive;
}
示例11: getDataFormByTypeCode
@POST
@Path("/deliverables/agency/{agencyNo}/type/{typeCode}")
@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 list dataform by agencyNo and typeCode")
@ApiResponses(value = {
@ApiResponse (code = HttpURLConnection.HTTP_OK, message = "Return a list dataform"),
@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 = "Accsess denied", response = ExceptionModel.class) })
public Response getDataFormByTypeCode (@Context HttpServletRequest request, @Context HttpHeaders header, @Context Company company,
@Context Locale locale, @Context User user, @Context ServiceContext serviceContext,
@ApiParam(value = "id for agency", required = true) @PathParam("agencyNo") String agencyNo,
@ApiParam(value = "id for type", required = true) @PathParam("typeCode") String typeCode,
@FormParam("keyword") String keyword);
示例12: id
@GET
@Path("/{id}/contacts")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ApiOperation(value = "Get contacts of Dossier by its id (or referenceId)", response = DossierDetailModel.class)
@ApiResponses(value = {
@ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Returns a list of Dossiers have been filtered", 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 getContactsDossier(@Context HttpHeaders header, @Context ServiceContext serviceContext,
@PathParam("id") Long dossierId, @Context String referenceUid);
示例13: getFormScript
@GET
@Path("/deliverables/{id}/formscript")
@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 info formscript for deliverable id")
@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 defined", response = ExceptionModel.class) })
public Response getFormScript(@Context HttpServletRequest request, @Context HttpHeaders header,
@Context Company company, @Context Locale locale, @Context User user, @Context ServiceContext serviceContext,
@ApiParam(value = "id of Deliverable", required = true) @PathParam("id") Long id);
示例14: getServiceConfig
@GET
@Path("/{id}")
@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 a ServiceConfig by id", response = ServiceConfigDetailModel.class)
@ApiResponses(value = {
@ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Returns a ServiceConfig", response = ServiceConfigDetailModel.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 getServiceConfig(@Context HttpServletRequest request, @Context HttpHeaders header,
@Context Company company, @Context Locale locale, @Context User user,
@Context ServiceContext serviceContext,
@ApiParam(value = "serviceconfigId for get detail") @PathParam("id") long input);
示例15: doInBackground
@Override
protected String doInBackground(String... strings) {
try {
URL serviceEndPoint = new URL("http://jsonplaceholder.typicode.com/users/");
HttpURLConnection connection = (HttpURLConnection) serviceEndPoint.openConnection();
// timeout de la peticion
connection.setConnectTimeout(CONNECTION_TIMEOUT);
connection.setReadTimeout(READ_TIMEOUT);
// añadimos cabeceras a la conexión
connection.setRequestProperty("Accept", "application/json");
// connection.setRequestProperty("Authorization", "Basic lajskjflskjflsfjslfjslflsjfdls");
// indicamos que tipo de petición vamos a realizar (GET, POST, ....)
connection.setRequestMethod("GET");
// se lanza la petición y se mira el resultado
connection.connect();
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
// recuperamos un stream con la respuesta del servidor.
InputStream input = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
StringBuilder result = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
result.append(line);
}
// Se ha leido la respuesta de manera correcta. retornamos el json como string recibido
return result.toString();
}
else {
Log.e (TAG, "Error reading response from " + serviceEndPoint.toString() + " with code " + connection.getResponseCode());
}
} catch (MalformedURLException mue) {
Log.e(TAG, "MalformedURLException", mue);
} catch (IOException ioe) {
Log.e(TAG, "IOException", ioe);
}
return COMUNICATION_ERROR;
}