Apache XML-RPC Exception Handling - exception

What is the easiest way to extract the original exception from an exception returned via Apache's implementation of XML-RPC?

It turns out that getting the cause exception from the Apache exception is the right one.
} catch (XmlRpcException rpce) {
Throwable cause = rpce.getCause();
if(cause != null) {
if(cause instanceof ExceptionYouCanHandleException) {
handler(cause);
}
else { throw(cause); }
}
else { throw(rpce); }
}

According to the XML-RPC Spec it returns the "fault" in the xml.
Is this the "Exception" you are referring to or are you refering to a Java Exception generated while making the XML-RPC call?
Fault example
HTTP/1.1 200 OK
Connection: close
Content-Length: 426
Content-Type: text/xml
Date: Fri, 17 Jul 1998 19:55:02 GMT
Server: UserLand Frontier/5.1.2-WinNT
<?xml version="1.0"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value><int>4</int></value>
</member>
<member>
<name>faultString</name>
<value>
<string>Too many parameters.</string>
</value>
</member>
</struct>
</value>
</fault>
</methodResponse>

Related

Struts 2 Action not Consuming json data

I have configured and coded a simple web service call to a Struts 2 Action. I am not getting the data from the call but it is returning JSON properly. I am using Postman to make the call.
public class WSLaborJONAction
{
// this property is not getting populated on the call
private String test;
public String execute() throws Exception
{
...some code
return "success";
}
public String getTest()
{
return test;
}
public void setTest(String test)
{
this.test = test;
}
}
<package name="webservices" namespace="/" extends="json-default">
<result-types>
<result-type name="json" class="org.apache.struts2.json.JSONResult" />
</result-types>
<interceptors>
<interceptor name="json" class="org.apache.struts2.json.JSONInterceptor" />
</interceptors>
<!-- LABOR JON -->
<action name="WSLaborJON" class="mil.ndms.taa.af.webservices.labor.WSLaborJONAction">
<result name="success" type="json" />
</action>
</package>
GET /taa/WSLaborJON
Content-Type: application/json
User-Agent: PostmanRuntime/7.13.0
Accept: '*/*'
Cache-Control: no-cache
Postman-Token: 111a91a2-919f-4469-a96c-c5b666c9ebec
Host: localhost:8080
accept-encoding: gzip, deflate
content-length: 30
Connection: keep-alive
{
"test":"MyInputTest"
}
HTTP/1.1 200
status: 200
Server: Apache-Coyote/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 23
Date: Tue, 11 Jun 2019 18:02:13 GMT
{"test":"MyOutputTest"}
My String test is always null. I need to consume it in the Action from the JSON call. Any ideas of what I am missing?

Google Geocoding API returning 500 Internal Server Error

Let me preface this with: I am not a developer. I'm currently using Mulesoft to integrate several systems (application originally developed by an outsourced developer). Part of the application is to merge records that might be common across the systems. To do that, I'm using the record name and geocode for the associated address. Until the past week this was working fine. Now I'm receiving an error when this part of the application runs. The debug logs from the particular call that failed is:
[2016-10-11 16:02:06.163] DEBUG com.ning.http.client.providers.grizzly.AsyncHttpClientFilter [[tbosa-rpm].DefaultSftpConnector.receiver.01]: (t:null) REQUEST: HttpRequestPacket ( method=GET
url=/maps/api/geocode/json
query=key=[REMOVED]&address=%[REMOVED]%20[REMOVED]%20[REMOVED]%2CSPRING%20BRANCH%2CTX%22
protocol=HTTP/1.1
content-length=-1
headers=[
MULE_CORRELATION_SEQUENCE=969
MULE_CORRELATION_ID=bd4249f0-8fcb-11e6-9620-12fd3e455356
MULE_CORRELATION_GROUP_SIZE=4375
Host=maps.googleapis.com:443
User-Agent=AHC/1.0
Connection=keep-alive
Accept=*/*]
)
[2016-10-11 16:02:06.164] DEBUG org.mule.module.http.internal.HttpMessageLogger [[tbosa-rpm].DefaultSftpConnector.receiver.01]: (t:null) REQUESTER
GET /maps/api/geocode/json?key=[REMOVED]&address=%[REMOVED]%20[REMOVED]%20[REMOVED]%2CSPRING%20BRANCH%2CTX%22 HTTP/1.1
MULE_CORRELATION_SEQUENCE: 969
MULE_CORRELATION_ID: bd4249f0-8fcb-11e6-9620-12fd3e455356
MULE_CORRELATION_GROUP_SIZE: 4375
Host: maps.googleapis.com:443
User-Agent: AHC/1.0
Connection: keep-alive
Accept: */*
Content-Type: application/json; charset=UTF-8
[2016-10-11 16:02:07.684] DEBUG org.mule.module.http.internal.HttpMessageLogger [[tbosa-rpm].http.requester.GeocoderRequest.worker(1)]: (t:null) REQUESTER
HTTP/1.1 500 Internal Server Error
Content-Type: application/json; charset=UTF-8
Date: Tue, 11 Oct 2016 16:02:07 GMT
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Cache-Control: no-cache, must-revalidate
Access-Control-Allow-Origin: *
Server: mafe
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alt-Svc: quic=":443"; ma=2592000; v="36,35,34,33,32"
Accept-Ranges: none
Vary: Accept-Language,Accept-Encoding
Transfer-Encoding: chunked
35
{
"results" : [],
"status" : "UNKNOWN_ERROR"
}
0
[2016-10-11 16:02:07.684] DEBUG com.ning.http.client.providers.grizzly.AhcEventFilter [[tbosa-rpm].http.requester.GeocoderRequest.worker(1)]: (t:null) RESPONSE: HttpResponsePacket (
status=500
reason=Internal Server Error
protocol=HTTP/1.1
content-length=-1
committed=false
headers=[
content-type=application/json; charset=UTF-8
date=Tue, 11 Oct 2016 16:02:07 GMT
pragma=no-cache
expires=Fri, 01 Jan 1990 00:00:00 GMT
cache-control=no-cache, must-revalidate
access-control-allow-origin=*
server=mafe
x-xss-protection=1; mode=block
x-frame-options=SAMEORIGIN
alt-svc=quic=":443"; ma=2592000; v="36,35,34,33,32"
accept-ranges=none
vary=Accept-Language,Accept-Encoding
transfer-encoding=chunked]
)
The problem doesn't seem to be with the geocoding API itself, as I can make a manual call for the same address without any issues. The connection is throttled, so we shouldn't be hitting up against any limits on requests per second. This is the piece of code from the application that governs the API call:
<flow name="rpm-geocode-lookup" processingStrategy="synchronous">
<set-payload value="#[payload.addressLine1],#[payload.city],#[payload.state]" doc:name="Set Location"/>
<ee:cache cachingStrategy-ref="GeocoderCachingStrategy" doc:name="Geocoder Cache">
<json:object-to-json-transformer doc:name="Object to JSON"/>
<logger level="DEBUG" category="com.tbosa.esb.rpm" message="Making call to Geocoder for #[payload]" doc:name="Not Cached"/>
<http:request config-ref="GeocoderRequest" path="/geocode/json" method="GET" doc:name="Geocoder Request">
<http:request-builder>
<http:query-param paramName="key" value="${geocoder.key}"/>
<http:query-param paramName="address" value="#[payload]"/>
</http:request-builder>
</http:request>
<json:json-to-object-transformer returnClass="java.util.Map" doc:name="JSON to Object"/>
<choice doc:name="Choice">
<when expression="#[payload.status == 'OK' || payload.results.size() > 0]">
<set-payload value="#[new java.lang.String(payload.results[0].geometry.location.lat) + payload.results[0].geometry.location.lng]" doc:name="Latitude+Longitude"/>
</when>
<otherwise>
<logger message="Geocoder did not return any results. Result: #[payload]" level="WARN" category="com.tbosa.esb.rpm" doc:name="Logger"/>
<set-payload value="''" doc:name="Blank Value"/>
</otherwise>
</choice>
<expression-component doc:name="Expression">Thread.sleep(${geocoder.throttle.delay});</expression-component>
</ee:cache>
<exception-strategy ref="EmailExceptionStrategy" doc:name="Exceptions"/>
</flow>
The application hasn't changed. We've been running it successfully for 9 months, so I'm not sure where the issue might be. I'm honestly leaning toward an issue with Mulesoft, but they're trying to tell me this is an issue with the API. Thoughts?
500 error indicates that something wrong happened on Google side during processing the request. Have you retried request after a short delay?
Try to figure out which Google IP address hits your application. You can use traceroute maps.googleapis.com and ping maps.googleapis.com from the machine where you execute your application.
If 500 error persists, I would suggest filing an issue in public issue tracker with your results from traceroute and ping, sample HTTP request that demonstrates the issue, your public IP address and your project number.
https://code.google.com/p/gmaps-api-issues/
Hope it helps!

Soup UI - save JSON request and response

I'm using rest request in soapUI.
I want to save the JSON request and response to a file.
How can i do it?
Request payload (JSON) is not included in the report. Only request HTTP headers are captured in the report. Please let me know if you are able to log request JSON. I am using SoapUI 5.0.0
Right click on your testSuite and select Launch TestRunner, on Launch TestRunner panel select Reports tab, on this tab check Exports all results, and select a root folder to save this results on Root Folder:. Finally click on Launch.
Then in your root folder for each request you will have a file like TestSuiteName-TestCaseName-TestStepName-nIteration-result.txt with following content:
Status: OK
Time Taken: 409
Size: 793
Timestamp: Mon Apr 07 12:47:02 CEST 2014
TestStep: Test Request
----------------- Messages ------------------------------
----------------- Properties ------------------------------
Encoding: UTF-8
Endpoint: http://myHost.com/service/service
---------------- Request ---------------------------
Request Headers: Host : XX.XXX.X.XX
Content-Length : 321
SOAPAction : "http://myAction.com"
Accept-Encoding : gzip,deflate
User-Agent : Apache-HttpClient/4.1.1 (java 1.5)
Connection : Keep-Alive
Content-Type : text/xml;charset=UTF-8
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<element/>
<element/>
</soapenv:Header>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope>
---------------- Response --------------------------
Response Headers: Date : Mon, 07 Apr 2014 10:48:34 GMT
#status# : HTTP/1.1 200
Content-Length : 793
Expires : Thu, 01 Jan 1970 00:00:00 GMT
Content-Type : text/xml; charset=UTF-8
Connection : close
Server : XXXXXXXXXXXX
Cache-Control : no-cache
Pragma : no-cache
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
...
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
If you prefer to save only request and response with no additional information you can take a look on this and this.
Hope this helps,

DropWizard HealthCheck Json Response

I'm using dropwizard 0.6.2 for my service. The healthcheck response from dropwizard returns plain text. And I found a question in stackoverflow which had an answer that says we can pass a ObjectMapper to a healthcheck. But I couldn't able to find a way to pass the ObjectMapper to the HealthCheck.
Is there a way to return the healthcheck response in JSON?
As of Dropwizard 0.7, the /healthcheck path returns a JSON response:
HTTP/1.1 200 OK
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 299
Content-Type: application/json
Date: Thu, 14 Aug 2014 07:55:29 GMT
{
"My custom HealthCheck":
{
"healthy": true,
"message": "your message here"
},
"deadlocks":
{
"healthy": true
},
"storage":
{
"healthy": true
}
}
The Dropwizard use the codehale HealthCheck class.
You can call Result.healthy() and passing for parameter your JSON string.
In the method that you call the healthcheck you can use:
Result.healthy("your json");

Cannot receive JSON exception message/content type on remote requests

I have a ASP.NET MVC3 application, which uses JSON to comunicate with a Flash UI.
I´m use an ActionFilterAttribute to handle JSON exceptions (from Handle JSON Exceptions Gracefully in ASP.NET MVC 2: http://www.dotnetcurry.com/ShowArticle.aspx?ID=496):
public class HandleJsonExceptionAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
if (filterContext.Exception != null)
{
filterContext.HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
filterContext.Result = new JsonResult()
{
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
Data = new
{
filterContext.Exception.Message,
}
};
filterContext.ExceptionHandled = true;
}
}
}
It´s works ok when executes on localhost, details from fiddler:
HTTP/1.1 500 Internal Server Error
Cache-Control: private
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNetMvc-Version: 3.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 11 Apr 2011 19:05:21 GMT
Content-Length: 34
{"Message":"No está autenticado"}
But, when executed from remote clients, on the LAN for example, I get the response in "Content-Type: text/html" instead "Content-Type: application/json;" and the content is a standard html error page:
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
HTTP/1.1 500 Internal Server Error
Cache-Control: private
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-AspNetMvc-Version: 3.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 11 Apr 2011 19:07:53 GMT
Content-Length: 1208
What or where I need to configure something to get the JSON response on remote requests?
I need the flash UI receive a http 500 error, but with the json message instead the html.
Looking at the article the javascript only seems to be wire up for local requests.
What you need is to be using jsonp. (json with padding). This will allow you to do proper cross domain request returning a json object.
Further info can be found here and here.
I had a same problem, I solved with this code in web.config
<httpErrors existingResponse="PassTrough"></httpErrors>