RuntimeException could not be mapped to a response, re-throwing to the HTTP container com.hp.hpl.jena.update.UpdateException - response

i have a REST service for sending data to a triplestore:
VirtGraph virtGraph = new VirtGraph ("jdbc:virtuoso://localhost:1111", "demo", "demo");
Model virtModel = new VirtModel(virtGraph);
VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(str, virtGraph);
vur.exec();
virtGraph.close();
and although the data are stored the response i get is:
com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
com.hp.hpl.jena.update.UpdateException: Convert results are FAILED.:
at virtuoso.jena.driver.VirtuosoUpdateRequest.exec(VirtuosoUpdateRequest.java:72)
All the libraries needed are in the web folder of the project. Any ideas please?

Related

502 Bad Gateway on POST/PUT Web API Calls from ASP.NET Core MVC

I'm getting strange errors in ASP.NET Core when calling Web API that I have created for the application. GET requests go through fine and return all of the data that they should, but my POST/PUT commands all return a 502, specifically from the MVC application. I can call the API's from Postman and get a proper response and the object is created in the database.
502 - Web server received an invalid response while acting as a
gateway or proxy server. There is a problem with the page you are
looking for, and it cannot be displayed. When the Web server (while
acting as a gateway or proxy) contacted the upstream content server,
it received an invalid response from the content server.
I am impersonating an Integrated Windows Login with the following code for all web requests to the API:
async Task Action()
{
response = await _service.CreateIncident(model);
}
await WindowsIdentity.RunImpersonated(identity.AccessToken, Action);
CreateIncident(model):
using (var client = new HttpClient(new HttpClientHandler { UseDefaultCredentials = true }))
{
var newIncident = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
var response = await client.PostAsync(hostUri, newIncident);
return response;
}
There is also one GET Request that I make through Ajax to get an incremented ID to display to the user before they create their new Incident that returns a 502 Bad Gateway as well. Is this an IIS Setting that is incorrect?
If you use WindowsIdentity.RunImpersonated and an asynchronous function, it will not work. You must be synchronous when doing non-GET requests. I have updated my GitHub issue, I'm hoping to get this bug addressed. If you are a future visitor to this topic, you can see where this ended up here.
I think it also depends on the size of the data. Smaller packages work, larger ones don't.

Error passing InputStream through multiple Jersey-Client requests

I’m using jersey-client v1.18.1
I need to make 2 sequential requests where the 1st request has an InputStream and then must pass that same InputStream along to the 2nd request (eg. sort of like a proxy). The 2nd request will then write the InputStream to disk and send back to the 1st request the fully qualified path to the location on disk where the 2nd request wrote the file.
The following code-snippet outlines what I have tried, but cannot get to work properly. I’m currently receiving the error:
"com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class org.seleniumhq.jetty9.server.HttpInputOverHTTP, and MIME media type, application/octet-stream, was not found”
I believe I have all the proper Maven dependencies in my project for the MIME and message body writers.
1st Request originating on Host 1 going to Host 2
Client client = Client.create();
client.resource(uri_for_request_1)
client.path(“request_1_servlet");
client.queryParam(“uri_for_request_2", uri_for_request_2);
client.queryParam("targetFilename", targetFilename);
ClientResponse response = client.accept(MediaType.APPLICATION_JSON).entity(inputStream).post(ClientResponse.class);
2nd Request originating on Host 2 going to Host 3
Client client = Client.create();
client.resource(request.getParamater(“uri_for_request_2"))
client.path(“request_2_servlet");
client.queryParam("targetFilename", request.getParamater(“targetFilename");
ClientResponse response = client.accept(MediaType.APPLICATION_JSON).entity(request.getInputStream()).post(ClientResponse.class);
Host 3
Writes InputStream to file and sends back to Host 2 fully qualified path.
Host 2
Sends back to Host 1 fully qualified path.
Variations I’ve tried on post calls:
client.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_OCTET_STREAM).entity(inputStream).post(ClientResponse.class);
client.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_OCTET_STREAM).post(ClientResponse.class, inputStream);
I can confirm the 1st request is being made on Host 1 and reaches Host 2. It is the 2nd request on Host 2 that fails during the post() call.

Event log warning "URL for this request exceeds the configured maxUrlLength" despite request succeeding

On my IIS server, I'm getting a warning message logged in the server's Application Event Log on a particular variety of incoming HTTP request with a long URL. Despite the warning message, ASP.NET MVC does correctly handle the request and return the expected response back to the client.
The event log message warning message includes the following text:
Event code: 3005
Event message: An unhandled exception has occurred.
...
Process information:
Process name: w3wp.exe
....
Exception information:
Exception type: HttpException
Exception message: The length of the URL for this request exceeds the configured maxUrlLength value.
at System.Web.HttpRequest.ValidateInputIfRequiredByConfig()
at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context)
Additional property/value information for the event log warning message:
Source: ASP.NET 4.0.30319.0
Event ID: 1309
Again, in this case the incoming HTTP request is ultimately succeeding, so unlike similar questions my question here is not how to successfully increase the max URL length for incoming requests on my server.
Rather, my question is: Given that my request is succeeding, can I prevent this (apparently spurious) warning message from being logged to my Application event log (adding noise to the log that may obscure other, "real" warnings)?
More details
This behavior (long HTTP request succeeds; warning message written to application event log) is reproducible both on my local workstation PC running Windows 10 and IIS 10, and on my production server running Windows Server 2008 R2 and IIS 7.5.
The project is being built with target framework: .NET Framework 4.5.1. (Update: The error still reproduces after rebuilding my project to target .NET Framework 4.6.1.)
The URLs that trigger the warning message to be written are long URLs (approximately 500 characters in length) of the form (for example):
https://myserver.example.com:443/api/MyDataRequestRoute/1862241,2146171,1998613,1916341,2150391,2067889,749865,2167130,1861707,1914448,668472,2170269,2162087,2024193,1857969,1869304,2162128,1980539,992479,1347745,1958431,282062,1925128,2147391,2153550,1187318,2039442,441327,1298384,2153556,1526985,1893085,2144727,2144288,1582412,2142540,2170281,1183488,1865249,1348332,1322007,2170282,2170283,1750061,2098502,1915955,905164,1353083,2099151,1347806,2160403,2147200,1191371,1347921,1909967,2017687,2012831
The URL is mapped to an ASP.NET MVC Controller method of the form:
[HttpGet]
[Route("MyDataRequestRoute/{commaSeparatedPropertyIDs}", Name = "MyDataRequestRoute")]
public HttpResponseMessage MyDataRequestRoute(string csv)
{
string xmlResult = // Code to build result based on the specified csv...
return new HttpResponseMessage()
{
Content = new StringContent(xmlResult, Encoding.UTF8, "text/xml")
};
}
In order to get these long URLs working, I previously made a few configuration changes to my application and server, specifically:
Set an UrlSegmentMaxLength value of 32766 in the server's Windows registry, per this answer.
Set attributes of the httpRuntime element in my "Api" project's web.config file:
<httpRuntime targetFramework="4.5" maxRequestLength="131072" maxUrlLength="32766" maxQueryStringLength="32766" />
Set the maxAllowedContentLength attribute of the requestLimits element in the same web.config file:
<requestLimits maxAllowedContentLength="134217728" />

Bad request on ProcessUserAuthorization (DotNetOpenAuth 4.2.2.13055)

I'm trying to upgrade the DotNetOpenAuth verson to 4.2.2.13055, in the Google dotnet client library.
So I downloaded the latest dlls - DotNetOpenAuth.Core, DotNetOpenAuth.OAuth2, etc. (we still don't work with NuGet).
I made a small change (changed the way I construct NativeApplcationClient with client_id and client_secret) to support the new version.
Then, I tried to run a sample we have in our samples repository (e.g. https://code.google.com/p/google-api-dotnet-client/source/browse/Tasks.SimpleOAuth2/Program.cs?repo=samples), and I got a bad request error, as following:
DotNetOpenAuth.Messaging.ProtocolException: Error occurred while sending a direct message or getting the response. --->
System.Net.WebException: The remote server returned an error: (400) Bad Request.
at System.Net.HttpWebRequest.GetResponse()
at DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request, DirectWebRequestOptions opt
ions)
--- End of inner exception stack trace ---
at DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request, DirectWebRequestOptions opt
ions)
at DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request)
at DotNetOpenAuth.Messaging.Channel.GetDirectResponse(HttpWebRequest webRequest)
at DotNetOpenAuth.Messaging.Channel.RequestCore(IDirectedProtocolMessage request)
at DotNetOpenAuth.Messaging.Channel.Request(IDirectedProtocolMessage requestMessage)
at DotNetOpenAuth.OAuth2.ClientBase.UpdateAuthorizationWithResponse(IAuthorizationState authorizationState, EndUserAu
thorizationSuccessAuthCodeResponse authorizationSuccess)
at DotNetOpenAuth.OAuth2.UserAgentClient.ProcessUserAuthorization(IAuthorizationState authorizationState, IDirectedPr
otocolMessage response)
at DotNetOpenAuth.OAuth2.UserAgentClient.ProcessUserAuthorization(Uri actualRedirectUrl, IAuthorizationState authoriz
ationState)
at Google.Apis.Authentication.OAuth2.DotNetOpenAuth.NativeApplicationClient.ProcessUserAuthorization(String authCode,
IAuthorizationState authorizationState) in c:\code.google.com\google-api-dotnet-client\default_oauth2\Src\GoogleApis.Au
thentication.OAuth2\DotNetOpenAuth\NativeApplicationClient.cs:line 102
at Google.Apis.Samples.TasksOAuth2.Program.GetAuthorization(NativeApplicationClient arg) in c:\code.google.com\google
-api-dotnet-client\samples_oauth2\Tasks.SimpleOAuth2\Program.cs:line 73
at Google.Apis.Authentication.OAuth2.OAuth2Authenticator`1.LoadAccessToken() in c:\code.google.com\google-api-dotnet-
client\default_oauth2\Src\GoogleApis.Authentication.OAuth2\OAuth2Authenticator.cs:line 124
I noticed also that there is a different in the second request (in exchanging the code with a token): Authorization header was added to the request, and the body was missing my client_id and client_secret.
Similar code worked on old version - 4.0.0.11165,
Am I missing something?
I wonder if the problem is that the newer DNOA version supports putting client credentials in the HTTP header by default. If you create your Client class, passing in a different client credential provider into the constructor, it may work for you.
To change the behavior from using the HTTP Authorization header back to passing client credentials in the POST entity, instantiate your ClientBase-derived class passing in this as a parameter to the constructor:
ClientCredentialApplicator.PostParameter(clientSecret)

How to capture http POST requests with browsermob-proxy and selenium

Hello trying to capture the actual POST data in an HTTP POST request using browsermob proxy + selenium test framework. So basically i'm running an automated test using selenium and I want to capture the key/value pairs and the actual POST data of a HTTP POST request during the test. Using the following logic I can only capture the key/value pairs of the POST header but not the actual POST data (aka the form field id values). Is there a way to actually capture the POSTDATA (like sniffing applications do such as tamper/live headers in firefox)?
ProxyServer proxyServer = null;
proxyServer = new ProxyServer(9101);
proxyServer.start();
proxyServer.setCaptureContent(true);
proxyServer.setCaptureHeaders(true);
Proxy proxy = proxyServer.seleniumProxy();
proxy.setHttpProxy("localhost:9101");
//selenium test config code, omitted for brevity
proxyServer.addRequestInterceptor(new HttpRequestInterceptor() {
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
Header[] headers = request.getAllHeaders();
System.out.println("\nRequest Headers\n\n");
for(Header h : headers) {
System.out.println("Key: " + h.getName() + " | Value: " + h.getValue());
}
}
});
An alternate way I read about but could not get to work was to configure the following flags in the browsermob proxy server to true:
proxyServer.setCaptureContent(true);
proxyServer.setCaptureHeaders(true);
Then output the actual HAR file:
Har har = proxyServer.getHar();
Date date = new Date();
har.writeTo(new File("c:\\tmp\\har_" + date.getTime()));
To see the key/value pairs, POST Data, and actual content of the response... but when I parse the HAR file... I only see the key/value pairs of the POST header again... no POST data... no response content. I am only interested in the actual POST data though.
I also had same problem. As a solution, I captured all the data, converted the HAR file into JSON, and then filtered out only POST requests from the JSON file.

Resources