w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to setup a Jersey client with Jackson (2.x) provider to process a POST request
It looks like that is has something to do with the implementation of the ClientResponse class, i.e., returning the result directly, didn't cause the exception. So the following lines of code are working to make the test successful: String responseString = target.path(resourceIdentifier).request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(testObjectJSON.toStr‌​ing()), String.class);

Categories : Json

Jersey + Jackson + arbitrary json
Jersey won't automatically unwrap the json string to JSONObject on its own, but you could easily do as follows: @Override @POST @Consumes(MediaType.APPLICATION_JSON) public void post(String json) throws JSONException { JSONObject object = new JSONObject(json); // do things with object }

Categories : Json

Deserialize List with Jackson in JUnit (Jersey Client)
Probably too late and you found the solution, but here it is for some else who might run into the same problem. Make sure you register the JacksonFeature on a client config before creating your client, code example below. ClientConfig cc = new ClientConfig().register(new JacksonFeature()); Client client = ClientBuilder.newClient(cc); WebTarget target = client.target(url);

Categories : Json

Can't enable POJO based JSON binding support for Jackson in Jersey 2.0
The documentation is a bit outdated. The latest Jackson build provides an auto-discoverable provider. Add the following jars to the class path: 1) jackson-annotations-2.2.2.jar 2) jackson-core-2.2.2.jar 3) jackson-databind-2.2.2.jar 4) jackson-jaxrs-base-2.2.1.jar 5) jackson-jaxrs-json-provider-2.2.1.jar 6) jackson-module-jaxb-annotations-2.2.2.jar Make sure to add "com.fasterxml.jackson.jaxrs.json" to the "jersey.config.server.provider.packages" servlet config property, so the Jackson json provider can be auto-discovered.

Categories : Java

Using Jackson Json to parse Google Blogs post
I don't know if I correctly understand your problem. JSONObject data = new JSONObject(query); JSONObject responseData = data.getJSONObject("responseData"); JSONArray entries = responseData.getJSONArray("entries"); List<JSONObject> pEntries = new ArrayList<JSONObject>(); for(int i = 0; i < entries.length(); i++){ pEntries.add(entries.getJSONObject(i)); } For taking String from JSONObject call getString("name");

Categories : Android

Jersey/Grizzly POST fails for large URI
Have You tried with shorter URI? Probably Your server is unable to handle so long URI. You can read more about it here: What is the maximum length of a URL in different browsers? Why don't You put request data from URL to request body?

Categories : Java

Jersey: Consume all POST data into one object
Got it. As per this document, I can use a MultivaluedMap<K,V> or Form to get all the POST data of the type application/x-www-form-urlencoded in one object. A working exmple: @POST @Path("/urienodedeample") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.APPLICATION_JSON) public Response uriEncodedExample(MultivaluedMap<String,String> multivaluedMap) { logger.info(multivaluedMap); return Response.status(200).build(); }

Categories : Java

Jersey client: How do I POST nested JSON data?
Form is essentially a Map that limits your values to Strings. What you need is a simple Map (e.g. a HashMap). Every nested element will also be a map. So you will have something like this. Map<String, Object> data = new HashMap<String, Object>(); data.put("customer", "Someone"); data.put("date", "2013-09-12"); Map<String, Object> item1 = new HashMap<String, Object>(); item1.put("sequenceNo", 2); item1.put("name", "foo"); data.put("items", Arrays.asList(item1)); This way you can do as much nesting as you need. Alternatively you can create a few classes that represent your data structures. Jersey will know how to serialize it. class Item { String name; int sequenceNo; // getters & setters } class Data { String customer; String date; List<Ite

Categories : Java

Can jersey clients POST a JAXB object to the server using JSON?
I figured it out on my own. The problem was a server side issue. Once I removed the @FormParam annotation on the server, everything worked as expected. The combined question and answer will provide a rudimentary tutorial for others. My server now looks like: @POST @Path("apath") @Consumes(MediaType.APPLICATION_JSON) public String postAPath(InstanceWithXmlRootElementAnnotation instanceWithXmlRootElementAnnotation) {

Categories : Java

Using Jersey to POST to service - "A message body writer ... was not found"
There can be two problems: Make sure the consumes annotation is set on top of your REST web service method handling this request: @Consumes(MediaType.APPLICATION_XML) Secondly your bean seems to be missing the annotation on the getters. Here is your udpated bean: @XmlRootElement public class Subscriber { private String firstName; private String lastName; @XmlElement (name = "firstName") public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } @XmlElement (name = "lastName") public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public Subscriber() { } }

Categories : Java

Jersey ApplicationEventListener does not work
<init-param> <param-name>jersey.config.server.provider.classnames</param-name> <param-value>org.glassfish.jersey.filter.LoggingFilter;com.github.pires.example.rest.providers.SimpleApplicationEventListener</param-value> </init-param> You must remove the @Provider annotation. See the full example source-code.

Categories : Java

FasterXML Jackson ObjectMapper for .Net MVC4 JSON POST Result Type Objects
RoboSpice doesn't support yet parsing of XML using Jackson. It provides a module to parse XML using SimpleXMLSerializer but not jackson. Can you indicate which classes of Jackson you used, I would add a module soon to RS.

Categories : Android

In Jersey, how do you deal with @POST parameters of a deeply nested, complex object?
What about special handler which transforms object to e.g. json - kryo if you would prefer performance? You got couple options Look also at persistence ignorance.

Categories : Java

Jersey Client post binary data application-octet/stream
I think you can invoke a POST request with Entity which encapsulates binary data like this: Client client = ClientBuilder.newClient(); WebTarget webTarget = client.target("http://example.com/rest"); Response response = webTarget.request(MediaType.TEXT_PLAIN_TYPE) .post(Entity.entity("abc", MediaType.APPLICATION_OCTET_STREAM));

Categories : Java

How to mock builder.type().post() method in Jersey REST service
you have to first mock type() and then mock post(). not sure about the api of builder and easy-mock, the possible code might be: expect(builder.type(MediaType.APPLICATION_JSON)).andReturn(mockType) expect(mockType.post(ClientResponse.class, credentials)).andReturn(clientResponse)

Categories : Rest

How to read data in response of POST operation using jersey client (RestFull)
This issue has been resolved. I added type & accept in single line and it started returning expected json response. Now I can parse the json into any java object. Code : response = resource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept(MediaType.APPLICATION_JSON_TYPE).post(ClientResponse.class, communicatorVO.getFormData());;

Categories : Java

Getting 405 "Method Not Allowed" error using POST with @FormParam (Java web service with Jersey REST)
Okay. Due to the fact that I found the reason of the 405 error, I'll close this question. But I'll open a new one for the new found misstake of the 400 error. I explained the "solution" in a comment above: I moved my service from an older server (where POST didn't work at all and always threw a 405) to a newer one, and didn't change the service-url in my client! @_@ (so the new client still tried to reach the old server) But now, I can send a list of Strings, but none of my own class objects (entities or DTOs). Now I'm getting a HTTP 400 error "Bad Request". :-( But I didn't change anything else. Isn't it possible to send not-standard-types? (--> I'll ask that in a new question.) Sorry for this silly misstake. Jana

Categories : Java

Jackson JsonTypeInfo.As.EXTERNAL_PROPERTY doesn't work as expected
From Javadoc: Inclusion mechanism similar to PROPERTY, except that property is included one-level higher in hierarchy, i.e. as sibling property at same level as JSON Object to type. Note that this choice can only be used for properties, not for types (classes). Trying to use it for classes will result in inclusion strategy of basic PROPERTY instead. Noticed that can only be used for properties is bolded. Source: JsonTypeInfo.As.EXTERNAL_PROPERTY. So, you have to move all annotation from Info class to property info or setInfo method in Response class. @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type") @JsonSubTypes(value = { @JsonSubTypes.Type(value = Type1Info.class, name = "type1"), @JsonSubTypes.Type(value = T

Categories : Json

Why my simple filter in Jersey doesn't work?
I suspect your JAX-RS mapping for serving requests through Jersey may be /services/*. So you are attempting to filter a request that Jersey is not configured to process. /* Will match a wider set of URLs.

Categories : Java

Not able to read a large JSON file in memory from Amazon S3 in Jackson ArrayNode using Jackson
Please download the file from S3 using the S3 console, and then modify this perl script as appropriate to see if the data you have downloaded is actually valid Json: use warnings FATAL => qw(all); use strict; use Carp; use Data::Dump qw(dump); use JSON; my $File = "...."; # File name containing downloaded JSON open(my $f, "<$File") or die "Cannot open file $File for input"; local $/; # Enable localized slurp mode my $j = <$f>; my $d = decode_json $j; print dump($d);

Categories : Java

Jackson : NoSuchMethodError for org.codehaus.jackson.map.DeserializationConfig.withAnnotationIntrospector
You have libraries from different packages and diferent versions. Package: com.fasterxml.jackson.core Libraries in your project from this package: jackson-annotations-2.0.4.jar: jackson-databind-2.0.4.jar: jackson-core-2.0.4.jar: Package: org.codehaus.jackson Libraries in your project from this package: jackson-xc-1.9.11.jar: jackson-mapper-asl-1.9.8.jar jackson-core-asl-1.9.8.jar Jackson changed the name of the package in the version 2 to com.fasterxml.jackson.core, so you should remove all your libraries from previous version 1 in order to avoid incompatibilites problems. Here in this other link they had problems with version 1 and Spring 3, maybe it could add more information about your problem and possible changes you will have to do.

Categories : Java

Passing a Database query as an argument from jersey client to jersey webservice to perfom DML
First you need to correct your web service code to accept the params. If you are using GET, then you can use PathParam to accept your DB query strings. Something liek this: @Path("/insertInclusions") public void insertInclusions(@PathParam("insertQuery") String insertQuery, @PathParam("inclusionString") String inclusionString) In your jersey client code, you can simply add the params in the GET URL

Categories : Java

How to suppress Jersey exceptions that Jersey throws automatically?
Jersey will throw exceptions which are not handled in your code. So you need to wrap your webservice code in try/catch. And catch the Exception class in to make sure that you handle it gracefully in your web service class.

Categories : Java

Jersey 2.*. How to replace InjectableProvider and AbstractHttpContextInjectable of Jersey 1.*
You need to implement InjectionResolver<T> interface from HK2. Take a look at existing implementations that are present in Jersey workspace: ContextInjectionResolver handling @Context ParamInjectionResolver handling @PathParam, @QueryParam, ... (via it's subclasses) AutowiredInjectResolver handling @Autowired Once you have this, you need to extend AbstractBinder from HK2 and bind your InjectionResolver via it's #configure() method: public class MyResolverBinder extends AbstractBinder { @Override protected void configure() { bind(MyInjectionResolver.class) .to(new TypeLiteral<InjectionResolver<MyAnnotation>>() {}) .in(Singleton.class); } } ... and register an instance of this binder in your application class (or v

Categories : Java

Get Custom Post's Post Id By URL doesn't work
You probably have to build your own query, so then you can use the following code: /* A custom Query (without global var) */ $query2 = new WP_Query( $args2 ); // looping through the query2 result, you may use some other code while( $query2->have_posts() ) { $query2->next_post();//here your next post is set echo '<li>' . get_the_title( $query2->post->ID ) . '</li>'; } // Restore original Post Data wp_reset_postdata(); //do not forget this line! This example code is taken from http://codex.wordpress.org/Class_Reference/WP_Query where you can find other examples and custom queries. Read especially this part of the page: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters, I think, it solves your problem.

Categories : Wordpress

Cannot implement simple file upload in Jersey - "annotated with POST of resource, class is not recognized as valid resource method. unavailable"
One visible problem in your code is that, you are using the same name for both the input multipart param i.e. "file" @FormDataParam("file") Multipart params do have an identifier, so you need to use the correct name for the second object in your method signature. Otherwise same param is going in inputstream and also for FormDataContentDisposition.

Categories : Java

Difference com.sun.jersey and org.glassfish.jersey
The only difference between com.sun.jersey and org.glassfish.jersey is that the package name was changed because Jersey team is now part of another organization (Glassfish). Versions below 2 use package com.sun.jersey, versions above 2 use org.glassfish.jersey. And yes, there are some differences between 1.x and 2.x.

Categories : Java

Can't get AJAX post with PHP to work
The most obvious thing is that you have a gap between the < and the script. It must be ' There are other smaller points but here is a working version. Note that the address of your page may need to be root relitive. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script> <a href="javascript:void(0)" onclick="Generate()">Go Man Go</a> <input type="text" value="12" id="Min" /> <input type="text" value="12" id="Max" /> <script type="text/javascript"> function Generate() { var maxint = $("#Max").val(); var minint = $("#Min").val(); $.ajax({ type: "POST", async: true, url: "Untitled-1.php", data: { senduser: maxint,

Categories : PHP

Cannot get ajax post to work
Ah, so damned obvious. You aren't cancelling the default submit action so the form is submitting normally. Add this $("#login_form").submit(function (e) { e.preventDefault(); // and so on See http://api.jquery.com/event.preventDefault/

Categories : PHP

Web Api: PUT/ POST method does not work
The web api framework matches action methods which start with the http verb. So PutProductionState is ok as a name. I was able to make this work. The problems are the following: the second parameter of the action method should be marked with the [FromBody] attribute: public string PutProductionState(int id, [FromBody] FranchiseProductionStates state) { _franchiseService.ChangeProductionState(id, state); var redirectToUrl = "List"; return redirectToUrl; } And the ajax call should look like this: self.selectState = function (value) { $.ajax({ url: "/api/ProductionState/3", type: 'PUT', contentType: 'application/json', data: "'Pending'",

Categories : Asp Net Mvc

$this->post codeigniter don't work with rest api
json data you can't get through post method you have to use like this require(APPPATH . '/libraries/REST_Controller.php'); class user_api extends REST_Controller { function user_post() { $params = json_decode(file_get_contents('php://input'), TRUE); $user = array( 'id' => null, 'firstname' => $params['firstname'], 'lastname' => $params['lastname'] ); $result = $this->user_model->insert($user); if ($result) { $this->response($result, 200); // 200 being the HTTP response code } else { $this->response(NULL, 404); } } }

Categories : PHP

Why JSF POST requests don't work with PrettyFaces
First of all, thanks for helping. It is something strange, that's why I couldn't isolate the problem (to get it happen in another project), which is not executing the POST requests at first try, but from the second one. I have removed the filters I had in web.xml without any difference. The same behavior. I've just had the idea of testing the project in other Tomee version than 1.5.2. Surprisingly, dev version 1.6.0 from 29.07.2013 seems to don't have this problem. Why didn't I think at this sooner? :( I had to write separate Servlet components for my post functionalities. Aaaah! Well, this means that not PrettyFaces was problematic (Huraay!), but, probably, Apache MyFaces, CDI impl. or something else in Tomee. Uf...I'm so happy that it works now. Thanks again for trying to help. ////

Categories : JSF

Can't get GET to work when POST works perfectly
The problem is that you are passing JSON as query string. It works in POST but not in GET. for GET you need data: 'theDate=' + strDate + ' ' + strHours + ':' + strMinutes + ':00'

Categories : C#

why doesnt my post container work?
You haven't cleared #postcontainer - which is needed because it has floated descendants (which are taken out of the normal flow) - one remedy is to add overflow: hidden; so that it creates a new block formatting context for its floated descendants and height: auto; will then work like you'd expect. Remember that a floated element is not acknowledged by other block-level elements in the normal flow (read the above link if you don't understand), unless you clear it or provide a new block-formatting context for its parent. http://jsfiddle.net/ANhUn/1/

Categories : HTML

Ajax POST request does not work
As some of the comments suggest - you need to look in the error console of the Browser. NOT NETBEANS. Also, understand how to set breakpoints in JS, etc. Below is an example of what you are trying to achieve using jQuery which is much simple than using pure Javascript. <!DOCTYPE html> <html> <head> <script type="text/javascript" src="http://code.jquery.com/jquery-2.0.3.min.js"></script> <script type="text/javascript"> // jQuery allows you to use selectors rather than onClick, etc // So when anything with a class called "loadData" is clicked this function will run $(".loadData").click(function (event) { $.ajax({ url: 'demo_post.php', // The URL that your making the request to type: 'POST', // Type - GET or P

Categories : Javascript

JQuery post does not work correctly
I suggest either using JSON in your response with the proper response header content type, or explicitly tell jQuery .post what you expect back: $.post("temp.php", {par:item}, function(){}, 'text'); If you're simply echo'ing in your php script, you arent specifying a content type in your header, which may not be parsed by jQuery correctly as it has to take a guess of what it's working with. Also look for line breaks.

Categories : Jquery

Why does my second WP Custom post-type pagination not work?
You do not have any pagination arguments in the code .. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'posts_per_page' => 3, 'paged' => $paged ); or $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts('posts_per_page=3&paged=' . $paged); or also something like $paged = (get_query_var('paged') && get_query_var('paged') > 1) ? get_query_var('paged') : 1;

Categories : Wordpress

pyramid not work with angular $http post
Try setting contenttype in $http, something like below. $http( { url: url, contentType: "application/json", data: data, method: method }) .success(function (response) { successcb(response); }).error(function (data, status, headers, config) { errorcb(data); }); };

Categories : Angularjs

TTS Engine Post to Speech doesn't work
Since it's a PHP Plugin, you can't reload it without refreshing. PHP runs at server side. However, you can examine the code of the plugin, understand how it works and make an AJAX call to a webpage that will load the plugin and return speech file (or however it works..) and load it to the page. Bottom line, you won't be able to do it without some custom coding. (assuming you talked about this plugin, as it's documentation doesn't state anything about ajax reloading.

Categories : PHP

register post type doesn't work
_cpCreateCustomPostType() needs to run on every request; not just when you activate the plugin. Hook into the init hook, or whichever hook is commonly used register custom post types.

Categories : PHP



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