Commit 0d3bc987 authored by Andre Freyssinet's avatar Andre Freyssinet
Browse files

Prevent issues with JNDI names including '/' (JORAM-356).

Fix issues with CXF JORAM-367.
parent 8be07854
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2017 - 2019 ScalAgent Distributed Technologies
* Copyright (C) 2017 - 2020 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -25,9 +25,11 @@ package com.scalagent.joram.mom.dest.rest;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Constructor;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
......@@ -85,7 +87,14 @@ public class RESTAcquisition implements AcquisitionHandler {
destName = properties.getProperty(DestinationConstants.DESTINATION_NAME_PROP);
if (destName == null) {
throw new IllegalArgumentException("Missing Destination JNDI name.");
} else {
try {
destName = URLEncoder.encode(destName, "UTF-8");
} catch (UnsupportedEncodingException exc) {
// Should never happened
}
}
if (properties.containsKey(DestinationConstants.REST_HOST_PROP)) {
hostName = properties.getProperty(DestinationConstants.REST_HOST_PROP);
}
......@@ -163,7 +172,7 @@ public class RESTAcquisition implements AcquisitionHandler {
if (password != null)
wTarget = wTarget.queryParam("password", password);
response = wTarget.request().accept(MediaType.TEXT_PLAIN).post(Entity.entity(null, MediaType.APPLICATION_FORM_URLENCODED));
response = wTarget.request().accept(MediaType.TEXT_PLAIN).post(Entity.entity("", MediaType.APPLICATION_FORM_URLENCODED));
// if (logger.isLoggable(BasicLevel.DEBUG))
// logger.log(BasicLevel.DEBUG, "RESTAcquisition.createConsumer: response = " + response);
if (201 == response.getStatus()) {
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2017 - 2019 ScalAgent Distributed Technologies
* Copyright (C) 2017 - 2020 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -27,6 +27,7 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
......@@ -125,6 +126,12 @@ public class RESTDistribution implements DistributionHandler {
if (destName == null) {
logger.log(BasicLevel.ERROR,
"Missing Destination JNDI name, should fixed property " + DestinationConstants.DESTINATION_NAME_PROP);
} else {
try {
destName = URLEncoder.encode(destName, "UTF-8");
} catch (UnsupportedEncodingException exc) {
// Should never happened
}
}
}
......@@ -192,7 +199,7 @@ public class RESTDistribution implements DistributionHandler {
if (password != null) target = target.queryParam("password", password);
if (idleTimeout != null) target = target.queryParam("idle-timeout", idleTimeout);
response = target.request().accept(MediaType.TEXT_PLAIN).post(Entity.entity(null, MediaType.APPLICATION_FORM_URLENCODED));
response = target.request().accept(MediaType.TEXT_PLAIN).post(Entity.entity("", MediaType.APPLICATION_FORM_URLENCODED));
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
logger.log(BasicLevel.ERROR,
......
......@@ -242,6 +242,8 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
try {
// Get URI to create a consumer in ClientAcknowledge mode.
URI uriCreateConsumer = response.getLink("create-consumer-client-ack").getUri();
// TODO (AF): Be careful, unlike the other bridge components the RestAcquisitionAsync always use the
// old API with authentication fields in the URI.
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "RestAcquisitionAsync.createConsumer(): create-consumer = " + uriCreateConsumer);
......@@ -256,7 +258,7 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
if (password != null) target = target.queryParam("password", password);
// TODO (AF): to remove (use FormParam alternate URI)
// response = target.request().accept(MediaType.TEXT_PLAIN).post(Entity.entity(null, MediaType.APPLICATION_FORM_URLENCODED));
// response = target.request().accept(MediaType.TEXT_PLAIN).post(Entity.entity("", MediaType.APPLICATION_FORM_URLENCODED));
response = target.request().accept(MediaType.TEXT_PLAIN).post(null);
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment