No endpoint java exception - java

I get the exception : No endpoint.
This is the code:
InsuredDetailsLocator locator_MDP =new InsuredDetailsLocator();
locator_MDP.setInsuredDetailsSoapEndpointAddress("http://mgnt184:8056/MDP_InsuredDetails_WS/InsuredDetails.asmx");
InsuredDetailsSoapStub service = new InsuredDetailsSoapStub();
UpdateInsuredDetails_Input request_MDP =new UpdateInsuredDetails_Input();
request_MDP.setSystemName(urlProps.getProperty(MDP_USERNAME));
request_MDP.setSystemPassword(urlProps.getProperty(MDP_PASSWORD));
request_MDP.setID(11111);
request_MDP.setFAMILY_NAME("hhhh");
request_MDP.setFIRST_NAME("dddd");![enter image description here][1]
request_MDP.setKOD_DIVUR_SHIVUKI_ELC(insuree.getKodDivurShivukiElc());
//I get here the exception :No endpoint
//calling the method:
UpdateInsuredDetails_Output response_MDP= service.recieveMDMDataInsuredDetails(request_MDP);
When the compiler is going to the method: recieveMDMDataInsuredDetails , inside InsuredDetailsSoapStub class - I got the error from there, this is the code inside the method:
public il.co.migdal.ws.tempuri.UpdateInsuredDetails_Output recieveMDMDataInsuredDetails(il.co.migdal.ws.tempuri.UpdateInsuredDetails_Input l_input) throws java.rmi.RemoteException {
if (super.cachedEndpoint == null) {
throw new org.apache.axis.NoEndPointException();
}
.....

You are setting the endpoint on the locator_MDP object but making a call on the service object, which has no relation with locator_MDP (at least in the code posted)

Related

Java unit test - exception not being thrown

Trying to write a test that will call my method, when that method makes a call to another method we will throw a custom exception i have made. Here i have simplified it all
2 functions
public MyJsonResponse hello() {
MyJsonResponse response = new MyJsonResponse();
response.setErrorMessage("1");
response.setStatus("some status");
response.setData("1");
response.setHttpResponse(200);
try{
hi();
return response;
}catch (MyServiceException e) {
response.setErrorMessage(e.getMessage());
response.setStatus("error creating");
response.setData("2");
response.setHttpResponse(e.getResponseStatus());
return response;
}
}
public String hi() throws MyServiceException{
LOG.error("Exception");
return "yea";
}
The test I have written is this
#Test
public void myTest() throws Exception {
given(service.hi()).willAnswer( invocation -> { throw new MyServiceException("abc msg",511); });
MyJsonResponse actual = service.hello();
Assert.assertNotNull(actual);
assertEquals(511, actual.getHttpResponse());
}
But unfortunately the result is as follows
java.lang.AssertionError:
Expected :511
Actual :200
Please, be sure that you are using a spy as you want to use the actual code for some methods of your mocked service and just stubbing specific methods of it. Please, see for instance this related SO question about the subject.
Also, consider modifying your test definition to use willThrow instead of willAnswer: as pointed out by #eis, you can still use the later, but the former is more straightforward.
Your code will look similar to this:
#Test
public void myTest() throws Exception {
MyService service = spy(MyService.class);
willThrow(new MyServiceException("abc msg",511))
.given(service)
.hi()
;
// As pointed out by #eis, you can still use willAnswer
// willAnswer(
// invocation -> { throw new MyServiceException("abc msg",511);}
// )
// .given(service)
// .hi()
// ;
MyJsonResponse actual = service.hello();
Assert.assertNotNull(actual);
assertEquals(511, actual.getHttpResponse());
}
regarding what you explain and what your code look like, I am not sure if I have well understood.
Thus, if you want that, your hi() : function throws an exception.
You have to make it first throws an exception. Take a look at code below!
public String hi() throws MyServiceException{
/*LOG.error("Exception");//No don't just log, throw a real exception as below*/
throw new MyServiceException("text here, if your constructor support it or nothing otherwise")
/*return "yea";//Nothing to return? we have just break the code by throwing the exception above*/
}
After that, please be very sure that your 'MyServiceException.getHttpResponse()' will really return 511
For this test to make sense, your hi() call should be done calling another service that you stub/mock in your test class. You're not doing that, so this approach won't work.
You wrote "the real method that hi represents does a lot", so it's about time you extract that to another service.

IllegalFlowLogicException: A FlowLogicRef cannot be constructed for FlowLogic

In my Corda I am trying to call a flow using RPC but I am getting this error while making the call to initiate the flow:
net.corda.core.flows.IllegalFlowLogicException: A FlowLogicRef cannot
be constructed for FlowLogic of type
com.example.flow.PolicyFlow$Initiator: due to missing constructor for
arguments: [class com.example.state.PolicyState]
My Flow is shown in the snippet below:
public SignedTransaction call() throws FlowException {
class SignTxFlow extends SignTransactionFlow {
private SignTxFlow(FlowSession otherPartyFlow, ProgressTracker progressTracker) {
super(otherPartyFlow, progressTracker);
}
#Override
protected void checkTransaction(SignedTransaction stx) {
requireThat(require -> {
ContractState output = stx.getTx().getOutputs().get(0).getData();
require.using("This must be an Policy transaction.", output instanceof PolicyState);
PolicyState policy = (PolicyState) output;
require.using("I won't accept Policy without a first Name.", (!(policy.getFirstName().equals(""))));
return null;
});
}
}
return subFlow(new SignTxFlow(otherPartyFlow, SignTransactionFlow.Companion.tracker()));
}
The Function for RPC Connection and initiating the flow is given below:
Can someone help me with this?
Please check the constructor of PolicyFlow$Initiator Class there is a mismatch in constructor: you are sending policy but the constructor expects something else as I can see in code you provided in comments. there is no constructor in that class that accepts a policy state. You've a constructor with 10 fields.

Getting NullpointerException in Mockito

I have actual method below:
public ResponseEntity<Message> catEnter(#PathVariable("catId") BigInteger catId, #RequestBody Catrequest catReq, HttpServletRequest request) throws CatDataException, InvalidCatExcecatption {
Message message = new Message();
try {
message = catManager.submitData(catReq.getMessage(), catId, request);
} catch (IOException e) {
throw new CatDataAppException(e.getMessage());
}
return (ResponseEntity<Message>) restResponse(message, request.getMethod());
// Getting null pointer exception in above line
}
I am using mockito for my test code as below:
#Test
public void submitData() throws Exception {
Message mes = new Message();
mes.setCode("00");
mes.setMessage("hi");
ResponseEntity<Message> responseentity = ((ResponseEntity<Message>) catController.catEnter(BigInteger.valueOf(3431), catRequest, mockRequest));
}
I'm getting null pointer exception, Message going as a null, even I set the value explicitly?
Here:
You pass mockRequest when making that call to your production code:
ResponseEntity<Message> responseentity = ... catController.catEnter(... mockRequest));
And your production call does:
return (ResponseEntity<Message>) restResponse(message, request.getMethod());
So the only conclussion: mockRequest is null!
So, first make sure that the passed variable is not null; like:
Request mockedRequest = mock(Request.class);
Or, use the #Mock annotation in case that mockedRequest is a field in your test class.
On top of that; you probably want to do some mock-specification, like:
when(mockedRequest.getMethod()).thenReturn( whatever )
But beyond that, you are lacking a lot of the fundamental basics of Java:
naming conventions: variable names go camelCase, like entityResponse. And typically, tests are named like testCatEnter to express the method that is tested.
You have casts ... where they are not required.
You have quite some code there ... that is unused, like the mes declaration in your test method.
Long story short: I have the feeling that you are overburdening yourself dramatically. First learn the basics; then go for the advanced Mockito stuff.

AWS SWF - How can I pass an argument to a a workflow task?

I am just starting out with the AWS Flow Framework for Java. Essentially I am trying to extend the HelloWorld tutorial but have hit a wall.
I have defined a new method autoScale in the interface which accepts a String arguement as follows
public interface GreeterActivities {
public String getName();
public String getGreeting(String name);
public void say(String what);
public void autoScale(String groupName);
}
Implementation is fairly straight forward too.
Finally in the GreeterWorkflowImpl class, I am calling the new Task as follows
public void greet() {
Promise<String> name = operations.getName();
Promise<String> greeting = operations.getGreeting(name);
operations.say(greeting);
operations.autoScale("WebServerScalingGroup");
}
But I get errors such as AWS Error Code: ValidationError, AWS Error Message: 1 validation error detected: Value null at 'autoScalingGroupName' failed to satisfy constraint: Member must not be null
Any ideas on what I am doing wrong? Thanks!
The error appears coming from the Auto Scaling API. It probably means that activity was successfully invoked, but an exception was thrown from its implementation. How does your activity implementation looks like? Have you tried logging the fact of activity invocation and its parameters?

How can I throw exception from webservice?

I am using netbeans to make webservices, I want to make composite webservice using PBEL,
I face a problem in throwing exception in each service, I define complex Type in the schema of the exception I want to throw, and I make it in WSDL too , but inside the service I don't know how can I throw the exception , Here's the example I am working on :
#WebService(serviceName = "CreditCardService", portName = "CreditCardPort", endpointInterface = "org.netbeans.j2ee.wsdl.creditcard.CreditCardPortType", targetNamespace = "http://j2ee.netbeans.org/wsdl/CreditCard", wsdlLocation = "WEB-INF/wsdl/NewWebServiceFromWSDL/CreditCard.wsdl")
public class NewWebServiceFromWSDL implements CreditCardPortType {
public org.netbeans.xml.schema.creditcard.CreditCardResponseType isCreditCardValid(org.netbeans.xml.schema.creditcard.CreditCardType creditCardInfoReq) throws IsCreditCardValidFault {
List<CreditCardType> creditCards = parseCreditCardsFile();
CreditCardResponseType creditCardResponseElement = new CreditCardResponseType();
for (CreditCardType aCreditCard : creditCards) {
if (creditCardInfoReq.getCreditCardNo() == Long.parseLong(String.valueOf(aCreditCard.getCreditCardNo())) {
creditCardResponseElement.setValid(true);
return creditCardResponseElement;
}
}
throws IsCreditCardValidFault(); //here I want to throw an exception .
}
Please can Someone help?
throws IsCreditCardValidFault(); //here I want to throw an exception .
needs to be written as
throw new IsCreditCardValidFault();
throws is used in your declaration of the method, where the throw keyword is used inside the method to indicate where you will throw the exception.
so as an example
try {
//do something which generates an exception
}catch(Exception e){
throw e;
}
but in your case, you want to initiate the exception yourself so you have to create a new object of that exception type. You will create the exception yourself, so no need to enclose in a try/catch block.
throw new IsCreditCardValidFault();

Categories