I have a problem with Grails project.
I'm using HtmlUnit and I don't know why but Grails shows a Evaluator Exception.
The code is:
WebClient webClient = new WebClient();
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setActiveXNative(true);
webClient.getOptions().setAppletEnabled(true);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setPopupBlockerEnabled(true);
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setUseInsecureSSL(true);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
HtmlPage currentPage = webClient.getPage(web);
System.out.println("TITULO" + currentPage.getTitleText());
and the error is:
URI: /SRL/busqueda/showProgress2
Class: net.sourceforge.htmlunit.corejs.javascript.EvaluatorException
Message
In order to define a property, getter public void com.gargoylesoftware.htmlunit.javascript.host.html.HTMLInsElement.setCite(java.lang.String) must have zero parameters or a single ScriptableObject parameter. (BusquedaService.groovy#48)
The line contains the error is: HtmlPage currentPage = webClient.getPage(web);
Any idea o suggestion? :(
Related
I have the following requestMethod in a RestController class and it´s working fine:
#RequestMapping(path = "/api/v1/rest/websearcher/search/results", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<WebResultResponse> getSavedAvailability(#RequestBody final WebResultRequest navigationRequest,
#CookieValue(value = "forceSupplier", defaultValue = "") final String forceSupplier)
I´ve also a feign client working fine as well. I added a new parameter called forceSupplier in both methods, but after adding it, I´m having the issue Method has too many Body parameters but I don´t really understand why I´m receiving this message because the param is the same.
This is the method in Feign:
#RequestMapping(path = "/api/v1/rest/websearcher/search/results", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
ResponseEntity<WebResultResponse> getAndSavedAvailability(#RequestBody WebResultRequest webSearcherResultRequest, #CookieValue(value = "forceSupplier", defaultValue = "") String forceSupplier);
What am I doing wrong? Thanks
The annotation #CookieValue is not supported when using Spring Cloud OpenFeign. As a result, Feign sees your #RequestBody and #CookieValue parameters as the request entities, and since you only have one request entity, Feign throws the exception you are seeing.
There is currently no support for Cookies in Feign.
When I throw a WebApplicationException in my service like the following, I get a 404 response code which is what I'm expecting
throw new WebApplicationException(Response.Status.NOT_FOUND);
When I attempt to put a little more information in my exception via a ResponseBuilder, I'm getting a 500 response code. Here's my enhanced code and the response message I get back:
List<Error> errors = new ArrayList<>();
errors.add(new Error(ErrorCode.PDF_GENERATION_ERROR));
ErrorResponse errResponse = new ErrorResponse();
errResponse.setErrors(errors);
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity(errResponse).build());
javax.ws.rs.WebApplicationException:
com.sun.jersey.api.MessageExceptio n: A message body writer for Java
class idexx.ordering.rest.common.types.ErrorRe sponse, and Java type
class idexx.ordering.rest.common.types.ErrorResponse, and MIME media
type application/octet-stream was not found
My REST service has the following method signature:
#Produces("application/pdf")
#GET
#Path("/{id}")
public Response getPdfById(#PathParam("id") final Long id) {
Is there anyway I can get that extra error code information into the response when I throw a WebApplicationException?
Try this:
String errResponse = "convert your errors to text";
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity(errResponse).build());
Probably this will work because JAX-RS can convert basic types, but to convert List<Error> you need to register a custom MessageBodyWriter.
Hi I am trying to write small app with REST Json. I have some method that returns ArrayList of entity objects. And I am doing that:
#RequestMapping(value="/workers/", method = RequestMethod.GET)
public #ResponseBody ArrayList<Workers> showAllEmployes() throws Exception
{
ArrayList<Workers> workers = new ArrayList<Workers>();
workers = (ArrayList<Workers>) spiroService.getAllWorkers();
return workers;
}
And after this I got:
HTTP Status 500. The server encountered an internal error that prevented it from fulfilling this request.
When I try to return primitive data type then all is ok. I have nothing in server logs. And I have necessary imports. Please some tip.
Seems you have issue in produce json format, try this.
#RequestMapping(value = "/workers/", method = RequestMethod.GET,
produces={MediaType.APPLICATION_JSON_VALUE})
I know there are a bunch of questions on this already - I'm having a hard time sorting out which ones are related to problems with versions, and which ones are related to jQuery (which I'm not using), etc. I have the MVC4 RC (4.0.20505.0), Visual Studio 2010 Ultimate SP1.
I have a complex type in my model:
public HttpResponseMessage Post([FromUri]Person person)
{
TableStorageHelper personHelper = new TableStorageHelper();
personHelper.Save(personHelper.GetTableNameForType("Person"), person);
var response = Request.CreateResponse<Person>(HttpStatusCode.Created, person);
return response;
}
I am passing in this JSON string - using Fiddler mostly, but also trying from code in another controller (trying to do all testing locally just to verify that I can get values in the object received by the controller):
The JSON:
{"FirstName":"Andy","LastName":"Schultz","PartitionKey":"USW","RowKey":"per-928c8f74-2efd-4fc2-a71c-fb3ea8acc6d7","NickName":null,"FullName":"Andy Schultz","Description":null,"ImageLocation":null,"Region":"USW","CommentsAboutMe":{"Comments":[]},"CommentsByMe":{"Comments":[]}}
All of the properties here do exist in the class.
The code from the other controller:
HttpWebRequest request = HttpWebRequest.Create("http://127.0.0.2:8080/api/persons/") as HttpWebRequest;
request.Method = "POST";
request.ContentType = "text/json";
using (var writer = new StreamWriter(request.GetRequestStream()))
{
Person person = new Person("Andy", "Schultz", "USW");
Formatting formatting = new Formatting();
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
string json = JsonConvert.SerializeObject(person, formatting, settings);
writer.Write(json);
}
Every time, I get an empty Person object in my controller (I'm debugging on the very first line there). Every value is NULL.
You may have noticed the [FromUri] attribute on my controller - I had to do that to get around an error telling me there was no ModelBinder for an undefined type, but I'm not sure that it's correct - I'm not passing any info in the Uri, it's in the body, as you can tell.
Thank you Mike Stall: http://blogs.msdn.com/b/jmstall/archive/2012/04/16/how-webapi-does-parameter-binding.aspx
The [FromUri] attribute did indeed tell my controller to read the uri and not the request body looking for the parameter for my controller method. It wasn't there, so everything was null.
The error that adding that attribute fixed, which said there was no formatter defined for a type of content Undefined, was caused by my improperly declaring the content-type of the request. The correct way was "Content-Type: text/json; charset=utf-8
I am getting a 415 Error when sending a form entry to another client resource via JSON. The target URI in my code below ("/message") works when not using the form (i.e. hit "/message" with a test mock object).
Here is my code to get the values of the form and do the post to the target resource. Am I missing something that needs to be done?
I am using the following:
Restlet: 2.1 RC5
GAE: 1.6.1
Form Restlet:
#Post
public void handlePost(Representation entity) {
final Form webForm = new Form(entity);
MessageEntity newMessage = new MessageEntity();
String subject = webForm.getFirstValue("subject");
String sendto = webForm.getFirstValue("email");
String message = webForm.getFirstValue("message");
newMessage.setCategoryID(subject);
newMessage.setAccountID(sendto);
newMessage.setMessageText(message);
ClientResource cr = new ClientResource(getRootRef()+ "/message");
cr.post(newMessage, MediaType.APPLICATION_JSON);
}
Target Resource ("/message")
#Post("json")
public void HandleRequest(MessageEntity messageEntity) {
// Logic here
}
Please let me know if you need more information
Thanks!
I have code that is very similar to yours that works fine. I am also running similar versions of Restlet and GAE. First question I have is are there other #Post methods in your Target Resource as sometimes the ordering matters.
Here are two versions of code that I have that work....
1)
public Representation postHandler() {
Reference commitsRef = new Reference(Consts.RESOURCE_BASE + "commitments/");
ClientResource commitsResource = new ClientResource(getContext(), commitsRef);
....
Representation commitsRep = commitsResource.post(commitForm);
That is posting a form to a Target resource that handles both #Post("json") and #Post("form")
2)
public Representation doPostFromGet() {
Reference takeActRef = new Reference(Consts.RESOURCE_BASE + "commitment/"
+ commitmentId + "/userActs/");
ClientResource takeActResource = new ClientResource(getContext(), takeActRef);
...
Representation takeActRep = takeActResource.post(newAct);
That is posting a Java object to a form that uses what I call the "Peierls magic". See:
http://tembrel.blogspot.com/2012/03/converting-forms-in-restlet-to-pojos.html
It allows you to have one post() in the Target and accept both forms and pojos.
On a minor note, if you are doing a post to add a new message, should the url be "/messages/" (plural) - and perhaps there is a typo somewhere? (An unlikely possibility, but I thought I would mention it).
Good luck,
RB