This is code I am using in Button Click Event on SSJS:
try{
var doc:NotesDocument = currentDocument.getDocument();
doc.send(false,"tuser1#gmail.com");
}
catch(e)
{
sessionScope.Err123=e
}
This is an error I am getting :
message Exception occurred calling method NotesDocument.send(boolean, string) null
Please help, I am not able to send a mail in ssjs on xpages.
Related
We are using spring integration DSL to call downstream services. But we are facing issues when 4XX series error code is returned by downstream service.
Below is the code snippet that we are using to call downstream services
#Bean
public IntegrationFlow getDataChannelFlow() {
return IntegrationFlows.from(MessageChannels.executor("getDataChannel", Executors.newCachedThreadPool()))
.enrichHeaders(h -> h.headerExpression(USER_REF, SRC_USER_REF)
.handle(Http.outboundGateway(endPoint1, auth2RestTemplate)
.uriVariable("data", PAYLOAD)
.httpMethod(HttpMethod.GET)
.transferCookies(true)
.expectedResponseType(String.class), e->e.advice(integrationAdvice).id("docIDAdvice"))
.transform(this::responseTransformer)
.enrichHeaders(header -> header.headerExpression("DOCUMENTS", PAYLOAD))
}
In case of 200 and 500 response from downstream services, our code is working fine but when we get 4XX series errors we are getting below exception in logs and control does not return back to transformer method
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8080/fetchUser": Attempted read from closed stream.; nested exception is java.io.IOException: Attempted read from closed stream.
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:785)
at org.springframework.security.oauth2.client.OAuth2RestTemplate.doExecute(OAuth2RestTemplate.java:138)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:732)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:612)
at org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler.exchange(HttpRequestExecutingMessageHandler.java:196)
... 42 more
Caused by: java.io.IOException: Attempted read from closed stream.
at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:141)
at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:118)
Few things that we noticed while debugging -
Spring's OAuth2ErrorHandler.java class differentiates between 4XX and 5XX series of errors
public boolean hasError(ClientHttpResponse response) throws IOException
{
return HttpStatus.Series.CLIENT_ERROR.equals(response.getStatusCode().series())
|| this.errorHandler.hasError(response);
}
In above code snippet hasError() method returns true for 4XX series of codes and due to this we are getting IOException when below code snippet is executed
protected <T> T doExecute(URI url, #Nullable HttpMethod method, #Nullable RequestCallback requestCallback,
#Nullable ResponseExtractor<T> responseExtractor) throws RestClientException {
Assert.notNull(url, "URI is required");
Assert.notNull(method, "HttpMethod is required");
ClientHttpResponse response = null;
try {
ClientHttpRequest request = createRequest(url, method);
if (requestCallback != null) {
requestCallback.doWithRequest(request);
}
response = request.execute();
handleResponse(url, method, response);
return (responseExtractor != null ? responseExtractor.extractData(response) : null);
}
catch (IOException ex) {
String resource = url.toString();
String query = url.getRawQuery();
resource = (query != null ? resource.substring(0, resource.indexOf('?')) : resource);
throw new ResourceAccessException("I/O error on " + method.name() +
" request for \"" + resource + "\": " + ex.getMessage(), ex);
}
finally {
if (response != null) {
response.close();
}
}
}
Our expectation is that control should return back to transformer method so that we will have the control over response processing.
Any suggestions on this issue would be much appreciated.
I'm trying to unit test using nunit framework and I am getting the exception below:
SignInManager = 'SignInManager' threw an exception of type 'System.NullReferenceException'
How can resolve this issue?
Below code throwing exception:
ApplicationUser User = await SignInManager.UserManager.FindByNameAsync (login.UserName);
if (User != null) {
}
How to get the real error message JSON when the Http.outboundGateway call is failed.
For example my program does the HTTP POST. The operation fails with the error code 400 Bad Request and the real error message is (tested with the Postman):
{
"name": [
"This field is needed."
]
}
I have the error channel like this:
#Bean
private IntegrationFlow myErrorChannel() {
return f -> f.handle("myErrorHandler", "handle")
....
;
}
and the Class MyErrorHandler is like this:
#Service
public class MyErrorHandler {
#ServiceActivator
public Message<MessageHandlingException> handle(Message<MessageHandlingException> message) {
...
}
}
Does the MessageHandlingException contain the real error message?
{
"name": [
"This field is needed."
]
}
I debugged the code and checked the MessageHandlingException exception and it seems it doesn't contain the real error message. The detailMessage contains the text 400 Bad Request, but I want to know the real error message.
How to get the real error message?
Edit:
This is working (I'm assigning the real error message to the new payload):
final RestClientResponseException clientException = (RestClientResponseException) messagingHandlingException.getCause();
payload = clientException.getResponseBodyAsString();
The Resttemplate uses a DefaultResponseErrorHandler by default. That one has a logic like:
protected void handleError(ClientHttpResponse response, HttpStatus statusCode) throws IOException {
String statusText = response.getStatusText();
HttpHeaders headers = response.getHeaders();
byte[] body = getResponseBody(response);
Charset charset = getCharset(response);
switch (statusCode.series()) {
case CLIENT_ERROR:
throw HttpClientErrorException.create(statusCode, statusText, headers, body, charset);
case SERVER_ERROR:
throw HttpServerErrorException.create(statusCode, statusText, headers, body, charset);
default:
throw new UnknownHttpStatusCodeException(statusCode.value(), statusText, headers, body, charset);
}
}
An exception from here is thrown to the HttpRequestExecutingMessageHandler which really wraps it into the MessageHandlingException.
Since you say that you can handle the last one via your MyErrorHandler, I would suggest you just take a look into the cause of the MessageHandlingException, and you'll that RestClientResponseException with all the required info from the response.
I've been thrashing for a bit and having difficulty figuring out how to pass server error messages to a client.
On the server I have (simplified):
export function get(req: express.ExpressServerRequest, res: express.ExpressServerResponse) {
res.statusCode = 500;
res.send('CUSTOM ERROR MESSAGE');
}
On the client:
public fetchObject(successF: Function, failF: Function): void {
this.myObj = new MyObj();
this.myObj.fetch({ success: successF, error: failF });
}
private failF(model, xhr, options): void {
// Want to get access to "CUSTOM ERROR MESSAGE"
}
The xhr object responseText is empty and the statusText is always "error".
Any suggestions? Thanks!
Found a solution. Define a class variable and capture the return from the fetch call:
private xhr: XMLHttpRequest = null;
Then:
public fetchObject(successF: Function, failF: Function): void {
this.myObj = new MyObj();
this.xhr = this.myObj.fetch({ success: successF, error: failF });
}
Finally:
private failF(model, xhr, options): void {
doSomething(this.xhr.responseText);
}
this.xhr will contain the reponseText (i.e. 'CUSTOM ERROR MESSAGE'). The local xhr will still be a blank string.
I'm still not sure why this is the case, and if anyone has some insight I'd appreciate it.
I get listitem data by using Lists.asmx in SharePoint 2010 (Form Authentication).
The code is like this.
private void GetItems(string listname)
{
ListsService.ListsSoapClient client = new ListsService.ListsSoapClient();
appset = new AppSettings();
client.CookieContainer = appset.CookieSetting;
client.GetListItemsAsync(listname, null, null, null, "10", null, null);
client.GetListItemsCompleted += new EventHandler<ListsService.GetListItemsCompletedEventArgs>(client_GetListItemsCompleted);
}
void client_GetListItemsCompleted(object sender, ListsService.GetListItemsCompletedEventArgs e)
{
listBox1.ItemsSource = from element in e.Result.Descendants(XName.Get("row", "#RowsetSchema"))
select new Lists
{
Title = (string)element.Attribute("ows_LinkTitle")
};
}
When the timeout of form authentication is occurred, unhandled CommunicationException is raised. The stack trace is here.
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest request, HttpWebResponse response, WebException responseException, HttpChannelFactory factory)
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.ProcessResponse(HttpWebResponse response, WebException responseException)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.OnGetResponse(IAsyncResult result)
at System.Net.Browser.ClientHttpWebRequest.<>c_DisplayClassa.b_8(Object state2)
at System.Threading.ThreadPool.WorkItem.doWork(Object o)
at System.Threading.Timer.ring()
I couldn't handle CommunicationException even if I use try~catch.
So, please let me know how to handle CommunicationException.
You should register for the GetListItemsCompleted event before calling GetListItemsAsync. Also, wrap GetListItemsAsync in a try-catch block.
Any error will be thrown as an exception from the call to GetListItemsAsync or will be reported as an error through GetListItemsCompletedEventArgs.