Camel ReST Proxy route in ServiceMix fails for Base64 uploads - rest

I have deployed on SMX the following route that proxies all ReST request to the real ReST service provider (Tomcat). All ReST calls to SMX routed successfully however a saveDocument service that uploads PDF files fail.
public void configure() throws Exception {
from("jetty:http://{{smx.host}}:{{smx.rest-proxy-port}}/{{smx.context}}matchOnUriPrefix=true")
.log("ReST call received (Java DSL)")
.to("jetty:http://{{real-server-address}}:{{real-ws-port}}/{{context}}?bridgeEndpoint=true&throwExceptionOnFailure=false")
.log("Rest call proxied (Java DSL)");
}
The following exception is logged in servicemix.log.
19:53:57,065 | WARN | HttpClient-137 | HttpExchange | 111 - org.eclipse.jetty.util - 7.5.4.v20111024 | EXCEPTION JettyContentExchange#188af650=POST//real-server-address...:8080/contextpath.../saveDocument#SENDING(3ms)->
EXCEPTED(0ms)sent=3ms java.lang.IndexOutOfBoundsException
Do I have to perform some additional processing on the base64 before redirect the call to the real ReST service?
UPDATE on my previous post.
This seems to work when I use txt file but fails for pdf or doc.
UPDATE 2: It also fails when txt size exceeds 7KB.
Is it possible to set camel jetty to accept big size files?

This can be solved if Multipart WS is used.
I have implemented a Multipart CXF ReST file upload service for testing the route in case of a multipart WS.
The following route works OK for multipart:
from("jetty:http://.../?matchOnUriPrefix=true&enableMultipartFilter=false")
.noStreamCaching()
.log("Service Proxied")
.to("jetty:http://...:../?bridgeEndpoint=true&throwExceptionOnFailure=false");
Still cannot find what is going wrong with the first WS.
The issue is tracked here also.

Related

Remove X-ORACLE-DMS-ECID and X-ORACLE-DMS-RID response headers

I have some JAX-RS services deployed in WebLogic 12.2.1. When any service send a response, WebLogic will add the following response headers:
X-ORACLE-DMS-ECID
X-ORACLE-DMS-RID
How do I remove these two response headers?
This can be done with the following JVM properties :
-Doracle.dms.context=OFF
-Dweblogic.diagnostics.context.DisableDMSHTTPAlways=true
But, removing these headers is not supported by Oracle when using FusionMiddleware because some OFMW components should not work properly any longer.

Swagger results with `TypeError: Failed to fetch` for .net core RedirectResult

I have .net core WebApi application setup with swagger. An endpoint that responses with RedirectResult is not handled by swagger ui and shown up as Undocumented: TypeError: Failed to fetch
The redirect result itself contains a SAS url to Azure Storage Blob file.
I've tried to call this endpoint with SoapUI and Postman and the actual file appeared in response with application/octet-stream content type
The endpoint is built in format
Task<IActionResult> DownloadDocument([FromRoute] Guid id)
{
...
return Redirect(blobSasUri)
}
There is support for that or even some workaround or I've missed something?

How can i get failed http request details in jmeter via mail?

I am trying to send the mail through jmeter for failed http request, I want to know the sampler details like name of http request?
I have added if controller to check the assertion of previously running request sand send a mail if it fails.It gives me error message
"Message from Jmeter thread # Test failed: code expected to match /200/"
But I want to know the name of http request which has been failed so i can know specifically which request is failing?
You can use JSR223 PreProcessor to get the previous sampler details using the following code:
def sampler = ctx.getPreviousSampler()
Example usage:
def previousSamplerName = ctx.getPreviousSampler().getName()
log.info("Failed sampler name: " + previousSamplerName)
vars.put("SamplerName", previousSamplerName)
Demo:
If everything goes fine you will be able to access previous sampler name as ${SamplerName} in the SMTP Request sampler
ctx is a shorthand to JMeterContext class instance, see the JavaDoc for available methods and fields
vars is a shorthand to JMeterVariables class instance, it provides read/write access to all JMeter Variables in scope.
Also check out Groovy Is the New Black guide to get familiarized with using Groovy in JMeter tests.

Cross domain REST/Jersey web services with CORS

I want to make Cross domain REST web services with CORS(Cross-Origin Resource Sharing). I am using Jersey Libraries for making services.
I need to know
What code/configuration changes i need to do from server side perspective?
How to invoke this services from HTML5/js.
Thanks
All the information for your server side configuration can be found at enable-cors.org.
There is no need to change any code clientside, but I would recommend checking the Browsers capability for CORS before using it. Testing code can be found, e.g., here.
I have chosen to solve this problem by providing the server CORS response at the Jersey container level. This might offer more convenience for some applications since it can apply for all responses from the container without modification to the resource handling code.
First one has to create a container response filter that will inject the appropriate header(s). For example for a container that indicates Access-Control-Allow-Origin:* for any response:
class CORSFilter implements ContainerResponseFilter {
#Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
response.getHttpHeaders().add("Access-Control-Allow-Origin", "*");
return response;
}
}
Then the filter must be added be added to the Jersey response filter chain. This can be done through the resource config in use for the application.
...
DefaultResourceConfig rc = new ClasspathResourceConfig();
rc.getContainerResponseFilters().add(new CORSFilter());
// now create a simple lightweight server using this resource config.
HttpServer server = HttpServerFactory.create(uri,rc);
...
Steps which I used to enable CORS Filter in my Jersey based embedded Jetty application.
jetty-servlet version - 2.12
Added cors-filter dependency in pom
<dependency>
<groupId>com.thetransactioncompany</groupId>
<artifactId>cors-filter</artifactId>
<version>2.1.2</version>
</dependency>
Add the corsfilter to ServletContextHandler of your application.
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.addFilter(CORSFilter.class, "/*", EnumSet.of(DispatcherType.INCLUDE,DispatcherType.REQUEST));
server.setHandler(context);//set handle to your server

Downloading file by WebClient Exception

I have a problem downloading particular file types by WebClient. So there are no problems with usual types - mp3, doc and others, but when I rename file extension to config it returns me:
InnerException = {System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
when I'm trying to access this file in browser (http://localhost:3182/Silverlight.config) - it's a usual xml file within - server returns me following error page:
Server Error in '/' Application.
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.config' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /Silverlight.config
So I suppose this hapens because of some server configuration, which blocks files of unknown type.
downloading code is simple:
WebClient webClient = new WebClient();
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
webClient.OpenReadAsync(new Uri("../Silverlight.config", UriKind.RelativeOrAbsolute));
completted eventhandler omitted for simplicity.
I'm not sure this is possible.
The .config extension is handled by the ASP.NET engine, for security reasons (sensitive data like connection strings need to be kept safe and hidden from unauthorized viewers).
This means that visitors cannot view your web.config file's content by simply entering "www.example.com/web.config" into their browser's adress bar.
EDIT : actually you can but I don't recommand it. If you really need to do it, you have to remove the mapping between the .config extension and ASP.NET ISAPI filter in IIS.