elasticsearch - Incorrect HTTP method for uri [/] and method [PUT], allowed: [DELETE, GET, HEAD] - elasticsearch

This is my JSON data.
"{\"athena\":{\"settings\":{\"index\":{\"max_ngram_diff\":\"49\",\"mapping\":{\"total_fields\":{\"limit\":\"3000\"},\"ignore_malformed\":\"true\"},\"refresh_interval\":\"30s\",\"number_of_shards\":\"1\",\"max_shingle_diff\":\"4\",\"max_result_window\":\"100000\",\"analysis\":{\"filter\":{\"searchkick_index_shingle\":{\"token_separator\":\"\",\"type\":\"shingle\"},\"analyzed_ngram\":{\"token_chars\":[\"letter\",\"digit\"],\"min_gram\":\"2\",\"type\":\"edge_ngram\",\"max_gram\":\"10\"},\"location_synonym_filter\":{\"type\":\"synonym\",\"synonyms\":[\"e=>east\",\"w=>west\",\"n=>north\",\"s=>south\",\"rd=>road\",\"st=>street\",\"av=>avenue\",\"pkwy=>parkway\",\"hwy=>highway\"]},\"searchkick_stemmer\":{\"type\":\"snowball\",\"language\":\"English\"}},\"char_filter\":{\"ampersand\":{\"type\":\"mapping\",\"mappings\":[\"&=> and \"]}},\"normalizer\":{\"lowercase_normalizer\":{\"filter\":[\"lowercase\"],\"type\":\"custom\"}},\"analyzer\":{\"searchkick_index\":{\"filter\":[\"lowercase\",\"asciifolding\",\"searchkick_index_shingle\",\"searchkick_stemmer\"],\"char_filter\":[\"ampersand\"],\"type\":\"custom\",\"tokenizer\":\"standard\"},\"autocomplete_analyzer\":{\"filter\":[\"lowercase\",\"location_synonym_filter\"],\"token_chars\":[\"letter\",\"digit\"],\"type\":\"custom\",\"stopwords\":\"_none_\",\"tokenizer\":\"standard\"}}},\"number_of_replicas\":\"0\"}}}}"
and I am running this command.
elasticdump --input=./athena-analyzer.json --output=http://localhost:9200 --type=analyzer
and i am getting this error.
{"error":"Incorrect HTTP method for uri [/] and method [PUT], allowed: [DELETE, GET, HEAD]","status":405}

Related

how to pass a parameter in the Header with multipartFormData

#PostMapping(value = "/uploadCV" , consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseEntity<?> uploadCV(#RequestHeader("token") String token,
#RequestParam("file") MultipartFile cvFile) throws Exception {
log.info(token + cvFile.getOriginalFilename()));
return curriculumService.addCurriculum(token, pdfFile);
}
If i use MediaType.MULTIPART_FORM_DATA_VALUE don't get the value "token" :
2022-11-11 16:13:28.040 WARN 7283 --- [nio-8080-exec-4] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.bind.MissingRequestHeaderException: Required request header 'token' for method parameter type String is not present]
If i use MediaType.MULTIPART_MIXED_VALUE don't get file:
org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
how can i do?
The code that you have written with MediaType.MULTIPART_FORM_DATA_VALUE is absolutely correct. It is very clear from error message what is the issue.
2022-11-11 16:13:28.040 WARN 7283 --- [nio-8080-exec-4] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.bind.MissingRequestHeaderException: Required request header 'token' for method parameter type String is not present]
Issue:
Code is expecting header name with key token should present in the request but it is not present.
Solution:
Please add header name with key token like this and try again.

Feign Client: How to log the server name which the request was sent to?

I am using a Feign Client to call a REST endpoint with success, and have logging turned on to FULL. This is helpfully shows me the request sent and the response received. However, I cannot see which server the request was sent to. It only shows me that it was POSTed to http://foo-service which is the name of the service, not the name of the server.
How can I log which server name this request was sent to?
This is what I see in the logs:
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] ---> POST http://foo-service/some-endoint HTTP/1.1
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] Accept: application/json
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] Content-Type: application/json
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] Content-Length: 15
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar]
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] {"name":"John"}
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] ---> END HTTP (15-byte body)
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] <--- HTTP/1.1 200 (8ms)
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] Transfer-Encoding: chunked
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] X-Application-Context: fooService:9006
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] Date: Tue, 10 Oct 2017 09:25:36 GMT
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] Content-Type: application/json;charset=UTF-8
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar]
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] {"result":"Hello John"}
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] <--- END HTTP (23-byte body)
To turn on logging, I declare this bean:
#Bean
public feign.Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
We are using spring-cloud-netflix-core:1.1.0.M4
You will need to provide your own Logger to achieve this. The default Logger is very simple and logs the host before the request is sent. When using Ribbon the information will be available with the Response. If you override the logAndRebufferResponse method, the response.url property will be the entire url submitted, including host name.
protected Response logAndRebufferResponse(
String configKey,
Level logLevel,
Response response,
long elapsedTime) throws IOException {
/* ask the response for the request and log the uri */
log(response.request.url());
}
Enable logging via logback and set log level of debug or these classes
<logger name="com.netflix.loadbalancer.BaseLoadBalancer" level="DEBUG"/>
<logger name="com.netflix.loadbalancer.LoadBalancerContext" level="DEBUG"/>
<logger name="com.netflix.loadbalancer.reactive.LoadBalancerCommand" level="DEBUG"/>
I can see where each request is going (server:port) and request failed on which server
DEBUG [ c.a.m.c.f.CommonProducerClient][72] - [CommonProducerClient#findAllEmployee] ---> GET http://COMMON-PRODUCER/allemployee HTTP/1.1
DEBUG [ c.n.loadbalancer.LoadBalancerContext][492] - COMMON-PRODUCER using LB returned Server: localhost:7001 for request http:///allemployee
DEBUG [ c.n.l.reactive.LoadBalancerCommand][314] - Got error java.net.ConnectException: Connection refused: connect when executed on server localhost:7001
DEBUG [ c.n.l.reactive.LoadBalancerCommand][314] - Got error java.net.ConnectException: Connection refused: connect when executed on server localhost:7001
DEBUG [ c.n.l.reactive.LoadBalancerCommand][314] - Got error java.net.ConnectException: Connection refused: connect when executed on server localhost:7001
DEBUG [ c.n.loadbalancer.LoadBalancerContext][492] - COMMON-PRODUCER using LB returned Server: localhost:7003 for request http:///allemployee
DEBUG [ c.a.m.c.f.CommonProducerClient][72] - [CommonProducerClient#findAllEmployee] <--- HTTP/1.1 200 (4010ms)
From Logs its clear, first request went to port 7001, connection refused there, second request goes to 7003, all good there.

Header Enricher for spring xd to call http-client t pass headers

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

PUT request returns HTTP 400 Bas Request in Spring Mvc - only occasionally

I have a strange issue using Spring mvc: while I'm trying to update one of my resources via PUT, it returns 400 Bad Request for the very same request - but only occasionally.
In Firebug, I use right click "resend" function, so assume all my PUT requests are completely the same.
I also set the log level to ALL for org.springframework.web to find out what's happening on the server side. In case of the response is 200 OK, everything seems fine:
2015-04-10 10:40:20,794 [http-8443-exec-12] TRACE servlet.DispatcherServlet:1048 - Bound request context to thread: SecurityContextHolderAwareRequestWrapper[ FirewalledRequest[ org.apache.catalina.connector.RequestFacade#321fa1b9]]
2015-04-10 10:40:20,795 [http-8443-exec-12] DEBUG servlet.DispatcherServlet:845 - DispatcherServlet with name 'springRestAPI' processing PUT request for [/rest/sites/25]
2015-04-10 10:40:20,796 [http-8443-exec-12] TRACE servlet.DispatcherServlet:1101 - Testing handler map [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#6c9ddcc4] in DispatcherServlet with name 'springRestAPI'
2015-04-10 10:40:20,796 [http-8443-exec-12] DEBUG annotation.RequestMappingHandlerMapping:297 - Looking up handler method for path /sites/25
2015-04-10 10:40:20,797 [http-8443-exec-12] TRACE annotation.RequestMappingHandlerMapping:335 - Found 1 matching mapping(s) for [/sites/25] : [{[/sites/{siteId}],methods=[PUT],params=[],headers=[],consumes=[],produces=[],custom=[]}]
2015-04-10 10:40:20,797 [http-8443-exec-12] DEBUG annotation.RequestMappingHandlerMapping:302 - Returning handler method [public void something.SiteController.updateSite(long,something.resources.UpdatedSiteResource,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)]
2015-04-10 10:40:20,797 [http-8443-exec-12] TRACE servlet.DispatcherServlet:1141 - Testing handler adapter [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#5ec2c20d]
2015-04-10 10:40:20,798 [http-8443-exec-12] DEBUG mvc.WebContentInterceptor:146 - Looking up cache seconds for [/sites/25]
2015-04-10 10:40:20,798 [http-8443-exec-12] DEBUG mvc.WebContentInterceptor:158 - Applying default cache seconds to [/sites/25]
2015-04-10 10:40:20,799 [http-8443-exec-12] DEBUG annotation.RequestResponseBodyMethodProcessor:135 - Reading [class something.resources.UpdatedSiteResource] as "application/json;charset=utf-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter#4de52e6]
2015-04-10 10:40:21,280 [http-8443-exec-12] DEBUG servlet.DispatcherServlet:1018 - Null ModelAndView returned to DispatcherServlet with name 'springRestAPI': assuming HandlerAdapter completed request handling
2015-04-10 10:40:21,281 [http-8443-exec-12] TRACE servlet.DispatcherServlet:1058 - Cleared thread-bound request context: SecurityContextHolderAwareRequestWrapper[ FirewalledRequest[ org.apache.catalina.connector.RequestFacade#321fa1b9]]
2015-04-10 10:40:21,281 [http-8443-exec-12] DEBUG servlet.DispatcherServlet:996 - Successfully completed request
But when the response is 400, there is nothing in the log: it does not even reaches the DispatcherServlet!
Any idea, how to proceed with this?

Savon 2.1.0 basic auth not functioning

I am trying to access a SOAP service which has the following charateristics:
1. WSDL is available without authentication
2. The service is accessible over https with basic_auth
3. According to the SOAP service, the "Authorization" header needs to be included in every request
Here is my code for construction the soap client:
#wsdl="https://example.com/table.do&WSDL"
#proxy="http://internal.proxy.com:8080"
#basic_auth=["user","pass"]
#headers={"Authorization" => "Basic"}
client = Savon.client do |globals|
globals.wsdl #wsdl
globals.proxy #proxy
globals.basic_auth #basic_auth
globals.headers #headers
end
Here is the client.globals.inspect:
#<Savon::GlobalOptions:0x0000000382c7a8 #options={:encoding=>"UTF-8",
:soap_version=>1, :namespaces=>{}, :logger=>#<Logger:0x0000000382c730 #progname=nil,
#level=0, #default_formatter=#<Logger::Formatter:0x0000000382c708
#datetime_format=nil>,
#formatter=nil, #logdev=#<Logger::LogDevice:0x0000000382c6b8 #shift_size=nil,
#shift_age=nil, #filename=nil, #dev=#<IO:<STDOUT>>,
#mutex=#<Logger::LogDevice::LogDeviceMutex:0x0000000382c690 #mon_owner=nil,
#mon_count=0, #mon_mutex=#<Mutex:0x0000000382c640>>>>, :log=>true, :filters=>[],
:pretty_print_xml=>false, :raise_errors=>true, :strip_namespaces=>true,
:convert_response_tags_to=>#<Proc:0x0000000382c5c8#/usr/local/rvm/gems/ruby-2.0.0-p0/gems/savon-2.1.0/lib/savon/options.rb:48 (lambda)>,
:wsdl=>"https://example.com/table.do&WSDL",
:proxy=>"http://internal.proxy.com:8080",
:basic_auth=>["user", "pass"],
:headers=>{"Authorization"=>"Basic"}}>
when i call:
client.call(:get, message: { sys_id: "67d2f77ed9377840c53fc6da9c094635" })
The service is returning:
DEBUG -- : HTTPI GET request to xseaddev.service-now.com (net_http)
INFO -- : SOAP request: https://xseaddev.service-now.com/change_task_list.do?displayvalue=all&SOAP
INFO -- : SOAPAction: "http://www.service-now.com/change_task/get", Content-Type: text/xml;charset=UTF-8, Content-Length: 408
DEBUG -- : <?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://www.service-now.com" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="http://www.service-now.com/change_task"><env:Body><ins0:get><tns:sysId>67d2f77ed9377840c53fc6da9c094635</tns:sysId></ins0:get></env:Body></env:Envelope>
DEBUG -- : HTTPI POST request to xseaddev.service-now.com (net_http)
INFO -- : SOAP response (status 401)
Am i constructing the client incorrectly? I don't see any authentication headers being sent on either the GET or PoST requests.
Do i need to add/remove anything to get this working? Your help would be appreciated.
I imagine you should be able to do the following:
client = Savon.client(endpoint: ENDPOINT, namespace: NAMESPACE, basic_auth: ["user", "password"])
(Or the same in block form).
Check this page under the "Authentication" heading: http://savonrb.com/version2/globals.html
(I am doing the same, but with a WSDL).

Resources