How can i change the HTTP response - java

I'm working on a Java project that i have to create a new specific protocol based on HTTP 1.1, but without the GET and POST methods (with some specifics methods).
The problem that I face is how to change the HTTP header response especially the status line : HTTP 1.1 and change it with the name of my protocol WHATEVER 1.0
And for the rest of methods, Should I just modify the HTTP Api or This could cause some problems ?

Related

JMeter | Request with Patch Method giving error-"Invalid HTTP method: PATCH"

I am getting the below error when I am trying to hit a request having Method: PATCH
Using JMeter Version:-apache-jmeter-5.4.1
"java.net.ProtocolException: Invalid HTTP method: PATCH at
java.base/java.net.HttpURLConnection.setRequestMethod(HttpURLConnection.java:487)
at
java.base/sun.net.www.protocol.http.HttpURLConnection.setRequestMethod(HttpURLConnection.java:596)"
It will be helpful if I get expert assistance to resolve their issue.
Thanks
You need to change "Client Implementation" to HttpClient4 either at "Advanced" tab of the HTTP Request sampler or in the HTTP Request Defaults - this way the change will be applied to all HTTP Request samplers in the HTTP Request Defaults scope
There are diffrent HTTPSampler implementations the Java one uses HttpURLConnection here. As you can see in this bug ticket it does not support PATCH
In user.properties
HTTPSampler.implementation: HttpClient4
or in jmx using
<stringProp name="HTTPSampler.implementation">HttpClient4</stringProp>

CXF SOAP can't parse request on client side in case of 401 HTTP response code

Colleagues,
I have SOAP web-service based on CXF implementation with enabled SSL & WSS configuration (cofigured using WSP).
I have test tool for testing this service also written using CXF.
Positive cases are working. Trying to test negative cases with security errors (wrong certificate / signature).
I have requirement from customer that in case of security errors return fault:401 and HTTP response code 401.
Problem:
When I return HTTP code 401 from web-service on receiver side (in test tool) I receive Marshaling errors because of incoming internal InputStream is empty (without content). When I return any other HTTP code (200/403/419/500/503) - there isn't any problem on receiver side! And I'm able to see SOAP fault with message generated in web-service side.
Questions:
Maybe there are some specific handling 401 HTTP code in CXF ?
Maybe there are some specific requirements in SOAP in general ?
If returning 401 HTTP code in SOAP it's bad practice could you please provide documents/source code to prove this behavior and help me change customer requirements. I tried to look throw the code and haven't find place where this case handles
P.S: Tried to capture traffic using WireShark and RawCap and tried to decode it without success.
I think answer in this question will help you
question
The question also includes a reference to the soap specification for your customers about fault response codes.
Be careful because there are some major differences between SOAP 1.1 and SOAP 1.2 in the allowed HTTP status codes when a SOAP fault is returned.
in SOAP 1.1, the status code must always be 500 “Internal Server Error”.
in SOAP 1.2, it varies based on the type of the SOAP fault

HTTP Status 405 - Request method 'POST' not supported in jmeter

I have recorded a script and running it. But I'm receiving the following error.
HTTP Status 405 - Request method 'POST' not supported in jmeter
I'm not sure whether it is script issue or coding issue.
Our application is installed on HTTPS but security certificate not yet installed.
Could any one please help me out.
It could be one of below
The endpoint you are requesting is not supported for POST, It may support only GET, Please change the method in Jmeter to GET or the method your url supports
The endpoint may expect proper CSRF token. It might mismatch with one you recorded. So Please extract CSRF token from previous request's response and use it. You can do via RegEx Extractor in Jmeter.
JMeter does support POST method so it may be due to:
Endpoint you're using doesn't support POST method (it expects other method(s) like GET, PUT, DELETE, etc.)
You're sending not properly configured request.
The most common reason is missing relevant Content-Type header. You can use HTTP Header Manager in order to send the relevant Content-Type header which is usually application/json for REST or text/xml or similar for SOAP.
See Testing SOAP/REST Web Services Using JMeter article for more information on API testing using JMeter.
You can also consider the following approach:
Use specialized Web Services testing tool like SoapUI or RESTClient to fire a request
Either use aforementioned tool or 3rd-party sniffer like Wireshark to capture the request
Configure JMeter to send exactly the same request

How do I use Apache Http Components to relay a POST request from a servlet?

I'm a little unfamiliar both with the Servlet API and Apache Http Components.
I need to handle an incoming POST request with unknown data (although probably the result of a form submission) using HttpServlet.doPost() which I've implemented, and request the same posted information from another URL, effectively acting as a relay for the HTTP POST. I then need to convert the response to a String (it will be text/html) and process it further before returning it to the web browser that requested it from me.
Due to my unfamiliarity with these libraries, its not clear to me how to handle issues like the content-type of the posted data, and also avoiding any problems due to neglecting to release resources.
Can anyone provide any pointers on this?
You should start by having a look at HttpClient class from apache API.
It will handle both get and posts as needed and later you could feel its request with the data you receive in your own servlet.

Can a .NET 2.0 Web Service handle a call from a client when the SoapAction is missing?

We have a .NET 2.0 web service (.ASMX file). This web service is being called by a Java client and they are not passing in a SoapAction header.
This causes our web service to fail with the error: : "Server did not recognize the value of HTTP Header SOAPAction: ."
There is no chance that I can convince the development team in charge of the calling Java client to include a SoapAction header.
Is there anyway to resolve this problem on my end?
Can I prevent .NET from throwing this error when the SoapAction is missing? Can I direct the call to the correct WebMethod programmatically?
Something like this psuedo-code,
if (Header.SoapAction == String.Empty) then MyWebMethod();
According to the SOAP 1.1 specification this is required of HTTP clients.
6.1 SOAP HTTP Request
Although SOAP might be used in
combination with a variety of HTTP
request methods, this binding only
defines SOAP within HTTP POST requests
(see section 7 for how to use SOAP for
RPC and section 6.3 for how to use the
HTTP Extension Framework).
6.1.1 The SOAPAction HTTP Header Field
The SOAPAction HTTP request header
field can be used to indicate the
intent of the SOAP HTTP request. The
value is a URI identifying the intent.
SOAP places no restrictions on the
format or specificity of the URI or
that it is resolvable. An HTTP client
MUST use this header field when
issuing a SOAP HTTP Request.
Source http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528
From a quick Google it seems this is a common issue with Java and Axis, but there is some debate whether it is required. Could this help you convince the Java developers that they need to implement the header?
Edit:
The correct URI for your SoapAction http header is defined in the WSDL document.
Goto http://mydomain.com/myservice.asmx?wsdl
Look for the wsdl:operation element for the method you are calling, it should have a child element soap:operation which has a attribute called soapaction, the URI in there is the one you should use. In a webservice i tested it looks like the namespace followed by / and the method name as follows.
<wsdl:operation name="AddTwoNumbers">
<soap:operation soapAction="http://mydomain.com/myservice/AddTwoNumbers" style="document"/>

Categories