Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JT400 Inquiry test #5954

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion integration-tests/jt400/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ Message queue can be created by following the command
CRTMSGQ LIBRARY/TESTMSGQ
```


Second queue is required for testing of inquiry messages:

```
CRTMSGQ LIBRARY/REPLYMSGQ
```

==== Data queue testing

Two data-queues are required for the testing. One created as `keyed=true` and one as `LIFO`.
Expand All @@ -90,6 +97,7 @@ export JT400_LIBRARY=#library_if_not_LIBRARY
export JT400_LIFO_QUEUE=#lifoqueue_if_not_TESTLIFO.DTAQ
export JT400_KEYED_QUEUE=#lkeyedqueue_if_not_TESTKEYED.DTAQ
export JT400_MESSAGE_QUEUE=#messagequeue_if_not_TESTMSGQ.MSGQ
export JT400_MESSAGE_REPLYTO_QUEUE=#messagequeueinquiry_if_not_REPLYMSGQ.MSGQ
export JT400_USER_SPACE=#userspace_if_not_PROGCALL
```

Expand All @@ -99,6 +107,7 @@ or for Windows:
$Env:JT400_LIBRARY = "#library_if_not_LIBRARY"
$Env:JT400_LIFO_QUEUE="#lifoqueue_if_not_TESTLIFO.DTAQe"
$Env:JT400_KEYED_QUEUE="#lkeyedqueue_if_not_TESTKEYED.DTAQ"
$Env:JT400_MESSAGE_QUEUE="#messagequeue_if_not_TESTMSGQ.MSGQe"
$Env:JT400_MESSAGE_QUEUE="#messagequeue_if_not_TESTMSGQ.MSGQ"
$Env:JT400_MESSAGE_REPLYTO_QUEUE="#messagequeueinquiry_if_not_REPLYMSGQ.MSGQ"
$Env:JT400_USER_SPACE="#userspace_if_not_PROGCALL"
```
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.Map;
import java.util.Optional;

import com.ibm.as400.access.AS400;
import com.ibm.as400.access.MessageQueue;
import com.ibm.as400.access.QueuedMessage;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
Expand All @@ -31,6 +33,7 @@
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.apache.camel.CamelContext;
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.Exchange;
import org.apache.camel.ProducerTemplate;
Expand All @@ -45,7 +48,7 @@ public class Jt400Resource {
String jt400Url;

@ConfigProperty(name = "cq.jt400.username")
String jt400USername;
String jt400Username;

@ConfigProperty(name = "cq.jt400.password")
String jt400Password;
Expand All @@ -62,6 +65,9 @@ public class Jt400Resource {
@ConfigProperty(name = "cq.jt400.message-queue")
String jt400MessageQueue;

@ConfigProperty(name = "cq.jt400.message-replyto-queue")
String jt400MessageReplyToQueue;

@ConfigProperty(name = "cq.jt400.user-space")
String jt400UserSpace;

Expand All @@ -71,6 +77,9 @@ public class Jt400Resource {
@Inject
ConsumerTemplate consumerTemplate;

@Inject
CamelContext context;

@Path("/dataQueue/read/")
@POST
@Produces(MediaType.APPLICATION_JSON)
Expand Down Expand Up @@ -123,6 +132,36 @@ public Response keyedDataQueueWrite(@QueryParam("key") String key,
return Response.ok().entity(ex).build();
}

@Path("/client/inquiryMessage/write/")
@POST
@Produces(MediaType.TEXT_PLAIN)
public Response clientInquiryMessageWrite(String data) throws Exception {
Jt400Endpoint jt400Endpoint = context.getEndpoint(getUrlForLibrary(jt400MessageReplyToQueue), Jt400Endpoint.class);
AS400 as400 = jt400Endpoint.getConfiguration().getConnection();
//send inquiry message (with the same client as is used in the component, to avoid `CPF2451 Message queue TESTMSGQ is allocated to another job`.
MessageQueue queue = new MessageQueue(as400, jt400Endpoint.getConfiguration().getObjectPath());
try {
queue.sendInquiry(data, "/QSYS.LIB/" + jt400Library + ".LIB/" + jt400MessageReplyToQueue);
} catch (Exception e) {
return Response.status(500).entity(e.getMessage()).build();
}
return Response.ok().build();
}

@Path("/client/queuedMessage/read")
@POST
@Produces(MediaType.TEXT_PLAIN)
public Response clientQueuedMessageRead(String queueName) throws Exception {

Jt400Endpoint jt400Endpoint = context.getEndpoint(getUrlForLibrary(queueName), Jt400Endpoint.class);
AS400 as400 = jt400Endpoint.getConfiguration().getConnection();
//send inquiry message (with the same client as is used in the component, to avoid `CPF2451 Message queue TESTMSGQ is allocated to another job`.
MessageQueue queue = new MessageQueue(as400, jt400Endpoint.getConfiguration().getObjectPath());
QueuedMessage message = queue.receive(null);

return Response.ok().entity(message != null ? message.getText() : "").build();
}

@Path("/messageQueue/write/")
@POST
@Produces(MediaType.TEXT_PLAIN)
Expand All @@ -135,8 +174,9 @@ public Response messageQueueWrite(String data) {
@Path("/messageQueue/read/")
@POST
@Produces(MediaType.APPLICATION_JSON)
public Response messageQueueRead() {
Exchange ex = consumerTemplate.receive(getUrlForLibrary(jt400MessageQueue));
public Response messageQueueRead(@QueryParam("queue") String queue) {
Exchange ex = consumerTemplate
.receive(getUrlForLibrary(queue == null ? jt400MessageQueue : queue));

return generateResponse(ex.getIn().getBody(String.class), ex);
}
Expand Down Expand Up @@ -164,12 +204,12 @@ public Response programCall() throws Exception {
}

private String getUrlForLibrary(String suffix) {
return String.format("jt400://%s:%s@%s%s", jt400USername, jt400Password, jt400Url,
return String.format("jt400://%s:%s@%s%s", jt400Username, jt400Password, jt400Url,
"/QSYS.LIB/" + jt400Library + ".LIB/" + suffix);
}

private String getUrl(String suffix) {
return String.format("jt400://%s:%s@%s%s", jt400USername, jt400Password, jt400Url, suffix);
return String.format("jt400://%s:%s@%s%s", jt400Username, jt400Password, jt400Url, suffix);
}

Response generateResponse(String result, Exchange ex) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.component.jt400.it;

import com.ibm.as400.access.AS400Message;
import jakarta.enterprise.context.ApplicationScoped;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jt400.Jt400Constants;
import org.eclipse.microprofile.config.inject.ConfigProperty;

@ApplicationScoped
public class Jt400Routes extends RouteBuilder {

@ConfigProperty(name = "cq.jt400.library")
String jt400Library;

@ConfigProperty(name = "cq.jt400.url")
String jt400Url;

@ConfigProperty(name = "cq.jt400.username")
String jt400Username;

@ConfigProperty(name = "cq.jt400.password")
String jt400Password;

@ConfigProperty(name = "cq.jt400.message-replyto-queue")
String jt400MessageReplyToQueue;

@Override
public void configure() throws Exception {
from(getUrlForLibrary(jt400MessageReplyToQueue + "?sendingReply=true"))
.choice()
.when(header(Jt400Constants.MESSAGE_TYPE).isEqualTo(AS400Message.INQUIRY))
.process((exchange) -> {
String reply = "reply to: " + exchange.getIn().getBody(String.class);
exchange.getIn().setBody(reply);
})
.to(getUrlForLibrary(jt400MessageReplyToQueue));
}

private String getUrlForLibrary(String suffix) {
return String.format("jt400://%s:%s@%s%s", jt400Username, jt400Password, jt400Url,
"/QSYS.LIB/" + jt400Library + ".LIB/" + suffix);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ cq.jt400.password=${JT400_PASSWORD:password}
cq.jt400.library=${JT400_LIBRARY:LIBRARY}
cq.jt400.user-space=${JT400_USER_SPACE:PROGCALL}
cq.jt400.message-queue=${JT400_MESSAGE_QUEUE:TESTMSGQ.MSGQ}
cq.jt400.message-replyto-queue=${JT400_MESSAGE_REPLYTO_QUEUE:REPLYMSGQ.MSGQ}
cq.jt400.keyed-queue=${JT400_KEYED_QUEUE:TESTKEYED.DTAQ}
cq.jt400.lifo-queue=${JT400_LIFO_QUEUE:TESTLIFO.DTAQ}
Loading
Loading