GWT RPC GWTTestCase + GUICE 2.0 - gwt

Im trying to create an app with the GWT on the front end and GUICE on the backend served on the Google App Engine.
I have created a very simple app using the example setup
http://stuffthathappens.com/blog/2009/09/14/guice-with-gwt/#comment-49355
The app works fine, however I wanted to add some unit tests for the GWT RPC calls.
I am trying to use the GWTTestCase as below:
`public void testContactMessageService() {
ContactMessage message = new ContactMessage();
message.setName("Jeff");
message.setMessage("Just wanted to say I'm a fan.");
message.setEmail("man.nick.utd#gmail.com");
ContactMessageServiceAsync contactMessageService = GWT.create(ContactMessageService.class);
contactMessageService.sendMessage(message,
new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
// Show the RPC error message to the user
System.out.println(caught);
fail("big time failure");
finishTest();
}
public void onSuccess(String result) {
System.out.println("success, biatch");
assertTrue(true);
finishTest();
}
});
delayTestFinish(1000);
}
`/**
However when I run the test it fails and on the console it prints
[WARN] 404 - POST /com.resume.Contacthandler.JUnit/GWT.rpc (192.168.0.11) 1425 bytes
Request headers
Host: 192.168.0.11:4016
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.19) Gecko/2010031422 Firefox/3.0.19
Accept-Language: en-us
Accept: /
Connection: Keep-Alive
Referer: 192.168.0.11:4016/com.resume.Contacthandler.JUnit/junit.html?gwt.codesvr=192.168.0.11:4012
X-GWT-Permutation: HostedMode
X-GWT-Module-Base: 192.168.0.11:4016/com.resume.Contacthandler.JUnit/
Content-Type: text/x-gwt-rpc; charset=utf-8
Content-Length: 285
Response headers
Content-Type: text/html; charset=iso-8859-1
Content-Length: 1425
com.google.gwt.user.client.rpc.StatusCodeException: 404
HTTP ERROR: 404 NOT_FOUND
RequestURI=/com.resume.Contacthandler.JUnit/GWT.rpc
From this output I am assuming something on the server side with Guice is not getting setup.
How do you setup the server side Guice servlets when running GWTTestCases ?

There are much simpler ways to get Guice and GWT working other than the approach in the stuffthathappens blog. For instance, the following code is most of what you'd need to do to get a servlet up and running. This doesn't touch any GWT code so it's easy to test with pure JRE tests - you'd just need to set up a test injector and get an instance of the Service Impl.
serve("/myapp/importservice").with(SourceImportServiceImpl.class);
#Singleton
public class SourceImportServiceImpl extends RemoteServiceServlet {
private Provider<SimpleDao> daoProvider;
#Inject
public SourceImportServiceImpl(Provider<SimpleDao> daoProvider) {
this.daoProvider = daoProvider;
}
... RPC method implementations
}

Related

CLIO API - Internal Server Error - Create Communication

I am attempting to update my old v2 application to v4. I am currently running into a problem where I am getting an "Internal Server Error" message when I try to create a communication using C# implementing RestSharp. My schema is as follows:
public class CommunicationList
{
public List<MakeCommunication> data { get; set; }
}
public class MakeCommunication
{
public string body { get; set; }
public DateTime date { get; set; }
public NestedMatter matter { get; set; }
public string subject { get; set; }
public string type { get; set; }
}
public class NestedMatter
{
public int id { get; set; }
}
I am populating the objects with the appropriate data. My setup for the RestSharp POST is as follows:
var request = new RestRequest("api/v4/communications.json", Method.POST);
request.AddHeader("Authorization", "Bearer " + ConfigIt.readConfiguration("token"));
request.AddParameter("fields", "body, date, matter{id}, subject, type");
I am serializing the object without the AddJsonBody method because my research led me to believe that AddJsonBody method was producing malformed json so I am using the following code to serialize the objects:
request.RequestFormat = DataFormat.Json;
request.AddBody(commWrapper);
comWrapper is an object of type CommunicationList from below.
Getting a generic Internal Server Error really isn't pointing me in any direction for debugging this thing. Anyone seen a similar issue? Any suggestions?
Thanks for any help you can give, my eyes are going crossed at this point.
UPDATE - Saturday Dec 15th
I have done some more digging on this. Using Fiddler I was able to verify that this is what is being sent to the server:
POST https://app.goclio.com/api/v4/communications.json HTTP/1.1
Authorization: Bearer ******************************
Accept: application/json, text/json, text/x-json, text/javascript,
application/xml, text/xml
User-Agent: RestSharp/106.5.4.0
Content-Type: application/json
Host: app.goclio.com
Content-Length: 151
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
{"data":[{"body":"test email for debug","date":"2018-12-15T14:23:23Z","matter:{"id":1035117666},"subject":"test","type":"EmailCommunication"}]}
I went back to the api documentation at https://app.clio.com/api/v4/documentation#operation/Communication#create to double check that I was sending the right request. I believe it looks correct but clearly I am missing something.
This is the response I am getting back from the server.
HTTP/1.1 500 Internal Server Error
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Status: 500 Internal Server Error
X-RateLimit-Limit: 600
X-RateLimit-Reset: 1544883900
X-RateLimit-Remaining: 599
X-Request-Id: 41199f9a-f569-4688-97a7-04b309cf85ed
X-Frame-Options: SAMEORIGIN
Cache-Control: private, no-cache, no-store, must-revalidate
X-XSS-Protection: 1; mode=block
X-API-VERSION: 4.0.5
X-Content-Type-Options: nosniff
Date: Sat, 15 Dec 2018 14:24:09 GMT
Server: nginx
Content-Length: 75
{"error":{"type":"InternalServiceError","message":"Something went wrong."}}
I am hoping that someone may have encountered this before. Any help is greatly appreciated.
It looks like the value you're sending for data in your request payload is an Array, not an Object. There is an example of the correct data format in the sidebar on the documentation page that you linked.
It also looks like the payload you provided has invalid json in it. There is a double-quote missing after matter.
So if you change your payload to look something like this, it should work (expanded for readability):
{
"data":{
"body":"test email for debug",
"date":"2018-12-15T14:23:23Z",
"matter":{"id":1035117666},
"subject":"test",
"type":"EmailCommunication"
}
}

Disable Redirect by Spring Security in Jersey Spring Boot Application

I am pulling my hair out. The environment is a JAXRS (using Jersey) Restful application configured via Spring Boot. I am developing an orchestration layer that communicates with microservices. The orchestration layer uses RestTemplate to perform the calls to the microservices.
For some reason, when there is an error level status code returned from the orchestration service, Spring Security attempts to post to http://localhost:65448/error. I have NO idea who is doing this. I have turned up logging, traced through the code, scoured the internet, and read all the documentation...I cannot determine what class is attempting to do this. I cannot stop it.
Here is my Spring Configuration (groovy) for the security bits:
#Configuration
#EnableWebSecurity
#Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
#Inject
private UserService userService
#Inject
private StatelessAuthenticationFilter statelessAuthenticationFilter
void configure(WebSecurity web) throws Exception {
}
void configure(HttpSecurity http) throws Exception {
http
.anonymous().and()
// .servletApi().and()
.headers().cacheControl().and()
.exceptionHandling().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.rememberMe().disable()
.csrf().disable()
.formLogin().disable()
.httpBasic().disable()
.jee().disable()
.logout().disable()
//.openidLogin().disable()
.authorizeRequests()
.filterSecurityInterceptorOncePerRequest(true)
// Allow anonymous logins
.antMatchers('/security/authc').permitAll()
// All other request need to be authenticated
.anyRequest().authenticated().and()
// Custom Token based authentication based on the header previously given to the client
.addFilterAfter(statelessAuthenticationFilter, BasicAuthenticationFilter)
}
void configure(AuthenticationManagerBuilder auth) {
auth
.userDetailsService(userService)
.passwordEncoder(passwordEncoder())
}
#Bean
PasswordEncoder passwordEncoder() {
new BCryptPasswordEncoder()
}
#Bean
AuthenticationManager authenticationManagerBean() {
super.authenticationManagerBean()
}
}
The test code is performing a simple rest-based authentication by posting an Authorization header to the authc endpoint. This works as expected unless the orchestration service returns an error level status code.
Here is the relevant logging:
[2015-06-03 07:07:15.621] boot - 47784 INFO [qtp1012776440-21] --- LoggingFilter: 1 * Server has received a request on thread qtp1012776440-21
1 > POST http://localhost:65448/security/authc
1 > Accept: */*
1 > Accept-Encoding: gzip,deflate
1 > Authorization: bm90ZXhpc3RzOnRlc3RwYXNz
1 > Connection: keep-alive
1 > Content-Length: 0
1 > Content-Type: application/x-www-form-urlencoded; charset=ISO-8859-1
1 > Host: localhost:65448
1 > User-Agent: Apache-HttpClient/4.2.1 (java 1.5)
[2015-06-03 07:07:15.753] boot - 47784 INFO [qtp1012776440-21] --- LoggingFilter: 1 * Server responded with a response on thread qtp1012776440-21
1 < 400
[2015-06-03 07:07:15.757] boot - 47784 INFO [qtp1012776440-21] --- LoggingFilter: 2 * Server has received a request on thread qtp1012776440-21
2 > POST http://localhost:65448/error
2 > Accept: */*
2 > Accept-Encoding: gzip,deflate
2 > Authorization: bm90ZXhpc3RzOnRlc3RwYXNz
2 > Connection: keep-alive
2 > Content-Length: 0
2 > Content-Type: application/x-www-form-urlencoded; charset=ISO-8859-1
2 > Host: localhost:65448
2 > User-Agent: Apache-HttpClient/4.2.1 (java 1.5)
[2015-06-03 07:07:15.781] boot - 47784 INFO [qtp1012776440-21] --- LoggingFilter: 2 * Server responded with a response on thread qtp1012776440-21
2 < 404
2 < Content-Type: application/json
HTTP/1.1 404 Not Found
Date: Wed, 03 Jun 2015 11:07:15 GMT
Pragma: no-cache
X-Application-Context: Test:test:0
Content-Type: application/json
Transfer-Encoding: chunked
Server: Jetty(9.2.9.v20150224)
Please help before I toss my computer out the window.
Cheers
This is caused by the ErrorMvcAutoConfiguration. You can either disable it (via exclude on the annotation EnableAutoConfiguration) or change its path, if you have a custom error path, with the property error.path.
Hy,
This the default behaviour of Jetty when the server responds with a status code >=400 (except for 404 ) and the response has no entity. You can "disable" this behaviour by settings an empty error pages list
#Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
return new EmbeddedServletContainerCustomizer() {
#Override
public void customize(ConfigurableEmbeddedServletContainer container) {
// On skippe la redirection /error realise
container.setErrorPages(Sets.<ErrorPage> newConcurrentHashSet());
}
};
}
Despite of this workaround, the server will send the real http status with a XML body (see ErrorHandler)
This is also the case for undertow.

Using real HTTP error code in wicket

I need to respond with an error code. When I am using AbortWithHttpStatusException my response is like that:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
portlet.http-status-code: 507
Content-Type: text/html;charset=UTF-8
Content-Length: 0
Date: Tue, 10 Jan 2012 09:49:52 GMT
which is interpreted by browser (firefox at least) as 200 OK, which seems ok, since there is HTTP/1.1 200 OK at the beginning. How can I force wicket to return other http code?
I am using wicket 1.4.18
I needed the same customize HTTP Status Code (e.g. 404 Not Found) in Wicket functionality too (not with portlet) and configureResponse() works beautifully:
package org.soluvas.web.bootstrap;
import org.apache.wicket.request.http.WebResponse;
/**
* #author atang
*
*/
public class PageNotFound extends BootstrapPage {
private static final long serialVersionUID = 1L;
public PageNotFound() {
super();
// add(new Page404());
}
#Override
protected void configureResponse(WebResponse response) {
super.configureResponse(response);
response.setStatus(404);
}
}
Taken from https://github.com/soluvas/soluvas-web project.

500 Server Error HTML returned from MVC AJAX call when plain text specified

I am trying to return plain text from my MVC AJAX methods that indicates an error code. This is working fine on my dev machine, but when deployed to a server (Win2008 R2) I am always getting the HTML of the 500.htm page back in the error.responseText from my AJAX call instead of the text I specified. Any ideas why I would not get back the plain text I intended?
Here is my error handling logic in my controller.
protected override void OnException(
ExceptionContext filterContext
)
{
try
{
Error error = ControllerCommon.ProcessException(filterContext);
// return error
filterContext.Result = HandleError(error.Type);
filterContext.ExceptionHandled = true;
}
catch (Exception ex)
{
Logger.Instance.LogImportantInformation(ex.Message, 0, Constants.EventSourcePortal);
}
}
#endregion
#region Private Methods and Members
private ActionResult HandleError()
{
return HandleError(Error.ErrorType.Unknown);
}
private ActionResult HandleError(
Error.ErrorType errorType
)
{
// set return status code
HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
Logger.Instance.LogImportantInformation(((int)errorType).ToString(CultureInfo.InvariantCulture), 0, Constants.EventSourcePortal);
// return error type
return Content(((int)errorType).ToString(CultureInfo.InvariantCulture), "text/plain");
}
Here is the header that I get back from the Server.
Response Headers
Cache-Control private
Content-Type text/html
Server Microsoft-IIS/7.5
X-AspNet-Version 4.0.30319
X-Powered-By ASP.NET
Date Mon, 20 Jun 2011 16:00:42 GMT
Content-Length 1208
Request Headers
Host pqompo2test01.dns.microsoft.com
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Accept text/html, /
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
Content-Type application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With XMLHttpRequest
Referer https://pqompo2test01.dns.microsoft.com/Incident/List
Content-Length 330
Cookie MC1=GUID=111c287d88c64447a63719bb2c858981&HASH=7d28&LV=20114&V=3; A=I&I=AxUFAAAAAACJCAAAMuSpPH1Citx6nZO0iHfvdA!!&CS=116|9n002j21b03; WT_FPC=id=131.107.0.73-1717525904.30146426:lv=1308581948698:ss=1308581948698; MUID=7F438FBFEEE948D88DA06B04F6923159; MSID=Microsoft.CreationDate=04/20/2011 16:45:49&Microsoft.LastVisitDate=06/20/2011 15:59:10&Microsoft.VisitStartDate=06/20/2011 15:59:10&Microsoft.CookieId=4c7552d0-5e75-4e5e-98b9-4ca52421a738&Microsoft.TokenId=ffffffff-ffff-ffff-ffff-ffffffffffff&Microsoft.NumberOfVisits=27&Microsoft.CookieFirstVisit=1&Microsoft.IdentityToken=AA==&Microsoft.MicrosoftId=0668-8044-9161-9043; ANON=A=FA4FB528F204DDFA69239A4FFFFFFFFF&E=b4d&W=4; NAP=V=1.1&E=af3&C=hJtCCJq27admlaiwmdzvTmnAwIEVXv1jFR2I2bJ-gncMGQOJce96RQ&W=4; mcI=Wed, 27 Apr 2011 16:48:43 GMT; omniID=fd752842_58d3_4833_9a0f_d0e1e3bbfef3; WT_NVR_RU=0=msdn:1=:2=; ASP.NET_SessionId=dbcqi222tehjorefcopchuzu; MS0=7fc23d65df4241c89554b502149ccc13; MICROSOFTSESSIONCOOKIE=Microsoft.CookieId=94c8a34f-9184-4e10-84c5-2b9c43c7a962&Microsoft.CreationDate=06/20/2011 15:59:10&Microsoft.LastVisitDate=06/20/2011 15:59:10&Microsoft.NumberOfVisits=1&SessionCookie.Id=04DF98242DBD0730C9388487546F2F37; RPSMCA=FAAaARSsz90pZKmFSg5n0wbtR5MnQAldBwNmAAAEgAAACDNAEUimN1wb2AD%2Bp1PnEJUdd7n5VumQIQerCQYdD5IEd6ZCDEshkiTkvVl5a9eA6%2B9a0Os/1FpoqtvsGYMdWUUc98PUl5ZTo%2BFXAqxiZ9BL5D69OLCPsZEXitrZMulmKXFGQiAD5FqJY8JOOSJ1xptRwdkdrxGF8PuNit/Si87Ft7g4sF9vE878lMSx6TSmQq3nrurnBbdbUvDvwTKLoY0gAikOxJ7GmZoLw4kbzaLR/6/a/XSJFv%2BZ6uHsIwkMn6mndoZKfg3LLjDlCpozrHBlnKtgkn7yZXtd8Or420IXuPMUAF3gfp8VAkhKlVceTXpBv2h4gs6g; RPSMCSA=FAAaARSsz90pZKmFSg5n0wbtR5MnQAldBwNmAAAEgAAACEdSXDQ0SIKI2AC/tM6y7CeHdaKVAab/n/4TLKkF5/01jGkXR0vA07MTvS5vhwgjCPMs4zke%2B0jnB1DqOV2vI4VqQ/%2BOIYh52QkaLREoD5L718AjEJOQdDVRRZiIB51CiYtS0P/kgIkEtfDa5yuTr3w6V2IKhy2%2B6wVrP/UqxsJR%2BZ1QmGxtjv7eQVGdIndrkPx5e9wFqj1qEcf9FNfH0/uajuaTFaNmi/3dQfWuEKxGpoHWNxgoMf8PHLVi2hqltqK47OloCGqQGLPQPx0PSg1K73FTZHhl3%2BuxyNqyWJumKsAUAGuMUzFhTPsQ7JdOSfY2SYyHeaZP; RPSShare=1; MSPAuth=1NNm8kdmWAFrAuL2d8qOShxJKehL!CxEkCQvsgPdNGDqo0XFGsreQZ9GMVjiT1*bHPlGcNVsyfbVO7h!eY32bCNY7Farp2grIyEgAFv7YgJqWZN2Q87*LBZnZ0ASWmhPqe; MSPProf=1ZN*xhGN9GRXSO*HEmrISYo6cowSUbmxtIsYfqtHv!!VzEybb1I33*BdWWJrz54tkO5BzS3eTprAXL1LO9ELLBziO8Sm8WTzkSbV*E6ECcX9N92*AFiJztc4rlwCLQnMBhxlV0qzvlRN4dS1SajyzABZDNBTG*tdyqfnuP6jkSevAhuXYvnEuKZQKAF5fvgr4!oiBQ2KhnuH0$; RequestVerificationToken_Lw=TOS6XUQ+17bDOxh2T75NhhFy2KIJP5BP9MetB7cAa4i68ZEHIEpgE7xwQhzid/YiZCm4GsbW2zsJjlIxkB1hrhVGoU++E1I5BP9X2PyKn0O8tic84cWNz8QRjLDcaAcF4iYEQQ==; prmrsdninc=1
When I run locally on my Win7 machine I simply get the text back that I am expecting.
I was having the same problem trying to return 500 pages containing only text for processing by telerik controls. Of course it worked tickity-boo on my development machine and failed when published up to the proper IIS servers.
This fixed it for me:
http://blog.janjonas.net/2011-04-13/asp_net-prevent-iis_75_overriding-custom-error-page-iis-default-error-page
Summary: Type putting a
Response.TrySkipIisCustomErrors = true;
line in your action

SOAP servers and clients with Zend framework (Getting errors)

I am testing a server and client i made on my webspace.
when i try to call a simple "testServer" function defined in a ServerMap class, I get
"Looks like we got no XML document"
..?
I called getFunctions on the client and testServer is a valid function. I tried catching all exceptions and then calling __getLastResponseHeaders() and __getLastResponse.
header:
string(348) "HTTP/1.1 200 OK
Date: Tue, 23 Jun 2009 19:36:29 GMT
Server: Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.9
X-Powered-By: PHP/5.2.9
Cache-Control: max-age=1
Expires: Tue, 23 Jun 2009 19:36:30 GMT
Vary: Accept-Encoding
Content-Length: 1574
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
"
response:
string(1574) "DEBUG HEADER : This is a cached page !
"
If i look at the source html of the response, its actually:
string(1574) "DEBUG HEADER : This is a cached page !<?xml version="1.0"?>
<A lot of xml that looks pretty much like my WSDL file that my Zend_Soap_AutoDiscover generates>
So whats going on? I searched online and i didnt really find any solid solutions.
I don't have blank space before my ..
If you are outputting to the browser, it is hiding the xml cause it is in a . Browsers ignore tags they don't understad.
Do a echo htmlentities($output); to see the xml tags.
Not sure what your problem is, but I can provide a bit of code that I know works for us using Zend Framework 1.8x as a backend SOAP service for silverlight and WCF. This service simples takes 2 integers, adds them and returns the result. Simple as you can get.
Controller Class example:
class SoapController extends Zend_Controller_Action {
/*
* SOAP server action
*/
public function indexAction() {
$request = $this->getRequest();
if ($request->getParam('wsdl') !== null) {
$wsdl = new Zend_Soap_AutoDiscover();
$wsdl->setClass('SoapMath');
$wsdl->handle();
}
else {
$module = $request->getModuleName();
$controller = $request->getControllerName();
$uri = 'http://' . Zend_Registry::get('fullUrl') . '/' . $module . '/' . $controller . '?wsdl';
$server = new Zend_Soap_Server($uri);
$server->setClass('SoapMath');
$server->handle();
}
exit;
}
}
And the actual work is done by 'SoapMath' which is defined as:
class SoapMath {
public function add($a,$b) {
return ($a + $b);
}
}