org.apache.cxf.transport.http.HTTPException: HTTP response '415 - http

I am trying to call an external webservice running outside my machine and i have written the rout logic using camel framework
Routing Code:
from("direct:test1").process(new Processor() {
#Override
public void process(Exchange arg0) throws Exception {
arg0.getOut().setBody("testmessage");
}
}).to("cxf://http://localhost:8085/FinEdge-General/xrmServices/2011/Organization.svc?serviceClass=com.hcl.flsl.integration.msdn.crmwcf.IOrganizationService&defaultOperationName=Retrieve")
But when i execute the program i am getting the below error.
Error
org.apache.cxf.transport.http.HTTPException: HTTP response '415:
Cannot process the message because the content type 'text/xml;
charset=UTF-8' was not the expected type 'application/soap+xml;
charset=utf-8'.' when communicating with
\\http://localhost:port/FinEdge-General/xrmServices/2011/Organization.svc
Note: Webservice is developed in .NET(WCF) and SOAP 1.2.

It looks like the CXF is sending the message with SOAP 1.1, you need to let it switch to SOAP 1.2 by apply the WSDL file as the serviceClass you use is not has that information.
BTW, you can find difference between the SOAP 1.1 message and SOAP 1.2 message here.

As #Willem Jiang mentioned, you have to change the SOAP version to 1.2 . I do it programmatically:
service = Service.create("your service name");
service.addPort("your port", SOAPBinding.SOAP12HTTP_BINDING, "your url");

Related

Grpc integration with spring camel web app

I have a web service built on spring-camel. I am trying to integrate the grpc server using grpc-spring-boot-starter. My implementation of grpc service is as below.
#GrpcService
public class GreetingServiceImpl extends GreetingServiceGrpc.GreetingServiceImplBase {
#Override
public void processGrpcRequest(GreetingRequest request, StreamObserver<GreetingResponse> responseObserver) {
String receivedMessage = request.getRequest();
GreetingResponse response = GreetingResponse.newBuilder()
.setResponse("Your message received " + receivedMessage).build();
responseObserver.onNext(response);
responseObserver.onCompleted();
}
}
I package my web service as a war and I find no error during deployement of the war file in my application server. However, when I try to communicate with my grpc server, I get the following error message.
Exception in thread "main" 15:18:01.363 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler - [id: 0x02a01ffb, L:/127.0.0.1:56000 - R:localhost/127.0.0.1:9089] INBOUND PING: ack=true bytes=1234
io.grpc.StatusRuntimeException: UNIMPLEMENTED: HTTP status code 404
invalid content-type: text/html
headers: Metadata(:status=404,content-type=text/html,date=Fri, 04 Mar 2022 09:48:01 GMT,content-length=74)
DATA-----------------------------
<html><head><title>Error</title></head><body>404 - Not Found</body></html>
at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:262)
at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:243)
at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:156)
at com.test.grpc.GreetingServiceGrpc$GreetingServiceBlockingStub.processGrpcRequest(GreetingServiceGrpc.java:156)
at com.test.grpc.GrpcClient.main(GrpcClient.java:16)
I have recreated the same issue with minimal setup and code is available here github . Please can anyone help on this. Thanks

How to invoke a SignalR Core hub method from Postman WebSocket

I have a SignalR Core 5.0 app that works in Visual Studio 2019. I will deploy the SignalR server to IIS but want to do some testing in Postman using the new WebSockets.
Taking one of my hub methods in my VS project, let's call it "SomeHubMethod" that returns some data, what is the proper syntax to invoke the hub method?
For instance, how would I translate this C# invoke for Postman WebSocket?
SomeHubMethod = The hub method
groupxyz = The name of the client originating the call to SignalR server, and so the response from the server should be sent to "groupxyz". Let's say the response is "Hello World!"
"1234" = Just some test data.
In my VS project...
private async void SendSomeHubMethod()
{
await connection.InvokeAsync("SomeHubMethod", "groupxyz", "1234");
}
Where the response would be received in my class...
connection.On<string>("TheHubResponse", (m) =>
{
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => Debug.WriteLine(m));
// Hello World!
});
My assembled request that I found in link below for Postman WebSocket...
{"arguments":["groupxyz", "1234"],"invocationId":"0","target":"SomeHubMethod","type":1}
On Send, Postman shows Connected but "Hello World!" is not returned from my hub.
I found this post but it is not detailed on invoke.
reference example
You can but it's kinda problematic, so let's start from beginning..
When you have your defined SignalR hub endpoint (ie. wss://localhost:5005/hub/notifications) then
Make a POST request to following URL (notice the https, not the wss): https://localhost:5005/hub/notifications/negotiate?negotiateVersion=1.
In answer you will receive following information:
{
"negotiateVersion": 1,
"connectionId": "zJ1cqyAe4FRyLCGMzzC0Fw",
"connectionToken": "HYunLu0j0IHdBY4NNrkm0g",
"availableTransports": [
{
"transport": "WebSockets",
"transferFormats": [
"Text",
"Binary"
]
},
{
"transport": "ServerSentEvents",
"transferFormats": [
"Text"
]
},
{
"transport": "LongPolling",
"transferFormats": [
"Text",
"Binary"
]
}
]
}
Get the connectionToken from the step above and copy it. Now open a websocket connection with your hub like following:
wss://localhost:5005/hub/notifications?id={connectionToken} where connectionToken is the token from previous step. The url should look like: wss://localhost:5005/hub/notifications?id=HYunLu0j0IHdBY4NNrkm0g.
Now hold something.. according to the Microsoft documentation (https://github.com/dotnet/aspnetcore/blob/main/src/SignalR/docs/specs/HubProtocol.md#overview) we need to send a handshake request with following informations:
{
"protocol": "json",
"version": 1
}
It's hard to achieve by plain text because it needs to ends with a 0xE1 ASCII character, so we need to convert the handshake request with that character to base64 and send it. I did it for you and this string is:
eyJwcm90b2NvbCI6Impzb24iLCAidmVyc2lvbiI6MX0e
Now when we have all these info, let's deep dive into Postman:
Connect to the endpoint:
Just send a request with string I pasted above to this URL with content-type: Binary using Base64.
As you can see, we are receiving message {"type": 6} what means we are connected to the Hub and it's pinging us.
You can now send/receive any messages from your hub:
Now you can change the content-type to JSON and invoke your hub endpoints.
How to invoke a SignalR Core hub method from Postman WebSocket
Short answer, you can't.
Long answer, SignalR is a protocol that requires certain ceremony to start sending and receiving messages. For example, you need an ID in the query string that is generated by the server. Then you need to send the handshake request over the transport before you can start making invocations.

Custom Webhook Receiver in .Net core 2.1

I'm trying to create webhooks receiver for bigcommerce webhooks.
[HttpPost("customer_update")]
public void GetCustomerUpdateHook()
{
d_logger.Information("Process Webhook reply Web Response Hit");
}
my function is getting hit without any issues. But I don't know how to access the receiving data. I'm not sure how to use WebHookHandler.
framework => .Net core 2.1
controller => API Controller
I was able to receive the data, without using webhook handler or receiver. I just created a "POST" method in my controller by getting data from request body.
[HttpPost("customer_update")]
public void GetCustomerUpdateHook([FromBody] WebhookResponse p_data)
{
d_logger.Information("Process Webhook reply Web Response Hit");
var dataAsString = Newtonsoft.Json.JsonConvert.SerializeObject(p_data);
d_logger.Information("Response ==> {#data}", dataAsString);
}
But WebhookResponse class must match the data you are getting. for sender authentication, I added custom headers in Bigcommerce webhooks registration.

Spring mvc and websockets using STOMP jackson issue

I have been able to get websockets working with my application using sock.js stompjs and spring 4. However I'm having jackson mapping issues when I try to send a json object and use #validated. The jackson error is:
Could not read JSON: can not deserialize instance of com.... out of START_ARRAY token
Here is the server side code:
#MessageMapping("/notify/{id}")
#SendTo("/subscription/{id}")
#ResponseBody
public SimpleDemoObject add(#Payload #Validated ReqObject req, #DestinationVariable("id") Long id, Errors errors)
And the client side:
socket.stomp.send( _contextPath + "/notify/" + id, {"content-type": "application/json"}, data);
I was previously trying to use #RequestBody but I believe #Payload is the correct way here?
I can get it to work if I remove #Payload and #Validated but I would like to use spring validation on my request object. Any tips on what I'm doing wrong?

Customize HTTP codes and error message in JBoss AS 7

can anyone tell me how i can customize http codes and reasonphrase in JBoss AS 7?
basically i have a REST webservice that returns a nonstandard status code '499' with reasonphrase 'app error'
In standalone.xml, I set the org.apache.coyote.Constants.USE_CUSTOM_STATUS_MSG_IN_HEADER to true under systemproperties, but AS still overrides the HTTP error message.
There seems to be a mistake in JBoss documentation, the correct property name is:
org.apache.coyote.USE_CUSTOM_STATUS_MSG_IN_HEADER
So in the standalone you should have something like this:
<system-properties>
<property name="org.apache.coyote.USE_CUSTOM_STATUS_MSG_IN_HEADER" value="true"/>
</system-properties>
I assume that the REST service is interpretted using RestEasy.
That provides a nice feature of injecting a HTTP response object using #Context:
The #Context annotation allows you to inject instances of javax.ws.rs.core.HttpHeaders, javax.ws.rs.core.UriInfo, javax.ws.rs.core.Request, javax.servlet.HttpServletRequest, javax.servlet.HttpServletResponse, javax.servlet.ServletConfig, javax.servlet.ServletContext, and javax.ws.rs.core.SecurityContext objects.
#Path("/")
public class MyService {
#Context org.jboss.resteasy.spi.HttpResponse response;
#GET #Path("/") public void myMethod(){
response.sendError(499, "The file was censored by NSA.")
}
}
But maybe you should rather consider using a proprietary HTTP header:
response.getOutputHeaders().putSingle("X-MyApp-Error",
"499 Our server is down and admin is on holiday. MaƱana.");

Resources