w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Where to store resources URIs in a REST API
On the API design, you shouldn't be returning URIs as part of the data in an HTTP API response. There's a header field for that if your resource is available from multiple URIs, and the domain logic of your application alongside good naming of the URIs on your part should allow guessing of the resource location. For instance, if {'name':'foo', 'id':100} is a Foo, you (and users) would usually expect its URI to be /foos/100, so why would you need to return the URI inside the response data? Now more pragmatically, since supporting those fancy HTTP headers could make it harder for your clients to adopt your API, I believe you should store URIs in a 1:many relationship with your resources if you expect your resources to change URI a lot (I hope they don't), so it might be easier for you to s

Categories : Database

Client config of WCF REST service is not being updated
Visual Studio service reference does the magic because SOAP services provide WSDL. If you create a REST service, there is no WSDL and it will not work. The moment you switch to basic HTTP, it works because it is SOAP. You have to use HTTP libraries like HttpClient to talk to a REST endpoint.

Categories : Wcf

How to model REST URIs from a dynamic XML tree
I respectfully submit that an endpoint structure that fluid is going to cause all kinds of problems. I'm not aware of Jersey cleanly supporting what you want, nor any other java library for that matter. I guess you could hack something together yourself, but I would strongly discourage it. For instance, you could make endpoints for each level of the tree, like /level0/{id}/level1/{id}/level2/{id} Without knowing your business requirements, it's hard to give alternative suggestions, but perhaps just returning the tree as the response from a single endpoint would be better?

Categories : Xml

Is it possible/feasible integrate non-Microsoft REST client application in to Sharepoint 2013 OAuth to obtain an access token for a REST client?
I'm trying to do the same thing: authenticate on SharePoint 2013 REST APIs from android app, and it seems that the only solution is to use OAuth 2.0 for authentication: If you’re calling into SharePoint from a remotely hosted application that can’t use client-side code (HTML and JavaScript) exclusively, and there’s no firewall between SharePoint and your application, you can use OAuth 2.0 tokens with Microsoft Access Control Service (ACS) as the secure token server. source: http://msdn.microsoft.com/en-us/magazine/dn198245.aspx

Categories : Javascript

PayPal REST API java sdk - custom config file
So here is the solution I found: Create an empty sdk_config.properties file in default location Load your own properties: private static void initPayPal() { InputStream is = null; try { is = ApplicationConfig.class.getResourceAsStream( IS_PRODUCTION ? "/my_paypal_sdk_config.properties" : "/my_paypal_sdk_config_test.properties"); Properties props = new Properties(); props.load(is); PayPalResource.initConfig(props); ConfigManager.getInstance().load(props); String clientID = ConfigManager.getInstance().getConfigurationMap().get("clientID"); String clientSecret = ConfigManager.getInstance().getConfigurationMap().get("clientSecret"); PAYPAL_ACCESS_TOKEN = new OAuthTokenCredential(clientID, clientSecret).getAccessToke

Categories : Java

linux Bash - read contents of file , store them in a variable and create network config file
I tried yesterday and I am very close to the solution. Researching the internet , I made a perl script and was able to create multiple interface by extracting data from csv file. But there is small issue I see and not able to figure out why an extra character is coming in the file. Following is the code: #!/usr/bin/perl use strict; use warnings; sub main { # Note: this could be a full file path my $filename = "file1.csv"; open(INPUT, $filename) or die "Cannot open $filename"; # Read the header line. #my $line = <INPUT>; my $line; # Read the lines one by one. while($line = <INPUT>) { chomp($line); # Display the header, just to check things are working.

Categories : Linux

properties file to store sensitive config
Your plan sounds good to me except storing keys inside the keystore. Basically, there is only one keystore instance created for all system-level and third-party apps on the device. After Android 4.0, the keystore is integrated with the unlock screen and it is unlocked when the user unlocked the device. So, if you store your key as a key/value pair inside the keystore, then your key is ready before you open your app. Or, if you store it as key/encrypted(value) pair, then you have to derive the key from the password at run-time and decrypt the encrypted value. But you may end up having two password for unlocking the phone screen and unlocking the key. I probably go with with only one password, i.e. screen unlock password. Since the keystore is mapped to the Process ID, it is only accessed fr

Categories : Android

Split Android attrs.xml resource file to get UI colors separated from the rest
Yes, of course you can, just define a colors.xml in your values folder and place there your desired colors like so: <?xml version="1.0" encoding="utf-8"?> <resources> <color name="my_blue">#c00e</color> <color name="my_welcome_color">#3399cc</color> <color name="my_transperent_white">#afff</color> .... </resources>

Categories : Android

C# Best way to user resource file for client side in mvc - 4 project
I apparently rambled on a bit here, short version is if you need localized strings in Javascript then I would recommend using hidden fields to hold the translated values and grab from them. There are two parts to handling multiple languages, globalization and localization. Globalization is handling numbers and related things based on the current culture's norms. For instance in the US we would write $1,000.00 while in Germany they would (assuming my Googling is correct) write $1.000,00 (currencies are also a complex topic but don't fall under either IMO). This is the bit that we have lots of Javascript libraries for since Javascript often has to render some compound data as user output (for instance summing up the items in a cart without requiring a page load) Localization is handling

Categories : C#

Am I deviating from REST pattern, if I allow my user to change resource identifier of the resource during PUT calls?
HTTP PUT means "put the body of my request here", where the URL at which you make the request is where to put the entity. If you PUT a resource somewhere, you should be able to GET it again. If the content of the request means that the resource will not be found at the URL you just PUT it at, you've broken one of the HTTP constraints. I can think of a couple of options to handle this scenario which would all fit within HTTP's constraints: Make it so that the URL of the resource is immutable. The "real" ID of any resource in a RESTful system is its URL. If you want to have an ID which is mutable, make it a surrogate key supported by an immutable identifier which is used to build the URL, or just make the URL the primary key. Remove the ID of the entity from its representation (so there

Categories : Rest

Getting a zip file with a java rest client (restEasy)
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.util.Date; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class ZipReader { // Expands the zip file passed as argument 1, into the // directory provided in argument 2 public static void main(String args[]) throws Exception { if(args.length != 2) { System.err.println("zipreader zipfile outputdir"); return; } // create a buffer to improve copy performance later. byte[] buffer = new byte[2048]; // open the zip file stream InputStream theFile = new FileInputStream(args[0]); ZipInputStream stream = new ZipInputS

Categories : Java

ClientHandlerException in REST client only when executing jar file
I fixed this problem by myself after hours of thinking and trying. The Problem was the creation of the executable jar by maven. Some dependencies missed in it, so i changed the plugin configuration: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>prepare-package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build

Categories : Java

Ruby error: cannot load such file -- rest-client
Assuming you're using https://github.com/rest-client/rest-client (since you didn't specify), your require line should be require 'rest_client' according to the README. Also, make sure you restart your rails server after adding the gem to your Gemfile and running bundle.

Categories : Ruby On Rails

Do we really need a rest java client or we can directly fire rest request from HTML page
You can use "curl" if you are on unix systems. for example to fire http GET request you can execute following command - curl -X GET "http://google.com" to get verbose output you can use "-v" to add headers you can use "--header" similarly to post data to server curl -X POST "http://google.com/answers" --data "a=b;c=d" If you want to use browser to make REST calls you can use following plugin for chrome - chrome://restclient/content/restclient.html Similary plugins can be found for other browsers. Which one is better ? depends on your need. If you are just testing and if you don't like command line so much then, you can use chrome plugin but then you can't write script around it which you can do with curl.

Categories : Java

How to store and convert IP addresses in H2?
Unless you want to index it and unless you store really a lot of IP addresses, I would use VARCHAR. If you store many entries, you could use BINARY. You could create user defined functions in the H2 database for INET_ATON and INET_NTOA.

Categories : Database

Sending Objects from Spring MVC 3 REST client to REST provider
Reasons for your issues: If you want to accept data in your controller through @RequestParam, the request should contain the data as, well request parameters. Think url containing ?empCode=xyz&password=abc. Or in the request body as empCode=xyz&password=abc The way you are sending an Employee object in the client code, the object will be serialized into the request body. With the code you have provided, the client will make a request with the employee object converted to its JSON representation in the request body. Something your controller method is not equipped to read. (Assuming you have mapping jackson jars in the classpath) Possible solutions: Change the controller method signature, instead of @RequestParam, use @RequestBody, which tell Spring to extract the value of the

Categories : Json

Bing maps rest service get full addresses from postcode
There is no functionality to do that in Bing Maps. The closest thing you would be able to do is geocode a postal code and then reverse geocode a bunch of points in the surrounding area until you stop getting addresses with the same postal code. This would be very slow and would generate a lot of transactions against your Bing Maps account. You can find a code sample of how to reverse geocode over an area here: http://rbrundritt.wordpress.com/2010/01/09/reverse-geocoding-over-a-search-area/

Categories : Rest

How to store the function addresses when it is called in C?
If you are on linux: You can trace your program using ptrace and check the register. To get the informations about your functions you can use the libelf. (or use nm & objdump)

Categories : C

Datatype to store range of IP addresses in Java
The InetAddress class would be the ideal type store IP addresses. It is a lot more than you've asked for here. But would be useful for getting IP from name/address or the other way round. Since you are using CIDR masks not supported by INetAddress you'll need other types Code sample using Apache SubnetUtils String subnet = "12.21.31.0/24"; SubnetUtils utils = new SubnetUtils(subnet); utils.getInfo().isInRange(address); Code sample using CIDRUtils CIDRUtils cidrUtils = new CIDRUtils("10.21.31.0/24"); String networkAddress = cidrUtils.getNetworkAddress(); String broadcastAddress = cidrUtils.getBroadcastAddress();

Categories : Java

Store a single character (tab, new line, any character) in User.config file
You could store the decimal ASCII code for the character by converting to an int, and convert it back to a char in your program. e.g. char charToSave = ' '; int code = (int)charToSave; SaveCharToUserConfig(code); ... int code = GetCodeFromUserConfig(); char savedChar = (char)code;

Categories : C#

How can I get my hands on client addresses for logging using Grizzly / Jersey?
In your MdcFilter, try to inject the HttpServletRequest into your class and use that as you would normally to call getRemoteAddr() or any other such function as in: class MdcFilter implements ContainerRequestFilter, ContainerResponseFilter { @Context protected HttpServletRequest r; @Override public ContainerRequest filter(ContainerRequest request) { MDC.put("http-client", "foo" r.getRemoteAddr()); return request; } @Override public ContainerResponse filter(ContainerRequest request, ContainerResponse response) { MDC.remove("http-client"); return response; } } I tested this out using a similar approach to "firing things up by hand" and it worked out for me in that case. I assume it would work for you as well.

Categories : Java

AngularJS Client, JAX-RS Jersey Rest Service - application/json client request throwing 'Error parsing media type'
Your Content-Type header is invalid (see spec 14.17 Content-Type). Based on you JAX-RS resource you should use application/json as Content-Type (without application/x-www-form-urlencoded): $http({ method: 'POST', data: $scope.Patient, url:'/ManagePatient/AddPatient', headers: {'Content-Type':'application/json'} }); EDIT 1: If you want to see requests that are coming to your server you can register LoggingFilter and it will show you some useful information. You can turn it on in: web.xml (add it to the JAX-RS servlet definition): <init-param> <param-name>jersey.config.server.provider.classnames</param-name> <param-value>org.glassfish.jersey.filter.LoggingFilter</param-value> </init-param> Application extension: public class MyAppl

Categories : Angularjs

Can I store settings in a settings.config file in ASP.NET MVC?
To answer the title question, yes you can store settings in a separate config file, to do so you need to define the configSource property of appSettings element E.g. <appSettings configSource="settings.config" /> and in the settings.config file <?xml version="1.0" encoding="UTF-8"?> <appSettings> <add key="settingKey" value="environmentValue" /> </appSettings> However, for the sake of environment specific settings, you may want to look at config transforms. Setting up a transform config for each environment then deploying to that environment with the specified build configuration. E.g. Web.Dev.config (provided you have setup a 'Dev' build configuration) <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <app

Categories : C#

override git config --system in .gitconfig user file ( git config --global )
If it is a system wide config, each user can override a config value in his/her global and local settings. But there is no easy way to "deactivate" a setting in a lower config file. Even set it to "" generally has unintended consequences. That very topic was discussed in April 2010. For instance, deactivating the send-email option: True, after thinking a bit about this using no value to unset is a horrible, horrible hack. git-send-email should be corrected to not only check that there is value from config or command line option, but also that it is sane (i.e. non-empty, or simply true-ish if we say that smtpuser = "0" is not something we need to worry about supporting). That would be true for any setting: the diff.c#run_diff_cmd() function will attempt to run an external diff i

Categories : GIT

codeigniter custom config file calling config data
it seems you create form at wrong place, try to get main controller first: $CI =$ get_instence(); 'rules'=>'required|min_length['.$CI->config->item('min_password_length', 'ion_auth').']'

Categories : Codeigniter

Passing config file as argument to config parse module
start.py ... options.ConfigFile = args.filename ... options.py from ConfigReader import getConfigValue as getVal, ConfigFile def getTest(): Test = getVal('main', 'test') return Test ConfigReader.py import os import ConfigParser ConfigFile='default.cfg' def config(): cfg = ConfigParser.ConfigParser() for f in set(['default.cfg',ConfigFile]):

Categories : Python

Is there a way to unset a global git config section in a local git config file?
No Git config includes operate: as if its contents had been found at the location of the include directive ref That means you can't override/remove the include itself, as as soon as it's found the contents of the included file are injected/loaded. You can of course override the settings it contains in a more specific config file: # ~/.git.config.team [user] name = name Locally, via git config user.name nic # /some/project/.git/config [user] name = alias Yielding: /some/project $ git config user.name alias /some/project $

Categories : GIT

Updating a config file adds additional config sections
Try changing the ConfigurationSaveMode from ConfigurationSaveMode.Minimal to ConfigurationSaveMode.Modified Modified only saves the properties that you have changed. From MSDN: Full Causes all properties to be written to the configuration file. This is useful mostly for creating information configuration files or moving configuration values from one machine to another. Minimal Causes only properties that differ from inherited values to be written to the configuration file. Modified Causes only modified properties to be written to the configuration file, even when the value is the same as the inherited value.

Categories : C#

mongoDB, could not read from config file -- config in different folder / Uninstall it?
Issue resolved with following steps (thanks to Karl Seguin's 'The Little MongoDB Book'). If you installed MongoDB via the download package from mongodb.org, you have to create create your own config file in /bin. Follow the instructions below (copied from Karl Seguin's book): download package unzip package Create a new text file in the bin subfolder named mongodb.config (if you have permission issues saving the file, save it first to your desktop then move file into folder). Add a single line to your mongodb.config: dbpath=PATH_TO_WHERE_YOU_WANT_TO_STORE_YOUR_DATABASE_FILES. For example, on Windows you might do dbpath=c:mongodbdata and on Linux you might do dbpath=/var/lib/ mongodb/data. Make sure the dbpath you specified exists Launch mongod with the --config /path/to/your/mongodb

Categories : Mongodb

Why can JSF resource bundle var be used differently with f:loadBundle and faces-config
Both <f:loadBundle> and <resource-bundle> are different ways to load properties with difference being in their access scopes. The latter has by the way the additional benefit that the bundle is also injectable in a managed bean by @ManagedProperty("#{myProp}") Using <resource-bundle> in faces-config.xml creates a global resource bundle which can be accessed anywhere in your application. This is implemented through a java.util.ResourceBundle instance. Using <f:loadBundle> in your view creates a view-specific resource bundle which is accessible only within that view. The tag handler implements this using an internal implementation of a Map. This is as specified in the VDL of the tag: Load a resource bundle localized for the Locale of the current view, and expo

Categories : JSF

Configuring wcf rest services in web.config
In order to configure a WCF REST service, you need a few things in your web.config file 1) Declare your service and its endpoint <services> <service name="SparqlService.SparqlService" behaviorConfiguration="ServiceBehavior"> <endpoint binding="webHttpBinding" contract="SparqlService.ISparqlService" behaviorConfiguration="webHttp"/> </service> </services> Service name will be [project name].[service name] Behavior configuration will be same name as the behavior you declare in the next step Binding must be webHttpBinding because you want it as REST. If you want SOAP, you declare as basicHttpBinding Contract is the [project name].[interface name] Behavior configuration in the endpoint will be the name you declare in next step 2) Declare

Categories : Wcf

ConfigurationManager reading wrong file - Web.config instead of App.config
App.config that resides in a Class Library project would not be loaded (at least not without extra effort), the only configuration loaded by the framework is the Client configuration (i.e the Web.config of a project that references and uses your Class Library). See this answer for possible solutions.

Categories : Asp Net Mvc

REST - Resource and Collection Representations
That falls entirely on what you want it to do. The great thing about REST APIs is that they are so flexible. You can represent data in any way (theoretically) that you want. Personally, I would have an attribute that allows the user to specify a subset or style of representation. For instance /users/{userid}.json?output=simple or /users/{userid}.json?subset=raw Something along those lines would also allow you to nest representations and fine tune what you want without sacrificing flexibility: /users/{userid}.json?output=simple&subset=raw The sky is the limit

Categories : Rest

REST resource call from JavaScript
Looks like REST application. The mapping is done by your web application container (Java EE/Spring/...), exact configuration might vary. The basic mapping definition is done by @Path annotations(here the class StudentListResource handles request going to /list and concrete method getStudentDemographic then handles "relative URL" /student/demographic, thus together /list/student/demographic. This URL is the relative to your web application, that I assume is called "api" (or at least is mapped to /api/**) @GET annotation just says that it handles only HTTP GET request, similarly @PUT, @POST etc @Consumes and @Produces specifies that the input and output is expected to be JSON, which is then mapped to Java objects, the input to the method is taken from query (@QueryParam) @Override is jus

Categories : Java

calling rest api from anguler js using $resource?
As others have pointed out, the angular looks ok but perhaps it is not sending the data in the correct format for your php service. I had to do the following for a service that was expecting form-encoded data. Hopefully it (or something similar) will work for you. $http({ method: 'POST', url: 'rest/mm/login', data: 'username=' + $scope.username + "&password=" + $scope.password, headers: {'Content-Type': 'application/x-www-form-urlencoded'} }).success(function (result) { authService.loginConfirmed(result); }); (clearly the username/password should be url encoded for safety etc)

Categories : Javascript

Are memory addresses reported in valgrind absolute, physical addresses?
In modern processors / operating systems, memory is mapped into the process space of a program. The program has no notion (or interest in) the actual physical memory address of the space it's using--only device drivers really have the need.

Categories : Misc

Rest API design multiple URLs to same resource?
For me, as a rule of thumb, I look at what I'm returning from the API and this usually informs what I'm representing. For example, you are actually returning sites, not users for the URL: example.com/api/v1/users/123/sites. In this case, I would prefer to address sites, as that is what is being returned. So, I would opt for this URL: example.com/api/v1/sites?user=123 IMHO, this is utilizing the query string as an actual query for sites. So, for the site representation I would build it up like this: All sites: example.com/api/v1/sites A particular site: example.com/api/v1/sites/1 A user's site: example.com/api/v1/sites?user-123 Current user's site: example.com/api/v1/sites?user=current

Categories : Rest

How can I access Dropwizard Resource directly, and not via REST
I can see a couple of approaches: You manually create a ProviderDao and construct your ProviderResource(dao) with the dao you create. You create an HttpClient object to make an HTTP call to your resource while it's running. For this, you could use Dropwizard's client libraries You can create a mock call and response (this will only validate the Resource and not the DAO). You can specifically test the DAO. From the JDBI documentation, you can test like this: DBI dbi = new DBI("jdbc:h2:mem:test"); YourDAO dao = dbi.open(YourDAO.class); // Test something dao.close();

Categories : Java

Rest uri design for changing the status for resource
Your second option looks better because you're maintaining the RESTful url structure and not appending RPC-style methods to the end of it. Why not just do this: PUT to /resources/:id and send the data transition=void with the request. It behaves in the same way it would if you were receiving a POST request, just grab the data out of the request body.

Categories : Json

Angular resource REST has no method '$save'
You need to create an instance of your Monitoring class like this (not tested): var m = new Monitoring({id:id}); m.command = command; m.schedule = schedule; m.$save(); The documentation (http://docs.angularjs.org/api/ngResource.$resource) has a similar example: var newCard = new CreditCard({number:'0123'}); newCard.name = "Mike Smith"; newCard.$save(); I asked the same question about the @ sign a while ago: "at" sign in parameter names in resource definition. Basically @ sign means that the value will be read from the object's property. Or as the same documentation says: If the parameter value is prefixed with @ then the value of that parameter is extracted from the data object (useful for non-GET operations). The $ is not any special character, it is just a part

Categories : Angularjs



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.