I am hitting a multipart API which is working fine in all 2XX and 4XX cases except 401s, it is not able to map to ClientResponse class and throws ClientHandlerException, this is how I am making the call:
ClientResponse response = client.resource(uri)
.accept("application/json")
.header("X-FORWARDED-FOR", "X.X.X.X")
.header("Authorization", authorization)
.type(MediaType.MULTIPART_FORM_DATA_TYPE)
.post(ClientResponse.class, part);
athorization: Basic authorization header
part: FormDataMultiPart object
here are the error logs:
ERROR [2017-06-02 21:46:01,362] [ ] io.dropwizard.jersey.errors.LoggingExceptionMapper: Error handling a request: 91277b4e45d2df98
! com.sun.jersey.api.client.ClientHandlerException: java.io.IOException: Error writing to server
! at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:155)
! at com.sun.jersey.api.client.Client.handle(Client.java:652)
! at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
! at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
! at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570)
... some more application logs and then..
! Caused by: java.io.IOException: Error writing to server
! at sun.net.www.protocol.http.HttpURLConnection.writeRequests(HttpURLConnection.java:666)
! at sun.net.www.protocol.http.HttpURLConnection.writeRequests(HttpURLConnection.java:666)
! at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1534)
Jersey-client version: 1.18.1
Related
error": {
"code": "ExtensionError",
"message": "Operation: Read; Exception: [Status Code: 429; Reason: Resource 'OData_GetSubscription__UserMailbox_f' has reached limit of '250'. Please retry after '2/17/2022 3:53:22 PM']",
}
how can I resolve this error
Use Eclipse IDE in an attempt to create a java websocket client for an OpenHab project, thus using default Jetty websocket library. The OpenHab project intend to connect to a websocket endpoint requiring token authorization, send a request message and retrieve live/continuous measurements.
So, I have
public static final String SUBSCRIPTION_URL = "wss://api.tibber.com/v1-beta/gql/subscriptions";
Further, my WS open code:
public void open() throws Exception {
if (isConnected()) {
logger.warn("Open: connection is already open");
}
logger.warn("Connecting to: {}", SUBSCRIPTION_URL);
sslContextFactory = new SslContextFactory(true);
sslContextFactory.setTrustAll(true);
client = new WebSocketClient(sslContextFactory);
client.setMaxIdleTimeout(360 * 1000);
TibberWebSocketListener socket = new TibberWebSocketListener();
request = new ClientUpgradeRequest();
String token = new StringBuilder("Bearer ").append(configuration.getToken()).toString();
request.setHeader("Authorization", token);
request.setSubProtocols("graphql-subscriptions");
client.start();
client.connect(socket, new URI(SUBSCRIPTION_URL), request);
}
However, with this code it seems like I get connected, but end up with an IOException: Broken pipe after 1 minute. I get the same error both if I just connect without message / connect with send message.
13:59:15.987 [safeCall-1] WARN o.o.b.t.i.handler.TibberHandler:346 - Connecting to: wss://api.tibber.com/v1-beta/gql/subscriptions
13:59:16.390 [#1379116703-141] WARN o.o.b.t.i.handler.TibberHandler:385 - Connected to Server
14:00:16.430 [#1379116703-142] WARN o.o.b.t.i.handler.TibberHandler:392 - Closing a WebSocket due to Disconnected
14:00:16.434 [#1379116703-139] WARN o.o.b.t.i.handler.TibberHandler:399 - Error during websocket communication: Broken pipe
java.io.IOException: Broken pipe
at org.eclipse.jetty.io.ssl.SslConnection$DecryptedEndPoint.flush(SslConnection.java:928)
at org.eclipse.jetty.io.WriteFlusher.flush(WriteFlusher.java:422)
at org.eclipse.jetty.io.WriteFlusher.write(WriteFlusher.java:277)
at org.eclipse.jetty.io.AbstractEndPoint.write(AbstractEndPoint.java:381)
at org.eclipse.jetty.websocket.common.io.FrameFlusher.flush(FrameFlusher.java:264)
at org.eclipse.jetty.websocket.common.io.FrameFlusher.process(FrameFlusher.java:193)
at org.eclipse.jetty.util.IteratingCallback.processing(IteratingCallback.java:241)
at org.eclipse.jetty.util.IteratingCallback.iterate(IteratingCallback.java:223)
at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.outgoingFrame(AbstractWebSocketConnection.java:516)
at org.eclipse.jetty.websocket.client.io.WebSocketClientConnection.outgoingFrame(WebSocketClientConnection.java:72)
at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.close(AbstractWebSocketConnection.java:184)
at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.onFillable(AbstractWebSocketConnection.java:458)
at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.onFillable(AbstractWebSocketConnection.java:428)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
at org.eclipse.jetty.io.ssl.SslConnection$DecryptedEndPoint.onFillable(SslConnection.java:426)
at org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:320)
at org.eclipse.jetty.io.ssl.SslConnection$2.succeeded(SslConnection.java:158)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129)
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:367)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:782)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:918)
at java.lang.Thread.run(Thread.java:748)
14:00:16.435 [#1379116703-139] WARN o.o.b.t.i.handler.TibberHandler:392 - Closing a WebSocket due to Broken pipe
java.io.IOException: Broken pipe
That means the OS or network below Java (and Jetty) detected that the connection was closed.
"Broken Pipe" is actually fairly common, especially with mobile devices or wireless networking.
Not much Java or Jetty can do about it either, it happened outside of its control.
Exception Message: TF30063: You are not authorized to access http://Server Name/tfs/Collection Name. (type TeamFoundationServerUnauthorizedException) Exception Stack Trace: at Microsoft.TeamFoundation.Build.Hosting.BuildMachine.StartOperation.End(IAsyncResult result, HttpRouter& router, TfsMessageQueue& messageQueue, List`1& processHosts, MachineLifecycleActivity& traceActivity) at Microsoft.TeamFoundation.Build.Hosting.BuildMachine.EndStart(IAsyncResult result) at Microsoft.TeamFoundation.Build.Machine.WindowsService.EndStartMachine(IAsyncResult result) Inner Exception Details: Exception Message: The remote server returned an error: (401) Unauthorized. (type WebException)Status: ProtocolError Response Status Code: Unauthorized Response Status Message: Unauthorized Exception Stack Trace: at System.Net.HttpWebRequest.GetResponse() at Microsoft.TeamFoundation.Client.Channels.TfsHttpWebRequest.SendRequestAndGetResponse(HttpWebRequest webRequest, WebException& webException)
Try to add the port number of your sever, default is 8080:
http://ServerName:8080/tfs/CollectionName
I am using http header enricher component to pass the headers but I am not able to make a http request using http-client
I have a stream like below I am trying to make a http rest Post request and log it to the logger.I have a API-Key header for which I used this below header enricher module
https://github.com/spring-projects/spring-xd-modules/tree/master/header-enricher
stream create --name test24 --definition "http |header-enricher --headers={\"Api-Key\":\"'xyz'\"}| http-client --url='''http://xyz:/abc''' --httpMethod=POST | log " --deploy
http post --data '{"profileReferenceID":"pPPpe85Ht91e%2FpCvlkJMkniwiM%2BGvPjATkjc6HGqaJFS065txVj%2BhqDPsHz54KEm1RrCXftjNCSl2fpBKKKdrie9n6t9jetWhk29ELCmbw0%3D","templateURL":{"type":"type","href":"/content/notification/templates/EOSWEL?firstName=Abcd&userName=dddd&accountLast=2144&phone=1234&SvcgLOBCd=MS","method":"POST"}}'
> POST (text/plain;Charset=UTF-8) http://localhost:9000 {"profileReferenceID":"pPPpe85Ht91e%2FpCvlkJMkniwiM%2BGvPjATkjc6HGqaJFS065txVj%2BhqDPsHz54KEm1RrCXftjNCSl2fpBKKKdrie9n6t9jetWhk29ELCmbw0%3D","templateURL":{"type":"type","href":"/content/notification/templates/EOSWEL?firstName=Abcd&userName=dddd&accountLast=2144&phone=1234&SvcgLOBCd=MS","method":"POST"}}
2015-11-16T13:05:24-0600 1.2.1.RELEASE WARN xdbus.test24.1-1 retry.RejectAndDontRequeueRecoverer - Retries exhausted for message (Body:'{"profileReferenceID":"pPPpe85Ht91e%2FpCvlkJMkniwiM%2BGvPjATkjc6HGqaJFS065txVj%2BhqDPsHz54KEm1RrCXftjNCSl2fpBKKKdrie9n6t9jetWhk29ELCmbw0%3D","templateURL":{"type":"type","href":"/content/notification/templates/EOSWEL?firstName=Abcd&userName=dddd&accountLast=2144&phone=1234&SvcgLOBCd=MS","method":"POST"}}'MessageProperties [headers={requestMethod=POST, User-Agent=Java/1.8.0_60, Host=localhost:9000, Content-Length=305, contentType=text/plain, Api-Key=xyz, requestPath=/, originalContentType=text/plain;Charset=UTF-8}, timestamp=null, messageId=null, userId=null, appId=null, clusterId=null, type=null, correlationId=null, replyTo=null, contentType=text/plain, contentEncoding=null, contentLength=0, deliveryMode=null, expiration=null, priority=0, redelivered=false, receivedExchange=, receivedRoutingKey=xdbus.test24.1, deliveryTag=2, messageCount=0])
I am getting 403 forbidden i get this error from my webservice if my client api key is not passed which i was able to reproduce in post man .So I assume my API-Key header is not passed.
caused by: org.springframework.messaging.MessageHandlingException: HTTP request execution failed for URI [http://xyx/abc]; nested exception is org.springframework.web.client.HttpClientErrorException: 403 Forbidden
at org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler.handleRequestMessage(HttpRequestExecutingMessageHandler.java:410) ~[spring-integration-http-4.1.6.RELEASE.jar:na]
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:99) ~[spring-integration-core-4.1.6.RELEASE.jar:na]
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78) ~[spring-integration-core-4.1.6.RELEASE.jar:na]
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116) ~[spring-integration-core-4.1.6.RELEASE.jar:na]
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:101) ~[spring-integration-core-4.1.6.RELEASE.jar:na]
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97) ~[spring-integration-core-4.1.6.RELEASE.jar:na]
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77) ~[spring-integration-core-4.1.6.RELEASE.jar:na]
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:287) ~[spring-integration-core-4.1.6.RELEASE.jar:na]
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:245) ~[spring-integration-core-4.1.6.RELEASE.jar:na]
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115) ~[spring-messaging-4.1.7.RELEASE.jar:4.1.7.RELEASE]
You should add your Api-Key header to be mapped to the HTTP request header:
http-client --url='''http://xyz:/abc''' --httpMethod=POST --mappedRequestHeaders=HTTP_REQUEST_HEADERS,Api-Key
mappedRequestHeaders
request message header names to be propagated to/from the adpater/gateway (String, default: HTTP_REQUEST_HEADERS)
Where HTTP_REQUEST_HEADERS is a set of only standard HTTP headers which are appropriate for request.
http://docs.spring.io/spring-xd/docs/current/reference/html/#http-client
I have a Grails application that makes HTTP requests to a back end server for it's data. That server can be taken down for maintenance, and when that happens it will return a "site down" message to the Grails app in the HTTP response. The Grails app is detecting this and throws a custom SiteDownException. In URLMappings.groovy this is then directed to a specific error page.
This works well apart from for AJAX requests. What seems to happen is that the "site down" URL mapping is triggered (as expected) followed by the catch all '500' mapping.
URLMappings.groovy
"500"(controller: "error", action: "siteDown", exception: SiteDownException)
"500"(controller: "error", action: "error500")
ErrorController.groovy
def siteDown() {
println ">>>> site down <<<<"
}
def error500() {
println ">>>> 500 <<<<"
}
The error is thrown using
throw new SiteDownException()
For regular requests the stacktrace shows...
[11/11/13 16:52:50.945 error] SiteDownException occurred when processing request: [POST] /portal/contact/detail - parameters:
fileKeyIdentifier:
mode: add
Stacktrace follows: [org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver http-bio-8080-exec-6]
com.ui.exceptions.SiteDownException
at com.ui.backend.Backend$$EOMu30qx.getResponse(Backend.groovy:118)
at com.ui.backend.Backend$$EOMu30qx.getResponseAsDomainObject(Backend.groovy:41)
at com.ui.contact.ContactService.detail(ContactService.groovy:166)
at com.ui.contact.ContactController.detail(ContactController.groovy:87)
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
>>>> site down <<<<
Spot on, but for AJAX requests...
[11/11/13 16:54:09.380 error] SiteDownException occurred when processing request: [POST] /portal/contact/searchBody
Stacktrace follows: [org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver http-bio-8080-exec-7]
com.ui.exceptions.SiteDownException
at com.ui.backend.Backend$$EOMu30qx.getResponse(Backend.groovy:118)
at com.ui.backend.Backend$$EOMu30qx.getResponseAsDomainObject(Backend.groovy:41)
at com.ui.contact.ContactService.searchBody(ContactService.groovy:55)
at com.ui.contact.ContactController.searchBody(ContactController.groovy:23)
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
>>>> site down <<<<
>>>> 500 <<<<
The last bit is key - it displays the "site down" message from the siteDown action, and "500" from the catch all error500 action.
Can anyone help explain why are both mappings being called for AJAX errors? Thanks
I've found the problem. I had an error trap in the jQuery AJAX wrapper:
error: function(XMLHttpRequest,textStatus,errorThrown){
window.location.href = config.contextPath + '/error/error500'; // Error - show the 500 error page
}
So the SiteDownException was correctly firing the SiteDown mapping, then the AJAX error handler was firing error500 mapping.