I wrote below method to call soap client which connects to web service. below code work fine in test class but after deploy my war into bea weblogic9 i got HTTP/1.1 500 error. and i am can not what is wrong in my code as it works fine locally.`
public boolean isServiceReady(String msisdn) throws Exception
{
logger.info("check if the service ready or not for " + msisdn);
if("".equals(msisdn))
{
throw new IllegalArgumentException("no active msisdn for logged user");
}
ServiceReadyClient nfcClient = ServiceReadyClient.getInstance(true);
ServiceReadyServices services = nfcClient.getServices();
if(services == null)
{
throw new ServiceReadyClientException("NFC Client not ready yet");
}
IsServiceReadyResponse result = services.isServiceReady("tel:" + msisdn, CSS_CLIENT);
return (result != null && result.getReadinessStatus() != null) ?
"YES".equals(result.getReadinessStatus().getValue()) : false;
}
ServiceReadyServices and ServiceReadyClient are from your custom API's?
Try passing Web service URL to above API classes.
Related
I have a Spring Boot RESTful API to receive and send SMS to clients. My application connects to our local SMS server and receives and pushes SMS to clients via mobile operators. My application works well. But I wanted to optimize my application by implementing cache. I am using the Simple cache of Spring Boot. I face some challenges when creating new SMS.
All SMSes sent/received are in the form of conversations (per ticket) and have clients attached to it. So I faced difficult saving a client into the cache. Below is createClient() snippet:
#Transactional
#Caching(evict = {
#CacheEvict("allClientsPage"),
#CacheEvict("countClients")
}, put = {
#CachePut(value = "clients", key = "#result.id", unless="#result != null"),
#CachePut(value = "clientsByPhone", key = "#result.phoneNumber", unless="#result != null")
})
public Client create(Client client) {
Client c = new Client();
if (client.getName() != null) c.setName(client.getName().trim());
c.setPhoneNumber(client.getPhoneNumber().trim());
/**---***/
c.setCreatedAt(new Date());
return clientRepository.save(c);
}
When I tried creating a new client, a
org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'id' cannot be found on null
is thrown.
Any assistance shall be greatly appreciated.
instead of using unless="# result! = null" use condition="#result != null"
I have a Spring Boot Java REST application with many APIs exposed to our clients and UI. I was tasked with implementing a Transaction logging framework that will capture the incoming transactions along with the response we send.
I have this working with Spring AOP and an Around inspect and I'm currently utilizing the HttpServletRequest and HttpServletResponse objects to obtain a lot of the data I need.
From my local system I am not having any issues capturing the server used since I'm connecting to my system directly. However, once I deployed my code I saw that the load balancer URL was being captured instead of the actual server name.
I am also using Eureka to discover the API by name as it's only a single application running on HAProxy.
Imagine this flow:
/*
UI -> https://my-lb-url/service-sidecar/createUser
HAProxy directs traffic to -> my-lb-url/service-sidecar/ to one of below:
my-server-1:12345
my-server-2:12345
my-server-3:12345
Goal : http://my-server-1:1235/createUser
Actual: https://my-lb-url/createUser
Here is the code I am using to get the incoming URL.
String url = httpRequest.getRequestURL().toString();
if(httpRequest.getQueryString() != null){
transaction.setApi(url + "?" + httpRequest.getQueryString());
} else {
transaction.setApi(url);
}
Note:
I am not as familiar with HAProxy/Eurkea/etc. as I would like to be. If something stated above seems off or wrong then I apologize. Our system admin configured those and locked the developers out.
UPDATE
This is the new code I am using to construct the Request URL, but I am still seeing the output the same.
// Utility Class
public static String constructRequestURL(HttpServletRequest httpRequest) {
StringBuilder url = new StringBuilder(httpRequest.getScheme());
url.append("://").append(httpRequest.getServerName());
int port = httpRequest.getServerPort();
if(port != 80 && port != 443) {
url.append(":").append(port);
}
url.append(httpRequest.getContextPath()).append(httpRequest.getServletPath());
if(httpRequest.getPathInfo() != null) {
url.append(httpRequest.getPathInfo());
}
if(httpRequest.getQueryString() != null) {
url.append("?").append(httpRequest.getQueryString());
}
return url.toString();
}
// Service Class
transaction.setApi(CommonUtil.constructRequestURL(httpRequest));
I found a solution to this issue, but it's not the cleanest route and I would gladly take another suggestion if possible.
I am autowiring the port number from my application.yml.
I am running the "hostname" command on the Linux server that is hosting the application to determine the server fulfilling the request.
Now the URL stored in the Transaction Logs is accurate.
--
#Autowired
private int serverPort;
/*
* ...
*/
private String constructRequestURL(HttpServletRequest httpRequest) {
StringBuilder url = new StringBuilder(httpRequest.getScheme())
.append("://").append(findHostnameFromServer()).append(":").append(serverPort)
.append(httpRequest.getContextPath()).append(httpRequest.getServletPath());
if(httpRequest.getPathInfo() != null) {
url.append(httpRequest.getPathInfo());
}
if(httpRequest.getQueryString() != null) {
url.append("?").append(httpRequest.getQueryString());
}
return url.toString();
}
private String findHostnameFromServer(){
String hostname = null;
LOGGER.info("Attempting to Find Hostname from Server...");
try {
Process process = Runtime.getRuntime().exec(new String[]{"hostname"});
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
hostname = reader.readLine();
}
} catch (IOException e) {
LOGGER.error(CommonUtil.ERROR, e);
}
LOGGER.info("Found Hostname: {}", hostname);
return hostname;
}
In the code below, can anyone tell me how the assertion consumer service is being derived, if I am not setting this value in my metadata.
What is happening now is that a user is entering a URL on the command line like:
http://test1:11100/blah/blah/login.jsp
The application redirects OK. But the saml request being generated has a completely different ACS, i.e...
AssertionConsumerServiceURL="http://test5:11101/blah/saml/SSO
This causes issues because the response has the wrong URL (should have the test1 one above).
It is not clear to me how the ip and port are derived, if I am not supplying this information in my code or configuration.
I basically want the request to have the IP/port that the user enters.
Thanks.
from: org.springframework.security.saml.websso.WebSSOProfileImpl.java
protected AssertionConsumerService getAssertionConsumerService(WebSSOProfileOptions options, IDPSSODescriptor idpSSODescriptor, SPSSODescriptor spDescriptor) throws MetadataProviderException {
List<AssertionConsumerService> services = spDescriptor.getAssertionConsumerServices();
// Use user preference
if (options.getAssertionConsumerIndex() != null) {
for (AssertionConsumerService service : services) {
if (options.getAssertionConsumerIndex().equals(service.getIndex())) {
if (!isEndpointSupported(service)) {
throw new MetadataProviderException("Endpoint designated by the value in the WebSSOProfileOptions is not supported by this profile");
} else {
log.debug("Using consumer service determined by user preference with binding {}", service.getBinding());
return service;
}
}
}
throw new MetadataProviderException("AssertionConsumerIndex " + options.getAssertionConsumerIndex() + " not found for spDescriptor " + spDescriptor);
}
// Use default
if (spDescriptor.getDefaultAssertionConsumerService() != null && isEndpointSupported(spDescriptor.getDefaultAssertionConsumerService())) {
AssertionConsumerService service = spDescriptor.getDefaultAssertionConsumerService();
log.debug("Using default consumer service with binding {}", service.getBinding());
return service;
}
// Iterate and find first match
if (services.size() > 0) {
for (AssertionConsumerService service : services) {
if (isEndpointSupported(service)) {
log.debug("Using first available consumer service with binding {}", service.getBinding());
return service;
}
}
}
throw new MetadataProviderException("Service provider has no assertion consumer service available for the selected profile " + spDescriptor);
}
By using HtmlUnit browser, I am getting the HTTP standard response code. Based on response code, we are deciding whether the server is running or not to control another thread.
Problem what we are facing here is, if we stop the Server, still we get 200 (running) response code.
Index file of the site is a plain HTML file, so we tried by clearing Cookie and Cache. But still we are getting the response code as 200 even after we switched off the server. Please guide to find a way to track when the running server become off/not responding (HttpHostConnectException)
HtmlUnit code:
while(alive)
{
try
{
c.clear();
cm.clearCookies();
SST = client.getPage("http://**ip**/DDT/").getWebResponse().getStatusCode();
}
catch(HttpHostConnectException he)
{
isServerUP = false;
}
catch(FailingHttpStatusCodeException fhe)
{
isServerUP = false;
}
System.out.println(SST);
if(SST == 200)
{
isServerUP = true;
}
else
{
isServerUP = false;
}
}
I am unable to reproduce, possibly WebClient is differently configured.
With latest version, the below successfully handles stopping/starting the server:
try (WebClient webClient = new WebClient()) {
while (true) {
try {
int status = webClient.getPage("http://localhost/test.html").getWebResponse().getStatusCode();
System.out.println(new Date() + " " + status);
}
catch(Exception e) {
System.out.println(e.getMessage());
}
Thread.sleep(1000);
}
}
I want to connect to a web service in a SSL connection. I connect to it and I get Service and Port but when I send Requests, it just returns null.
I searched the web but I could not understand what is the problem. may be because it is SSL, I need to connect it different as an Http connection, is it true?
I used auto code generators, they return null too, WireShark says that SSL Packages transmitted correctly but I cannot read the SOAP from these packages because they are SSL.
I test the web service with some applications and the tools and got correct answers from them.
Question:
is it possible that the null value is because SSL connection?
what mistakes could make this null returning?
How can I see the SOAP messeges I send and I get?
Here is My Java Code:
public class WS_TheServeice
{
private static QName qname;
private static URL url;
private static Service service;
private static ImplementationServicePortType sender;
static
{
qname = new QName("http://wservice.com/", "ImplementationService");
try
{
url = new URL("https://to-service?wsdl");
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
service = Service.create(url, qname);
sender = service.getPort(ImplementationServicePortType.class);
}
public static boolean PayToAcceptor(int AcceptorID, int Kipa) throws Exception
{
getUserInfo req = new getUserInfo();
req.zpID = AcceptorID;
req.kipa = Kipa;
getUserInfoResponse user_info = new getUserInfoResponse();//user_info is not NULL here
user_info = sender.getUserInfo(req);//But web server makes it NULL
if (user_info!=null) //// ---- HERE, IT Always return NULL
{
System.out.println("YouWon");
return true;
}
else
{
System.out.println("YouLoose");
return false;
}
}
public static void main(String Args[]) throws Exception
{
PayToAcceptor(12345, 1);
}
}
thanks.
Did you figure out how to do this? I've had similar problems in the past..
Did you try this: SSL Connection for consuming web services ?