Azure App Service WebJob httpclient getasync request returning 500 internal server error - azure-webjobs

I have a webjob that is triggered by storage queued and makes a web api call when a new message is received. I tested the get request in fiddler and it works, but gets 500 internal server error when the request is made via httpclient getasync within the webjob. Can a call to a web api be made within a webjob?

I tested the get request in fiddler and it works, but gets 500 internal server error when the request is made via httpclient getasync within the webjob.
As far as I know, the 500 internal server error is thrown by your Web API server-side. Please try to wrap your code with try-catch in your Web API application and find the detailed error.
Can a call to a web api be made within a webjob?
You could send http requests within the WebJob. Here is my code sample which could work well both on my side and Azure, you could refer to it.
Functions.cs
// This function will get triggered/executed when a new message is written
// on an Azure Queue called queue.
public static async void ProcessQueueMessage([QueueTrigger("queue")] string message, TextWriter log)
{
log.WriteLine(message);
string requestUrl = "https://bruce-chen-001.azurewebsites.net/api/values";
HttpClient client = new HttpClient();
var response = await client.GetAsync(requestUrl);
log.WriteLine("responseļ¼š{0}", await response.Content.ReadAsStringAsync());
}
Result
responseļ¼š["value1","value2"]

Related

Postman Mock Server Call Log empty

I make a request to my mock server using Postman and receive the expected result. Then I check the Mock Server Call Log and it is empty. I just see a message "No mock server calls yet".
I tried making a request from my own application and again I receive a successful response from the mock server. The Server Call Log is still empty.
Looks like the logs are just shown with a delay.

Why does grails websockets connection fail but continue to receive messages that have been subscribed to in the browser while using an AWS ELB?

Using Grails 2.5.5 with the spring-websockets plugin 1.3.1 and tomcat 8.0.37.
While using an AWS Elastic Load Balancer, the following error is shown in the Javascript console when loading the application in the browser
WebSocket connection to 'ws://...s.com/Application/stomp/059/uyqk9cdn/websocket' failed: Error during WebSocket handshake: Unexpected response code: 400
From research it has been found that the ELB doesn't support websockets and proxying within the ELB, a third party load balancer or potentially using a new Application Load Balancer (the applications are not in a VPC so this is not an easy solution) might be required.
However, after the error, the following logging is received:
Web Socket Opened...
>>> CONNECT
accept-version:1.1,1.0
heart-beat:10000,10000
<<< CONNECTED
version:1.1
heart-beat:0,0
user-name:admin
connected to server undefined
>>> SUBSCRIBE
id:sub-0
destination:/topic/someTopic
Messages are then received by the client fine when they are broadcast
<<< MESSAGE
destination:/topic/someTopic
content-type:application/json;charset=UTF-8
subscription:sub-0
message-id:xb71g__u-16
content-length:89
The code to initiate the websocket connection is
<r:require module="spring-websocket"/>
<r:script>
var socket = new SockJS("${createLink(uri: '/stomp')}");
var client = Stomp.over(socket);
client.connect({}, function () {
var topic = "/topic/digTicketUpdated";
console.log("Subscribing to -> " + topic);
client.subscribe(topic, function (message) {
console.log("Push Message Received From Server");
updateStatus(message.body);
});
});
</r:script>
This is taken from the grails-spring-websocket github page.
Is it possible to figure out if this is fallback that has kicked in, the websocket actually working or some other scenario. To summarise :
Is the websocket falling back to another protocol?
Is there any way to get rid of the 400 error?
Thanks to the suggestions in the comments, it was found that after the "Unexpected response code: 400" was thrown, SockJS attempted to use a long POST XHR request to emulate the web socket and it worked. This was viewable in the Network tab of Chrome Developer Tools as "xhr_streaming".
To prevent the 400 error showing in the development console, a configurable switch was implemented so web socket connections are not attempted when it is known they are not supported, such as on an AWS ELB. This was achieved by passing by removing "websocket" from the allowed protocols when instantiating SockJS :
var allowedProtocols = ['xdr-streaming', 'xhr-streaming', 'iframe-eventsource', 'iframe-htmlfile', 'xdr-polling', 'xhr-polling', 'iframe-xhr-polling', 'jsonp-polling']
var socket = new SockJS(uri, {}, {protocols_whitelist : allowedProtocols});
var client = Stomp.over(socket);

How are request response tracked in a application server

Look at this scenario in a massive webserver/application server
The user sends multiple requests that get processed async and call an webservice.
How is the request response cycle?
How does the application server know which packet of response goes to which request?
I know this is a very silly question, however i am not able to find any documentation on how this is handled?
How does the application server track the request and the response?

Setting up a HTTP Receiver in Tibco Businessworks for an existing Web Service

So currently I managed to reach an existant Web Service and use one of it's functions to alter a database.
However, the Web Service does not respond with a Soap Response, but with just the HTTP Respond Code 200, which I want to use to create a "Success!"-like notification.
Using BusinessWorks I was able to to connect the process with a HTTP Receiver in the Modeler-View, but it doesn't work and gives me the error message
"Process configuration error. The activity [HTTPReceiver] in the process [webservices.module.IWSContract] cannot have an input transition."
My goal is to catch the HTTP Response Code 200 from the Web Service, and optionally display it to the user.
As you mention you use TIBCO BW 6. this should be the "Invoke" activity instead of SOAPRequestreply (Basic Palette -> Invoke)
You need to use a SOAP Request-Reply activity to invoke the web service. Technically, the "HTTP 200" response won't be visible but you will get an empty output in case of a success:
You can then choose to return whatever success message to the user.

Apache CXF web service response re-routing on web service client gone detection

Working with Apache Camel for EIP, I have an Apache CXF Web Service Endpoint which when called, will put requests into an MQ queue. Requests in that MQ queue are processed asynchronously where, responses are then generated and placed into a response MQ queue. The Apache CXF Web Service collects a request's response from the response MQ queue which it then writes to the Exchange's out channel for the calling client to receive.
Is it possible to configure my web service so that it can detect if a client is still connected when it is trying to send the asynchronous response back to it? And when this detect occurs, to route the response to another Camel route?
A use case scenario would be for example where the client makes a call to the web service but disconnects after 5 seconds of not receiving a response from the web service. And later, when the web service processes the request and fails to send the response to the no longer connected client, it re-routes the response to, for example, an smtp route.
* UPDATE *
Having read various online documentation and forum posts, I have my service configured as follows:
<camelContext xmlns="http://camel.apache.org/schema/spring" handleFault="true">
<routeBuilder ref="aServiceRoute" />
</camelContext>
and in my AServiceRoute route, I have configured my route as follows:
#Override
public void configure() throws Exception {
onException(Exception.class).process(new Processor() {
public void process(Exchange exchange) throws Exception {
log.debug("caught Exception A!!!");
}});
from(cxfUri)
.onException(Exception.class).process(new Processor() {
public void process(Exchange exchange) throws Exception {
log.debug("caught Exception B!!!");
}}).end()
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
// do something..
}
})
.to(ExchangePattern.InOut, mqUri);
For my first test, I force an Exception throw in the process where the // do something.. comment is. When I run this test, I see the log "caught Exception A!!!" which is great.
For my second test, I basically run the test scenario I have described in this post. When I run this test, I see a cxf stacktrace logged:
=09-05-14 12:25:32 [WARN ] org.apache.cxf.phase.PhaseInterceptorChain - Interceptor for {http://camel.apache.org/cxf/jaxws/provider}DefaultPayloadProviderSEIService#{http://cxf.component.camel.apache.org/}invoke has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not send Message.
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)
but none of my route's onException() methods are called.
What am I missing? Do I need to place the onException() method somewhere else in service's route?
Thanks in advance, PM.
The Dead Letter Channel will offer the behaviour you need: https://camel.apache.org/dead-letter-channel.html